Skip to content
Snippets Groups Projects
Commit 94062c7b authored by AlQuemist's avatar AlQuemist
Browse files

convert GUI/View/MaterialEditor/MaterialEditorDialog.ui to C++ code

parent 997f653f
No related branches found
No related tags found
1 merge request!2148Replace Qt UI files with C++ code
......@@ -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
......
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment