Placefile line hover in-work

This commit is contained in:
Dan Paulat 2023-08-28 00:15:57 -05:00
parent 37d751774d
commit 8dfb9f1105
14 changed files with 243 additions and 36 deletions

View file

@ -77,7 +77,8 @@ void DrawLayer::Deinitialize()
}
bool DrawLayer::RunMousePicking(
const QMapLibreGL::CustomLayerRenderParameters& params)
const QMapLibreGL::CustomLayerRenderParameters& params,
const glm::vec2& mousePos)
{
bool itemPicked = false;
@ -85,7 +86,7 @@ bool DrawLayer::RunMousePicking(
for (auto it = p->drawList_.rbegin(); it != p->drawList_.rend(); ++it)
{
// Run mouse picking on each draw item
if ((*it)->RunMousePicking(params))
if ((*it)->RunMousePicking(params, mousePos))
{
// If a draw item was picked, don't process additional items
itemPicked = true;

View file

@ -23,8 +23,9 @@ public:
Render(const QMapLibreGL::CustomLayerRenderParameters&) override;
virtual void Deinitialize() override;
virtual bool RunMousePicking(
const QMapLibreGL::CustomLayerRenderParameters& params) override;
virtual bool
RunMousePicking(const QMapLibreGL::CustomLayerRenderParameters& params,
const glm::vec2& mousePos) override;
protected:
void AddDrawItem(const std::shared_ptr<gl::draw::DrawItem>& drawItem);

View file

@ -27,7 +27,8 @@ GenericLayer::GenericLayer(std::shared_ptr<MapContext> context) :
GenericLayer::~GenericLayer() = default;
bool GenericLayer::RunMousePicking(
const QMapLibreGL::CustomLayerRenderParameters& /* params */)
const QMapLibreGL::CustomLayerRenderParameters& /* params */,
const glm::vec2& /* mousePos */)
{
// By default, the layer has nothing to pick
return false;

View file

@ -6,6 +6,7 @@
#include <QObject>
#include <QMapLibreGL/QMapLibreGL>
#include <glm/gtc/type_ptr.hpp>
namespace scwx
{
@ -32,11 +33,13 @@ public:
* @brief Run mouse picking on the layer.
*
* @param [in] params Custom layer render parameters
* @param [in] mousePos Mouse cursor location in map screen coordinates
*
* @return true if a draw item was picked, otherwise false
*/
virtual bool
RunMousePicking(const QMapLibreGL::CustomLayerRenderParameters& params);
RunMousePicking(const QMapLibreGL::CustomLayerRenderParameters& params,
const glm::vec2& mousePos);
protected:
std::shared_ptr<MapContext> context() const;

View file

@ -13,6 +13,7 @@
#include <scwx/qt/map/radar_range_layer.hpp>
#include <scwx/qt/model/imgui_context_model.hpp>
#include <scwx/qt/util/file.hpp>
#include <scwx/qt/util/maplibre.hpp>
#include <scwx/qt/view/radar_product_view_factory.hpp>
#include <scwx/util/logger.hpp>
#include <scwx/util/time.hpp>
@ -172,6 +173,7 @@ public:
common::Level2Product selectedLevel2Product_;
bool hasMouse_ {false};
QPointF lastPos_;
std::size_t currentStyleIndex_;
const MapStyle* currentStyle_;
@ -862,6 +864,16 @@ void MapWidgetImpl::AddLayer(const std::string& id,
layerList_.push_back(id);
}
void MapWidget::enterEvent(QEnterEvent* /* ev */)
{
p->hasMouse_ = true;
}
void MapWidget::leaveEvent(QEvent* /* ev */)
{
p->hasMouse_ = false;
}
void MapWidget::keyPressEvent(QKeyEvent* ev)
{
switch (ev->key())
@ -1024,7 +1036,10 @@ void MapWidget::paintGL()
p->map_->render();
// Perform mouse picking
p->RunMousePicking();
if (p->hasMouse_)
{
p->RunMousePicking();
}
// Render ImGui Frame
ImGui::Render();
@ -1039,13 +1054,17 @@ void MapWidgetImpl::RunMousePicking()
const QMapLibreGL::CustomLayerRenderParameters params =
context_->render_parameters();
auto coordinate = map_->coordinateForPixel(lastPos_);
auto mouseScreenCoordinate =
util::maplibre::LatLongToScreenCoordinate(coordinate);
// For each layer in reverse
// TODO: All Generic Layers, not just Placefile Layers
for (auto it = placefileLayers_.rbegin(); it != placefileLayers_.rend();
++it)
{
// Run mouse picking for each layer
if ((*it)->RunMousePicking(params))
if ((*it)->RunMousePicking(params, mouseScreenCoordinate))
{
// If a draw item was picked, don't process additional layers
break;

View file

@ -119,7 +119,9 @@ private:
qreal pixelRatio();
// QWidget implementation.
void enterEvent(QEnterEvent* ev) override final;
void keyPressEvent(QKeyEvent* ev) override final;
void leaveEvent(QEvent* ev) override final;
void mousePressEvent(QMouseEvent* ev) override final;
void mouseMoveEvent(QMouseEvent* ev) override final;
void wheelEvent(QWheelEvent* ev) override final;