Add right click to edit location marker

This commit is contained in:
AdenKoperczak 2024-11-28 13:09:34 -05:00
parent cfed61c6ff
commit fc8d65d4d1
3 changed files with 65 additions and 6 deletions

View file

@ -38,7 +38,7 @@ static constexpr std::size_t kIntegersPerVertex_ = 4;
static constexpr std::size_t kIntegerBufferLength_ = static constexpr std::size_t kIntegerBufferLength_ =
kNumTriangles * kVerticesPerTriangle * kIntegersPerVertex_; kNumTriangles * kVerticesPerTriangle * kIntegersPerVertex_;
struct GeoIconDrawItem struct GeoIconDrawItem : types::EventHandler
{ {
units::length::nautical_miles<double> threshold_ {}; units::length::nautical_miles<double> threshold_ {};
std::chrono::sys_time<std::chrono::seconds> startTime_ {}; std::chrono::sys_time<std::chrono::seconds> startTime_ {};
@ -691,7 +691,7 @@ void GeoIcons::Impl::UpdateSingleBuffer(
hoverIcons.end(), hoverIcons.end(),
[&di](auto& entry) { return entry.di_ == di; }); [&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; const units::angle::radians<double> radians = angle;
@ -903,7 +903,7 @@ bool GeoIcons::RunMousePicking(
const QPointF& mouseGlobalPos, const QPointF& mouseGlobalPos,
const glm::vec2& mouseCoords, const glm::vec2& mouseCoords,
const common::Coordinate& /* mouseGeoCoords */, const common::Coordinate& /* mouseGeoCoords */,
std::shared_ptr<types::EventHandler>& /* eventHandler */) std::shared_ptr<types::EventHandler>& eventHandler )
{ {
std::unique_lock lock {p->iconMutex_}; std::unique_lock lock {p->iconMutex_};
@ -993,12 +993,27 @@ bool GeoIcons::RunMousePicking(
if (it != p->currentHoverIcons_.crend()) if (it != p->currentHoverIcons_.crend())
{ {
itemPicked = true; 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; return itemPicked;
} }
void GeoIcons::RegisterEventHandler(
const std::shared_ptr<GeoIconDrawItem>& di,
const std::function<void(QEvent*)>& eventHandler)
{
di->event_ = eventHandler;
}
} // namespace draw } // namespace draw
} // namespace gl } // namespace gl
} // namespace qt } // namespace qt

View file

@ -183,6 +183,16 @@ public:
*/ */
void FinishIcons(); 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: private:
class Impl; class Impl;

View file

@ -1,8 +1,14 @@
#include <scwx/qt/map/marker_layer.hpp> #include <scwx/qt/map/marker_layer.hpp>
#include <scwx/qt/manager/marker_manager.hpp> #include <scwx/qt/manager/marker_manager.hpp>
#include <scwx/util/logger.hpp> #include <scwx/util/logger.hpp>
#include <scwx/qt/types/marker_types.hpp>
#include <scwx/qt/gl/draw/geo_icons.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 namespace scwx
{ {
@ -18,7 +24,9 @@ class MarkerLayer::Impl
{ {
public: public:
explicit Impl(MarkerLayer* self, std::shared_ptr<MapContext> context) : 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(); ConnectSignals();
} }
@ -30,6 +38,7 @@ public:
MarkerLayer* self_; MarkerLayer* self_;
std::shared_ptr<gl::draw::GeoIcons> geoIcons_; std::shared_ptr<gl::draw::GeoIcons> geoIcons_;
std::shared_ptr<ui::EditMarkerDialog> editMarkerDialog_;
}; };
void MarkerLayer::Impl::ConnectSignals() void MarkerLayer::Impl::ConnectSignals()
@ -55,11 +64,36 @@ void MarkerLayer::Impl::ReloadMarkers()
markerManager->for_each( markerManager->for_each(
[this](const types::MarkerInfo& marker) [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(); std::shared_ptr<gl::draw::GeoIconDrawItem> icon = geoIcons_->AddIcon();
geoIcons_->SetIconTexture(icon, marker.iconName, 0); geoIcons_->SetIconTexture(icon, marker.iconName, 0);
geoIcons_->SetIconLocation(icon, marker.latitude, marker.longitude); geoIcons_->SetIconLocation(icon, marker.latitude, marker.longitude);
geoIcons_->SetIconHoverText(icon, marker.name); geoIcons_->SetIconHoverText(icon, marker.name);
geoIcons_->SetIconModulate(icon, marker.iconColor); 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(); geoIcons_->FinishIcons();