diff --git a/GUI/View/MaterialEditor/MaterialEditorDialog.cpp b/GUI/View/MaterialEditor/MaterialEditorDialog.cpp index 2299291f3e6977de61ca1e0f23c8666f462239eb..c499ca1c72704416a2fef26d23e8e56700c77119 100644 --- a/GUI/View/MaterialEditor/MaterialEditorDialog.cpp +++ b/GUI/View/MaterialEditor/MaterialEditorDialog.cpp @@ -19,6 +19,7 @@ #include "GUI/Model/Project/ProjectDocument.h" #include "GUI/Model/Sample/ItemWithMaterial.h" #include "GUI/Model/Sample/SampleModel.h" +#include "GUI/Model/Types/DoubleDescriptor.h" #include "GUI/Model/Types/VectorItem.h" #include "GUI/View/MaterialEditor/MaterialEditorModel.h" #include "GUI/View/Tool/EditUtil.h" @@ -145,12 +146,9 @@ MaterialEditorDialog::~MaterialEditorDialog() appSettings->saveWindowSizeAndPos(this); } -//! replaces original material model with the model modified by MaterialEditor void MaterialEditorDialog::accept() { - if (*m_document->materialModel() != *m_tmpMaterialModel) - m_document->materialModel()->initFrom(m_tmpMaterialModel.get(), nullptr); - + m_document->materialModel()->initFrom(*m_tmpMaterialModel); QDialog::accept(); } @@ -251,13 +249,11 @@ void MaterialEditorDialog::fill() m_ui->selectColorButton->setIcon(pixmap); if (materialItem->hasRefractiveIndex()) { - m_ui->deltaEdit->setText(QString::number(materialItem->refractiveIndexDelta(), 'g')); - m_ui->betaEdit->setText(QString::number(materialItem->refractiveIndexBeta(), 'g')); + m_ui->deltaEdit->setText(QString::number(materialItem->delta().get(), 'g')); + m_ui->betaEdit->setText(QString::number(materialItem->beta().get(), 'g')); } else { - m_ui->realEdit->setText( - QString::number(materialItem->scatteringLengthDensity().real(), 'g')); - m_ui->imaginaryEdit->setText( - QString::number(materialItem->scatteringLengthDensity().imag(), 'g')); + m_ui->realEdit->setText(QString::number(materialItem->sldRe().get(), 'g')); + m_ui->imaginaryEdit->setText(QString::number(materialItem->sldIm().get(), 'g')); } m_ui->xSpinBox->setValue(materialItem->magnetization().x()); diff --git a/GUI/View/MaterialEditor/MaterialEditorDialog.h b/GUI/View/MaterialEditor/MaterialEditorDialog.h index 11f0e7e9e0129fbeba099bd3274857e28d590d45..bf37d20260d359f32624ff68bcb17c5bc2b93834 100644 --- a/GUI/View/MaterialEditor/MaterialEditorDialog.h +++ b/GUI/View/MaterialEditor/MaterialEditorDialog.h @@ -49,6 +49,7 @@ private: MaterialEditorDialog(ProjectDocument* document, QWidget* parent = nullptr); ~MaterialEditorDialog() override; + //! updates original material model with the edited model void accept() override; void addRefractiveMaterial(); diff --git a/GUI/View/MaterialEditor/MaterialEditorModel.cpp b/GUI/View/MaterialEditor/MaterialEditorModel.cpp index 607cab48710de4a33fb1309b4ff142f4ee1f0807..6bf828f20ccf03a95ef834e2ced6350cc1a95859 100644 --- a/GUI/View/MaterialEditor/MaterialEditorModel.cpp +++ b/GUI/View/MaterialEditor/MaterialEditorModel.cpp @@ -15,6 +15,7 @@ #include "GUI/View/MaterialEditor/MaterialEditorModel.h" #include "GUI/Model/Material/MaterialItem.h" #include "GUI/Model/Material/MaterialModel.h" +#include "GUI/Model/Types/DoubleDescriptor.h" #include "GUI/Model/Types/VectorItem.h" #include <QApplication> #include <QFontMetrics> @@ -69,13 +70,9 @@ QVariant MaterialEditorModel::data(const QModelIndex& index, int role /*= Qt::Di case PARAMETERS: if (material->hasRefractiveIndex()) - return QString("delta: %1, beta: %2") - .arg(material->refractiveIndexDelta()) - .arg(material->refractiveIndexBeta()); + return QString("delta: %1, beta: %2").arg(material->delta()).arg(material->beta()); else - return QString("re: %1, im: %2") - .arg(material->scatteringLengthDensity().real()) - .arg(material->scatteringLengthDensity().imag()); + return QString("re: %1, im: %2").arg(material->sldRe()).arg(material->sldIm()); case MAGNETIZATION: return QString("%1/%2/%3") @@ -142,7 +139,7 @@ void MaterialEditorModel::setZ(const QModelIndex& index, double value) void MaterialEditorModel::setDelta(const QModelIndex& index, double value) { auto* m = materialFromIndex(index); - m->setRefractiveIndex(value, m->refractiveIndexBeta()); + m->setRefractiveIndex(value, m->beta()); const auto paramIndex = this->index(index.row(), PARAMETERS); emit dataChanged(paramIndex, paramIndex); } @@ -150,7 +147,7 @@ void MaterialEditorModel::setDelta(const QModelIndex& index, double value) void MaterialEditorModel::setBeta(const QModelIndex& index, double value) { auto* m = materialFromIndex(index); - m->setRefractiveIndex(m->refractiveIndexDelta(), value); + m->setRefractiveIndex(m->delta(), value); const auto paramIndex = this->index(index.row(), PARAMETERS); emit dataChanged(paramIndex, paramIndex); } @@ -158,7 +155,7 @@ void MaterialEditorModel::setBeta(const QModelIndex& index, double value) void MaterialEditorModel::setRe(const QModelIndex& index, double value) { auto* m = materialFromIndex(index); - m->setScatteringLengthDensity(complex_t(value, m->scatteringLengthDensity().imag())); + m->setScatteringLengthDensity(complex_t(value, m->sldIm())); auto paramIndex = this->index(index.row(), PARAMETERS); emit dataChanged(paramIndex, paramIndex); } @@ -166,7 +163,7 @@ void MaterialEditorModel::setRe(const QModelIndex& index, double value) void MaterialEditorModel::setIm(const QModelIndex& index, double value) { auto* m = materialFromIndex(index); - m->setScatteringLengthDensity(complex_t(m->scatteringLengthDensity().real(), value)); + m->setScatteringLengthDensity(complex_t(m->sldRe(), value)); auto paramIndex = this->index(index.row(), PARAMETERS); emit dataChanged(paramIndex, paramIndex); } @@ -219,7 +216,7 @@ MaterialItem* MaterialEditorModel::addSLDMaterial(const QString& name, double sl MaterialItem* MaterialEditorModel::cloneMaterial(const QModelIndex& index) { beginInsertRows(QModelIndex(), rowCount(), rowCount()); - auto* m = m_model->cloneMaterial(materialFromIndex(index)); + auto* m = m_model->insertCopy(*materialFromIndex(index)); endInsertRows(); return m; }