diff --git a/GUI/View/Instrument/InstrumentLibraryEditor.cpp b/GUI/View/Instrument/InstrumentLibraryEditor.cpp index b62efdf5be215a405ab1d135987b98b8ca7dffbd..07522a4e0fb1e62955af4b710229b526f56b65fb 100644 --- a/GUI/View/Instrument/InstrumentLibraryEditor.cpp +++ b/GUI/View/Instrument/InstrumentLibraryEditor.cpp @@ -24,41 +24,76 @@ #include "GUI/View/Item/ItemViewOverlayButtons.h" #include "GUI/View/Tool/ItemDelegateForHTML.h" #include "GUI/View/Widget/ApplicationSettings.h" -#include "ui_InstrumentLibraryEditor.h" #include <QAction> #include <QFormLayout> #include <QInputDialog> #include <QPushButton> #include <QTextEdit> +// UI +#include <QDialog> +#include <QDialogButtonBox> +#include <QScrollArea> +#include <QSplitter> +#include <QTreeView> +#include <QVBoxLayout> + InstrumentLibraryEditor::InstrumentLibraryEditor(QWidget* parent, InstrumentLibrary* instrumentLibrary) : QDialog(parent) , m_instrumentLibrary(instrumentLibrary) - , m_ui(new Ui::InstrumentLibraryEditor) , m_treeModel(new TreeModel(this, instrumentLibrary->instrumentModel())) , m_chosenItem(nullptr) { - m_ui->setupUi(this); + // object name is needed to reload application settings + if (this->objectName().isEmpty()) + this->setObjectName("InstrumentLibraryEditor"); + + setGeometry(0, 0, 780, 429); + + auto* verticalLayout = new QVBoxLayout(this); + setLayout(verticalLayout); + + auto* splitter = new QSplitter; + verticalLayout->addWidget(splitter); + splitter->setOrientation(Qt::Horizontal); + + m_treeView = new QTreeView; + splitter->addWidget(m_treeView); + + m_scrollArea = new QScrollArea; + splitter->addWidget(m_scrollArea); + m_scrollArea->setWidgetResizable(true); + + auto* scrollAreaWidgetContents = new QWidget; + scrollAreaWidgetContents->setGeometry(0, 0, 69, 380); + m_scrollArea->setWidget(scrollAreaWidgetContents); + + m_buttonBox = new QDialogButtonBox; + verticalLayout->addWidget(m_buttonBox); + m_buttonBox->setOrientation(Qt::Horizontal); + m_buttonBox->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok); setWindowIcon(QIcon(":/images/library.svg")); setWindowFlag(Qt::WindowContextHelpButtonHint, false); m_treeModel->enableEmptyHeadlines(false); - m_ui->treeView->setItemsExpandable(false); - m_ui->treeView->setRootIsDecorated(false); - m_ui->treeView->setHeaderHidden(true); - m_ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu); - m_ui->treeView->setModel(m_treeModel); - m_ui->treeView->expandAll(); - m_ui->treeView->setVerticalScrollMode(QTreeView::ScrollPerPixel); - m_ui->treeView->setIndentation(0); - m_ui->treeView->setItemDelegate(new ItemDelegateForHTML(this)); - m_ui->treeView->setIconSize(QSize(128, 128)); + m_treeView->setItemsExpandable(false); + m_treeView->setRootIsDecorated(false); + m_treeView->setHeaderHidden(true); + m_treeView->setContextMenuPolicy(Qt::CustomContextMenu); + m_treeView->setModel(m_treeModel); + m_treeView->expandAll(); + m_treeView->setVerticalScrollMode(QTreeView::ScrollPerPixel); + m_treeView->setIndentation(0); + m_treeView->setItemDelegate(new ItemDelegateForHTML(this)); + m_treeView->setIconSize(QSize(128, 128)); - connect(m_treeModel, &QAbstractItemModel::modelReset, - [this]() { m_ui->treeView->expandAll(); }); + connect(m_treeModel, &QAbstractItemModel::modelReset, [this]() { m_treeView->expandAll(); }); + + connect(m_buttonBox, &QDialogButtonBox::accepted, this, &InstrumentLibraryEditor::accept); + connect(m_buttonBox, &QDialogButtonBox::rejected, this, &InstrumentLibraryEditor::reject); // ensure a current item when widget is shown GUI::Style::setResizable(this); @@ -75,12 +110,12 @@ InstrumentItem* InstrumentLibraryEditor::execChoose() setWindowTitle("Instrument Library - Choose instrument"); ItemViewOverlayButtons::install( - m_ui->treeView, [this](const QModelIndex& i, bool h) { return getOverlayActions(i, h); }); - m_ui->treeView->setItemDelegate(new ItemDelegateForHTML(this)); + m_treeView, [this](const QModelIndex& i, bool h) { return getOverlayActions(i, h); }); + m_treeView->setItemDelegate(new ItemDelegateForHTML(this)); - connect(m_ui->treeView, &QTreeView::doubleClicked, this, + connect(m_treeView, &QTreeView::doubleClicked, this, &InstrumentLibraryEditor::onItemDoubleClickedForChoose); - connect(m_ui->treeView->selectionModel(), &QItemSelectionModel::currentChanged, this, + connect(m_treeView->selectionModel(), &QItemSelectionModel::currentChanged, this, &InstrumentLibraryEditor::onCurrentChangedForChoose); onCurrentChangedForChoose(); @@ -100,19 +135,15 @@ void InstrumentLibraryEditor::execAdd(const InstrumentItem& instrumentToAdd) m_treeModel->setNewInstrument(addedInstrument); ItemViewOverlayButtons::install( - m_ui->treeView, [this](const QModelIndex& i, bool h) { return getOverlayActions(i, h); }); - m_ui->treeView->setItemDelegate(new ItemDelegateForHTML(this)); - connect(m_ui->treeView->selectionModel(), &QItemSelectionModel::currentChanged, this, + m_treeView, [this](const QModelIndex& i, bool h) { return getOverlayActions(i, h); }); + m_treeView->setItemDelegate(new ItemDelegateForHTML(this)); + connect(m_treeView->selectionModel(), &QItemSelectionModel::currentChanged, this, &InstrumentLibraryEditor::createWidgetsForCurrentInstrument); - m_ui->buttonBox->addButton(QDialogButtonBox::Close); - m_ui->buttonBox->button(QDialogButtonBox::Ok)->hide(); - m_ui->buttonBox->button(QDialogButtonBox::Cancel)->hide(); - QModelIndex index = m_treeModel->indexForItem(addedInstrument); - m_ui->treeView->expandAll(); - m_ui->treeView->setCurrentIndex(index); - m_ui->treeView->scrollTo(index, QAbstractItemView::PositionAtTop); + m_treeView->expandAll(); + m_treeView->setCurrentIndex(index); + m_treeView->scrollTo(index, QAbstractItemView::PositionAtTop); createWidgetsForCurrentInstrument(); exec(); } @@ -126,8 +157,8 @@ void InstrumentLibraryEditor::onItemDoubleClickedForChoose(const QModelIndex& in void InstrumentLibraryEditor::onCurrentChangedForChoose() { - m_chosenItem = m_treeModel->itemForIndex(m_ui->treeView->currentIndex()); - m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(m_chosenItem != nullptr); + m_chosenItem = m_treeModel->itemForIndex(m_treeView->currentIndex()); + m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(m_chosenItem != nullptr); createWidgetsForCurrentInstrument(); } @@ -156,17 +187,17 @@ QList<QAction*> InstrumentLibraryEditor::getOverlayActions(const QModelIndex& in void InstrumentLibraryEditor::createWidgetsForCurrentInstrument() { - auto* currentInstrument = m_treeModel->itemForIndex(m_ui->treeView->currentIndex()); + auto* currentInstrument = m_treeModel->itemForIndex(m_treeView->currentIndex()); if (!currentInstrument) { - m_ui->scrollArea->setWidget(new QWidget(m_ui->scrollArea)); // blank widget + m_scrollArea->setWidget(new QWidget(m_scrollArea)); // blank widget return; } - QWidget* w = new QWidget(m_ui->scrollArea); + QWidget* w = new QWidget(m_scrollArea); auto* layout = new QVBoxLayout(w); auto title = QString("Summary (%1 instrument)").arg(currentInstrument->instrumentType()); - auto* g = new CollapsibleGroupBox(title, m_ui->scrollArea, currentInstrument->expandInfo); + auto* g = new CollapsibleGroupBox(title, m_scrollArea, currentInstrument->expandInfo); g->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); auto* formLayout = new QFormLayout(g->body()); formLayout->setContentsMargins(17, 17, 17, 17); @@ -191,40 +222,40 @@ void InstrumentLibraryEditor::createWidgetsForCurrentInstrument() auto* ec = m_instrumentLibrary->editController(); if (auto* sp = dynamic_cast<SpecularInstrumentItem*>(currentInstrument)) { - auto* editor = new SpecularInstrumentEditor(m_ui->scrollArea, sp, ec); + auto* editor = new SpecularInstrumentEditor(m_scrollArea, sp, ec); connect(editor, &SpecularInstrumentEditor::dataChanged, this, &InstrumentLibraryEditor::onInstrumentChangedByEditor); layout->addWidget(editor); } else if (auto* os = dynamic_cast<OffspecInstrumentItem*>(currentInstrument)) { - auto* editor = new OffspecInstrumentEditor(m_ui->scrollArea, os, ec); + auto* editor = new OffspecInstrumentEditor(m_scrollArea, os, ec); connect(editor, &OffspecInstrumentEditor::dataChanged, this, &InstrumentLibraryEditor::onInstrumentChangedByEditor); layout->addWidget(editor); } else if (auto* gisas = dynamic_cast<GISASInstrumentItem*>(currentInstrument)) { - auto* editor = new GISASInstrumentEditor(m_ui->scrollArea, gisas); + auto* editor = new GISASInstrumentEditor(m_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, ec); + auto* editor = new DepthprobeInstrumentEditor(m_scrollArea, dp, ec); connect(editor, &DepthprobeInstrumentEditor::dataChanged, this, &InstrumentLibraryEditor::onInstrumentChangedByEditor); layout->addWidget(editor); } else ASSERT_NEVER; - m_ui->scrollArea->setWidget(w); + m_scrollArea->setWidget(w); } void InstrumentLibraryEditor::onInstrumentNameEdited(const QString& newName) { - QModelIndex index = m_ui->treeView->currentIndex(); + QModelIndex index = m_treeView->currentIndex(); m_treeModel->setData(index, newName, Qt::EditRole); } void InstrumentLibraryEditor::onInstrumentDescriptionEdited(const QString& t) { - QModelIndex index = m_ui->treeView->currentIndex(); + QModelIndex index = m_treeView->currentIndex(); m_treeModel->setData(index, t, Qt::ToolTipRole); } @@ -232,7 +263,7 @@ void InstrumentLibraryEditor::onInstrumentChangedByEditor() { // uses 'MultiInstrumentNotifier::instrumentChanged' signal to set // 'InstrumentLibrary:m_modified' flag to true ==> save library on close. - auto* currentInstrument = m_treeModel->itemForIndex(m_ui->treeView->currentIndex()); + auto* currentInstrument = m_treeModel->itemForIndex(m_treeView->currentIndex()); m_instrumentLibrary->editController()->notifyInstrumentChanged(currentInstrument); } diff --git a/GUI/View/Instrument/InstrumentLibraryEditor.h b/GUI/View/Instrument/InstrumentLibraryEditor.h index 92aecda385e38ea0f94f73b7d87aee8dfc4efc1c..cf6fc168525678ef8721a62348a93bebf6448fd1 100644 --- a/GUI/View/Instrument/InstrumentLibraryEditor.h +++ b/GUI/View/Instrument/InstrumentLibraryEditor.h @@ -21,10 +21,9 @@ class InstrumentItem; class InstrumentLibrary; - -namespace Ui { -class InstrumentLibraryEditor; -} +class QTreeView; +class QScrollArea; +class QDialogButtonBox; class InstrumentLibraryEditor : public QDialog { Q_OBJECT @@ -66,9 +65,13 @@ private: }; InstrumentLibrary* m_instrumentLibrary; - Ui::InstrumentLibraryEditor* m_ui; TreeModel* m_treeModel; InstrumentItem* m_chosenItem; + + // UI + QTreeView* m_treeView; + QScrollArea* m_scrollArea; + QDialogButtonBox* m_buttonBox; }; #endif // BORNAGAIN_GUI_VIEW_INSTRUMENT_INSTRUMENTLIBRARYEDITOR_H diff --git a/GUI/View/Instrument/InstrumentLibraryEditor.ui b/GUI/View/Instrument/InstrumentLibraryEditor.ui deleted file mode 100644 index 3768677680cce285df50c47463564b0af57a3675..0000000000000000000000000000000000000000 --- a/GUI/View/Instrument/InstrumentLibraryEditor.ui +++ /dev/null @@ -1,87 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>InstrumentLibraryEditor</class> - <widget class="QDialog" name="InstrumentLibraryEditor"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>780</width> - <height>429</height> - </rect> - </property> - <property name="windowTitle"> - <string>Dialog</string> - </property> - <layout class="QVBoxLayout" name="verticalLayout"> - <item> - <widget class="QSplitter" name="splitter"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <widget class="QTreeView" name="treeView"/> - <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> - <widget class="QDialogButtonBox" name="buttonBox"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="standardButtons"> - <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> - </property> - </widget> - </item> - </layout> - </widget> - <resources/> - <connections> - <connection> - <sender>buttonBox</sender> - <signal>accepted()</signal> - <receiver>InstrumentLibraryEditor</receiver> - <slot>accept()</slot> - <hints> - <hint type="sourcelabel"> - <x>248</x> - <y>254</y> - </hint> - <hint type="destinationlabel"> - <x>157</x> - <y>274</y> - </hint> - </hints> - </connection> - <connection> - <sender>buttonBox</sender> - <signal>rejected()</signal> - <receiver>InstrumentLibraryEditor</receiver> - <slot>reject()</slot> - <hints> - <hint type="sourcelabel"> - <x>316</x> - <y>260</y> - </hint> - <hint type="destinationlabel"> - <x>286</x> - <y>274</y> - </hint> - </hints> - </connection> - </connections> -</ui> diff --git a/GUI/View/MaterialEditor/MaterialEditorDialog.cpp b/GUI/View/MaterialEditor/MaterialEditorDialog.cpp index ef251b8d4e31e33e30009b1b8b725422a5ac287d..42fe95f487fbaa6520541fe8a9c9aab3949ea243 100644 --- a/GUI/View/MaterialEditor/MaterialEditorDialog.cpp +++ b/GUI/View/MaterialEditor/MaterialEditorDialog.cpp @@ -23,39 +23,155 @@ #include "GUI/View/Tool/mainwindow_constants.h" #include "GUI/View/Widget/ApplicationSettings.h" #include "GUI/View/Widget/StyledToolbar.h" -#include "ui_MaterialEditorDialog.h" #include <QAction> #include <QColorDialog> +#include <QDialogButtonBox> +#include <QDoubleSpinBox> +#include <QFormLayout> +#include <QGroupBox> +#include <QHeaderView> +#include <QLabel> +#include <QLineEdit> #include <QMessageBox> #include <QPushButton> #include <QSettings> +#include <QSplitter> +#include <QTreeView> #include <QVBoxLayout> + MaterialEditorDialog::MaterialEditorDialog(SampleItem* sample, QWidget* parent) : QDialog(parent) - , m_ui(new Ui::MaterialEditorDialog) , m_sample(sample) { + // object name is needed to reload application settings + if (this->objectName().isEmpty()) + this->setObjectName("MaterialEditorDialog"); + m_tmpMaterialModel.initFrom(m_sample->materialModel()); m_model = new MaterialEditorModel(&m_tmpMaterialModel); - m_ui->setupUi(this); + setGeometry(0, 0, 1023, 469); + setWindowTitle("Material Editor"); + + auto* m_mainLayout = new QVBoxLayout(this); + setLayout(m_mainLayout); + + auto* splitter = new QSplitter; + m_mainLayout->addWidget(splitter); + splitter->setOrientation(Qt::Horizontal); + splitter->setChildrenCollapsible(false); + + m_treeView = new QTreeView; + splitter->addWidget(m_treeView); + m_treeView->setContextMenuPolicy(Qt::ActionsContextMenu); + m_treeView->setSelectionMode(QAbstractItemView::SingleSelection); + m_treeView->setSelectionBehavior(QAbstractItemView::SelectRows); + m_treeView->setRootIsDecorated(false); + + m_propertiesWidget = new QWidget; + splitter->addWidget(m_propertiesWidget); + auto* verticalLayout_2 = new QVBoxLayout; + m_propertiesWidget->setLayout(verticalLayout_2); + verticalLayout_2->setSpacing(6); + verticalLayout_2->setContentsMargins(0, 0, 0, 0); + + auto* formLayout_3 = new QFormLayout; + verticalLayout_2->addLayout(formLayout_3); + auto* label = new QLabel("Name:"); + formLayout_3->setWidget(0, QFormLayout::LabelRole, label); + m_nameEdit = new QLineEdit; + formLayout_3->setWidget(0, QFormLayout::FieldRole, m_nameEdit); + auto* label_2 = new QLabel("Color:"); + formLayout_3->setWidget(1, QFormLayout::LabelRole, label_2); + + m_refractiveGroupBox = new QGroupBox("Material data (refractive index based)"); + verticalLayout_2->addWidget(m_refractiveGroupBox); + + auto* horizontalLayout = new QHBoxLayout; + + m_selectColorButton = new QPushButton; + horizontalLayout->addWidget(m_selectColorButton); + QSizePolicy sizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed); + sizePolicy.setHorizontalStretch(0); + sizePolicy.setVerticalStretch(0); + sizePolicy.setHeightForWidth(m_selectColorButton->sizePolicy().hasHeightForWidth()); + m_selectColorButton->setSizePolicy(sizePolicy); + m_selectColorButton->setToolTip("Choose color"); + m_selectColorButton->setText(QString()); + + m_colorInfo = new QLineEdit; + horizontalLayout->addWidget(m_colorInfo); + m_colorInfo->setEnabled(false); + formLayout_3->setLayout(1, QFormLayout::FieldRole, horizontalLayout); + + auto* formLayout_5 = new QFormLayout(m_refractiveGroupBox); // WHERE USED? + auto* label_3 = new QLabel("Delta:"); + m_deltaEdit = new QLineEdit; + m_deltaEdit->setToolTip("Delta of refractive index (n = 1 - delta + i*beta)"); + auto* label_4 = new QLabel("Beta:"); + m_betaEdit = new QLineEdit; + m_betaEdit->setToolTip("Beta of refractive index (n = 1 - delta + i*beta)"); + formLayout_5->addRow(label_3, m_deltaEdit); + formLayout_5->addRow(label_4, m_betaEdit); + + m_sldGroupBox = new QGroupBox("Material data (SLD based [1/Ų])"); + verticalLayout_2->addWidget(m_sldGroupBox); + auto* formLayout_4 = new QFormLayout; + auto* label_5 = new QLabel("Real:"); + m_realEdit = new QLineEdit; + m_realEdit->setToolTip("Real part of SLD (SLD = real - i*imag), AA^{-2}"); + auto* label_6 = new QLabel("Imaginary:"); + m_imaginaryEdit = new QLineEdit; + m_imaginaryEdit->setToolTip("Imaginary part of SLD (SLD = real - i*imag), AA^{-2}"); + formLayout_4->addRow(label_5, m_realEdit); + formLayout_4->addRow(label_6, m_imaginaryEdit); + + auto* groupBox_3 = new QGroupBox("Magnetization"); + verticalLayout_2->addWidget(groupBox_3); + auto* formLayout_2 = new QFormLayout(groupBox_3); + + auto* label_7 = new QLabel("X:"); + m_xSpinBox = new QDoubleSpinBox; + formLayout_2->addRow(label_7, m_xSpinBox); + m_xSpinBox->setSuffix(" A/m"); + m_xSpinBox->setToolTip("x coordinate of magnetization"); + + auto* label_8 = new QLabel("Y:"); + m_ySpinBox = new QDoubleSpinBox; + formLayout_2->addRow(label_8, m_ySpinBox); + m_ySpinBox->setSuffix(" A/m"); + m_ySpinBox->setToolTip("y coordinate of magnetization"); + + auto* label_9 = new QLabel("Z:"); + m_zSpinBox = new QDoubleSpinBox; + formLayout_2->addRow(label_9, m_zSpinBox); + m_zSpinBox->setSuffix(" A/m"); + m_zSpinBox->setToolTip("z coordinate of magnetization"); + + auto* verticalSpacer = new QSpacerItem(20, 15, QSizePolicy::Minimum, QSizePolicy::Expanding); + verticalLayout_2->addItem(verticalSpacer); + + auto* m_buttonBox = new QDialogButtonBox; + m_mainLayout->addWidget(m_buttonBox); + m_buttonBox->setOrientation(Qt::Horizontal); + m_buttonBox->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok); using GUI::View::NumberUtil::configScientificDoubleEdit; - configScientificDoubleEdit(m_ui->deltaEdit, RealLimits::limitless()); - configScientificDoubleEdit(m_ui->betaEdit, RealLimits::limitless()); - configScientificDoubleEdit(m_ui->realEdit, RealLimits::limitless()); - configScientificDoubleEdit(m_ui->imaginaryEdit, RealLimits::limitless()); + configScientificDoubleEdit(m_deltaEdit, RealLimits::limitless()); + configScientificDoubleEdit(m_betaEdit, RealLimits::limitless()); + configScientificDoubleEdit(m_realEdit, RealLimits::limitless()); + configScientificDoubleEdit(m_imaginaryEdit, RealLimits::limitless()); using GUI::View::NumberUtil::configSpinbox; - configSpinbox(m_ui->xSpinBox, 3, RealLimits::limitless()); - configSpinbox(m_ui->ySpinBox, 3, RealLimits::limitless()); - configSpinbox(m_ui->zSpinBox, 3, RealLimits::limitless()); + configSpinbox(m_xSpinBox, 3, RealLimits::limitless()); + configSpinbox(m_ySpinBox, 3, RealLimits::limitless()); + configSpinbox(m_zSpinBox, 3, RealLimits::limitless()); // Setting z-component is temporary disabled (see issue #654) // When implemented, rm disabling - m_ui->zSpinBox->setDisabled(true); + m_zSpinBox->setDisabled(true); auto* addRefractiveMaterialAction = new QAction("Add material (refractive index)", parent); addRefractiveMaterialAction->setIcon(QIcon(":/images/shape-square-plus.svg")); @@ -80,15 +196,15 @@ MaterialEditorDialog::MaterialEditorDialog(SampleItem* sample, QWidget* parent) connect(m_removeMaterialAction, &QAction::triggered, this, &MaterialEditorDialog::removeCurrentMaterial); - m_ui->treeView->addAction(addRefractiveMaterialAction); - m_ui->treeView->addAction(addSldMaterialAction); - m_ui->treeView->addAction(m_cloneMaterialAction); + m_treeView->addAction(addRefractiveMaterialAction); + m_treeView->addAction(addSldMaterialAction); + m_treeView->addAction(m_cloneMaterialAction); auto* separator = new QAction(this); separator->setSeparator(true); - m_ui->treeView->addAction(separator); - m_ui->treeView->addAction(m_removeMaterialAction); - m_ui->treeView->setModel(m_model); - m_ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents); + m_treeView->addAction(separator); + m_treeView->addAction(m_removeMaterialAction); + m_treeView->setModel(m_model); + m_treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents); auto* toolbar = new StyledToolbar(this); toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); @@ -96,50 +212,51 @@ MaterialEditorDialog::MaterialEditorDialog(SampleItem* sample, QWidget* parent) toolbar->addAction(addSldMaterialAction); toolbar->addAction(m_cloneMaterialAction); toolbar->addAction(m_removeMaterialAction); - m_ui->mainLayout->insertWidget(0, toolbar); + m_mainLayout->insertWidget(0, toolbar); GUI::Style::setResizable(this); appSettings->loadWindowSizeAndPos(this); - connect(m_ui->treeView->selectionModel(), &QItemSelectionModel::currentChanged, this, + connect(m_treeView->selectionModel(), &QItemSelectionModel::currentChanged, this, &MaterialEditorDialog::fill); - connect(m_ui->treeView->selectionModel(), &QItemSelectionModel::currentChanged, this, + connect(m_treeView->selectionModel(), &QItemSelectionModel::currentChanged, this, &MaterialEditorDialog::updateActionEnabling); - connect(m_ui->selectColorButton, &QPushButton::clicked, this, - &MaterialEditorDialog::onSelectColor); + connect(m_selectColorButton, &QPushButton::clicked, this, &MaterialEditorDialog::onSelectColor); - connect(m_ui->nameEdit, &QLineEdit::textEdited, + connect(m_nameEdit, &QLineEdit::textEdited, [&](const QString& t) { m_model->setMaterialItemName(currentIndex(), t); }); - connect(m_ui->xSpinBox, &QDoubleSpinBox::valueChanged, + connect(m_xSpinBox, &QDoubleSpinBox::valueChanged, [&](double value) { m_model->setX(currentIndex(), value); }); - connect(m_ui->ySpinBox, &QDoubleSpinBox::valueChanged, + connect(m_ySpinBox, &QDoubleSpinBox::valueChanged, [&](double value) { m_model->setY(currentIndex(), value); }); - connect(m_ui->zSpinBox, &QDoubleSpinBox::valueChanged, + connect(m_zSpinBox, &QDoubleSpinBox::valueChanged, [&](double value) { m_model->setZ(currentIndex(), value); }); - connect(m_ui->deltaEdit, &QLineEdit::editingFinished, - [&]() { m_model->setDelta(currentIndex(), m_ui->deltaEdit->text().toDouble()); }); + connect(m_deltaEdit, &QLineEdit::editingFinished, + [&]() { m_model->setDelta(currentIndex(), m_deltaEdit->text().toDouble()); }); - connect(m_ui->betaEdit, &QLineEdit::editingFinished, - [&]() { m_model->setBeta(currentIndex(), m_ui->betaEdit->text().toDouble()); }); + connect(m_betaEdit, &QLineEdit::editingFinished, + [&]() { m_model->setBeta(currentIndex(), m_betaEdit->text().toDouble()); }); - connect(m_ui->realEdit, &QLineEdit::editingFinished, - [&]() { m_model->setRe(currentIndex(), m_ui->realEdit->text().toDouble()); }); + connect(m_realEdit, &QLineEdit::editingFinished, + [&]() { m_model->setRe(currentIndex(), m_realEdit->text().toDouble()); }); - connect(m_ui->imaginaryEdit, &QLineEdit::editingFinished, - [&]() { m_model->setIm(currentIndex(), m_ui->imaginaryEdit->text().toDouble()); }); + connect(m_imaginaryEdit, &QLineEdit::editingFinished, + [&]() { m_model->setIm(currentIndex(), m_imaginaryEdit->text().toDouble()); }); + connect(m_buttonBox, &QDialogButtonBox::accepted, this, &MaterialEditorDialog::accept); + connect(m_buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); if (m_model->rowCount() > 0) - m_ui->treeView->setCurrentIndex(m_model->first()); + m_treeView->setCurrentIndex(m_model->first()); else { - m_ui->sldGroupBox->hide(); - m_ui->propertiesWidget->setEnabled(false); + m_sldGroupBox->hide(); + m_propertiesWidget->setEnabled(false); } } @@ -226,56 +343,56 @@ void MaterialEditorDialog::fill() { auto* materialItem = currentMaterialItem(); - m_ui->propertiesWidget->setEnabled(materialItem != nullptr); + m_propertiesWidget->setEnabled(materialItem != nullptr); if (materialItem == nullptr) { - m_ui->refractiveGroupBox->show(); - m_ui->sldGroupBox->hide(); - for (auto* lineEdit : m_ui->propertiesWidget->findChildren<QLineEdit*>()) + m_refractiveGroupBox->show(); + m_sldGroupBox->hide(); + for (auto* lineEdit : m_propertiesWidget->findChildren<QLineEdit*>()) lineEdit->clear(); - for (auto* spinBox : m_ui->propertiesWidget->findChildren<QDoubleSpinBox*>()) + for (auto* spinBox : m_propertiesWidget->findChildren<QDoubleSpinBox*>()) spinBox->clear(); return; } - m_ui->refractiveGroupBox->setVisible(materialItem->hasRefractiveIndex()); - m_ui->sldGroupBox->setVisible(!materialItem->hasRefractiveIndex()); + m_refractiveGroupBox->setVisible(materialItem->hasRefractiveIndex()); + m_sldGroupBox->setVisible(!materialItem->hasRefractiveIndex()); - m_ui->nameEdit->setText(materialItem->matItemName()); - m_ui->colorInfo->setText(QString("[%1, %2, %3] (%4)") - .arg(materialItem->color().red()) - .arg(materialItem->color().green()) - .arg(materialItem->color().blue()) - .arg(materialItem->color().alpha())); - QPixmap pixmap(m_ui->selectColorButton->iconSize()); + m_nameEdit->setText(materialItem->matItemName()); + m_colorInfo->setText(QString("[%1, %2, %3] (%4)") + .arg(materialItem->color().red()) + .arg(materialItem->color().green()) + .arg(materialItem->color().blue()) + .arg(materialItem->color().alpha())); + QPixmap pixmap(m_selectColorButton->iconSize()); pixmap.fill(materialItem->color()); - m_ui->selectColorButton->setIcon(pixmap); + m_selectColorButton->setIcon(pixmap); if (materialItem->hasRefractiveIndex()) { - m_ui->deltaEdit->setText(QString::number(materialItem->delta().value(), 'g')); - m_ui->betaEdit->setText(QString::number(materialItem->beta().value(), 'g')); + m_deltaEdit->setText(QString::number(materialItem->delta().value(), 'g')); + m_betaEdit->setText(QString::number(materialItem->beta().value(), 'g')); } else { - m_ui->realEdit->setText(QString::number(materialItem->sldRe().value(), 'g')); - m_ui->imaginaryEdit->setText(QString::number(materialItem->sldIm().value(), 'g')); + m_realEdit->setText(QString::number(materialItem->sldRe().value(), 'g')); + m_imaginaryEdit->setText(QString::number(materialItem->sldIm().value(), 'g')); } - m_ui->xSpinBox->setValue(materialItem->magnetization().r3().x()); - m_ui->ySpinBox->setValue(materialItem->magnetization().r3().y()); - m_ui->zSpinBox->setValue(materialItem->magnetization().r3().z()); + m_xSpinBox->setValue(materialItem->magnetization().r3().x()); + m_ySpinBox->setValue(materialItem->magnetization().r3().y()); + m_zSpinBox->setValue(materialItem->magnetization().r3().z()); } void MaterialEditorDialog::setCurrentMaterial(const MaterialItem* m) { - m_ui->treeView->setCurrentIndex(m_model->indexFromMaterial(m)); + m_treeView->setCurrentIndex(m_model->indexFromMaterial(m)); } void MaterialEditorDialog::setCurrentMaterial(const QString& identifier) { - m_ui->treeView->setCurrentIndex(m_model->indexFromMaterial(identifier)); + m_treeView->setCurrentIndex(m_model->indexFromMaterial(identifier)); } QModelIndex MaterialEditorDialog::currentIndex() const { - return m_ui->treeView->currentIndex(); + return m_treeView->currentIndex(); } QStringList MaterialEditorDialog::identifiersOfUsedMaterials() const diff --git a/GUI/View/MaterialEditor/MaterialEditorDialog.h b/GUI/View/MaterialEditor/MaterialEditorDialog.h index 91af8b75abc51d1299d0023b602ac66b3381e563..46497eea4df17059f0a5a77e389239585401438d 100644 --- a/GUI/View/MaterialEditor/MaterialEditorDialog.h +++ b/GUI/View/MaterialEditor/MaterialEditorDialog.h @@ -22,10 +22,15 @@ class MaterialItem; class MaterialEditorModel; class SampleItem; - -namespace Ui { -class MaterialEditorDialog; -} +// UI +class QVBoxLayout; +class QTreeView; +class QPushButton; +class QWidget; +class QGroupBox; +class QDoubleSpinBox; +class QLineEdit; +class QDialogButtonBox; //! Dialog to select a material and also to edit the list of existing materials. //! The dialog operates on a copy of the current materials. The original material store is only @@ -74,10 +79,24 @@ private: QAction* m_cloneMaterialAction; QAction* m_removeMaterialAction; - Ui::MaterialEditorDialog* m_ui; - MaterialEditorModel* m_model; //! Model for the left list. Works on m_tmpMaterialModel SampleItem* m_sample; + + // UI + QTreeView* m_treeView; + QPushButton* m_selectColorButton; + QWidget* m_propertiesWidget; + QGroupBox* m_sldGroupBox; + QGroupBox* m_refractiveGroupBox; + QDoubleSpinBox* m_xSpinBox; + QDoubleSpinBox* m_ySpinBox; + QDoubleSpinBox* m_zSpinBox; + QLineEdit* m_deltaEdit; + QLineEdit* m_betaEdit; + QLineEdit* m_realEdit; + QLineEdit* m_imaginaryEdit; + QLineEdit* m_nameEdit; + QLineEdit* m_colorInfo; }; #endif // BORNAGAIN_GUI_VIEW_MATERIALEDITOR_MATERIALEDITORDIALOG_H diff --git a/GUI/View/MaterialEditor/MaterialEditorDialog.ui b/GUI/View/MaterialEditor/MaterialEditorDialog.ui deleted file mode 100644 index db4160736b1067d3abb7854f76c3209cce398ff3..0000000000000000000000000000000000000000 --- a/GUI/View/MaterialEditor/MaterialEditorDialog.ui +++ /dev/null @@ -1,311 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>MaterialEditorDialog</class> - <widget class="QDialog" name="MaterialEditorDialog"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>1023</width> - <height>469</height> - </rect> - </property> - <property name="windowTitle"> - <string>Material Editor</string> - </property> - <layout class="QVBoxLayout" name="mainLayout"> - <item> - <widget class="QSplitter" name="splitter"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="childrenCollapsible"> - <bool>false</bool> - </property> - <widget class="QTreeView" name="treeView"> - <property name="contextMenuPolicy"> - <enum>Qt::ActionsContextMenu</enum> - </property> - <property name="selectionMode"> - <enum>QAbstractItemView::SingleSelection</enum> - </property> - <property name="selectionBehavior"> - <enum>QAbstractItemView::SelectRows</enum> - </property> - <property name="rootIsDecorated"> - <bool>false</bool> - </property> - </widget> - <widget class="QWidget" name="propertiesWidget" native="true"> - <layout class="QVBoxLayout" name="verticalLayout_2"> - <property name="spacing"> - <number>6</number> - </property> - <property name="leftMargin"> - <number>0</number> - </property> - <property name="topMargin"> - <number>0</number> - </property> - <property name="rightMargin"> - <number>0</number> - </property> - <property name="bottomMargin"> - <number>0</number> - </property> - <item> - <layout class="QFormLayout" name="formLayout_3"> - <item row="0" column="0"> - <widget class="QLabel" name="label"> - <property name="text"> - <string>Name:</string> - </property> - </widget> - </item> - <item row="0" column="1"> - <widget class="QLineEdit" name="nameEdit"/> - </item> - <item row="1" column="0"> - <widget class="QLabel" name="label_2"> - <property name="text"> - <string>Color:</string> - </property> - </widget> - </item> - <item row="1" column="1"> - <layout class="QHBoxLayout" name="horizontalLayout"> - <item> - <widget class="QPushButton" name="selectColorButton"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="toolTip"> - <string>Choose color</string> - </property> - <property name="text"> - <string/> - </property> - </widget> - </item> - <item> - <widget class="QLineEdit" name="colorInfo"> - <property name="enabled"> - <bool>false</bool> - </property> - </widget> - </item> - </layout> - </item> - </layout> - </item> - <item> - <widget class="QGroupBox" name="refractiveGroupBox"> - <property name="title"> - <string>Material data (refractive index based)</string> - </property> - <layout class="QFormLayout" name="formLayout_5"> - <item row="0" column="0"> - <widget class="QLabel" name="label_3"> - <property name="text"> - <string>Delta:</string> - </property> - </widget> - </item> - <item row="0" column="1"> - <widget class="QLineEdit" name="deltaEdit"> - <property name="toolTip"> - <string>Delta of refractive index (n = 1 - delta + i*beta)</string> - </property> - </widget> - </item> - <item row="1" column="0"> - <widget class="QLabel" name="label_4"> - <property name="text"> - <string>Beta:</string> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="QLineEdit" name="betaEdit"> - <property name="toolTip"> - <string>Beta of refractive index (n = 1 - delta + i*beta)</string> - </property> - </widget> - </item> - </layout> - </widget> - </item> - <item> - <widget class="QGroupBox" name="sldGroupBox"> - <property name="title"> - <string>Material data (SLD based [1/Ų])</string> - </property> - <layout class="QFormLayout" name="formLayout_4"> - <item row="0" column="0"> - <widget class="QLabel" name="label_5"> - <property name="text"> - <string>Real:</string> - </property> - </widget> - </item> - <item row="0" column="1"> - <widget class="QLineEdit" name="realEdit"> - <property name="toolTip"> - <string>Real part of SLD (SLD = real - i*imag), AA^{-2}</string> - </property> - </widget> - </item> - <item row="1" column="0"> - <widget class="QLabel" name="label_6"> - <property name="text"> - <string>Imaginary:</string> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="QLineEdit" name="imaginaryEdit"> - <property name="toolTip"> - <string>Imaginary part of SLD (SLD = real - i*imag), AA^{-2}</string> - </property> - </widget> - </item> - </layout> - </widget> - </item> - <item> - <widget class="QGroupBox" name="groupBox_3"> - <property name="title"> - <string>Magnetization</string> - </property> - <layout class="QFormLayout" name="formLayout_2"> - <item row="0" column="0"> - <layout class="QFormLayout" name="formLayout"> - <item row="0" column="0"> - <widget class="QLabel" name="label_7"> - <property name="text"> - <string>X:</string> - </property> - </widget> - </item> - <item row="0" column="1"> - <widget class="QDoubleSpinBox" name="xSpinBox"> - <property name="toolTip"> - <string>x coordinate of magnetization</string> - </property> - <property name="suffix"> - <string> A/m</string> - </property> - </widget> - </item> - <item row="1" column="0"> - <widget class="QLabel" name="label_8"> - <property name="text"> - <string>Y:</string> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="QDoubleSpinBox" name="ySpinBox"> - <property name="toolTip"> - <string>y coordinate of magnetization</string> - </property> - <property name="suffix"> - <string> A/m</string> - </property> - </widget> - </item> - <item row="2" column="0"> - <widget class="QLabel" name="label_9"> - <property name="text"> - <string>Z:</string> - </property> - </widget> - </item> - <item row="2" column="1"> - <widget class="QDoubleSpinBox" name="zSpinBox"> - <property name="toolTip"> - <string>z coordinate of magnetization</string> - </property> - <property name="suffix"> - <string> A/m</string> - </property> - </widget> - </item> - </layout> - </item> - </layout> - </widget> - </item> - <item> - <spacer name="verticalSpacer"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>15</height> - </size> - </property> - </spacer> - </item> - </layout> - </widget> - </widget> - </item> - <item> - <widget class="QDialogButtonBox" name="buttonBox"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="standardButtons"> - <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> - </property> - </widget> - </item> - </layout> - <action name="actionsdf"> - <property name="text"> - <string>sdf</string> - </property> - </action> - </widget> - <resources/> - <connections> - <connection> - <sender>buttonBox</sender> - <signal>accepted()</signal> - <receiver>MaterialEditorDialog</receiver> - <slot>accept()</slot> - <hints> - <hint type="sourcelabel"> - <x>248</x> - <y>254</y> - </hint> - <hint type="destinationlabel"> - <x>157</x> - <y>274</y> - </hint> - </hints> - </connection> - <connection> - <sender>buttonBox</sender> - <signal>rejected()</signal> - <receiver>MaterialEditorDialog</receiver> - <slot>reject()</slot> - <hints> - <hint type="sourcelabel"> - <x>316</x> - <y>260</y> - </hint> - <hint type="destinationlabel"> - <x>286</x> - <y>274</y> - </hint> - </hints> - </connection> - </connections> -</ui>