mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 19: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_ =
|
||||
kNumTriangles * kVerticesPerTriangle * kIntegersPerVertex_;
|
||||
|
||||
struct GeoLineDrawItem
|
||||
struct GeoLineDrawItem : types::EventHandler
|
||||
{
|
||||
bool visible_ {true};
|
||||
units::length::nautical_miles<double> threshold_ {};
|
||||
|
|
@ -57,7 +57,7 @@ class GeoLines::Impl
|
|||
public:
|
||||
struct LineHoverEntry
|
||||
{
|
||||
std::shared_ptr<const GeoLineDrawItem> di_;
|
||||
std::shared_ptr<GeoLineDrawItem> di_;
|
||||
|
||||
glm::vec2 p1_;
|
||||
glm::vec2 p2_;
|
||||
|
|
@ -86,7 +86,7 @@ public:
|
|||
void Update();
|
||||
void UpdateBuffers();
|
||||
void UpdateModifiedLineBuffers();
|
||||
void UpdateSingleBuffer(const std::shared_ptr<const GeoLineDrawItem>& di,
|
||||
void UpdateSingleBuffer(const std::shared_ptr<GeoLineDrawItem>& di,
|
||||
std::size_t lineIndex,
|
||||
std::vector<float>& linesBuffer,
|
||||
std::vector<GLint>& integerBuffer,
|
||||
|
|
@ -517,7 +517,7 @@ void GeoLines::Impl::UpdateModifiedLineBuffers()
|
|||
}
|
||||
|
||||
void GeoLines::Impl::UpdateSingleBuffer(
|
||||
const std::shared_ptr<const GeoLineDrawItem>& di,
|
||||
const std::shared_ptr<GeoLineDrawItem>& di,
|
||||
std::size_t lineIndex,
|
||||
std::vector<float>& lineBuffer,
|
||||
std::vector<GLint>& integerBuffer,
|
||||
|
|
@ -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<double> radians = angle;
|
||||
|
||||
|
|
@ -697,7 +697,7 @@ bool GeoLines::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->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<GeoLineDrawItem>& di,
|
||||
const std::function<void(QEvent*)>& eventHandler)
|
||||
{
|
||||
di->event_ = eventHandler;
|
||||
}
|
||||
|
||||
} // namespace draw
|
||||
} // namespace gl
|
||||
} // namespace qt
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ struct GeoLineDrawItem;
|
|||
class GeoLines : public DrawItem
|
||||
{
|
||||
public:
|
||||
typedef std::function<void(std::shared_ptr<const GeoLineDrawItem>&,
|
||||
typedef std::function<void(std::shared_ptr<GeoLineDrawItem>&,
|
||||
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<GeoLineDrawItem>& di,
|
||||
const std::function<void(QEvent*)>& eventHandler);
|
||||
|
||||
private:
|
||||
class Impl;
|
||||
std::unique_ptr<Impl> p;
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
#include <boost/algorithm/string/join.hpp>
|
||||
#include <boost/container/stable_vector.hpp>
|
||||
#include <boost/container_hash/hash.hpp>
|
||||
#include <QEvent>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
|
|
@ -140,8 +141,9 @@ public:
|
|||
const std::shared_ptr<AlertLayerHandler::SegmentRecord>& segmentRecord);
|
||||
void ConnectAlertHandlerSignals();
|
||||
void ConnectSignals();
|
||||
void
|
||||
HandleGeoLinesHover(std::shared_ptr<const gl::draw::GeoLineDrawItem>& di,
|
||||
void HandleGeoLinesEvent(std::shared_ptr<gl::draw::GeoLineDrawItem>& di,
|
||||
QEvent* ev);
|
||||
void HandleGeoLinesHover(std::shared_ptr<gl::draw::GeoLineDrawItem>& di,
|
||||
const QPointF& mouseGlobalPos);
|
||||
|
||||
void AddLine(std::shared_ptr<gl::draw::GeoLines>& geoLines,
|
||||
|
|
@ -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<types::EventHandler>& eventHandler)
|
||||
{
|
||||
return DrawLayer::RunMousePicking(params,
|
||||
mouseLocalPos,
|
||||
mouseGlobalPos,
|
||||
mouseCoords,
|
||||
mouseGeoCoords,
|
||||
eventHandler);
|
||||
}
|
||||
|
||||
void AlertLayerHandler::HandleAlert(const types::TextEventKey& key,
|
||||
size_t messageIndex)
|
||||
{
|
||||
|
|
@ -531,11 +517,33 @@ void AlertLayer::Impl::AddLine(std::shared_ptr<gl::draw::GeoLines>& 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<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(
|
||||
std::shared_ptr<const gl::draw::GeoLineDrawItem>& di,
|
||||
std::shared_ptr<gl::draw::GeoLineDrawItem>& di,
|
||||
const QPointF& mouseGlobalPos)
|
||||
{
|
||||
if (di != lastHoverDi_)
|
||||
|
|
|
|||
|
|
@ -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<types::EventHandler>& eventHandler) override final;
|
||||
|
||||
private:
|
||||
class Impl;
|
||||
std::unique_ptr<Impl> p;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue