diff --git a/GUI/Model/Device/InstrumentCollection.cpp b/GUI/Model/Device/InstrumentCollection.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cf76bc5332db4b08c11d5e37e3bd90fb016bad76 --- /dev/null +++ b/GUI/Model/Device/InstrumentCollection.cpp @@ -0,0 +1,104 @@ +// ************************************************************************************************ +// +// BornAgain: simulate and fit reflection and scattering +// +//! @file GUI/Model/Device/InstrumentCollection.cpp +//! @brief Implement class InstrumentCollection +//! +//! @homepage http://www.bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2018 +//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) +// +// ************************************************************************************************ + +#include "GUI/Model/Device/InstrumentCollection.h" +#include "GUI/Model/Device/InstrumentItems.h" +#include "GUI/Model/CatDevice/InstrumentItemCatalog.h" +#include "GUI/Model/Data/RealDataItem.h" +#include "GUI/Support/XML/Serialize.h" +#include "GUI/Util/String.h" + +InstrumentCollection::~InstrumentCollection() +{ + qDeleteAll(m_instruments); +} + +void InstrumentCollection::clear() +{ + qDeleteAll(m_instruments); + m_instruments.clear(); +} + +void InstrumentCollection::serialize(Streamer& s) +{ + s.assertVersion(0); + Serialize::rwCatalogized<InstrumentItemCatalog>(s, "InstrumentCollection", m_instruments); +} + +InstrumentItem* InstrumentCollection::insertCopy(const InstrumentItem& source) +{ + auto* copy = source.createCopy(); + copy->setId(QUuid::createUuid().toString()); + m_instruments << copy; + return copy; +} + +QVector<InstrumentItem*> InstrumentCollection::collectedItems() const +{ + return m_instruments; +} + +QStringList InstrumentCollection::instrumentNames() const +{ + QStringList existingNames; + for (const auto* item : collectedItems()) + existingNames << item->instrumentName(); + return existingNames; +} + +QString InstrumentCollection::suggestInstrumentName(const QString& baseName) const +{ + return GUI::Util::String::suggestName(instrumentNames(), baseName); +} + +QVector<InstrumentItem*> InstrumentCollection::instrumentItems( + const std::function<bool(const InstrumentItem*)>& accept) const +{ + QVector<InstrumentItem*> result; + for (auto* p : collectedItems()) + if (accept(p)) + result << p; + + return result; +} + +QVector<Instrument2DItem*> InstrumentCollection::instrument2DItems() const +{ + QVector<Instrument2DItem*> result; + for (auto* p : collectedItems()) + if (auto* p2D = dynamic_cast<Instrument2DItem*>(p)) + result << p2D; + + return result; +} + +InstrumentItem* InstrumentCollection::findInstrumentById(const QString& instrumentId) const +{ + for (auto* instrument : collectedItems()) + if (instrument->id() == instrumentId) + return instrument; + + return nullptr; +} + +bool InstrumentCollection::instrumentExists(const QString& instrumentId) const +{ + return findInstrumentById(instrumentId) != nullptr; +} + +void InstrumentCollection::removeInstrument(InstrumentItem* instrument) +{ + m_instruments.removeAll(instrument); + delete instrument; +} diff --git a/GUI/Model/Device/InstrumentCollection.h b/GUI/Model/Device/InstrumentCollection.h new file mode 100644 index 0000000000000000000000000000000000000000..0e548e9eebf02eac30be081d98798be6e5e392a8 --- /dev/null +++ b/GUI/Model/Device/InstrumentCollection.h @@ -0,0 +1,64 @@ +// ************************************************************************************************ +// +// BornAgain: simulate and fit reflection and scattering +// +//! @file GUI/Model/Device/InstrumentCollection.h +//! @brief Defines class InstrumentCollection +//! +//! @homepage http://www.bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2018 +//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) +// +// ************************************************************************************************ + +#ifndef BORNAGAIN_GUI_MODEL_DEVICE_INSTRUMENTCOLLECTION_H +#define BORNAGAIN_GUI_MODEL_DEVICE_INSTRUMENTCOLLECTION_H + +#include <functional> +#include <memory> +#include <QStringList> +#include <QVector> + +class InstrumentItem; +class Instrument2DItem; +class Streamer; + +class InstrumentCollection { +public: + ~InstrumentCollection(); + + template <typename T> + T* addInstrument() + { + auto* t = new T(); + m_instruments << t; + return t; + } + + void removeInstrument(InstrumentItem* instrument); + void clear(); + + void serialize(Streamer& s); + + //! Inserts a deep copy (also of any non xml data in a pointwise axis) + //! The id will not be copied, but a new unique one will be created + //! Returns the newly created instrument. + InstrumentItem* insertCopy(const InstrumentItem& source); + + QVector<InstrumentItem*> collectedItems() const; + QVector<Instrument2DItem*> instrument2DItems() const; + QVector<InstrumentItem*> + instrumentItems(const std::function<bool(const InstrumentItem*)>& accept) const; + + InstrumentItem* findInstrumentById(const QString& instrumentId) const; + bool instrumentExists(const QString& instrumentId) const; + + QString suggestInstrumentName(const QString& baseName) const; + QStringList instrumentNames() const; + +private: + QVector<InstrumentItem*> m_instruments; +}; + +#endif // BORNAGAIN_GUI_MODEL_DEVICE_INSTRUMENTCOLLECTION_H diff --git a/GUI/Model/Device/InstrumentItems.cpp b/GUI/Model/Device/InstrumentItems.cpp index 5dd22d18a40f778957747741bbf0d9b3a0436574..25ce327684063e7981c4f9514888ef0588a08030 100644 --- a/GUI/Model/Device/InstrumentItems.cpp +++ b/GUI/Model/Device/InstrumentItems.cpp @@ -491,91 +491,3 @@ ICoordSystem* OffspecInstrumentItem::createCoordSystem() const const auto instrument = createInstrument(); return instrument->detector().offspecCoords(alphaAxis, instrument->beam().direction()); } - -// ************************************************************************************************ -// class InstrumentItems -// ************************************************************************************************ - -InstrumentItems::~InstrumentItems() -{ - qDeleteAll(m_instruments); -} - -void InstrumentItems::clear() -{ - qDeleteAll(m_instruments); - m_instruments.clear(); -} - -void InstrumentItems::serialize(Streamer& s) -{ - s.assertVersion(0); - Serialize::rwCatalogized<InstrumentItemCatalog>(s, "InstrumentItems", m_instruments); -} - -InstrumentItem* InstrumentItems::insertCopy(const InstrumentItem& source) -{ - auto* copy = source.createCopy(); - copy->setId(QUuid::createUuid().toString()); - m_instruments << copy; - return copy; -} - -QVector<InstrumentItem*> InstrumentItems::instrumentItems() const -{ - return m_instruments; -} - -QStringList InstrumentItems::instrumentNames() const -{ - QStringList existingNames; - for (const auto* item : instrumentItems()) - existingNames << item->instrumentName(); - return existingNames; -} - -QString InstrumentItems::suggestInstrumentName(const QString& baseName) const -{ - return GUI::Util::String::suggestName(instrumentNames(), baseName); -} - -QVector<InstrumentItem*> -InstrumentItems::instrumentItems(const std::function<bool(const InstrumentItem*)>& accept) const -{ - QVector<InstrumentItem*> result; - for (auto* p : instrumentItems()) - if (accept(p)) - result << p; - - return result; -} - -QVector<Instrument2DItem*> InstrumentItems::instrument2DItems() const -{ - QVector<Instrument2DItem*> result; - for (auto* p : instrumentItems()) - if (auto* p2D = dynamic_cast<Instrument2DItem*>(p)) - result << p2D; - - return result; -} - -InstrumentItem* InstrumentItems::findInstrumentById(const QString& instrumentId) const -{ - for (auto* instrument : instrumentItems()) - if (instrument->id() == instrumentId) - return instrument; - - return nullptr; -} - -bool InstrumentItems::instrumentExists(const QString& instrumentId) const -{ - return findInstrumentById(instrumentId) != nullptr; -} - -void InstrumentItems::removeInstrument(InstrumentItem* instrument) -{ - m_instruments.removeAll(instrument); - delete instrument; -} diff --git a/GUI/Model/Device/InstrumentItems.h b/GUI/Model/Device/InstrumentItems.h index e728afdccd2a41af33818aa3390c9bd34c06bbec..847f4920efad13692725cd6d8b680e101845e813 100644 --- a/GUI/Model/Device/InstrumentItems.h +++ b/GUI/Model/Device/InstrumentItems.h @@ -216,41 +216,4 @@ T* Instrument2DItem::setDetectorType() return dynamic_cast<T*>(m_detectorItem.get()); } -class InstrumentItems { -public: - ~InstrumentItems(); - - template <typename T> - T* addInstrument() - { - auto* t = new T(); - m_instruments << t; - return t; - } - - void removeInstrument(InstrumentItem* instrument); - void clear(); - - void serialize(Streamer& s); - - //! Inserts a deep copy (also of any non xml data in a pointwise axis) - //! The id will not be copied, but a new unique one will be created - //! Returns the newly created instrument. - InstrumentItem* insertCopy(const InstrumentItem& source); - - QVector<InstrumentItem*> instrumentItems() const; - QVector<Instrument2DItem*> instrument2DItems() const; - QVector<InstrumentItem*> - instrumentItems(const std::function<bool(const InstrumentItem*)>& accept) const; - - InstrumentItem* findInstrumentById(const QString& instrumentId) const; - bool instrumentExists(const QString& instrumentId) const; - - QString suggestInstrumentName(const QString& baseName) const; - QStringList instrumentNames() const; - -private: - QVector<InstrumentItem*> m_instruments; -}; - #endif // BORNAGAIN_GUI_MODEL_DEVICE_INSTRUMENTITEMS_H diff --git a/GUI/Model/Device/InstrumentLibrary.cpp b/GUI/Model/Device/InstrumentLibrary.cpp index ab6a051fd83700df81e6aac509d51f41f800b1b0..569c87708bfe1b137834d7e02296ca1346dafb26 100644 --- a/GUI/Model/Device/InstrumentLibrary.cpp +++ b/GUI/Model/Device/InstrumentLibrary.cpp @@ -55,12 +55,12 @@ InstrumentItem* InstrumentLibrary::add(const QString& name, const InstrumentItem bool InstrumentLibrary::isEmpty() const { - return m_instrumentItems.instrumentItems().isEmpty(); + return m_instrumentItems.collectedItems().isEmpty(); } -QList<InstrumentItem*> InstrumentLibrary::instrumentItems() const +QList<InstrumentItem*> InstrumentLibrary::collectedItems() const { - return m_instrumentItems.instrumentItems().toList(); + return m_instrumentItems.collectedItems().toList(); } InstrumentsEditController* InstrumentLibrary::editController() @@ -137,7 +137,7 @@ bool InstrumentLibrary::load() } } -InstrumentItems* InstrumentLibrary::instrumentItems() +InstrumentCollection* InstrumentLibrary::collectedItems() { return &m_instrumentItems; } diff --git a/GUI/Model/Device/InstrumentLibrary.h b/GUI/Model/Device/InstrumentLibrary.h index dc9bdfb9ac7dc871c19320cde61257ec3d65ef7a..ab18678354e830e5dd7851ab2beb283a32680c63 100644 --- a/GUI/Model/Device/InstrumentLibrary.h +++ b/GUI/Model/Device/InstrumentLibrary.h @@ -15,7 +15,7 @@ #ifndef BORNAGAIN_GUI_MODEL_DEVICE_INSTRUMENTLIBRARY_H #define BORNAGAIN_GUI_MODEL_DEVICE_INSTRUMENTLIBRARY_H -#include "GUI/Model/Device/InstrumentItems.h" +#include "GUI/Model/Device/InstrumentCollection.h" #include "GUI/Model/Device/InstrumentsEditController.h" class InstrumentLibrary { @@ -27,17 +27,17 @@ public: //! Returns the new element InstrumentItem* add(const QString& name, const InstrumentItem& itemToCopy); bool isEmpty() const; - QList<InstrumentItem*> instrumentItems() const; + QList<InstrumentItem*> collectedItems() const; bool saveIfModified(); bool load(); - InstrumentItems* instrumentItems(); + InstrumentCollection* collectedItems(); InstrumentsEditController* editController(); private: - InstrumentItems m_instrumentItems; + InstrumentCollection m_instrumentItems; InstrumentsEditController m_ec; bool m_modified; }; diff --git a/GUI/Model/Device/InstrumentsEditController.cpp b/GUI/Model/Device/InstrumentsEditController.cpp index 9b46bb344c954f91d337faa965e304d7ef7548d0..a2952fd56a62e229b642ee79955f473b66ba07e6 100644 --- a/GUI/Model/Device/InstrumentsEditController.cpp +++ b/GUI/Model/Device/InstrumentsEditController.cpp @@ -15,12 +15,12 @@ #include "GUI/Model/Device/InstrumentsEditController.h" #include "GUI/Model/Device/InstrumentItems.h" -InstrumentsEditController::InstrumentsEditController(InstrumentItems* instruments) +InstrumentsEditController::InstrumentsEditController(InstrumentCollection* instruments) : m_instruments(instruments) { } -InstrumentItems* InstrumentsEditController::instrumentItems() +InstrumentCollection* InstrumentsEditController::collectedItems() { return m_instruments; } diff --git a/GUI/Model/Device/InstrumentsEditController.h b/GUI/Model/Device/InstrumentsEditController.h index 684c5ef26ba827c7085aaf0272e5b64256ccba41..38b553f50151357d4d57172b6cb2c1f33f2414f9 100644 --- a/GUI/Model/Device/InstrumentsEditController.h +++ b/GUI/Model/Device/InstrumentsEditController.h @@ -15,9 +15,10 @@ #ifndef BORNAGAIN_GUI_MODEL_DEVICE_INSTRUMENTSEDITCONTROLLER_H #define BORNAGAIN_GUI_MODEL_DEVICE_INSTRUMENTSEDITCONTROLLER_H -#include "GUI/Model/Device/InstrumentItems.h" +#include "GUI/Model/Device/InstrumentCollection.h" #include <QObject> +class InstrumentCollection; class InstrumentItem; class RealDataItem; @@ -40,10 +41,10 @@ class InstrumentsEditController : public QObject { Q_OBJECT public: - InstrumentsEditController(InstrumentItems* instruments); + InstrumentsEditController(InstrumentCollection* instruments); //! The list of existing instruments. - InstrumentItems* instrumentItems(); + InstrumentCollection* collectedItems(); //! Add an instrument and emit the respective signal. template <typename T> @@ -82,8 +83,8 @@ signals: void instrumentNameChanged(const InstrumentItem* instrument); private: - InstrumentItems* m_instruments; //!< The edited/controlled instruments. This pointer is - //!< borrowed, not owned. + InstrumentCollection* m_instruments; //!< The edited/controlled instruments. This pointer is + //!< borrowed, not owned. }; template <typename T> diff --git a/GUI/Model/FromDomain/GUIObjectBuilder.cpp b/GUI/Model/FromDomain/GUIObjectBuilder.cpp index c093ec916b795fab86b92b948bfca75d0090df27..666695dc66dd0bf0459057318acc41c51ad08482 100644 --- a/GUI/Model/FromDomain/GUIObjectBuilder.cpp +++ b/GUI/Model/FromDomain/GUIObjectBuilder.cpp @@ -15,6 +15,7 @@ #include "GUI/Model/FromDomain/GUIObjectBuilder.h" #include "Base/Const/Units.h" #include "Base/Util/Assert.h" +#include "GUI/Model/Device/InstrumentCollection.h" #include "GUI/Model/Device/InstrumentItems.h" #include "GUI/Model/FromDomain/FromDomain.h" #include "GUI/Model/FromDomain/GUISampleBuilder.h" @@ -24,7 +25,7 @@ namespace { -GISASInstrumentItem* createGISASInstrumentItem(InstrumentItems* model, +GISASInstrumentItem* createGISASInstrumentItem(InstrumentCollection* model, const ScatteringSimulation& simulation) { auto* result = model->addInstrument<GISASInstrumentItem>(); @@ -35,7 +36,7 @@ GISASInstrumentItem* createGISASInstrumentItem(InstrumentItems* model, return result; } -OffspecInstrumentItem* createOffspecInstrumentItem(InstrumentItems* model, +OffspecInstrumentItem* createOffspecInstrumentItem(InstrumentCollection* model, const OffspecSimulation& simulation) { auto* result = model->addInstrument<OffspecInstrumentItem>(); @@ -51,7 +52,7 @@ OffspecInstrumentItem* createOffspecInstrumentItem(InstrumentItems* model, return result; } -SpecularInstrumentItem* createSpecularInstrumentItem(InstrumentItems* model, +SpecularInstrumentItem* createSpecularInstrumentItem(InstrumentCollection* model, const SpecularSimulation& simulation) { auto* result = model->addInstrument<SpecularInstrumentItem>(); @@ -67,9 +68,10 @@ SpecularInstrumentItem* createSpecularInstrumentItem(InstrumentItems* model, // class implementation // ************************************************************************************************ -InstrumentItems* GUI::Transform::FromDomain::createInstrumentItems(const ISimulation& simulation) +InstrumentCollection* +GUI::Transform::FromDomain::createInstrumentCollection(const ISimulation& simulation) { - auto* result = new InstrumentItems; + auto* result = new InstrumentCollection; if (const auto* gisasSimulation = dynamic_cast<const ScatteringSimulation*>(&simulation)) createGISASInstrumentItem(result, *gisasSimulation); @@ -83,8 +85,8 @@ InstrumentItems* GUI::Transform::FromDomain::createInstrumentItems(const ISimula return result; } -SimulationOptionsItem* GUI::Transform::FromDomain::createSimulationOptions( - const ISimulation& simulation) +SimulationOptionsItem* +GUI::Transform::FromDomain::createSimulationOptions(const ISimulation& simulation) { auto* result = new SimulationOptionsItem; diff --git a/GUI/Model/FromDomain/GUIObjectBuilder.h b/GUI/Model/FromDomain/GUIObjectBuilder.h index 3ae5f4722e4a651b2d678c19eb2385597da8c9cb..521feadb5dd0f87dc63086155d1d65af2d194e67 100644 --- a/GUI/Model/FromDomain/GUIObjectBuilder.h +++ b/GUI/Model/FromDomain/GUIObjectBuilder.h @@ -17,13 +17,13 @@ class SimulationOptionsItem; class ISimulation; -class InstrumentItems; +class InstrumentCollection; //! Contains set of methods to populate GUI models with content from domain. namespace GUI::Transform::FromDomain { -InstrumentItems* createInstrumentItems(const ISimulation& simulation); +InstrumentCollection* createInstrumentCollection(const ISimulation& simulation); SimulationOptionsItem* createSimulationOptions(const ISimulation& simulation); diff --git a/GUI/Model/FromDomain/GUISampleBuilder.cpp b/GUI/Model/FromDomain/GUISampleBuilder.cpp index c593a8845762a99651b8060920a8820651900327..7c1c3cfc77fbe9ab985182182c0aba86d46a2439 100644 --- a/GUI/Model/FromDomain/GUISampleBuilder.cpp +++ b/GUI/Model/FromDomain/GUISampleBuilder.cpp @@ -69,7 +69,7 @@ void copyParticleItem(ParticleItem* particleItem, MaterialItems& matItems, const } void copyParticle(const IParticle* iparticle, MaterialItems& matItems, - std::function<void(ItemWithParticles*)> addToParent) + std::function<void(ItemWithParticles*)> addToParent) { if (const auto* particle = dynamic_cast<const Particle*>(iparticle)) { auto* particle_item = new ParticleItem(&matItems); @@ -121,8 +121,8 @@ void copyParticle(const IParticle* iparticle, MaterialItems& matItems, particleCompositionItem->setAbundance(particleComposition->abundance()); particleCompositionItem->setPosition(particleComposition->particlePosition()); - GUI::Transform::FromDomain::setRotation( - particleCompositionItem, particleComposition->rotation()); + GUI::Transform::FromDomain::setRotation(particleCompositionItem, + particleComposition->rotation()); addToParent(particleCompositionItem); for (const auto* p : particleComposition->particles()) @@ -139,7 +139,7 @@ MultiLayerItem* createMultiLayerItem(const MultiLayer& sample, const QString& no { auto* result = new MultiLayerItem(); result->setSampleName(nodeName.isEmpty() ? QString::fromStdString(sample.sampleName()) - : nodeName); + : nodeName); result->crossCorrLength().set(sample.crossCorrLength()); result->setExternalField(sample.externalField()); diff --git a/GUI/Model/Model/ApplicationModels.h b/GUI/Model/Model/ApplicationModels.h index 7251cff5a4b81c3b0c664beac3bcf8f5e8fa6c4e..aafdd6743450ac0ae179058e93e50eb776bf48e4 100644 --- a/GUI/Model/Model/ApplicationModels.h +++ b/GUI/Model/Model/ApplicationModels.h @@ -20,7 +20,7 @@ class SessionModel; class SessionItem; class DocumentModel; -class InstrumentItems; +class InstrumentCollection; class RealDataModel; class JobModel; class MessageService; diff --git a/GUI/Model/Project/LinkInstrumentManager.cpp b/GUI/Model/Project/LinkInstrumentManager.cpp index 0206686dd1eab09afbc09b2c6e98915a398b1c67..d266b5d03842d9b933e752c07f6977c831167715 100644 --- a/GUI/Model/Project/LinkInstrumentManager.cpp +++ b/GUI/Model/Project/LinkInstrumentManager.cpp @@ -79,7 +79,7 @@ LinkInstrumentManager::LinkInstrumentManager(ProjectDocument* document) bool LinkInstrumentManager::canLinkDataToInstrument(const RealDataItem* realDataItem, const QString& identifier, QWidget* parent) { - auto* instrumentItem = m_document->instrumentItems()->findInstrumentById(identifier); + auto* instrumentItem = m_document->collectedItems()->findInstrumentById(identifier); // linking to null instrument is possible, it means unlinking from currently linked if (!instrumentItem) @@ -131,6 +131,6 @@ void LinkInstrumentManager::onInstrumentAddedOrRemoved() { // remove links in realDataItems (in case of a linked instrument was removed) for (auto* realDataItem : m_document->realDataModel()->realDataItems()) - if (!m_document->instrumentItems()->instrumentExists(realDataItem->instrumentId())) + if (!m_document->collectedItems()->instrumentExists(realDataItem->instrumentId())) realDataItem->unlinkFromInstrument(); } diff --git a/GUI/Model/Project/LinkInstrumentManager.h b/GUI/Model/Project/LinkInstrumentManager.h index 26585eaf04185b8a51ccf826c6b64312618b3835..a99362a66ae5d0b3c137f7bd0089f2d661359ba1 100644 --- a/GUI/Model/Project/LinkInstrumentManager.h +++ b/GUI/Model/Project/LinkInstrumentManager.h @@ -24,7 +24,7 @@ class InstrumentItem; class RealDataItem; class ProjectDocument; -//! The LinkInstrumentManager class provides communication between InstrumentItems and +//! The LinkInstrumentManager class provides communication between InstrumentCollection and //! RealDataModel. Particularly, it notifies RealDataItem about changes in linked instruments //! to adjust axes of IntensityDataItem. diff --git a/GUI/Model/Project/ProjectDocument.cpp b/GUI/Model/Project/ProjectDocument.cpp index 632eb5205e22b097ff2ee18ce1996d33c9a5891f..8d954ca9b76dd1b6ab8af671c34740aa3d384540 100644 --- a/GUI/Model/Project/ProjectDocument.cpp +++ b/GUI/Model/Project/ProjectDocument.cpp @@ -123,9 +123,9 @@ void ProjectDocument::setProjectFileName(const QString& projectFileName) setProjectDir(GUI::Project::Utils::projectDir(projectFileName)); } -InstrumentItems* ProjectDocument::instrumentItems() const +InstrumentCollection* ProjectDocument::collectedItems() const { - return const_cast<InstrumentItems*>(&m_instruments); + return const_cast<InstrumentCollection*>(&m_instruments); } MultiLayerItems* ProjectDocument::sampleItems() diff --git a/GUI/Model/Project/ProjectDocument.h b/GUI/Model/Project/ProjectDocument.h index 01123beca5c062a6cef6b3c2ffade87bfb69208c..34206bea9218f6d96004d5fbbfd5a836d4d049a6 100644 --- a/GUI/Model/Project/ProjectDocument.h +++ b/GUI/Model/Project/ProjectDocument.h @@ -70,7 +70,7 @@ public: QString projectFileName() const; void setProjectFileName(const QString& projectFileName); - InstrumentItems* instrumentItems() const; + InstrumentCollection* collectedItems() const; MultiLayerItems* sampleItems(); RealDataModel* realDataModel() const; JobModel* jobModel() const; @@ -145,7 +145,7 @@ private: SimulationOptionsItem m_simulationOptionsItem; MultiLayerItems m_sampleItems; InstrumentsEditController m_instrumentEditController; - InstrumentItems m_instruments; + InstrumentCollection m_instruments; }; Q_DECLARE_OPERATORS_FOR_FLAGS(ProjectDocument::Functionalities) diff --git a/GUI/View/Import/RealDataPropertiesWidget.cpp b/GUI/View/Import/RealDataPropertiesWidget.cpp index 0c622207e042f0b5e693bbd7f66f3ba20f437033..85605fbed1f5d22b388d873ab0eb9b24d578f6d3 100644 --- a/GUI/View/Import/RealDataPropertiesWidget.cpp +++ b/GUI/View/Import/RealDataPropertiesWidget.cpp @@ -83,7 +83,7 @@ void RealDataPropertiesWidget::onInstrumentComboIndexChanged(int /*index*/) if (m_document->linkInstrumentManager()->canLinkDataToInstrument( m_currentDataItem, newSelectedInstrumentId, GUI::Global::mainWindow)) { const auto* newSelectedInstrument = - m_document->instrumentItems()->findInstrumentById(newSelectedInstrumentId); + m_document->collectedItems()->findInstrumentById(newSelectedInstrumentId); m_currentDataItem->linkToInstrument(newSelectedInstrument); } else // Linking was impossible or denied. Set combo to previous state @@ -101,7 +101,7 @@ void RealDataPropertiesWidget::updateInstrumentComboEntries() // fill the combo. Userdata contains instrument's uid m_instrumentCombo->addItem("Undefined", ""); // undefined instrument - for (auto* instrumentItem : m_document->instrumentItems()->instrumentItems()) + for (auto* instrumentItem : m_document->collectedItems()->collectedItems()) m_instrumentCombo->addItem(instrumentItem->instrumentName(), instrumentItem->id()); updateInstrumentComboIndex(); diff --git a/GUI/View/Import/RealDataSelectorWidget.h b/GUI/View/Import/RealDataSelectorWidget.h index 2afdfed2cc67ba03d41ba3104125fd09808eab93..9ee62a27e18fc4ad456e08d73a1df23368004e5b 100644 --- a/GUI/View/Import/RealDataSelectorWidget.h +++ b/GUI/View/Import/RealDataSelectorWidget.h @@ -21,7 +21,7 @@ class RealDataPropertiesWidget; class RealDataItemSelectorWidget; -class InstrumentItems; +class InstrumentCollection; class RealDataModel; class SessionItem; class RealDataSelectorActions; diff --git a/GUI/View/Import/SpecularDataImportWidget.cpp b/GUI/View/Import/SpecularDataImportWidget.cpp index bd746ea7ad22400531d2036521aae35e155c540c..e1301c437547dea845b8847b6546583180cb9e38 100644 --- a/GUI/View/Import/SpecularDataImportWidget.cpp +++ b/GUI/View/Import/SpecularDataImportWidget.cpp @@ -349,7 +349,7 @@ void SpecularDataImportWidget::onPropertiesChanged() // Therefore check the compatibility and break the link if necessary ASSERT(gSessionData->projectDocument.has_value()); const auto* linkedInstrument = - gSessionData->projectDocument.value()->instrumentItems()->findInstrumentById( + gSessionData->projectDocument.value()->collectedItems()->findInstrumentById( realDataItem()->instrumentId()); if (linkedInstrument != nullptr) diff --git a/GUI/View/Instrument/InstrumentLibraryEditor.cpp b/GUI/View/Instrument/InstrumentLibraryEditor.cpp index 9de3e78e7a23d8aa665ed045c47ca6403a6c0784..1d236001783fcbe58f57e38d076d56daa4cc5c84 100644 --- a/GUI/View/Instrument/InstrumentLibraryEditor.cpp +++ b/GUI/View/Instrument/InstrumentLibraryEditor.cpp @@ -36,7 +36,7 @@ InstrumentLibraryEditor::InstrumentLibraryEditor(QWidget* parent) : QDialog(parent) , m_ui(new Ui::InstrumentLibraryEditor) - , m_treeModel(new TreeModel(this, gSessionData->instrumentLibrary.instrumentItems())) + , m_treeModel(new TreeModel(this, gSessionData->instrumentLibrary.collectedItems())) , m_chosenItem(nullptr) { m_ui->setupUi(this); @@ -266,7 +266,7 @@ void InstrumentLibraryEditor::onInstrumentChangedByEditor() /*********************************************************************************************/ -InstrumentLibraryEditor::TreeModel::TreeModel(QObject* parent, InstrumentItems* model) +InstrumentLibraryEditor::TreeModel::TreeModel(QObject* parent, InstrumentCollection* model) : InstrumentsTreeModel(parent, model) , m_newInstrument(nullptr) { diff --git a/GUI/View/Instrument/InstrumentLibraryEditor.h b/GUI/View/Instrument/InstrumentLibraryEditor.h index c13ac6a0ae5bc326733b055977fd6d5c43f72dfa..50524accc3838561852c762857cd750eae9db4bb 100644 --- a/GUI/View/Instrument/InstrumentLibraryEditor.h +++ b/GUI/View/Instrument/InstrumentLibraryEditor.h @@ -60,7 +60,7 @@ private: //! * creates a HTML text for the Display role class TreeModel : public InstrumentsTreeModel { public: - TreeModel(QObject* parent, InstrumentItems* model); + TreeModel(QObject* parent, InstrumentCollection* model); //! Set the instrument which shall have a "NEW" sign in its icon void setNewInstrument(InstrumentItem* addedInstrument); diff --git a/GUI/View/Instrument/InstrumentListModel.cpp b/GUI/View/Instrument/InstrumentListModel.cpp index f8b5a79ae590e8fce3cf4d313aed907c38a0db32..e056e0623543b1491988923e8d2bcf2f1141d283 100644 --- a/GUI/View/Instrument/InstrumentListModel.cpp +++ b/GUI/View/Instrument/InstrumentListModel.cpp @@ -71,12 +71,12 @@ InstrumentListModel::InstrumentListModel(QObject* parent, InstrumentsEditControl int InstrumentListModel::rowCount(const QModelIndex&) const { - return m_ec->instrumentItems()->instrumentItems().size(); + return m_ec->collectedItems()->collectedItems().size(); } QVariant InstrumentListModel::data(const QModelIndex& index, int role) const { - QVector<InstrumentItem*> instruments = m_ec->instrumentItems()->instrumentItems(); + QVector<InstrumentItem*> instruments = m_ec->collectedItems()->collectedItems(); if (!index.isValid() || index.row() >= instruments.size() || index.row() < 0) return {}; @@ -104,7 +104,7 @@ InstrumentItem* InstrumentListModel::instrumentForIndex(const QModelIndex& index if (!index.isValid()) return nullptr; - QVector<InstrumentItem*> instruments = m_ec->instrumentItems()->instrumentItems(); + QVector<InstrumentItem*> instruments = m_ec->collectedItems()->collectedItems(); if (index.row() >= 0 && index.row() < instruments.size()) return instruments[index.row()]; return nullptr; @@ -149,8 +149,8 @@ QModelIndex InstrumentListModel::copyInstrument(const QModelIndex& source) QModelIndex InstrumentListModel::copyInstrument(const InstrumentItem* source) { const QString copyName = - m_ec->instrumentItems()->suggestInstrumentName(source->instrumentName()); - const int row = m_ec->instrumentItems()->instrumentItems().size(); + m_ec->collectedItems()->suggestInstrumentName(source->instrumentName()); + const int row = m_ec->collectedItems()->collectedItems().size(); beginInsertRows(QModelIndex(), row, row); m_ec->addCopy(source, copyName); @@ -163,8 +163,8 @@ template <class Instrument> QModelIndex InstrumentListModel::addNewInstrument() { const QString name = - m_ec->instrumentItems()->suggestInstrumentName(defaultInstrumentName<Instrument>()); - const int row = m_ec->instrumentItems()->instrumentItems().size(); + m_ec->collectedItems()->suggestInstrumentName(defaultInstrumentName<Instrument>()); + const int row = m_ec->collectedItems()->collectedItems().size(); beginInsertRows(QModelIndex(), row, row); auto* instrument = m_ec->addInstrument<Instrument>(); @@ -176,7 +176,7 @@ QModelIndex InstrumentListModel::addNewInstrument() void InstrumentListModel::onInstrumentNameChanged(const InstrumentItem* instrument) { - const auto instruments = m_ec->instrumentItems()->instrumentItems(); + const auto instruments = m_ec->collectedItems()->collectedItems(); if (const auto row = instruments.indexOf(const_cast<InstrumentItem*>(instrument)); row != -1) emit dataChanged(index(row, 0), index(row, 0)); } diff --git a/GUI/View/Instrument/InstrumentListModel.h b/GUI/View/Instrument/InstrumentListModel.h index f3483d1ecb403fb71bca38af7f59c301ccb2fb50..118d7af3a05b51a0835c4a24bb206e4642772efa 100644 --- a/GUI/View/Instrument/InstrumentListModel.h +++ b/GUI/View/Instrument/InstrumentListModel.h @@ -19,7 +19,7 @@ #include <QIcon> class InstrumentItem; -class InstrumentItems; +class InstrumentCollection; class InstrumentsEditController; //! List model for instruments. diff --git a/GUI/View/Instrument/InstrumentListView.h b/GUI/View/Instrument/InstrumentListView.h index b9455828a508bc758ed332d8c962ffb6e71f2b85..3de21c5284cf3fd2d9858fee06cf7e8b17f79e49 100644 --- a/GUI/View/Instrument/InstrumentListView.h +++ b/GUI/View/Instrument/InstrumentListView.h @@ -17,7 +17,7 @@ #include <QWidget> -class InstrumentItems; +class InstrumentCollection; class QAction; class QListView; class InstrumentItem; diff --git a/GUI/View/Instrument/InstrumentsTreeModel.cpp b/GUI/View/Instrument/InstrumentsTreeModel.cpp index b2628b4a8aa35cb7cd74ba2f115bb7819962835b..2e763704287fbfc2770ede614d711bc19471eaaa 100644 --- a/GUI/View/Instrument/InstrumentsTreeModel.cpp +++ b/GUI/View/Instrument/InstrumentsTreeModel.cpp @@ -14,12 +14,13 @@ #include "GUI/View/Instrument/InstrumentsTreeModel.h" #include "GUI/Application/ApplicationSettings.h" +#include "GUI/Model/Device/InstrumentCollection.h" #include "GUI/Model/Device/InstrumentItems.h" #include <QApplication> #include <QtCore> #include <QtGui> -InstrumentsTreeModel::InstrumentsTreeModel(QObject* parent, InstrumentItems* model) +InstrumentsTreeModel::InstrumentsTreeModel(QObject* parent, InstrumentCollection* model) : QAbstractItemModel(parent) , m_model(model) , m_visibleTypes(All) @@ -51,7 +52,7 @@ void InstrumentsTreeModel::refreshAfterModelChange() // for (auto rank : m_visibleRanks) { // if (!m_items[rank - 1].isEmpty()) { // beginRemoveRows(indexOfHeadline(rank), 0, m_items[rank - 1].size() - 1); - // m_items[rank - 1] = m_model->InstrumentItems(rank); + // m_items[rank - 1] = m_model->InstrumentCollection(rank); // endRemoveRows(); // } // } diff --git a/GUI/View/Instrument/InstrumentsTreeModel.h b/GUI/View/Instrument/InstrumentsTreeModel.h index b843b64999b882919d3594cfd7f2895371734e70..fb4a4fe1e414da5000a5937f671ea9679e29db14 100644 --- a/GUI/View/Instrument/InstrumentsTreeModel.h +++ b/GUI/View/Instrument/InstrumentsTreeModel.h @@ -18,13 +18,13 @@ #include <QAbstractItemModel> #include <QSet> -class InstrumentItems; +class InstrumentCollection; class InstrumentItem; //! Tree model for instrument item selection. Used e.g. for the instrument library. class InstrumentsTreeModel : public QAbstractItemModel { public: - InstrumentsTreeModel(QObject* parent, InstrumentItems* model); + InstrumentsTreeModel(QObject* parent, InstrumentCollection* model); enum InstrumentType { None = 0x0, @@ -68,7 +68,7 @@ private: QVector<InstrumentItem*> instruments(InstrumentType type) const; private: - InstrumentItems* m_model = nullptr; + InstrumentCollection* m_model = nullptr; VisibleInstrumentTypes m_visibleTypes; bool m_namesAreEditable; bool m_enableEmptyHeadlines; diff --git a/GUI/View/PropertyEditor/CustomEditors.cpp b/GUI/View/PropertyEditor/CustomEditors.cpp index d68742fe195680b73252a1ba97918731387964c1..bf5216b36eb7d0e07745841f1aac6c53450c792a 100644 --- a/GUI/View/PropertyEditor/CustomEditors.cpp +++ b/GUI/View/PropertyEditor/CustomEditors.cpp @@ -14,6 +14,7 @@ #include "GUI/View/PropertyEditor/CustomEditors.h" #include "Base/Util/Assert.h" +#include "Fit/Param/RealLimits.h" #include "GUI/Model/Data/SessionData.h" #include "GUI/Util/ComboProperty.h" #include "GUI/View/Common/CustomEventFilters.h" diff --git a/GUI/View/Toplevel/ProjectSettingsView.cpp b/GUI/View/Toplevel/ProjectSettingsView.cpp index 980f574ff7e7d7a2daf1e3e18526540f6fafaff9..d244b85d0953938d3353f1eb89dfc8b0635b5a30 100644 --- a/GUI/View/Toplevel/ProjectSettingsView.cpp +++ b/GUI/View/Toplevel/ProjectSettingsView.cpp @@ -116,7 +116,7 @@ void ProjectSettingsView::storeAsDefaults() void ProjectSettingsView::onSingleInstrumentRadioToggled(bool newState) { if (newState) { - if (m_document->instrumentItems()->instrumentItems().size() > 1) { + if (m_document->collectedItems()->collectedItems().size() > 1) { QMessageBox::warning(this, "Select single instrument mode", "This project already contains more than one instrument. Changing " "this setting is not possible."); diff --git a/GUI/View/Toplevel/SimulationView.cpp b/GUI/View/Toplevel/SimulationView.cpp index 06b661b899090959786a257ca911f584b30215d9..3d0879fd33554804b526167e4a653ca81c467c95 100644 --- a/GUI/View/Toplevel/SimulationView.cpp +++ b/GUI/View/Toplevel/SimulationView.cpp @@ -106,7 +106,7 @@ void SimulationView::writeOptionsToUI() QSignalBlocker b6(m_ui->includeSpecularCheck); // -- selection group - updateSelection(m_ui->instrumentCombo, m_document->instrumentItems()->instrumentNames()); + updateSelection(m_ui->instrumentCombo, m_document->collectedItems()->instrumentNames()); updateSelection(m_ui->sampleCombo, m_document->sampleItems()->sampleNames()); updateSelection(m_ui->realDataCombo, m_document->realDataModel()->realDataNames(), true); @@ -235,9 +235,9 @@ QVector<MultiLayerItem*> SimulationView::sampleItems() const return m_document->sampleItems()->sampleItems(); } -QVector<InstrumentItem*> SimulationView::instrumentItems() const +QVector<InstrumentItem*> SimulationView::collectedItems() const { - return m_document->instrumentItems()->instrumentItems(); + return m_document->collectedItems()->collectedItems(); } QVector<RealDataItem*> SimulationView::realDataItems() const @@ -257,7 +257,7 @@ const MultiLayerItem* SimulationView::selectedSample() const const InstrumentItem* SimulationView::selectedInstrument() const { - return instrumentItems().value(m_ui->instrumentCombo->currentIndex(), nullptr); + return collectedItems().value(m_ui->instrumentCombo->currentIndex(), nullptr); } const RealDataItem* SimulationView::selectedRealData() const diff --git a/GUI/View/Toplevel/SimulationView.h b/GUI/View/Toplevel/SimulationView.h index 7fe9b8b1d5978bc0a876663dc50da8f872b76e5e..73944cc6e6a04a2c5961d1e535cf1f0fd753b9ca 100644 --- a/GUI/View/Toplevel/SimulationView.h +++ b/GUI/View/Toplevel/SimulationView.h @@ -83,7 +83,7 @@ private: // Convenience methods for easier access QVector<MultiLayerItem*> sampleItems() const; - QVector<InstrumentItem*> instrumentItems() const; + QVector<InstrumentItem*> collectedItems() const; QVector<RealDataItem*> realDataItems() const; SimulationOptionsItem* optionsItem() const; diff --git a/Tests/Functional/GUI/Check.cpp b/Tests/Functional/GUI/Check.cpp index 3e3a4218a7481cfa3b9c29207e652d7f2c168e73..2ee8a4093bb543fab0bbb7aad984f9740859c317 100644 --- a/Tests/Functional/GUI/Check.cpp +++ b/Tests/Functional/GUI/Check.cpp @@ -18,10 +18,9 @@ #include "Device/Histo/HistoUtils.h" #include "Device/Histo/IOFactory.h" #include "Device/Histo/SimulationResult.h" -#include "GUI/Model/Device/InstrumentItems.h" +#include "GUI/Model/Device/InstrumentCollection.h" #include "GUI/Model/FromDomain/GUIObjectBuilder.h" #include "GUI/Model/FromDomain/GUISampleBuilder.h" -#include "GUI/Model/Sample/MaterialItems.h" #include "GUI/Model/Sample/MultiLayerItem.h" #include "GUI/Model/ToDomain/DomainSimulationBuilder.h" #include "GUI/Support/Data/SimulationOptionsItem.h" @@ -30,41 +29,42 @@ namespace { -std::unique_ptr<Powerfield<double>> domainData(const ISimulation& direct_simulation) +//! Converts ISimulation from core to GUI representation and back. +std::unique_ptr<ISimulation> indirectSimulation(const ISimulation& sim) { std::unique_ptr<MultiLayerItem> sampleItem( - GUI::Transform::FromDomain::createMultiLayerItem(*direct_simulation.sample())); + GUI::Transform::FromDomain::createMultiLayerItem(*sim.sample())); - std::unique_ptr<InstrumentItems> instrumentItems( - GUI::Transform::FromDomain::createInstrumentItems(direct_simulation)); + std::unique_ptr<InstrumentCollection> instrumentItems( + GUI::Transform::FromDomain::createInstrumentCollection(sim)); std::unique_ptr<SimulationOptionsItem> optionsItem( - GUI::Transform::FromDomain::createSimulationOptions(direct_simulation)); + GUI::Transform::FromDomain::createSimulationOptions(sim)); - std::unique_ptr<ISimulation> domain_simulation = GUI::Transform::ToDomain::createSimulation( - sampleItem.get(), instrumentItems->instrumentItems().front(), *optionsItem); - - return std::unique_ptr<Powerfield<double>>(domain_simulation->simulate().data()); + return GUI::Transform::ToDomain::createSimulation( + sampleItem.get(), instrumentItems->collectedItems().front(), *optionsItem); } } // namespace //! Run simulation directly (in core) and through GUI model, and compare results. -bool checkSimulation(const std::string& name, ISimulation& direct_simulation, const double limit) +bool checkSimulation(const std::string& name, ISimulation& sim, const double limit) { - const std::unique_ptr<Powerfield<double>> domain_data = domainData(direct_simulation); + std::unique_ptr<ISimulation> sim2(indirectSimulation(sim)); + + const std::unique_ptr<Powerfield<double>> data2 = sim2->simulate().data(); - const std::unique_ptr<Powerfield<double>> ref_data = direct_simulation.simulate().data(); + const std::unique_ptr<Powerfield<double>> ref_data = sim.simulate().data(); - bool ok = DataUtils::Histo::checkRelativeDifference(*domain_data, *ref_data, limit); + bool ok = DataUtils::Histo::checkRelativeDifference(*data2, *ref_data, limit); if (ok) return true; // Save simulation, as it differs from reference. BaseUtils::Filesystem::createDirectories(BATesting::TestOutDir_AdHoc()); - std::map<const std::string, const Powerfield<double>*> tosave{{"gui", domain_data.get()}, + std::map<const std::string, const Powerfield<double>*> tosave{{"gui", data2.get()}, {"std", ref_data.get()}}; for (const auto& [kind, data] : tosave) { std::string out_fname = BaseUtils::Filesystem::jointPath(BATesting::TestOutDir_AdHoc(), diff --git a/Tests/Unit/GUI/TestDetectorItems.cpp b/Tests/Unit/GUI/TestDetectorItems.cpp index b9603f692a201553c5bdf671013f47f45e7ebf6c..321cfad47e162cd62f3a342b492e5b6aaa32ffd7 100644 --- a/Tests/Unit/GUI/TestDetectorItems.cpp +++ b/Tests/Unit/GUI/TestDetectorItems.cpp @@ -2,6 +2,7 @@ #include "Device/Detector/IDetector2D.h" #include "Device/Resolution/ConvolutionDetectorResolution.h" #include "Device/Resolution/ResolutionFunction2DGaussian.h" +#include "GUI/Model/Device/InstrumentCollection.h" #include "GUI/Model/Device/InstrumentItems.h" #include "GUI/Model/Device/RectangularDetectorItem.h" #include "GUI/Model/Device/ResolutionFunctionItems.h" @@ -14,7 +15,7 @@ class TestDetectorItems : public ::testing::Test { TEST_F(TestDetectorItems, resolutionFunction) { - InstrumentItems model; + InstrumentCollection model; auto* instrument = model.addInstrument<GISASInstrumentItem>(); DetectorItem* detectorItem = instrument->detectorItem(); diff --git a/Tests/Unit/GUI/TestInstrumentItems.cpp b/Tests/Unit/GUI/TestInstrumentItems.cpp index f5ba4cdf44f957c196016b4d0fb1c09a6680b747..70464f59f14c5ecea57b2f206e6005e9eeee726c 100644 --- a/Tests/Unit/GUI/TestInstrumentItems.cpp +++ b/Tests/Unit/GUI/TestInstrumentItems.cpp @@ -5,12 +5,12 @@ Q_DECLARE_METATYPE(const InstrumentItem*) -class TestInstrumentItems : public ::testing::Test { +class TestInstrumentCollection : public ::testing::Test { }; //! Checks whether instrumentAddedRemoved will be emitted as expected -TEST_F(TestInstrumentItems, instrumentAddedRemoved) +TEST_F(TestInstrumentCollection, instrumentAddedRemoved) { ProjectDocument document; @@ -29,7 +29,7 @@ TEST_F(TestInstrumentItems, instrumentAddedRemoved) } //! Test whether instrumentChanged will be emitted as expected -TEST_F(TestInstrumentItems, instrumentChanged) +TEST_F(TestInstrumentCollection, instrumentChanged) { qRegisterMetaType<const InstrumentItem*>(); ProjectDocument document; diff --git a/Tests/Unit/GUI/TestLinkInstrument.cpp b/Tests/Unit/GUI/TestLinkInstrument.cpp index af7e01f7f7644f8f341cf9a2c24d1065680a823d..cf945544b7c204406d8a8bd5df17593f22dd4ab1 100644 --- a/Tests/Unit/GUI/TestLinkInstrument.cpp +++ b/Tests/Unit/GUI/TestLinkInstrument.cpp @@ -35,7 +35,7 @@ TEST_F(TestLinkInstrument, canLinkToInstrument) ProjectDocument document; // populating instrument model - auto* instrument = document.instrumentItems()->addInstrument<GISASInstrumentItem>(); + auto* instrument = document.collectedItems()->addInstrument<GISASInstrumentItem>(); const QString identifier = instrument->id(); ASSERT_TRUE(!identifier.isEmpty()); diff --git a/Tests/Unit/GUI/TestProjectDocument.cpp b/Tests/Unit/GUI/TestProjectDocument.cpp index fe900ca55001147530972694b363b5381e7950ab..6e82861fca3f7297423140f8885cfd4b889f930d 100644 --- a/Tests/Unit/GUI/TestProjectDocument.cpp +++ b/Tests/Unit/GUI/TestProjectDocument.cpp @@ -16,7 +16,7 @@ protected: //! helper method to modify something in a model void modify_models(ProjectDocument& doc) { - auto* instrument = doc.instrumentItems()->instrumentItems().front(); + auto* instrument = doc.collectedItems()->collectedItems().front(); doc.instrumentsEditController()->setInstrumentName(instrument, QUuid::createUuid().toString()); } @@ -36,7 +36,7 @@ TEST_F(TestProjectDocument, projectDocument) EXPECT_EQ(document.projectName(), QString()); EXPECT_EQ(document.projectFileName(), QString()); - auto* instrument = document.instrumentItems()->addInstrument<GISASInstrumentItem>(); + auto* instrument = document.collectedItems()->addInstrument<GISASInstrumentItem>(); instrument->setInstrumentName("GISAS"); // Checking document name and isModified status after project save @@ -70,13 +70,13 @@ TEST_F(TestProjectDocument, projectDocumentWithData) UTest::GUI::create_dir(projectDir); ProjectDocument document; - auto* instrument = document.instrumentItems()->addInstrument<GISASInstrumentItem>(); + auto* instrument = document.collectedItems()->addInstrument<GISASInstrumentItem>(); instrument->setInstrumentName("GISAS"); RealDataItem* realData = UTest::GUI::createRealData("TestData", *document.realDataModel()); ASSERT(realData); DataItem* intensityItem = realData->dataItem(); GUI::Model::JobItemUtils::createDefaultDetectorMap( - intensityItem, document.instrumentItems()->instrument2DItems().front()); + intensityItem, document.collectedItems()->instrument2DItems().front()); document.save(projectDir + "/untitled.pro"); diff --git a/Tests/Unit/GUI/TestSaveService.cpp b/Tests/Unit/GUI/TestSaveService.cpp index 4b107f3c8c2d128e6a462ca72c9be14b4ce712b4..c0b98946717984cf8f750ff20c74ed7a72bebe21 100644 --- a/Tests/Unit/GUI/TestSaveService.cpp +++ b/Tests/Unit/GUI/TestSaveService.cpp @@ -18,7 +18,7 @@ protected: // helper method to modify something in a model void modify_models(ProjectDocument& doc) { - auto* instrument = doc.instrumentItems()->instrumentItems().front(); + auto* instrument = doc.collectedItems()->collectedItems().front(); doc.instrumentsEditController()->setInstrumentName(instrument, QUuid::createUuid().toString()); } @@ -38,7 +38,7 @@ TEST_F(TestSaveService, autoSaveController) const int autosave_time(100); std::unique_ptr<ProjectDocument> document(new ProjectDocument); - auto* instrument = document->instrumentItems()->addInstrument<GISASInstrumentItem>(); + auto* instrument = document->collectedItems()->addInstrument<GISASInstrumentItem>(); instrument->setInstrumentName("GISAS"); document->save(projectFileName); @@ -82,7 +82,7 @@ TEST_F(TestSaveService, autoSaveController) TEST_F(TestSaveService, autoSaveControllerNewDocument) { std::unique_ptr<ProjectDocument> document(new ProjectDocument); - auto* instrument = document->instrumentItems()->addInstrument<GISASInstrumentItem>(); + auto* instrument = document->collectedItems()->addInstrument<GISASInstrumentItem>(); instrument->setInstrumentName("GISAS"); const int autosave_time(100); @@ -109,7 +109,7 @@ TEST_F(TestSaveService, saveService) std::unique_ptr<ProjectDocument> document(new ProjectDocument); - auto* instrument = document->instrumentItems()->addInstrument<GISASInstrumentItem>(); + auto* instrument = document->collectedItems()->addInstrument<GISASInstrumentItem>(); instrument->setInstrumentName("GISAS"); modify_models(*document); @@ -142,7 +142,7 @@ TEST_F(TestSaveService, failingSaveService) const QString projectFileName(projectDir + "/document.pro"); std::unique_ptr<ProjectDocument> document(new ProjectDocument); - auto* instrument = document->instrumentItems()->addInstrument<GISASInstrumentItem>(); + auto* instrument = document->collectedItems()->addInstrument<GISASInstrumentItem>(); instrument->setInstrumentName("GISAS"); modify_models(*document); @@ -173,14 +173,14 @@ TEST_F(TestSaveService, saveServiceWithData) const QString projectFileName(projectDir + "/document.pro"); std::unique_ptr<ProjectDocument> document(new ProjectDocument); - auto* instrument = document->instrumentItems()->addInstrument<GISASInstrumentItem>(); + auto* instrument = document->collectedItems()->addInstrument<GISASInstrumentItem>(); instrument->setInstrumentName("GISAS"); RealDataItem* realData = UTest::GUI::createRealData("TestData", *document->realDataModel()); ASSERT(realData); DataItem* intensityItem = realData->dataItem(); GUI::Model::JobItemUtils::createDefaultDetectorMap( - intensityItem, document->instrumentItems()->instrument2DItems().front()); + intensityItem, document->collectedItems()->instrument2DItems().front()); EXPECT_FALSE(QFile::exists(projectFileName)); @@ -208,13 +208,13 @@ TEST_F(TestSaveService, autosaveEnabled) std::unique_ptr<ProjectDocument> document(new ProjectDocument()); document->setProjectFileName(projectFileName); - auto* instrument = document->instrumentItems()->addInstrument<GISASInstrumentItem>(); + auto* instrument = document->collectedItems()->addInstrument<GISASInstrumentItem>(); instrument->setInstrumentName("GISAS"); RealDataItem* realData = UTest::GUI::createRealData("TestData", *document->realDataModel()); DataItem* intensityItem = realData->dataItem(); GUI::Model::JobItemUtils::createDefaultDetectorMap( - intensityItem, document->instrumentItems()->instrument2DItems().front()); + intensityItem, document->collectedItems()->instrument2DItems().front()); document->clearModified(); EXPECT_FALSE(document->isModified()); diff --git a/Tests/Unit/GUI/TestSessionModel.cpp b/Tests/Unit/GUI/TestSessionModel.cpp index 98a40ecffaac7502e48e21b6f6bea1e428684504..2d901c0728d2a9956c3163b916eae2f588cb68b6 100644 --- a/Tests/Unit/GUI/TestSessionModel.cpp +++ b/Tests/Unit/GUI/TestSessionModel.cpp @@ -1,5 +1,5 @@ #include "GUI/Model/BaseItem/PropertyItem.h" -#include "GUI/Model/Device/InstrumentItems.h" +#include "GUI/Model/Device/InstrumentCollection.h" #include "GUI/Model/Device/MaskItems.h" #include "GUI/Model/Job/JobItem.h" #include "GUI/Model/Model/JobModel.h" @@ -50,7 +50,7 @@ TEST_F(TestSessionModel, copyItem) sample1->setSampleName("sample1"); sample1->addStandardMaterials(); - InstrumentItems instrumentItems; + InstrumentCollection instrumentItems; auto* instrument1 = instrumentItems.addInstrument<GISASInstrumentItem>(); instrument1->setInstrumentName("instrument1");