diff --git a/GUI/View/Instrument/InstrumentLibraryEditor.cpp b/GUI/View/Instrument/InstrumentLibraryEditor.cpp index 50fc323e941e131e0b5c120460a93b0767b25276..f033fb8867671f62b3ac6d2da947eb74f53844cf 100644 --- a/GUI/View/Instrument/InstrumentLibraryEditor.cpp +++ b/GUI/View/Instrument/InstrumentLibraryEditor.cpp @@ -33,10 +33,12 @@ #include <QPushButton> #include <QTextEdit> -InstrumentLibraryEditor::InstrumentLibraryEditor(QWidget* parent) +InstrumentLibraryEditor::InstrumentLibraryEditor(QWidget* parent, + InstrumentLibrary* instrumentLibrary) : QDialog(parent) , m_ui(new Ui::InstrumentLibraryEditor) - , m_treeModel(new TreeModel(this, gSessionData->instrumentLibrary.instrumentModel())) + , m_instrumentLibrary(instrumentLibrary) + , m_treeModel(new TreeModel(this, instrumentLibrary->instrumentModel())) , m_chosenItem(nullptr) { m_ui->setupUi(this); @@ -115,9 +117,8 @@ InstrumentItem* InstrumentLibraryEditor::execChoose() void InstrumentLibraryEditor::execAdd(const InstrumentItem& instrumentToAdd) { - const QString& newName = - gSessionData->instrumentLibrary.suggestName(instrumentToAdd.instrumentName()); - auto* addedInstrument = gSessionData->instrumentLibrary.addItemCopy(newName, instrumentToAdd); + const QString& newName = m_instrumentLibrary->suggestName(instrumentToAdd.instrumentName()); + auto* addedInstrument = m_instrumentLibrary->addItemCopy(newName, instrumentToAdd); setWindowTitle("Instrument Library - Add instrument"); @@ -220,8 +221,8 @@ void InstrumentLibraryEditor::createWidgetsForCurrentInstrument() GroupBoxCollapser::installIntoGroupBox(g); if (auto* sp = dynamic_cast<SpecularInstrumentItem*>(currentInstrument)) { - auto* editor = new SpecularInstrumentEditor( - m_ui->scrollArea, sp, gSessionData->instrumentLibrary.editController()); + auto* editor = new SpecularInstrumentEditor(m_ui->scrollArea, sp, + m_instrumentLibrary->editController()); connect(editor, &SpecularInstrumentEditor::dataChanged, this, &InstrumentLibraryEditor::onInstrumentChangedByEditor); layout->addWidget(editor); @@ -261,7 +262,7 @@ void InstrumentLibraryEditor::onInstrumentDescriptionEdited(const QString& t) void InstrumentLibraryEditor::onInstrumentChangedByEditor() { auto* currentInstrument = m_treeModel->itemForIndex(m_ui->treeView->currentIndex()); - gSessionData->instrumentLibrary.editController()->notifyInstrumentChanged(currentInstrument); + m_instrumentLibrary->editController()->notifyInstrumentChanged(currentInstrument); } /*********************************************************************************************/ diff --git a/GUI/View/Instrument/InstrumentLibraryEditor.h b/GUI/View/Instrument/InstrumentLibraryEditor.h index 4e74ba9138a925cd0fb694ba1c9e8d8fcf49057a..4a890aaae28e27e6e1ee0d900fb7f6063f3cb724 100644 --- a/GUI/View/Instrument/InstrumentLibraryEditor.h +++ b/GUI/View/Instrument/InstrumentLibraryEditor.h @@ -19,6 +19,7 @@ #include <QDialog> class InstrumentItem; +class InstrumentLibrary; namespace Ui { @@ -29,7 +30,7 @@ class InstrumentLibraryEditor : public QDialog { Q_OBJECT public: - InstrumentLibraryEditor(QWidget* parent); + InstrumentLibraryEditor(QWidget* parent, InstrumentLibrary* instrumentLibrary); ~InstrumentLibraryEditor() override; void setGisasEnabled(bool b); @@ -71,6 +72,7 @@ private: InstrumentItem* m_newInstrument = nullptr; }; + InstrumentLibrary* m_instrumentLibrary; Ui::InstrumentLibraryEditor* m_ui; TreeModel* m_treeModel; InstrumentItem* m_chosenItem; diff --git a/GUI/View/Instrument/InstrumentListView.cpp b/GUI/View/Instrument/InstrumentListView.cpp index b88ffb514ae4b9e93eb44e19c0351698c6c05eb9..e0573bc62b87f670a33e06fa50f511c245844062 100644 --- a/GUI/View/Instrument/InstrumentListView.cpp +++ b/GUI/View/Instrument/InstrumentListView.cpp @@ -24,10 +24,12 @@ #include <QMessageBox> #include <QVBoxLayout> -InstrumentListView::InstrumentListView(ProjectDocument* document, QWidget* parent, +InstrumentListView::InstrumentListView(ProjectDocument* document, + InstrumentLibrary* instrumentLibrary, QWidget* parent, Qt::WindowFlags f) : QWidget(parent, f) , m_document(document) + , m_instrumentLibrary(instrumentLibrary) { setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); @@ -217,7 +219,7 @@ void InstrumentListView::onStoreInLibrary() QModelIndex idx = m_listView->selectionModel()->selectedIndexes().front(); InstrumentItem* instrument = m_model->instrumentItemForIndex(idx); - InstrumentLibraryEditor dlg(GUI::Global::mainWindow); + InstrumentLibraryEditor dlg(GUI::Global::mainWindow, m_instrumentLibrary); dlg.setGisasEnabled(m_document->functionalities().testFlag(ProjectDocument::Gisas)); dlg.setOffspecEnabled(m_document->functionalities().testFlag(ProjectDocument::Offspec)); dlg.setSpecularEnabled(m_document->functionalities().testFlag(ProjectDocument::Specular)); @@ -227,13 +229,13 @@ void InstrumentListView::onStoreInLibrary() void InstrumentListView::onLoadFromLibrary() { - if (gSessionData->instrumentLibrary.isEmpty()) { + if (m_instrumentLibrary->isEmpty()) { QMessageBox::information(GUI::Global::mainWindow, "Select from library", "The library does not contain instruments so far."); return; } - InstrumentLibraryEditor dlg(GUI::Global::mainWindow); + InstrumentLibraryEditor dlg(GUI::Global::mainWindow, m_instrumentLibrary); dlg.setGisasEnabled(m_document->functionalities().testFlag(ProjectDocument::Gisas)); dlg.setOffspecEnabled(m_document->functionalities().testFlag(ProjectDocument::Offspec)); dlg.setSpecularEnabled(m_document->functionalities().testFlag(ProjectDocument::Specular)); diff --git a/GUI/View/Instrument/InstrumentListView.h b/GUI/View/Instrument/InstrumentListView.h index 2230b03e6dcd9979351a83606fa1b3cd15fbc7f1..d05e5c417dfb40d92a3c9f95c723261abab826fb 100644 --- a/GUI/View/Instrument/InstrumentListView.h +++ b/GUI/View/Instrument/InstrumentListView.h @@ -23,6 +23,7 @@ class QListView; class InstrumentItem; class InstrumentListModel; class ProjectDocument; +class InstrumentLibrary; //! Instrument selector on the left side of InstrumentView. @@ -30,8 +31,8 @@ class InstrumentListView : public QWidget { Q_OBJECT public: - InstrumentListView(ProjectDocument* document, QWidget* parent = nullptr, - Qt::WindowFlags f = Qt::WindowFlags()); + InstrumentListView(ProjectDocument* document, InstrumentLibrary* instrumentLibrary, + QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); QSize sizeHint() const override; QSize minimumSizeHint() const override; @@ -67,6 +68,7 @@ private: ProjectDocument* m_document; QListView* m_listView; InstrumentListModel* m_model; + InstrumentLibrary* m_instrumentLibrary; QAction* m_newGisasAction; QAction* m_newOffspecAction; QAction* m_newSpecularAction; diff --git a/GUI/View/Instrument/InstrumentView.cpp b/GUI/View/Instrument/InstrumentView.cpp index 084e49295774ef2616e8bf939a8d8e04ec07e60c..5fe7fe161da8883bd072f0f6666c690a70df4d93 100644 --- a/GUI/View/Instrument/InstrumentView.cpp +++ b/GUI/View/Instrument/InstrumentView.cpp @@ -30,7 +30,8 @@ #include <QScrollArea> #include <QTextEdit> -InstrumentView::InstrumentView(QWidget* parent, ProjectDocument* document) +InstrumentView::InstrumentView(QWidget* parent, ProjectDocument* document, + InstrumentLibrary* instrumentLibrary) : QWidget(parent) , m_document(document) { @@ -38,7 +39,7 @@ InstrumentView::InstrumentView(QWidget* parent, ProjectDocument* document) setProperty("stylable", true); // for stylesheet addressing auto* horizontalLayout = new QHBoxLayout; - m_instrumentListView = new InstrumentListView(document, this); + m_instrumentListView = new InstrumentListView(document, instrumentLibrary, this); horizontalLayout->addWidget(m_instrumentListView); m_scrollArea = new QScrollArea(this); diff --git a/GUI/View/Instrument/InstrumentView.h b/GUI/View/Instrument/InstrumentView.h index 17c4a573f3777955839b0cbc4de5a1ebd8a2e57b..1ae8ab39a44f570345b7df4af28281a39f51e51d 100644 --- a/GUI/View/Instrument/InstrumentView.h +++ b/GUI/View/Instrument/InstrumentView.h @@ -15,20 +15,20 @@ #ifndef BORNAGAIN_GUI_VIEW_INSTRUMENT_INSTRUMENTVIEW_H #define BORNAGAIN_GUI_VIEW_INSTRUMENT_INSTRUMENTVIEW_H -#include <QWidget> +#include <QLineEdit> +#include <QScrollArea> class InstrumentItem; class InstrumentListView; class ProjectDocument; -class QScrollArea; -class QLabel; -class QLineEdit; +class InstrumentLibrary; class InstrumentView : public QWidget { Q_OBJECT public: - InstrumentView(QWidget* parent, ProjectDocument* document); + InstrumentView(QWidget* parent, ProjectDocument* document, + InstrumentLibrary* instrumentLibrary); protected: void showEvent(QShowEvent*) override; diff --git a/GUI/View/Main/MainWindow.cpp b/GUI/View/Main/MainWindow.cpp index 4dd79cfd949b54b20450390347c841bf2316ae9a..db6b92b4a1e073b1b4065d46862ca820ab01c71e 100644 --- a/GUI/View/Main/MainWindow.cpp +++ b/GUI/View/Main/MainWindow.cpp @@ -232,7 +232,7 @@ void MainWindow::initViews() if (gSessionData->projectDocument.has_value()) { auto* doc = gSessionData->projectDocument.value(); - m_instrumentView = new InstrumentView(this, doc); + m_instrumentView = new InstrumentView(this, doc, &gSessionData->instrumentLibrary); m_sampleView = new SampleView(this, doc); m_importDataView = new ImportDataView(this, doc); m_simulationView = new SimulationView(this, doc);