diff --git a/src/ScatterplotPlugin.cpp b/src/ScatterplotPlugin.cpp index af60d4b..2615ac9 100644 --- a/src/ScatterplotPlugin.cpp +++ b/src/ScatterplotPlugin.cpp @@ -334,7 +334,7 @@ void ScatterplotPlugin::selectPoints() auto& pixelSelectionTool = _scatterPlotWidget->getPixelSelectionTool(); // Only proceed with a valid points position dataset and when the pixel selection tool is active - if (!_positionDataset.isValid() || !pixelSelectionTool.isActive() || _scatterPlotWidget->isNavigating()) + if (!_positionDataset.isValid() || !pixelSelectionTool.isActive() || _scatterPlotWidget->isNavigating() || !pixelSelectionTool.isEnabled()) return; auto selectionAreaImage = pixelSelectionTool.getAreaPixmap().toImage(); @@ -424,13 +424,11 @@ void ScatterplotPlugin::samplePoints() { auto& samplerPixelSelectionTool = _scatterPlotWidget->getSamplerPixelSelectionTool(); - if (!_positionDataset.isValid() || _scatterPlotWidget->isNavigating()) + if (!_positionDataset.isValid() || !samplerPixelSelectionTool.isActive() || _scatterPlotWidget->isNavigating() || !samplerPixelSelectionTool.isEnabled()) return; auto selectionAreaImage = samplerPixelSelectionTool.getAreaPixmap().toImage(); - auto selectionSet = _positionDataset->getSelection(); - std::vector targetSelectionIndices; targetSelectionIndices.reserve(_positionDataset->getNumPoints()); diff --git a/src/ScatterplotPlugin.h b/src/ScatterplotPlugin.h index 27320a5..17f135a 100644 --- a/src/ScatterplotPlugin.h +++ b/src/ScatterplotPlugin.h @@ -110,7 +110,7 @@ class ScatterplotPlugin : public ViewPlugin private: mv::gui::DropWidget* _dropWidget; /** Widget for dropping datasets */ - ScatterplotWidget* _scatterPlotWidget; /** THe visualization widget */ + ScatterplotWidget* _scatterPlotWidget; /** The visualization widget */ Dataset _positionDataset; /** Smart pointer to points dataset for point position */ Dataset _positionSourceDataset; /** Smart pointer to source of the points dataset for point position (if any) */ diff --git a/src/ScatterplotWidget.cpp b/src/ScatterplotWidget.cpp index 4dc380d..f3a1767 100644 --- a/src/ScatterplotWidget.cpp +++ b/src/ScatterplotWidget.cpp @@ -18,7 +18,7 @@ #include -#include "ScatterplotPlugin.h" +#include using namespace mv; @@ -48,7 +48,7 @@ namespace } } -ScatterplotWidget::ScatterplotWidget() : +ScatterplotWidget::ScatterplotWidget(mv::plugin::ViewPlugin* parentPlugin) : QOpenGLWidget(), _pointRenderer(), _densityRenderer(DensityRenderer::RenderMode::DENSITY), @@ -65,7 +65,8 @@ ScatterplotWidget::ScatterplotWidget() : _pixelRatio(1.0), _mousePositions(), _isNavigating(false), - _weightDensity(false) + _weightDensity(false), + _parentPlugin(parentPlugin) { setContextMenuPolicy(Qt::CustomContextMenu); setAcceptDrops(true); @@ -152,19 +153,33 @@ bool ScatterplotWidget::event(QEvent* event) if (!event) return QOpenGLWidget::event(event); + auto setIsNavigating = [this](bool isNavigating) -> void { + _isNavigating = isNavigating; + _pixelSelectionTool.setEnabled(!isNavigating); + if (isNavigating) { + _samplerPixelSelectionTool.setEnabled(false); + } + else if (_parentPlugin) { // reset to UI-setting + _samplerPixelSelectionTool.setEnabled(_parentPlugin->getSamplerAction().isEnabled()); + } + + }; + // Set navigation flag on Alt press/release - if (event->type() == QEvent::KeyRelease) - { - if (const auto* keyEvent = static_cast(event)) - if (keyEvent->key() == Qt::Key_Alt) - _isNavigating = false; + if (event->type() == QEvent::KeyRelease) { + if (const auto* keyEvent = static_cast(event)) { + if (keyEvent->key() == Qt::Key_Alt) { + setIsNavigating(false); + } + } } - else if (event->type() == QEvent::KeyPress) - { - if (const auto* keyEvent = static_cast(event)) - if (keyEvent->key() == Qt::Key_Alt) - _isNavigating = true; + else if (event->type() == QEvent::KeyPress) { + if (const auto* keyEvent = static_cast(event)) { + if (keyEvent->key() == Qt::Key_Alt) { + setIsNavigating(true); + } + } } @@ -192,7 +207,7 @@ bool ScatterplotWidget::event(QEvent* event) // Navigation if (mouseEvent->buttons() == Qt::LeftButton) { - _pixelSelectionTool.setEnabled(false); + setIsNavigating(true); setCursor(Qt::ClosedHandCursor); _mousePositions << mouseEvent->pos(); update(); @@ -204,7 +219,7 @@ bool ScatterplotWidget::event(QEvent* event) case QEvent::MouseButtonRelease: { - _pixelSelectionTool.setEnabled(true); + setIsNavigating(false); setCursor(Qt::ArrowCursor); _mousePositions.clear(); update(); diff --git a/src/ScatterplotWidget.h b/src/ScatterplotWidget.h index 0c331fc..1b9545c 100644 --- a/src/ScatterplotWidget.h +++ b/src/ScatterplotWidget.h @@ -17,11 +17,14 @@ #include #include -class ScatterplotPlugin; - using namespace mv::gui; using namespace mv::util; +namespace mv::plugin +{ + class ViewPlugin; +} + struct widgetSizeInfo { float width; float height; @@ -49,7 +52,7 @@ class ScatterplotWidget : public QOpenGLWidget, protected QOpenGLFunctions_3_3_C }; public: - ScatterplotWidget(); + ScatterplotWidget(mv::plugin::ViewPlugin* parentPlugin = nullptr); ~ScatterplotWidget(); @@ -323,5 +326,7 @@ private slots: bool _isNavigating; /** Boolean determining whether view navigation is currently taking place or not */ bool _weightDensity; /** Use point scalar sizes to weight density */ + mv::plugin::ViewPlugin* _parentPlugin = nullptr; + friend class NavigationAction; };