diff --git a/GUI/Model/Device/InstrumentLibrary.cpp b/GUI/Model/Device/InstrumentLibrary.cpp index a9b957c3a388be5afa329be00e5bec0e966cb3a4..ab6a051fd83700df81e6aac509d51f41f800b1b0 100644 --- a/GUI/Model/Device/InstrumentLibrary.cpp +++ b/GUI/Model/Device/InstrumentLibrary.cpp @@ -63,6 +63,11 @@ QList<InstrumentItem*> InstrumentLibrary::instrumentItems() const return m_instrumentItems.instrumentItems().toList(); } +InstrumentsEditController* InstrumentLibrary::editController() +{ + return &m_ec; +} + bool InstrumentLibrary::saveIfModified() { if (!m_modified) diff --git a/GUI/Model/Device/InstrumentLibrary.h b/GUI/Model/Device/InstrumentLibrary.h index 85ec57621129163cc59e1de19aa52c2ffa357b7d..dc9bdfb9ac7dc871c19320cde61257ec3d65ef7a 100644 --- a/GUI/Model/Device/InstrumentLibrary.h +++ b/GUI/Model/Device/InstrumentLibrary.h @@ -34,6 +34,8 @@ public: InstrumentItems* instrumentItems(); + InstrumentsEditController* editController(); + private: InstrumentItems m_instrumentItems; InstrumentsEditController m_ec; diff --git a/GUI/View/Instrument/InstrumentLibraryEditor.cpp b/GUI/View/Instrument/InstrumentLibraryEditor.cpp index aac92d6b7033c5359ccf9dd6d1703280b5270405..6b44717799bb65f2b19863192c5639128df3f470 100644 --- a/GUI/View/Instrument/InstrumentLibraryEditor.cpp +++ b/GUI/View/Instrument/InstrumentLibraryEditor.cpp @@ -17,14 +17,21 @@ #include "GUI/Model/Data/SessionData.h" #include "GUI/Model/Device/InstrumentItems.h" #include "GUI/View/Common/ItemViewOverlayButtons.h" +#include "GUI/View/Instrument/DepthProbeInstrumentEditor.h" +#include "GUI/View/Instrument/GISASInstrumentEditor.h" +#include "GUI/View/Instrument/OffSpecularInstrumentEditor.h" +#include "GUI/View/Instrument/SpecularInstrumentEditor.h" +#include "GUI/View/Tool/GroupBoxCollapser.h" #include "GUI/View/Tool/ItemDelegateForHTML.h" #include "GUI/View/Tool/StyleUtils.h" #include "ui_InstrumentLibraryEditor.h" #include <QAction> #include <QFormLayout> +#include <QGroupBox> #include <QInputDialog> #include <QMessageBox> #include <QPushButton> +#include <QTextEdit> InstrumentLibraryEditor::InstrumentLibraryEditor(QWidget* parent) : QDialog(parent) @@ -52,8 +59,6 @@ InstrumentLibraryEditor::InstrumentLibraryEditor(QWidget* parent) m_ui->treeView->setItemDelegate(new ItemDelegateForHTML(this)); m_ui->treeView->setIconSize(QSize(128, 128)); - m_ui->textBrowser->hide(); // ...as long as no further info is implemented - connect(m_treeModel, &QAbstractItemModel::modelReset, [this]() { m_ui->treeView->expandAll(); }); @@ -122,6 +127,8 @@ void InstrumentLibraryEditor::execAdd(const InstrumentItem& instrumentToAdd) ItemViewOverlayButtons::install( m_ui->treeView, [=](const QModelIndex& i, bool h) { return getOverlayActions(i, h); }); m_ui->treeView->setItemDelegate(new ItemDelegateForHTML(this)); + connect(m_ui->treeView->selectionModel(), &QItemSelectionModel::currentChanged, this, + &InstrumentLibraryEditor::createWidgetsForCurrentInstrument); m_ui->buttonBox->addButton(QDialogButtonBox::Close); m_ui->buttonBox->button(QDialogButtonBox::Ok)->hide(); @@ -131,6 +138,7 @@ void InstrumentLibraryEditor::execAdd(const InstrumentItem& instrumentToAdd) m_ui->treeView->expandAll(); m_ui->treeView->setCurrentIndex(index); m_ui->treeView->scrollTo(index, QAbstractItemView::PositionAtTop); + createWidgetsForCurrentInstrument(); setModal(true); show(); editNameAndDescription(addedInstrument); @@ -148,6 +156,7 @@ void InstrumentLibraryEditor::onCurrentChangedForChoose() { m_chosenItem = m_treeModel->itemForIndex(m_ui->treeView->currentIndex()); m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(m_chosenItem != nullptr); + createWidgetsForCurrentInstrument(); } QList<QAction*> InstrumentLibraryEditor::getOverlayActions(const QModelIndex& index, bool asHover) @@ -223,6 +232,87 @@ void InstrumentLibraryEditor::editNameAndDescription(InstrumentItem* item) appSettings->saveWindowSizeAndPos(&dlg); } +void InstrumentLibraryEditor::createWidgetsForCurrentInstrument() +{ + auto* currentInstrument = m_treeModel->itemForIndex(m_ui->treeView->currentIndex()); + if (!currentInstrument) { + m_ui->scrollArea->setWidget(new QWidget(m_ui->scrollArea)); // blank widget + return; + } + + QWidget* w = new QWidget(m_ui->scrollArea); + auto* layout = new QVBoxLayout(w); + + w->setAttribute(Qt::WA_StyledBackground, true); + w->setProperty("stylable", true); // for stylesheet addressing + + auto* g = new QGroupBox(m_ui->scrollArea); + g->setTitle(QString("Information (%1 instrument)").arg(currentInstrument->instrumentType())); + + auto* formLayout = new QFormLayout(g); + formLayout->setMargin(17); + formLayout->setSpacing(8); + layout->addWidget(g); + + auto* nameEdit = new QLineEdit(g); + formLayout->addRow("Name:", nameEdit); + nameEdit->setText(currentInstrument->instrumentName()); + connect(nameEdit, &QLineEdit::textEdited, this, + &InstrumentLibraryEditor::onInstrumentNameEdited); + + auto* descriptionEdit = new QLineEdit(g); + formLayout->addRow("Description:", descriptionEdit); + descriptionEdit->setText(currentInstrument->description()); + connect(descriptionEdit, &QLineEdit::textEdited, this, + &InstrumentLibraryEditor::onInstrumentDescriptionEdited); + + GroupBoxCollapser::installIntoGroupBox(g); + + if (auto* sp = dynamic_cast<SpecularInstrumentItem*>(currentInstrument)) { + auto* editor = new SpecularInstrumentEditor( + m_ui->scrollArea, sp, gSessionData->instrumentLibrary.editController()); + connect(editor, &SpecularInstrumentEditor::dataChanged, this, + &InstrumentLibraryEditor::onInstrumentChangedByEditor); + layout->addWidget(editor); + } else if (auto* os = dynamic_cast<OffSpecularInstrumentItem*>(currentInstrument)) { + auto* editor = new OffSpecularInstrumentEditor(m_ui->scrollArea, os); + connect(editor, &OffSpecularInstrumentEditor::dataChanged, this, + &InstrumentLibraryEditor::onInstrumentChangedByEditor); + layout->addWidget(editor); + } else if (auto* gisas = dynamic_cast<GISASInstrumentItem*>(currentInstrument)) { + auto* editor = new GISASInstrumentEditor(m_ui->scrollArea, gisas); + connect(editor, &GISASInstrumentEditor::dataChanged, this, + &InstrumentLibraryEditor::onInstrumentChangedByEditor); + layout->addWidget(editor); + } else if (auto* dp = dynamic_cast<DepthProbeInstrumentItem*>(currentInstrument)) { + auto* editor = new DepthProbeInstrumentEditor(m_ui->scrollArea, dp); + connect(editor, &DepthProbeInstrumentEditor::dataChanged, this, + &InstrumentLibraryEditor::onInstrumentChangedByEditor); + layout->addWidget(editor); + } else + ASSERT(false); + + m_ui->scrollArea->setWidget(w); +} + +void InstrumentLibraryEditor::onInstrumentNameEdited(const QString& newName) +{ + QModelIndex index = m_ui->treeView->currentIndex(); + m_treeModel->setData(index, newName, Qt::EditRole); +} + +void InstrumentLibraryEditor::onInstrumentDescriptionEdited(const QString& t) +{ + QModelIndex index = m_ui->treeView->currentIndex(); + m_treeModel->setData(index, t, Qt::ToolTipRole); +} + +void InstrumentLibraryEditor::onInstrumentChangedByEditor() +{ + auto* currentInstrument = m_treeModel->itemForIndex(m_ui->treeView->currentIndex()); + gSessionData->instrumentLibrary.editController()->notifyInstrumentChanged(currentInstrument); +} + /*********************************************************************************************/ InstrumentLibraryEditor::TreeModel::TreeModel(QObject* parent, InstrumentItems* model) diff --git a/GUI/View/Instrument/InstrumentLibraryEditor.h b/GUI/View/Instrument/InstrumentLibraryEditor.h index 44ccf0bf5da0736c67b821f5f0c249a490538ca2..812ad133ffa9947deac35873f5bd0b14763f2fdf 100644 --- a/GUI/View/Instrument/InstrumentLibraryEditor.h +++ b/GUI/View/Instrument/InstrumentLibraryEditor.h @@ -49,6 +49,11 @@ private: void onCurrentChangedForChoose(); QList<QAction*> getOverlayActions(const QModelIndex& index, bool asHover); void editNameAndDescription(InstrumentItem* item); + void createWidgetsForCurrentInstrument(); + + void onInstrumentNameEdited(const QString& newName); + void onInstrumentDescriptionEdited(const QString& t); + void onInstrumentChangedByEditor(); private: //! A model extension for InstrumentsTreeModel which diff --git a/GUI/View/Instrument/InstrumentLibraryEditor.ui b/GUI/View/Instrument/InstrumentLibraryEditor.ui index 22ae3fd9977e9a1295f3df7a91904d0c61c37a22..3768677680cce285df50c47463564b0af57a3675 100644 --- a/GUI/View/Instrument/InstrumentLibraryEditor.ui +++ b/GUI/View/Instrument/InstrumentLibraryEditor.ui @@ -20,7 +20,21 @@ <enum>Qt::Horizontal</enum> </property> <widget class="QTreeView" name="treeView"/> - <widget class="QTextBrowser" name="textBrowser"/> + <widget class="QScrollArea" name="scrollArea"> + <property name="widgetResizable"> + <bool>true</bool> + </property> + <widget class="QWidget" name="scrollAreaWidgetContents"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>69</width> + <height>380</height> + </rect> + </property> + </widget> + </widget> </widget> </item> <item>