Skip to content

Commit e4e5170

Browse files
committed
Refactor scalar source model and update ScalarAction
Convert ScalarSourceModel from QAbstractListModel to QStandardItemModel and introduce typed row items (NameItem, IdItem, Item) and a two-column layout (Name/ID). Datasets are now stored as rows (with helper Row class) and looked up by dataset ID via matching; getDatasets(), getDataset(), add/remove dataset and removeAllDatasets were adapted accordingly. Added getRowIndex() and removed the old per-dataset vector/updateData machinery. Update GUI data handling into Item/NameItem/IdItem (decoration, display and tooltip roles) and connect GUI name changes to emit updates. In ScalarAction: use getRowIndex() instead of rowIndex(), changed setCurrentSourceIndex parameter to std::int32_t, simplified getCurrentDataset() return, and left a TODO-commented dataset connection block. These changes centralize model data in QStandardItem rows, enable multi-column metadata, and simplify dataset lookup/removal by ID.
1 parent e58acaa commit e4e5170

File tree

4 files changed

+308
-164
lines changed

4 files changed

+308
-164
lines changed

src/ScalarAction.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ void ScalarAction::addDataset(const Dataset<DatasetImpl>& dataset)
4343

4444
sourceModel.addDataset(dataset);
4545

46+
/* TODO: this connection is not removed when the dataset is removed from the model, but that should not cause any issues since the dataset will be invalid and the connection will not do anything in that case
4647
connect(&sourceModel.getDatasets().last(), &Dataset<DatasetImpl>::dataChanged, this, [this, dataset]() {
4748
const auto currentDataset = getCurrentDataset();
4849
@@ -55,6 +56,8 @@ void ScalarAction::addDataset(const Dataset<DatasetImpl>& dataset)
5556
emit sourceDataChanged(dataset);
5657
});
5758
59+
*/
60+
5861
connect(&_magnitudeAction, &DecimalAction::valueChanged, this, [this, dataset](const float& value) {
5962
emit magnitudeChanged(value);
6063
});
@@ -72,20 +75,20 @@ Dataset<DatasetImpl> ScalarAction::getCurrentDataset()
7275
const auto currentSourceIndex = _sourceAction.getPickerAction().getCurrentIndex();
7376

7477
if (currentSourceIndex < ScalarSourceModel::DefaultRow::DatasetStart)
75-
return Dataset<DatasetImpl>();
78+
return {};
7679

7780
return scalarSourceModel.getDataset(currentSourceIndex);
7881
}
7982

8083
void ScalarAction::setCurrentDataset(const Dataset<DatasetImpl>& dataset)
8184
{
82-
const auto datasetRowIndex = _sourceAction.getModel().rowIndex(dataset);
85+
const auto datasetRowIndex = _sourceAction.getModel().getRowIndex(dataset);
8386

8487
if (datasetRowIndex >= 0)
8588
_sourceAction.getPickerAction().setCurrentIndex(datasetRowIndex);
8689
}
8790

88-
void ScalarAction::setCurrentSourceIndex(bool sourceIndex)
91+
void ScalarAction::setCurrentSourceIndex(std::int32_t sourceIndex)
8992
{
9093
_sourceAction.getPickerAction().setCurrentIndex(sourceIndex);
9194
}

src/ScalarAction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class ScalarAction : public GroupAction
5151
* Set the current source index
5252
* @param sourceIndex Source index
5353
*/
54-
void setCurrentSourceIndex(bool sourceIndex);
54+
void setCurrentSourceIndex(std::int32_t sourceIndex);
5555

5656
/** Determines whether the scalar source is a constant */
5757
bool isSourceConstant() const;

0 commit comments

Comments
 (0)