Skip to content

Commit 48caa9f

Browse files
committed
Cache current dataset and handle dataChanged
Add a _currentDataset member to ScalarAction and wire up its dataChanged signal when a new source is selected. Previously connections could accumulate; the code now disconnects any existing dataset signal before connecting the new one and forwards updates via a lambda that calls sourceDataChanged(getCurrentDataset()). Also update several parameter names in comments for clarity (variantMap, sourceSelectionIndex, offset).
1 parent 227f92f commit 48caa9f

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/ScalarAction.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ ScalarAction::ScalarAction(QObject* parent, const QString& title, const float& m
3333
scatterplotPlugin->addNotification(QString("The number of points in the scalar source dataset does not match the number of points in the position dataset. (numPositions=%1, numScalars:%2)").arg(QString::number(numPositions), QString::number(numScalars)));
3434
}
3535
}
36+
37+
if (_currentDataset.isValid()) {
38+
disconnect(&_currentDataset, &Dataset<>::dataChanged, this, nullptr);
39+
}
40+
41+
connect(&_currentDataset, &Dataset<>::dataChanged, this, [this]() -> void {
42+
sourceDataChanged(getCurrentDataset());
43+
});
3644
}
3745

3846
if (emitSourceSelectionChanged)

src/ScalarAction.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class ScalarAction : public GroupAction
8181

8282
/**
8383
* Load widget action from variant map
84-
* @param Variant map representation of the widget action
84+
* @param variantMap Variant map representation of the widget action
8585
*/
8686
void fromVariantMap(const QVariantMap& variantMap) override;
8787

@@ -100,7 +100,7 @@ class ScalarAction : public GroupAction
100100

101101
/**
102102
* Signals that the source selection changed
103-
* @param sourceIndex Index of the selected source (0 is constant, 1 is selection, above is a dataset)
103+
* @param sourceSelectionIndex Index of the selected source (0 is constant, 1 is selection, above is a dataset)
104104
*/
105105
void sourceSelectionChanged(const std::uint32_t& sourceSelectionIndex);
106106

@@ -125,13 +125,14 @@ class ScalarAction : public GroupAction
125125

126126
/**
127127
* Signals that the scalar offset changed
128-
* @param magnitude Scalar magnitude
128+
* @param offset Scalar offset
129129
*/
130130
void offsetChanged(const float& offset);
131131

132132
private:
133133
DecimalAction _magnitudeAction; /** Scalar magnitude action */
134134
ScalarSourceAction _sourceAction; /** Scalar source action */
135+
Dataset<> _currentDataset; /** Cached current dataset (if any) */
135136

136137
friend class mv::AbstractActionsManager;
137138
};

0 commit comments

Comments
 (0)