mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 18:50:05 +00:00
Add right click to edit location marker
This commit is contained in:
parent
cfed61c6ff
commit
fc8d65d4d1
3 changed files with 65 additions and 6 deletions
|
|
@ -38,7 +38,7 @@ static constexpr std::size_t kIntegersPerVertex_ = 4;
|
|||
static constexpr std::size_t kIntegerBufferLength_ =
|
||||
kNumTriangles * kVerticesPerTriangle * kIntegersPerVertex_;
|
||||
|
||||
struct GeoIconDrawItem
|
||||
struct GeoIconDrawItem : types::EventHandler
|
||||
{
|
||||
units::length::nautical_miles<double> threshold_ {};
|
||||
std::chrono::sys_time<std::chrono::seconds> startTime_ {};
|
||||
|
|
@ -691,7 +691,7 @@ void GeoIcons::Impl::UpdateSingleBuffer(
|
|||
hoverIcons.end(),
|
||||
[&di](auto& entry) { return entry.di_ == di; });
|
||||
|
||||
if (di->visible_ && !di->hoverText_.empty())
|
||||
if (di->visible_ && (!di->hoverText_.empty() || di->event_ != nullptr))
|
||||
{
|
||||
const units::angle::radians<double> radians = angle;
|
||||
|
||||
|
|
@ -903,7 +903,7 @@ bool GeoIcons::RunMousePicking(
|
|||
const QPointF& mouseGlobalPos,
|
||||
const glm::vec2& mouseCoords,
|
||||
const common::Coordinate& /* mouseGeoCoords */,
|
||||
std::shared_ptr<types::EventHandler>& /* eventHandler */)
|
||||
std::shared_ptr<types::EventHandler>& eventHandler )
|
||||
{
|
||||
std::unique_lock lock {p->iconMutex_};
|
||||
|
||||
|
|
@ -993,12 +993,27 @@ bool GeoIcons::RunMousePicking(
|
|||
if (it != p->currentHoverIcons_.crend())
|
||||
{
|
||||
itemPicked = true;
|
||||
util::tooltip::Show(it->di_->hoverText_, mouseGlobalPos);
|
||||
if (!it->di_->hoverText_.empty())
|
||||
{
|
||||
// Show tooltip
|
||||
util::tooltip::Show(it->di_->hoverText_, mouseGlobalPos);
|
||||
}
|
||||
if (it->di_->event_ != nullptr)
|
||||
{
|
||||
eventHandler = it->di_;
|
||||
}
|
||||
}
|
||||
|
||||
return itemPicked;
|
||||
}
|
||||
|
||||
void GeoIcons::RegisterEventHandler(
|
||||
const std::shared_ptr<GeoIconDrawItem>& di,
|
||||
const std::function<void(QEvent*)>& eventHandler)
|
||||
{
|
||||
di->event_ = eventHandler;
|
||||
}
|
||||
|
||||
} // namespace draw
|
||||
} // namespace gl
|
||||
} // namespace qt
|
||||
|
|
|
|||
|
|
@ -183,6 +183,16 @@ public:
|
|||
*/
|
||||
void FinishIcons();
|
||||
|
||||
/**
|
||||
* Registers an event handler for an icon.
|
||||
*
|
||||
* @param [in] di Icon draw item
|
||||
* @param [in] eventHandler Event handler function
|
||||
*/
|
||||
static void
|
||||
RegisterEventHandler(const std::shared_ptr<GeoIconDrawItem>& di,
|
||||
const std::function<void(QEvent*)>& eventHandler);
|
||||
|
||||
private:
|
||||
class Impl;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,14 @@
|
|||
#include <scwx/qt/map/marker_layer.hpp>
|
||||
#include <scwx/qt/manager/marker_manager.hpp>
|
||||
#include <scwx/util/logger.hpp>
|
||||
#include <scwx/qt/types/marker_types.hpp>
|
||||
#include <scwx/qt/gl/draw/geo_icons.hpp>
|
||||
#include <scwx/qt/types/marker_types.hpp>
|
||||
#include <scwx/qt/ui/edit_marker_dialog.hpp>
|
||||
|
||||
#include <QGeoPositionInfo>
|
||||
#include <QMouseEvent>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
|
|
@ -18,7 +24,9 @@ class MarkerLayer::Impl
|
|||
{
|
||||
public:
|
||||
explicit Impl(MarkerLayer* self, std::shared_ptr<MapContext> context) :
|
||||
self_ {self}, geoIcons_ {std::make_shared<gl::draw::GeoIcons>(context)}
|
||||
self_ {self},
|
||||
geoIcons_ {std::make_shared<gl::draw::GeoIcons>(context)},
|
||||
editMarkerDialog_ {std::make_shared<ui::EditMarkerDialog>()}
|
||||
{
|
||||
ConnectSignals();
|
||||
}
|
||||
|
|
@ -30,6 +38,7 @@ public:
|
|||
MarkerLayer* self_;
|
||||
|
||||
std::shared_ptr<gl::draw::GeoIcons> geoIcons_;
|
||||
std::shared_ptr<ui::EditMarkerDialog> editMarkerDialog_;
|
||||
};
|
||||
|
||||
void MarkerLayer::Impl::ConnectSignals()
|
||||
|
|
@ -55,11 +64,36 @@ void MarkerLayer::Impl::ReloadMarkers()
|
|||
markerManager->for_each(
|
||||
[this](const types::MarkerInfo& marker)
|
||||
{
|
||||
// must use local ID, instead of reference to marker in event handler
|
||||
// callback.
|
||||
types::MarkerId id = marker.id;
|
||||
|
||||
std::shared_ptr<gl::draw::GeoIconDrawItem> icon = geoIcons_->AddIcon();
|
||||
geoIcons_->SetIconTexture(icon, marker.iconName, 0);
|
||||
geoIcons_->SetIconLocation(icon, marker.latitude, marker.longitude);
|
||||
geoIcons_->SetIconHoverText(icon, marker.name);
|
||||
geoIcons_->SetIconModulate(icon, marker.iconColor);
|
||||
geoIcons_->RegisterEventHandler(
|
||||
icon,
|
||||
[this, id](QEvent* ev)
|
||||
{
|
||||
switch (ev->type())
|
||||
{
|
||||
case QEvent::Type::MouseButtonPress:
|
||||
{
|
||||
QMouseEvent* mouseEvent = reinterpret_cast<QMouseEvent*>(ev);
|
||||
if (mouseEvent->buttons() == Qt::MouseButton::RightButton)
|
||||
{
|
||||
editMarkerDialog_->setup(id);
|
||||
editMarkerDialog_->show();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
geoIcons_->FinishIcons();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue