diff --git a/scwx-qt/source/scwx/qt/gl/draw/geo_lines.cpp b/scwx-qt/source/scwx/qt/gl/draw/geo_lines.cpp index bace40e0..d9f2c023 100644 --- a/scwx-qt/source/scwx/qt/gl/draw/geo_lines.cpp +++ b/scwx-qt/source/scwx/qt/gl/draw/geo_lines.cpp @@ -34,7 +34,7 @@ static constexpr std::size_t kIntegersPerVertex_ = 4; static constexpr std::size_t kIntegerBufferLength_ = kNumTriangles * kVerticesPerTriangle * kIntegersPerVertex_; -struct GeoLineDrawItem +struct GeoLineDrawItem : types::EventHandler { bool visible_ {true}; units::length::nautical_miles threshold_ {}; @@ -57,7 +57,7 @@ class GeoLines::Impl public: struct LineHoverEntry { - std::shared_ptr di_; + std::shared_ptr di_; glm::vec2 p1_; glm::vec2 p2_; @@ -86,9 +86,9 @@ public: void Update(); void UpdateBuffers(); void UpdateModifiedLineBuffers(); - void UpdateSingleBuffer(const std::shared_ptr& di, - std::size_t lineIndex, - std::vector& linesBuffer, + void UpdateSingleBuffer(const std::shared_ptr& di, + std::size_t lineIndex, + std::vector& linesBuffer, std::vector& integerBuffer, std::vector& hoverLines); @@ -517,11 +517,11 @@ void GeoLines::Impl::UpdateModifiedLineBuffers() } void GeoLines::Impl::UpdateSingleBuffer( - const std::shared_ptr& di, - std::size_t lineIndex, - std::vector& lineBuffer, - std::vector& integerBuffer, - std::vector& hoverLines) + const std::shared_ptr& di, + std::size_t lineIndex, + std::vector& lineBuffer, + std::vector& integerBuffer, + std::vector& hoverLines) { // Threshold value units::length::nautical_miles threshold = di->threshold_; @@ -625,8 +625,8 @@ void GeoLines::Impl::UpdateSingleBuffer( hoverLines.end(), [&di](auto& entry) { return entry.di_ == di; }); - if (di->visible_ && - (!di->hoverText_.empty() || di->hoverCallback_ != nullptr)) + if (di->visible_ && (!di->hoverText_.empty() || + di->hoverCallback_ != nullptr || di->event_ != nullptr)) { const units::angle::radians radians = angle; @@ -697,7 +697,7 @@ bool GeoLines::RunMousePicking( const QPointF& mouseGlobalPos, const glm::vec2& mouseCoords, const common::Coordinate& /* mouseGeoCoords */, - std::shared_ptr& /* eventHandler */) + std::shared_ptr& eventHandler) { std::unique_lock lock {p->lineMutex_}; @@ -790,17 +790,31 @@ bool GeoLines::RunMousePicking( if (!it->di_->hoverText_.empty()) { + // Show tooltip util::tooltip::Show(it->di_->hoverText_, mouseGlobalPos); } else if (it->di_->hoverCallback_ != nullptr) { it->di_->hoverCallback_(it->di_, mouseGlobalPos); } + + if (it->di_->event_ != nullptr) + { + // Register event handler + eventHandler = it->di_; + } } return itemPicked; } +void GeoLines::RegisterEventHandler( + const std::shared_ptr& di, + const std::function& eventHandler) +{ + di->event_ = eventHandler; +} + } // namespace draw } // namespace gl } // namespace qt diff --git a/scwx-qt/source/scwx/qt/gl/draw/geo_lines.hpp b/scwx-qt/source/scwx/qt/gl/draw/geo_lines.hpp index 07131ced..b7b792d0 100644 --- a/scwx-qt/source/scwx/qt/gl/draw/geo_lines.hpp +++ b/scwx-qt/source/scwx/qt/gl/draw/geo_lines.hpp @@ -19,7 +19,7 @@ struct GeoLineDrawItem; class GeoLines : public DrawItem { public: - typedef std::function&, + typedef std::function&, const QPointF&)> HoverCallback; @@ -159,6 +159,16 @@ public: */ void FinishLines(); + /** + * Registers an event handler for a geo line. + * + * @param [in] di Geo line draw item + * @param [in] eventHandler Event handler function + */ + static void + RegisterEventHandler(const std::shared_ptr& di, + const std::function& eventHandler); + private: class Impl; std::unique_ptr p; diff --git a/scwx-qt/source/scwx/qt/map/alert_layer.cpp b/scwx-qt/source/scwx/qt/map/alert_layer.cpp index 18a1d5d6..77273afa 100644 --- a/scwx-qt/source/scwx/qt/map/alert_layer.cpp +++ b/scwx-qt/source/scwx/qt/map/alert_layer.cpp @@ -15,6 +15,7 @@ #include #include #include +#include namespace scwx { @@ -140,9 +141,10 @@ public: const std::shared_ptr& segmentRecord); void ConnectAlertHandlerSignals(); void ConnectSignals(); - void - HandleGeoLinesHover(std::shared_ptr& di, - const QPointF& mouseGlobalPos); + void HandleGeoLinesEvent(std::shared_ptr& di, + QEvent* ev); + void HandleGeoLinesHover(std::shared_ptr& di, + const QPointF& mouseGlobalPos); void AddLine(std::shared_ptr& geoLines, std::shared_ptr& di, @@ -256,22 +258,6 @@ void AlertLayer::Deinitialize() DrawLayer::Deinitialize(); } -bool AlertLayer::RunMousePicking( - const QMapLibre::CustomLayerRenderParameters& params, - const QPointF& mouseLocalPos, - const QPointF& mouseGlobalPos, - const glm::vec2& mouseCoords, - const common::Coordinate& mouseGeoCoords, - std::shared_ptr& eventHandler) -{ - return DrawLayer::RunMousePicking(params, - mouseLocalPos, - mouseGlobalPos, - mouseCoords, - mouseGeoCoords, - eventHandler); -} - void AlertLayerHandler::HandleAlert(const types::TextEventKey& key, size_t messageIndex) { @@ -531,12 +517,34 @@ void AlertLayer::Impl::AddLine(std::shared_ptr& geoLines, this, std::placeholders::_1, std::placeholders::_2)); + + gl::draw::GeoLines::RegisterEventHandler( + di, + std::bind(&AlertLayer::Impl::HandleGeoLinesEvent, + this, + di, + std::placeholders::_1)); + } +} + +void AlertLayer::Impl::HandleGeoLinesEvent( + std::shared_ptr& di, QEvent* ev) +{ + switch (ev->type()) + { + case QEvent::Type::MouseButtonPress: + auto it = segmentsByLine_.find(di); + if (it != segmentsByLine_.cend()) + { + logger_->info("Selected alert: {}", it->second->key_.ToString()); + } + break; } } void AlertLayer::Impl::HandleGeoLinesHover( - std::shared_ptr& di, - const QPointF& mouseGlobalPos) + std::shared_ptr& di, + const QPointF& mouseGlobalPos) { if (di != lastHoverDi_) { diff --git a/scwx-qt/source/scwx/qt/map/alert_layer.hpp b/scwx-qt/source/scwx/qt/map/alert_layer.hpp index e93c4bb7..1bcf91c9 100644 --- a/scwx-qt/source/scwx/qt/map/alert_layer.hpp +++ b/scwx-qt/source/scwx/qt/map/alert_layer.hpp @@ -27,14 +27,6 @@ public: void Render(const QMapLibre::CustomLayerRenderParameters&) override final; void Deinitialize() override final; - bool RunMousePicking( - const QMapLibre::CustomLayerRenderParameters& params, - const QPointF& mouseLocalPos, - const QPointF& mouseGlobalPos, - const glm::vec2& mouseCoords, - const common::Coordinate& mouseGeoCoords, - std::shared_ptr& eventHandler) override final; - private: class Impl; std::unique_ptr p;