diff --git a/GUI/Model/Data/RealDataModel.cpp b/GUI/Model/Data/RealDataModel.cpp index d5d4ffd694e079120fcf14a6fa0441ee98f932b7..54554179a723994a5627a150848a76029d569d45 100644 --- a/GUI/Model/Data/RealDataModel.cpp +++ b/GUI/Model/Data/RealDataModel.cpp @@ -98,6 +98,14 @@ void RealDataModel::remove(RealDataItem* item) removeItem(item); } +QStringList RealDataModel::realDataNames() const +{ + QStringList result; + for (auto item : realDataItems()) + result.append(item->itemName()); + return result; +} + void RealDataModel::onRowsChange(const QModelIndex& parent, int, int) { // valid parent means not a data (which is top level item) but something below diff --git a/GUI/Model/Data/RealDataModel.h b/GUI/Model/Data/RealDataModel.h index 9356dbc065d57e3c4123fa991cc46a0848d54179..c8df8eaa248b4472b895b026d73994df59485c35 100644 --- a/GUI/Model/Data/RealDataModel.h +++ b/GUI/Model/Data/RealDataModel.h @@ -41,6 +41,8 @@ public: void remove(RealDataItem* item); + QStringList realDataNames() const; + signals: void realDataAddedOrRemoved(); diff --git a/GUI/Model/From/SampleListModel.cpp b/GUI/Model/From/SampleListModel.cpp index 2be7e27509eef29b0e4a5900494a2ac4220ab706..49ea321ab7f3b13fac29fe01a0152ee360ec535b 100644 --- a/GUI/Model/From/SampleListModel.cpp +++ b/GUI/Model/From/SampleListModel.cpp @@ -126,12 +126,12 @@ void SampleListModel::removeSample(MultiLayerItem* item) QModelIndex SampleListModel::createSample() { - using namespace GUI::Model::ItemUtils; + const QStringList existingNames = m_sampleModel->multiLayerNames(); const int row = m_sampleModel->multiLayerItems().size(); beginInsertRows(QModelIndex(), row, row); auto* multilayer_item = m_sampleModel->addMultiLayer(); - multilayer_item->setSampleName(suggestName(topItemNames(m_sampleModel), "Sample")); + multilayer_item->setSampleName(GUI::Model::ItemUtils::suggestName(existingNames, "Sample")); endInsertRows(); return indexForItem(multilayer_item); } diff --git a/GUI/Model/Instrument/InstrumentModel.cpp b/GUI/Model/Instrument/InstrumentModel.cpp index 3ccfd10f486e8a3c8ac8f7740df6807b118466fa..cac494dda7739ed926f92c0b74000d5d34f3463e 100644 --- a/GUI/Model/Instrument/InstrumentModel.cpp +++ b/GUI/Model/Instrument/InstrumentModel.cpp @@ -100,10 +100,17 @@ QVector<InstrumentItem*> InstrumentModel::instrumentItems() const return topItems<InstrumentItem>(); } +QStringList InstrumentModel::instrumentNames() const +{ + QStringList existingNames; + for (const auto* item : instrumentItems()) + existingNames << item->instrumentName(); + return existingNames; +} + QString InstrumentModel::suggestInstrumentName(const QString& baseName) const { - using namespace GUI::Model::ItemUtils; - return suggestName(topItemNames(this), baseName); + return GUI::Model::ItemUtils::suggestName(instrumentNames(), baseName); } QVector<InstrumentItem*> diff --git a/GUI/Model/Instrument/InstrumentModel.h b/GUI/Model/Instrument/InstrumentModel.h index 66e71cd7fdd91c6fa06d06154faec20ad7f15870..7dd9a8cdd80212a31389d55044ed51d3268e96f6 100644 --- a/GUI/Model/Instrument/InstrumentModel.h +++ b/GUI/Model/Instrument/InstrumentModel.h @@ -49,6 +49,8 @@ public: QVector<InstrumentItem*> instrumentItems(std::function<bool(const InstrumentItem*)> accept) const; + QStringList instrumentNames() const; + signals: void instrumentAddedOrRemoved(); void instrumentNameChanged(const InstrumentItem* instrument); diff --git a/GUI/Model/Sample/SampleModel.cpp b/GUI/Model/Sample/SampleModel.cpp index 001bc665d0f1705807ec4d67dc501effeab27508..57c09de0089f5f5b73d6e33bae9aed7ee48d05e1 100644 --- a/GUI/Model/Sample/SampleModel.cpp +++ b/GUI/Model/Sample/SampleModel.cpp @@ -60,6 +60,14 @@ void SampleModel::removeMultiLayer(MultiLayerItem* item) emit sampleAddedOrRemoved(); } +QStringList SampleModel::multiLayerNames() const +{ + QStringList existingNames; + for (const auto* item : multiLayerItems()) + existingNames << item->sampleName(); + return existingNames; +} + void SampleModel::onDataChanged(const QModelIndex& index, const QModelIndex&) { // check whether it's an item, then emit the relevant signal diff --git a/GUI/Model/Sample/SampleModel.h b/GUI/Model/Sample/SampleModel.h index d310ed74fcfa3dbb0330535acdd6e28cfe0dbb79..335e8cfe96e0dbe8cb3cff697e977569d9ce0573 100644 --- a/GUI/Model/Sample/SampleModel.h +++ b/GUI/Model/Sample/SampleModel.h @@ -38,6 +38,8 @@ public: MultiLayerItem* addMultiLayer(); void removeMultiLayer(MultiLayerItem* item); + QStringList multiLayerNames() const; + signals: //! This signal is emitted if any item data changed (compare to //! QAbstractItemModel::dataChanged). diff --git a/GUI/View/Toplevel/SimulationView.cpp b/GUI/View/Toplevel/SimulationView.cpp index d9e39265eed55218748df693a801c9fc1902843d..01ee666ee71832fb329848e4ed7c578c3176d776 100644 --- a/GUI/View/Toplevel/SimulationView.cpp +++ b/GUI/View/Toplevel/SimulationView.cpp @@ -120,9 +120,9 @@ void SimulationView::writeOptionsToUI() // -- selection group using GUI::Model::ItemUtils::itemNames; - updateSelection(m_ui->instrumentCombo, itemNames(instrumentItems())); - updateSelection(m_ui->sampleCombo, sampleNames(multiLayerItems())); - updateSelection(m_ui->realDataCombo, itemNames(realDataItems()), true); + updateSelection(m_ui->instrumentCombo, m_document->instrumentModel()->instrumentNames()); + updateSelection(m_ui->sampleCombo, m_document->sampleModel()->multiLayerNames()); + updateSelection(m_ui->realDataCombo, m_document->realDataModel()->realDataNames(), true); // -- options group optionsItem()->runImmediately() ? m_ui->runPolicyImmediatelyRadio->setChecked(true)