Skip to content

Commit 24bf9fd

Browse files
authored
Always disable pixel selection during navigation (#163)
* Always disable pixel selection during navigation * Further ensure that the sample widget is correctly activated/disactivated
1 parent 29c0bc0 commit 24bf9fd

File tree

4 files changed

+41
-23
lines changed

4 files changed

+41
-23
lines changed

src/ScatterplotPlugin.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ void ScatterplotPlugin::selectPoints()
334334
auto& pixelSelectionTool = _scatterPlotWidget->getPixelSelectionTool();
335335

336336
// Only proceed with a valid points position dataset and when the pixel selection tool is active
337-
if (!_positionDataset.isValid() || !pixelSelectionTool.isActive() || _scatterPlotWidget->isNavigating())
337+
if (!_positionDataset.isValid() || !pixelSelectionTool.isActive() || _scatterPlotWidget->isNavigating() || !pixelSelectionTool.isEnabled())
338338
return;
339339

340340
auto selectionAreaImage = pixelSelectionTool.getAreaPixmap().toImage();
@@ -424,13 +424,11 @@ void ScatterplotPlugin::samplePoints()
424424
{
425425
auto& samplerPixelSelectionTool = _scatterPlotWidget->getSamplerPixelSelectionTool();
426426

427-
if (!_positionDataset.isValid() || _scatterPlotWidget->isNavigating())
427+
if (!_positionDataset.isValid() || !samplerPixelSelectionTool.isActive() || _scatterPlotWidget->isNavigating() || !samplerPixelSelectionTool.isEnabled())
428428
return;
429429

430430
auto selectionAreaImage = samplerPixelSelectionTool.getAreaPixmap().toImage();
431431

432-
auto selectionSet = _positionDataset->getSelection<Points>();
433-
434432
std::vector<std::uint32_t> targetSelectionIndices;
435433

436434
targetSelectionIndices.reserve(_positionDataset->getNumPoints());

src/ScatterplotPlugin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class ScatterplotPlugin : public ViewPlugin
110110

111111
private:
112112
mv::gui::DropWidget* _dropWidget; /** Widget for dropping datasets */
113-
ScatterplotWidget* _scatterPlotWidget; /** THe visualization widget */
113+
ScatterplotWidget* _scatterPlotWidget; /** The visualization widget */
114114

115115
Dataset<Points> _positionDataset; /** Smart pointer to points dataset for point position */
116116
Dataset<Points> _positionSourceDataset; /** Smart pointer to source of the points dataset for point position (if any) */

src/ScatterplotWidget.cpp

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
#include <math.h>
2020

21-
#include "ScatterplotPlugin.h"
21+
#include <ViewPlugin.h>
2222

2323
using namespace mv;
2424

@@ -48,7 +48,7 @@ namespace
4848
}
4949
}
5050

51-
ScatterplotWidget::ScatterplotWidget() :
51+
ScatterplotWidget::ScatterplotWidget(mv::plugin::ViewPlugin* parentPlugin) :
5252
QOpenGLWidget(),
5353
_pointRenderer(),
5454
_densityRenderer(DensityRenderer::RenderMode::DENSITY),
@@ -65,7 +65,8 @@ ScatterplotWidget::ScatterplotWidget() :
6565
_pixelRatio(1.0),
6666
_mousePositions(),
6767
_isNavigating(false),
68-
_weightDensity(false)
68+
_weightDensity(false),
69+
_parentPlugin(parentPlugin)
6970
{
7071
setContextMenuPolicy(Qt::CustomContextMenu);
7172
setAcceptDrops(true);
@@ -152,19 +153,33 @@ bool ScatterplotWidget::event(QEvent* event)
152153
if (!event)
153154
return QOpenGLWidget::event(event);
154155

156+
auto setIsNavigating = [this](bool isNavigating) -> void {
157+
_isNavigating = isNavigating;
158+
_pixelSelectionTool.setEnabled(!isNavigating);
159+
if (isNavigating) {
160+
_samplerPixelSelectionTool.setEnabled(false);
161+
}
162+
else if (_parentPlugin) { // reset to UI-setting
163+
_samplerPixelSelectionTool.setEnabled(_parentPlugin->getSamplerAction().isEnabled());
164+
}
165+
166+
};
167+
155168
// Set navigation flag on Alt press/release
156-
if (event->type() == QEvent::KeyRelease)
157-
{
158-
if (const auto* keyEvent = static_cast<QKeyEvent*>(event))
159-
if (keyEvent->key() == Qt::Key_Alt)
160-
_isNavigating = false;
169+
if (event->type() == QEvent::KeyRelease) {
170+
if (const auto* keyEvent = static_cast<QKeyEvent*>(event)) {
171+
if (keyEvent->key() == Qt::Key_Alt) {
172+
setIsNavigating(false);
173+
}
174+
}
161175

162176
}
163-
else if (event->type() == QEvent::KeyPress)
164-
{
165-
if (const auto* keyEvent = static_cast<QKeyEvent*>(event))
166-
if (keyEvent->key() == Qt::Key_Alt)
167-
_isNavigating = true;
177+
else if (event->type() == QEvent::KeyPress) {
178+
if (const auto* keyEvent = static_cast<QKeyEvent*>(event)) {
179+
if (keyEvent->key() == Qt::Key_Alt) {
180+
setIsNavigating(true);
181+
}
182+
}
168183

169184
}
170185

@@ -192,7 +207,7 @@ bool ScatterplotWidget::event(QEvent* event)
192207
// Navigation
193208
if (mouseEvent->buttons() == Qt::LeftButton)
194209
{
195-
_pixelSelectionTool.setEnabled(false);
210+
setIsNavigating(true);
196211
setCursor(Qt::ClosedHandCursor);
197212
_mousePositions << mouseEvent->pos();
198213
update();
@@ -204,7 +219,7 @@ bool ScatterplotWidget::event(QEvent* event)
204219

205220
case QEvent::MouseButtonRelease:
206221
{
207-
_pixelSelectionTool.setEnabled(true);
222+
setIsNavigating(false);
208223
setCursor(Qt::ArrowCursor);
209224
_mousePositions.clear();
210225
update();

src/ScatterplotWidget.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@
1717
#include <QOpenGLWidget>
1818
#include <QPoint>
1919

20-
class ScatterplotPlugin;
21-
2220
using namespace mv::gui;
2321
using namespace mv::util;
2422

23+
namespace mv::plugin
24+
{
25+
class ViewPlugin;
26+
}
27+
2528
struct widgetSizeInfo {
2629
float width;
2730
float height;
@@ -49,7 +52,7 @@ class ScatterplotWidget : public QOpenGLWidget, protected QOpenGLFunctions_3_3_C
4952
};
5053

5154
public:
52-
ScatterplotWidget();
55+
ScatterplotWidget(mv::plugin::ViewPlugin* parentPlugin = nullptr);
5356

5457
~ScatterplotWidget();
5558

@@ -323,5 +326,7 @@ private slots:
323326
bool _isNavigating; /** Boolean determining whether view navigation is currently taking place or not */
324327
bool _weightDensity; /** Use point scalar sizes to weight density */
325328

329+
mv::plugin::ViewPlugin* _parentPlugin = nullptr;
330+
326331
friend class NavigationAction;
327332
};

0 commit comments

Comments
 (0)