Handle mouse button press of alert

This commit is contained in:
Dan Paulat 2024-07-27 01:05:36 -05:00
parent 2ab8f3a77a
commit efb03ab9cc
4 changed files with 67 additions and 43 deletions

View file

@ -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,9 +86,9 @@ public:
void Update();
void UpdateBuffers();
void UpdateModifiedLineBuffers();
void UpdateSingleBuffer(const std::shared_ptr<const GeoLineDrawItem>& di,
std::size_t lineIndex,
std::vector<float>& linesBuffer,
void UpdateSingleBuffer(const std::shared_ptr<GeoLineDrawItem>& di,
std::size_t lineIndex,
std::vector<float>& linesBuffer,
std::vector<GLint>& integerBuffer,
std::vector<LineHoverEntry>& hoverLines);
@ -517,11 +517,11 @@ void GeoLines::Impl::UpdateModifiedLineBuffers()
}
void GeoLines::Impl::UpdateSingleBuffer(
const std::shared_ptr<const GeoLineDrawItem>& di,
std::size_t lineIndex,
std::vector<float>& lineBuffer,
std::vector<GLint>& integerBuffer,
std::vector<LineHoverEntry>& hoverLines)
const std::shared_ptr<GeoLineDrawItem>& di,
std::size_t lineIndex,
std::vector<float>& lineBuffer,
std::vector<GLint>& integerBuffer,
std::vector<LineHoverEntry>& hoverLines)
{
// Threshold value
units::length::nautical_miles<double> 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<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

View file

@ -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;