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 642dbd84..bace40e0 100644 --- a/scwx-qt/source/scwx/qt/gl/draw/geo_lines.cpp +++ b/scwx-qt/source/scwx/qt/gl/draw/geo_lines.cpp @@ -49,6 +49,7 @@ struct GeoLineDrawItem float width_ {5.0}; units::angle::degrees angle_ {}; std::string hoverText_ {}; + GeoLines::HoverCallback hoverCallback_ {nullptr}; }; class GeoLines::Impl @@ -388,6 +389,16 @@ void GeoLines::SetLineVisible(const std::shared_ptr& di, } } +void GeoLines::SetLineHoverCallback(const std::shared_ptr& di, + const HoverCallback& callback) +{ + if (di->hoverCallback_ != nullptr || callback != nullptr) + { + di->hoverCallback_ = callback; + p->dirtyLines_.insert(di); + } +} + void GeoLines::SetLineHoverText(const std::shared_ptr& di, const std::string& text) { @@ -614,7 +625,8 @@ void GeoLines::Impl::UpdateSingleBuffer( hoverLines.end(), [&di](auto& entry) { return entry.di_ == di; }); - if (di->visible_ && !di->hoverText_.empty()) + if (di->visible_ && + (!di->hoverText_.empty() || di->hoverCallback_ != nullptr)) { const units::angle::radians radians = angle; @@ -715,8 +727,8 @@ bool GeoLines::RunMousePicking( // For each pickable line auto it = std::find_if( std::execution::par_unseq, - p->currentHoverLines_.crbegin(), - p->currentHoverLines_.crend(), + p->currentHoverLines_.rbegin(), + p->currentHoverLines_.rend(), [&mapDistance, &selectedTime, &mapMatrix, &mouseCoords](const auto& line) { if (( @@ -775,7 +787,15 @@ bool GeoLines::RunMousePicking( if (it != p->currentHoverLines_.crend()) { itemPicked = true; - util::tooltip::Show(it->di_->hoverText_, mouseGlobalPos); + + if (!it->di_->hoverText_.empty()) + { + util::tooltip::Show(it->di_->hoverText_, mouseGlobalPos); + } + else if (it->di_->hoverCallback_ != nullptr) + { + it->di_->hoverCallback_(it->di_, mouseGlobalPos); + } } return itemPicked; 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 78f6a5b0..07131ced 100644 --- a/scwx-qt/source/scwx/qt/gl/draw/geo_lines.hpp +++ b/scwx-qt/source/scwx/qt/gl/draw/geo_lines.hpp @@ -19,6 +19,10 @@ struct GeoLineDrawItem; class GeoLines : public DrawItem { public: + typedef std::function&, + const QPointF&)> + HoverCallback; + explicit GeoLines(std::shared_ptr context); ~GeoLines(); @@ -114,6 +118,15 @@ public: void SetLineVisible(const std::shared_ptr& di, bool visible); + /** + * Sets the hover callback enable of a geo line. + * + * @param [in] di Geo line draw item + * @param [in] enabled Hover enabled + */ + void SetLineHoverCallback(const std::shared_ptr& di, + const HoverCallback& callback); + /** * Sets the hover text of a geo line. * diff --git a/scwx-qt/source/scwx/qt/map/alert_layer.cpp b/scwx-qt/source/scwx/qt/map/alert_layer.cpp index d7495d3d..eb16e666 100644 --- a/scwx-qt/source/scwx/qt/map/alert_layer.cpp +++ b/scwx-qt/source/scwx/qt/map/alert_layer.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -11,6 +12,7 @@ #include #include +#include #include #include @@ -138,24 +140,28 @@ public: const std::shared_ptr& segmentRecord); void ConnectAlertHandlerSignals(); void ConnectSignals(); + void + HandleGeoLinesHover(std::shared_ptr& di, + const QPointF& mouseGlobalPos); - static void AddLine(std::shared_ptr& geoLines, - std::shared_ptr& di, - const common::Coordinate& p1, - const common::Coordinate& p2, - boost::gil::rgba32f_pixel_t color, - float width, - std::chrono::system_clock::time_point startTime, - std::chrono::system_clock::time_point endTime); - static void - AddLines(std::shared_ptr& geoLines, - const std::vector& coordinates, - boost::gil::rgba32f_pixel_t color, - float width, - std::chrono::system_clock::time_point startTime, - std::chrono::system_clock::time_point endTime, - boost::container::stable_vector< - std::shared_ptr>& drawItems); + void AddLine(std::shared_ptr& geoLines, + std::shared_ptr& di, + const common::Coordinate& p1, + const common::Coordinate& p2, + boost::gil::rgba32f_pixel_t color, + float width, + std::chrono::system_clock::time_point startTime, + std::chrono::system_clock::time_point endTime, + bool enableHover); + void AddLines(std::shared_ptr& geoLines, + const std::vector& coordinates, + boost::gil::rgba32f_pixel_t color, + float width, + std::chrono::system_clock::time_point startTime, + std::chrono::system_clock::time_point endTime, + bool enableHover, + boost::container::stable_vector< + std::shared_ptr>& drawItems); const awips::Phenomenon phenomenon_; @@ -166,7 +172,10 @@ public: std::unordered_map, boost::container::stable_vector< std::shared_ptr>> - linesBySegment_ {}; + linesBySegment_ {}; + std::unordered_map, + std::shared_ptr> + segmentsByLine_; std::mutex linesMutex_ {}; std::unordered_map lineColor_; @@ -402,19 +411,30 @@ void AlertLayer::Impl::AddAlert( // If draw items were added if (drawItems.second) { + // Add border AddLines(geoLines, coordinates, kBlack_, 5.0f, startTime, endTime, + true, drawItems.first->second); + + // Add only border to segmentsByLine_ + for (auto& di : drawItems.first->second) + { + segmentsByLine_.insert({di, segmentRecord}); + } + + // Add line AddLines(geoLines, coordinates, lineColor, 3.0f, startTime, endTime, + false, drawItems.first->second); } } @@ -452,6 +472,7 @@ void AlertLayer::Impl::AddLines( float width, std::chrono::system_clock::time_point startTime, std::chrono::system_clock::time_point endTime, + bool enableHover, boost::container::stable_vector>& drawItems) { @@ -476,7 +497,8 @@ void AlertLayer::Impl::AddLines( color, width, startTime, - endTime); + endTime, + enableHover); drawItems.push_back(di); } @@ -489,7 +511,8 @@ void AlertLayer::Impl::AddLine(std::shared_ptr& geoLines, boost::gil::rgba32f_pixel_t color, float width, std::chrono::system_clock::time_point startTime, - std::chrono::system_clock::time_point endTime) + std::chrono::system_clock::time_point endTime, + bool enableHover) { geoLines->SetLineLocation( di, p1.latitude_, p1.longitude_, p2.latitude_, p2.longitude_); @@ -497,6 +520,29 @@ void AlertLayer::Impl::AddLine(std::shared_ptr& geoLines, geoLines->SetLineWidth(di, width); geoLines->SetLineStartTime(di, startTime); geoLines->SetLineEndTime(di, endTime); + + if (enableHover) + { + geoLines->SetLineHoverCallback( + di, + std::bind(&AlertLayer::Impl::HandleGeoLinesHover, + this, + std::placeholders::_1, + std::placeholders::_2)); + } +} + +void AlertLayer::Impl::HandleGeoLinesHover( + std::shared_ptr& di, + const QPointF& mouseGlobalPos) +{ + auto it = segmentsByLine_.find(di); + if (it != segmentsByLine_.cend()) + { + util::tooltip::Show( + boost::algorithm::join(it->second->segment_->productContent_, "\n"), + mouseGlobalPos); + } } AlertLayerHandler& AlertLayerHandler::Instance()