Skip to content

Commit 8653ca8

Browse files
committed
Set point size and opacity same as color
Remove double call to addColorDataset
1 parent 797c7e8 commit 8653ca8

File tree

7 files changed

+57
-10
lines changed

7 files changed

+57
-10
lines changed

src/ColoringAction.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ Dataset<DatasetImpl> ColoringAction::getCurrentColorDataset() const
179179

180180
void ColoringAction::setCurrentColorDataset(const Dataset<DatasetImpl>& colorDataset)
181181
{
182+
if (!colorDataset.isValid())
183+
return;
184+
182185
addColorDataset(colorDataset);
183186

184187
const auto colorDatasetRowIndex = _colorByModel.rowIndex(colorDataset);

src/PointPlotAction.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,24 @@ void PointPlotAction::addPointOpacityDataset(const Dataset<DatasetImpl>& pointOp
210210
_opacityAction.addDataset(pointOpacityDataset);
211211
}
212212

213+
void PointPlotAction::setCurrentPointSizeDataset(const Dataset<DatasetImpl>& pointSizeDataset)
214+
{
215+
if (!pointSizeDataset.isValid())
216+
return;
217+
218+
addPointSizeDataset(pointSizeDataset);
219+
_sizeAction.setCurrentDataset(pointSizeDataset);
220+
}
221+
222+
void PointPlotAction::setCurrentPointOpacityDataset(const Dataset<DatasetImpl>& pointOpacityDataset)
223+
{
224+
if (!pointOpacityDataset.isValid())
225+
return;
226+
227+
addPointOpacityDataset(pointOpacityDataset);
228+
_opacityAction.setCurrentDataset(pointOpacityDataset);
229+
}
230+
213231
void PointPlotAction::updateDefaultDatasets()
214232
{
215233
if (_scatterplotPlugin == nullptr)

src/PointPlotAction.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ class PointPlotAction : public VerticalGroupAction
5858
*/
5959
void addPointOpacityDataset(const Dataset<DatasetImpl>& pointOpacityDataset);
6060

61+
/**
62+
* Set the current point size dataset
63+
* @param pointSizeDataset Smart pointer to point size dataset
64+
*/
65+
void setCurrentPointSizeDataset(const Dataset<DatasetImpl>& pointSizeDataset);
66+
67+
/**
68+
* Set the current opacity size dataset
69+
* @param pointOpacityDataset Smart pointer to opacity size dataset
70+
*/
71+
void setCurrentPointOpacityDataset(const Dataset<DatasetImpl>& pointOpacityDataset);
72+
6173
protected:
6274

6375
/** Update default datasets (candidates are children of points type and with matching number of points) */

src/ScalarAction.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ void ScalarAction::addDataset(const Dataset<DatasetImpl>& dataset)
3838
{
3939
auto& sourceModel = _sourceAction.getModel();
4040

41+
if (sourceModel.hasDataset(dataset))
42+
return;
43+
4144
sourceModel.addDataset(dataset);
4245

4346
connect(&sourceModel.getDatasets().last(), &Dataset<DatasetImpl>::dataChanged, this, [this, dataset]() {

src/ScalarSourceModel.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ QVariant ScalarSourceModel::data(const QModelIndex& index, int role) const
7474
if (row == DefaultRow::Selection)
7575
return "Selection";
7676
}
77+
78+
break;
7779
}
7880

7981
default:
@@ -86,7 +88,7 @@ QVariant ScalarSourceModel::data(const QModelIndex& index, int role) const
8688
void ScalarSourceModel::addDataset(const Dataset<DatasetImpl>& dataset)
8789
{
8890
// Avoid duplicates
89-
if (rowIndex(dataset) >= DefaultRow::DatasetStart)
91+
if (hasDataset(dataset))
9092
return;
9193

9294
// Insert row into model
@@ -127,6 +129,11 @@ void ScalarSourceModel::addDataset(const Dataset<DatasetImpl>& dataset)
127129
});
128130
}
129131

132+
bool ScalarSourceModel::hasDataset(const Dataset<DatasetImpl>& dataset) const
133+
{
134+
return rowIndex(dataset) >= DefaultRow::DatasetStart;
135+
}
136+
130137
void ScalarSourceModel::removeDataset(const Dataset<DatasetImpl>& dataset)
131138
{
132139
// Get row index of the dataset

src/ScalarSourceModel.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ class ScalarSourceModel : public QAbstractListModel
6565
*/
6666
void addDataset(const Dataset<DatasetImpl>& dataset);
6767

68+
/**
69+
* Determines whether a given dataset is already loaded
70+
* @param dataset Smart pointer to dataset
71+
* @return whether the dataset is already loaded
72+
*/
73+
bool hasDataset(const Dataset<DatasetImpl>& dataset) const;
74+
6875
/**
6976
* Remove a dataset
7077
* @param dataset Smart pointer to dataset

src/ScatterplotPlugin.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,22 +184,19 @@ ScatterplotPlugin::ScatterplotPlugin(const PluginFactory* factory) :
184184

185185
if (sameNumPoints || sameNumPointsAsFull) {
186186

187-
// The number of points is equal, so offer the option to use the points dataset as source for points colors
187+
// Offer the option to use the points dataset as source for points colors
188188
dropRegions << new DropWidget::DropRegion(this, "Point color", QString("Colorize %1 points with %2").arg(_positionDataset->text(), candidateDataset->text()), "palette", true, [this, candidateDataset]() {
189-
_settingsAction.getColoringAction().addColorDataset(candidateDataset);
190-
_settingsAction.getColoringAction().setCurrentColorDataset(candidateDataset);
189+
_settingsAction.getColoringAction().setCurrentColorDataset(candidateDataset); // calls addColorDataset internally
191190
});
192191

193-
// The number of points is equal, so offer the option to use the points dataset as source for points size
192+
// Offer the option to use the points dataset as source for points size
194193
dropRegions << new DropWidget::DropRegion(this, "Point size", QString("Size %1 points with %2").arg(_positionDataset->text(), candidateDataset->text()), "ruler-horizontal", true, [this, candidateDataset]() {
195-
_settingsAction.getPlotAction().getPointPlotAction().addPointSizeDataset(candidateDataset);
196-
_settingsAction.getPlotAction().getPointPlotAction().getSizeAction().setCurrentDataset(candidateDataset);
194+
_settingsAction.getPlotAction().getPointPlotAction().setCurrentPointSizeDataset(candidateDataset);
197195
});
198196

199-
// The number of points is equal, so offer the option to use the points dataset as source for points opacity
197+
// Offer the option to use the points dataset as source for points opacity
200198
dropRegions << new DropWidget::DropRegion(this, "Point opacity", QString("Set %1 points opacity with %2").arg(_positionDataset->text(), candidateDataset->text()), "brush", true, [this, candidateDataset]() {
201-
_settingsAction.getPlotAction().getPointPlotAction().addPointOpacityDataset(candidateDataset);
202-
_settingsAction.getPlotAction().getPointPlotAction().getOpacityAction().setCurrentDataset(candidateDataset);
199+
_settingsAction.getPlotAction().getPointPlotAction().setCurrentPointOpacityDataset(candidateDataset);
203200
});
204201
}
205202
}

0 commit comments

Comments
 (0)