mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 16:10:06 +00:00 
			
		
		
		
	Handle mouse button press of alert
This commit is contained in:
		
							parent
							
								
									2ab8f3a77a
								
							
						
					
					
						commit
						efb03ab9cc
					
				
					 4 changed files with 67 additions and 43 deletions
				
			
		|  | @ -34,7 +34,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 GeoLineDrawItem | struct GeoLineDrawItem : types::EventHandler | ||||||
| { | { | ||||||
|    bool                                        visible_ {true}; |    bool                                        visible_ {true}; | ||||||
|    units::length::nautical_miles<double>       threshold_ {}; |    units::length::nautical_miles<double>       threshold_ {}; | ||||||
|  | @ -57,7 +57,7 @@ class GeoLines::Impl | ||||||
| public: | public: | ||||||
|    struct LineHoverEntry |    struct LineHoverEntry | ||||||
|    { |    { | ||||||
|       std::shared_ptr<const GeoLineDrawItem> di_; |       std::shared_ptr<GeoLineDrawItem> di_; | ||||||
| 
 | 
 | ||||||
|       glm::vec2 p1_; |       glm::vec2 p1_; | ||||||
|       glm::vec2 p2_; |       glm::vec2 p2_; | ||||||
|  | @ -86,9 +86,9 @@ public: | ||||||
|    void Update(); |    void Update(); | ||||||
|    void UpdateBuffers(); |    void UpdateBuffers(); | ||||||
|    void UpdateModifiedLineBuffers(); |    void UpdateModifiedLineBuffers(); | ||||||
|    void UpdateSingleBuffer(const std::shared_ptr<const GeoLineDrawItem>& di, |    void UpdateSingleBuffer(const std::shared_ptr<GeoLineDrawItem>& di, | ||||||
|                            std::size_t                  lineIndex, |                            std::size_t                             lineIndex, | ||||||
|                            std::vector<float>&          linesBuffer, |                            std::vector<float>&                     linesBuffer, | ||||||
|                            std::vector<GLint>&          integerBuffer, |                            std::vector<GLint>&          integerBuffer, | ||||||
|                            std::vector<LineHoverEntry>& hoverLines); |                            std::vector<LineHoverEntry>& hoverLines); | ||||||
| 
 | 
 | ||||||
|  | @ -517,11 +517,11 @@ void GeoLines::Impl::UpdateModifiedLineBuffers() | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void GeoLines::Impl::UpdateSingleBuffer( | void GeoLines::Impl::UpdateSingleBuffer( | ||||||
|    const std::shared_ptr<const GeoLineDrawItem>& di, |    const std::shared_ptr<GeoLineDrawItem>& di, | ||||||
|    std::size_t                                   lineIndex, |    std::size_t                             lineIndex, | ||||||
|    std::vector<float>&                           lineBuffer, |    std::vector<float>&                     lineBuffer, | ||||||
|    std::vector<GLint>&                           integerBuffer, |    std::vector<GLint>&                     integerBuffer, | ||||||
|    std::vector<LineHoverEntry>&                  hoverLines) |    std::vector<LineHoverEntry>&            hoverLines) | ||||||
| { | { | ||||||
|    // Threshold value
 |    // Threshold value
 | ||||||
|    units::length::nautical_miles<double> threshold = di->threshold_; |    units::length::nautical_miles<double> threshold = di->threshold_; | ||||||
|  | @ -625,8 +625,8 @@ void GeoLines::Impl::UpdateSingleBuffer( | ||||||
|                                hoverLines.end(), |                                hoverLines.end(), | ||||||
|                                [&di](auto& entry) { return entry.di_ == di; }); |                                [&di](auto& entry) { return entry.di_ == di; }); | ||||||
| 
 | 
 | ||||||
|    if (di->visible_ && |    if (di->visible_ && (!di->hoverText_.empty() || | ||||||
|        (!di->hoverText_.empty() || di->hoverCallback_ != nullptr)) |                         di->hoverCallback_ != nullptr || di->event_ != nullptr)) | ||||||
|    { |    { | ||||||
|       const units::angle::radians<double> radians = angle; |       const units::angle::radians<double> radians = angle; | ||||||
| 
 | 
 | ||||||
|  | @ -697,7 +697,7 @@ bool GeoLines::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->lineMutex_}; |    std::unique_lock lock {p->lineMutex_}; | ||||||
| 
 | 
 | ||||||
|  | @ -790,17 +790,31 @@ bool GeoLines::RunMousePicking( | ||||||
| 
 | 
 | ||||||
|       if (!it->di_->hoverText_.empty()) |       if (!it->di_->hoverText_.empty()) | ||||||
|       { |       { | ||||||
|  |          // Show tooltip
 | ||||||
|          util::tooltip::Show(it->di_->hoverText_, mouseGlobalPos); |          util::tooltip::Show(it->di_->hoverText_, mouseGlobalPos); | ||||||
|       } |       } | ||||||
|       else if (it->di_->hoverCallback_ != nullptr) |       else if (it->di_->hoverCallback_ != nullptr) | ||||||
|       { |       { | ||||||
|          it->di_->hoverCallback_(it->di_, mouseGlobalPos); |          it->di_->hoverCallback_(it->di_, mouseGlobalPos); | ||||||
|       } |       } | ||||||
|  | 
 | ||||||
|  |       if (it->di_->event_ != nullptr) | ||||||
|  |       { | ||||||
|  |          // Register event handler
 | ||||||
|  |          eventHandler = it->di_; | ||||||
|  |       } | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|    return itemPicked; |    return itemPicked; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void GeoLines::RegisterEventHandler( | ||||||
|  |    const std::shared_ptr<GeoLineDrawItem>& di, | ||||||
|  |    const std::function<void(QEvent*)>&     eventHandler) | ||||||
|  | { | ||||||
|  |    di->event_ = eventHandler; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| } // namespace draw
 | } // namespace draw
 | ||||||
| } // namespace gl
 | } // namespace gl
 | ||||||
| } // namespace qt
 | } // namespace qt
 | ||||||
|  |  | ||||||
|  | @ -19,7 +19,7 @@ struct GeoLineDrawItem; | ||||||
| class GeoLines : public DrawItem | class GeoLines : public DrawItem | ||||||
| { | { | ||||||
| public: | public: | ||||||
|    typedef std::function<void(std::shared_ptr<const GeoLineDrawItem>&, |    typedef std::function<void(std::shared_ptr<GeoLineDrawItem>&, | ||||||
|                               const QPointF&)> |                               const QPointF&)> | ||||||
|       HoverCallback; |       HoverCallback; | ||||||
| 
 | 
 | ||||||
|  | @ -159,6 +159,16 @@ public: | ||||||
|     */ |     */ | ||||||
|    void FinishLines(); |    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<GeoLineDrawItem>& di, | ||||||
|  |                         const std::function<void(QEvent*)>&     eventHandler); | ||||||
|  | 
 | ||||||
| private: | private: | ||||||
|    class Impl; |    class Impl; | ||||||
|    std::unique_ptr<Impl> p; |    std::unique_ptr<Impl> p; | ||||||
|  |  | ||||||
|  | @ -15,6 +15,7 @@ | ||||||
| #include <boost/algorithm/string/join.hpp> | #include <boost/algorithm/string/join.hpp> | ||||||
| #include <boost/container/stable_vector.hpp> | #include <boost/container/stable_vector.hpp> | ||||||
| #include <boost/container_hash/hash.hpp> | #include <boost/container_hash/hash.hpp> | ||||||
|  | #include <QEvent> | ||||||
| 
 | 
 | ||||||
| namespace scwx | namespace scwx | ||||||
| { | { | ||||||
|  | @ -140,9 +141,10 @@ public: | ||||||
|       const std::shared_ptr<AlertLayerHandler::SegmentRecord>& segmentRecord); |       const std::shared_ptr<AlertLayerHandler::SegmentRecord>& segmentRecord); | ||||||
|    void ConnectAlertHandlerSignals(); |    void ConnectAlertHandlerSignals(); | ||||||
|    void ConnectSignals(); |    void ConnectSignals(); | ||||||
|    void |    void HandleGeoLinesEvent(std::shared_ptr<gl::draw::GeoLineDrawItem>& di, | ||||||
|    HandleGeoLinesHover(std::shared_ptr<const gl::draw::GeoLineDrawItem>& di, |                             QEvent*                                     ev); | ||||||
|                        const QPointF& mouseGlobalPos); |    void HandleGeoLinesHover(std::shared_ptr<gl::draw::GeoLineDrawItem>& di, | ||||||
|  |                             const QPointF& mouseGlobalPos); | ||||||
| 
 | 
 | ||||||
|    void AddLine(std::shared_ptr<gl::draw::GeoLines>&        geoLines, |    void AddLine(std::shared_ptr<gl::draw::GeoLines>&        geoLines, | ||||||
|                 std::shared_ptr<gl::draw::GeoLineDrawItem>& di, |                 std::shared_ptr<gl::draw::GeoLineDrawItem>& di, | ||||||
|  | @ -256,22 +258,6 @@ void AlertLayer::Deinitialize() | ||||||
|    DrawLayer::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<types::EventHandler>&         eventHandler) |  | ||||||
| { |  | ||||||
|    return DrawLayer::RunMousePicking(params, |  | ||||||
|                                      mouseLocalPos, |  | ||||||
|                                      mouseGlobalPos, |  | ||||||
|                                      mouseCoords, |  | ||||||
|                                      mouseGeoCoords, |  | ||||||
|                                      eventHandler); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void AlertLayerHandler::HandleAlert(const types::TextEventKey& key, | void AlertLayerHandler::HandleAlert(const types::TextEventKey& key, | ||||||
|                                     size_t                     messageIndex) |                                     size_t                     messageIndex) | ||||||
| { | { | ||||||
|  | @ -531,12 +517,34 @@ void AlertLayer::Impl::AddLine(std::shared_ptr<gl::draw::GeoLines>& geoLines, | ||||||
|                    this, |                    this, | ||||||
|                    std::placeholders::_1, |                    std::placeholders::_1, | ||||||
|                    std::placeholders::_2)); |                    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<gl::draw::GeoLineDrawItem>& 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( | void AlertLayer::Impl::HandleGeoLinesHover( | ||||||
|    std::shared_ptr<const gl::draw::GeoLineDrawItem>& di, |    std::shared_ptr<gl::draw::GeoLineDrawItem>& di, | ||||||
|    const QPointF&                                    mouseGlobalPos) |    const QPointF&                              mouseGlobalPos) | ||||||
| { | { | ||||||
|    if (di != lastHoverDi_) |    if (di != lastHoverDi_) | ||||||
|    { |    { | ||||||
|  |  | ||||||
|  | @ -27,14 +27,6 @@ public: | ||||||
|    void Render(const QMapLibre::CustomLayerRenderParameters&) override final; |    void Render(const QMapLibre::CustomLayerRenderParameters&) override final; | ||||||
|    void Deinitialize() 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<types::EventHandler>& eventHandler) override final; |  | ||||||
| 
 |  | ||||||
| private: | private: | ||||||
|    class Impl; |    class Impl; | ||||||
|    std::unique_ptr<Impl> p; |    std::unique_ptr<Impl> p; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat