diff --git a/GUI/View/PropertyEditor/CustomEditors.cpp b/GUI/View/PropertyEditor/CustomEditors.cpp index 58ba4bda10bf75e24d6da8c4b42fe50f541f9752..66f10b0bcbe018ccfc1961b6b607a7e8ed398558 100644 --- a/GUI/View/PropertyEditor/CustomEditors.cpp +++ b/GUI/View/PropertyEditor/CustomEditors.cpp @@ -14,26 +14,12 @@ #include "GUI/View/PropertyEditor/CustomEditors.h" #include "Base/Util/Assert.h" -#include "GUI/Model/Material/MaterialItem.h" -#include "GUI/Model/Material/MaterialItemUtils.h" #include "GUI/Model/State/SessionData.h" #include "GUI/Util/ComboProperty.h" #include "GUI/View/Common/ScientificSpinBox.h" -#include "GUI/View/Main/MainWindow.h" -#include "GUI/View/MaterialEditor/MaterialEditorDialog.h" #include "GUI/View/PropertyEditor/CustomEventFilters.h" -#include <QApplication> #include <QBoxLayout> -#include <QCheckBox> -#include <QColorDialog> #include <QComboBox> -#include <QDoubleSpinBox> -#include <QEvent> -#include <QKeyEvent> -#include <QLabel> -#include <QLineEdit> -#include <QToolButton> -#include <cmath> namespace { //! Single step for QDoubleSpinBox. @@ -66,64 +52,7 @@ void CustomEditor::setDataIntern(const QVariant& data) dataChanged(m_data); } -// --- MaterialPropertyEditor --- - -MaterialSelectionEditor::MaterialSelectionEditor(QWidget* parent) - : CustomEditor(parent) - , m_textLabel(new QLabel) - , m_pixmapLabel(new QLabel) - , m_focusFilter(new LostFocusFilter(this)) -{ - setMouseTracking(true); - setAutoFillBackground(true); - - auto* layout = new QHBoxLayout; - layout->setContentsMargins(4, 0, 0, 0); - - auto* button = new QToolButton; - button->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred)); - button->setText(QLatin1String(" . . . ")); - button->setToolTip("Material selector"); - layout->addWidget(m_pixmapLabel); - layout->addWidget(m_textLabel); - layout->addStretch(1); - layout->addWidget(button); - setFocusPolicy(Qt::StrongFocus); - setAttribute(Qt::WA_InputMethodEnabled); - connect(button, &QToolButton::clicked, this, &MaterialSelectionEditor::buttonClicked); - - setLayout(layout); -} - -void MaterialSelectionEditor::buttonClicked() -{ - // temporarily installing filter to prevent loss of focus caused by too insistent dialog - installEventFilter(m_focusFilter); - const QString materialIdentifier = m_data.toString(); - const QString newMaterialIdentifier = MaterialEditorDialog::chooseMaterial( - baWin, gSessionData->projectDocument, materialIdentifier); - - removeEventFilter(m_focusFilter); - - if (!newMaterialIdentifier.isEmpty() && newMaterialIdentifier != materialIdentifier) - setDataIntern(newMaterialIdentifier); -} - -void MaterialSelectionEditor::initEditor() -{ - ASSERT(m_data.canConvert<QString>()); - auto* const material = GUI::MaterialUtil::findMaterial(m_data.toString()); - - m_textLabel->setText(material->itemName()); - - const int size = qApp->fontMetrics().height(); - QPixmap pixmap(size, size); - pixmap.fill(material->color()); - - m_pixmapLabel->setPixmap(pixmap); -} - -// --- CustomComboEditor --- +// --- ComboPropertyEditor --- ComboPropertyEditor::ComboPropertyEditor(QWidget* parent) : CustomEditor(parent), m_box(new QComboBox), m_wheel_event_filter(new WheelEventEater(this)) @@ -203,107 +132,7 @@ void ComboPropertyEditor::setConnected(bool isConnected) this, &ComboPropertyEditor::onIndexChanged); } -// --- ScientificDoublePropertyEditor --- - -ScientificDoublePropertyEditor::ScientificDoublePropertyEditor(QWidget* parent) - : CustomEditor(parent), m_lineEdit(new QLineEdit), m_validator(nullptr) -{ - setAutoFillBackground(true); - - auto* layout = new QVBoxLayout; - layout->setMargin(0); - layout->setSpacing(0); - - layout->addWidget(m_lineEdit); - - m_validator = new QDoubleValidator(0.0, 1e+200, 1000, this); - m_validator->setNotation(QDoubleValidator::ScientificNotation); - m_lineEdit->setValidator(m_validator); - - connect(m_lineEdit, &QLineEdit::editingFinished, this, - &ScientificDoublePropertyEditor::onEditingFinished); - - setLayout(layout); -} - -void ScientificDoublePropertyEditor::setLimits(const RealLimits& limits) -{ - double minimum = limits.hasLowerLimit() ? std::max(limits.lowerLimit(), -1e+200) : -1e+200; - double maximum = limits.hasUpperLimit() ? std::min(limits.upperLimit(), +1e+200) : +1e+200; - m_validator->setRange(minimum, maximum, 1000); -} - -void ScientificDoublePropertyEditor::onEditingFinished() -{ - double new_value = m_lineEdit->text().toDouble(); - - if (new_value != m_data.toDouble()) - setDataIntern(QVariant::fromValue(new_value)); -} - -void ScientificDoublePropertyEditor::initEditor() -{ - ASSERT(m_data.type() == QVariant::Double); - m_lineEdit->setText(QString::number(m_data.toDouble(), 'g')); -} - -// --- DoubleEditor --- - -DoubleEditor::DoubleEditor(QWidget* parent) - : CustomEditor(parent), m_doubleEditor(new QDoubleSpinBox) -{ - setAutoFillBackground(true); - setFocusPolicy(Qt::StrongFocus); - m_doubleEditor->setFocusPolicy(Qt::StrongFocus); - m_doubleEditor->setKeyboardTracking(false); - - auto* layout = new QVBoxLayout; - layout->setMargin(0); - layout->setSpacing(0); - - layout->addWidget(m_doubleEditor); - - connect(m_doubleEditor, - static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), - [=] { this->onEditingFinished(); }); - - setLayout(layout); - - setFocusProxy(m_doubleEditor); -} - -void DoubleEditor::setLimits(const RealLimits& limits) -{ - m_doubleEditor->setMaximum(std::numeric_limits<double>::max()); - m_doubleEditor->setMinimum(std::numeric_limits<double>::lowest()); - - if (limits.hasLowerLimit()) - m_doubleEditor->setMinimum(limits.lowerLimit()); - if (limits.hasUpperLimit()) - m_doubleEditor->setMaximum(static_cast<int>(limits.upperLimit())); -} - -void DoubleEditor::setDecimals(int decimals) -{ - m_doubleEditor->setDecimals(decimals); - m_doubleEditor->setSingleStep(singleStep(decimals)); -} - -void DoubleEditor::onEditingFinished() -{ - double new_value = m_doubleEditor->value(); - - if (new_value != m_data.toDouble()) - setDataIntern(QVariant::fromValue(new_value)); -} - -void DoubleEditor::initEditor() -{ - ASSERT(m_data.type() == QVariant::Double); - m_doubleEditor->setValue(m_data.toDouble()); -} - -// --- DoubleEditor --- +// --- ScientificSpinBoxEditor --- ScientificSpinBoxEditor::ScientificSpinBoxEditor(QWidget* parent) : CustomEditor(parent), m_doubleEditor(new ScientificSpinBox) @@ -358,82 +187,3 @@ void ScientificSpinBoxEditor::initEditor() ASSERT(m_data.type() == QVariant::Double); m_doubleEditor->setValue(m_data.toDouble()); } - -// --- IntEditor --- - -IntEditor::IntEditor(QWidget* parent) : CustomEditor(parent), m_intEditor(new QSpinBox) -{ - setAutoFillBackground(true); - m_intEditor->setFocusPolicy(Qt::StrongFocus); - m_intEditor->setKeyboardTracking(false); - - auto* layout = new QVBoxLayout; - layout->setMargin(0); - layout->setSpacing(0); - - layout->addWidget(m_intEditor); - - connect(m_intEditor, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), - [=] { this->onEditingFinished(); }); - - setLayout(layout); - - setFocusProxy(m_intEditor); -} - -void IntEditor::setLimits(const RealLimits& limits) -{ - m_intEditor->setMaximum(std::numeric_limits<int>::max()); - - if (limits.hasLowerLimit()) - m_intEditor->setMinimum(static_cast<int>(limits.lowerLimit())); - if (limits.hasUpperLimit()) - m_intEditor->setMaximum(static_cast<int>(limits.upperLimit())); -} - -void IntEditor::onEditingFinished() -{ - int new_value = m_intEditor->value(); - - if (new_value != m_data.toInt()) - setDataIntern(QVariant::fromValue(new_value)); -} - -void IntEditor::initEditor() -{ - if (!m_data.isValid() || m_data.type() != QVariant::Int) - return; - m_intEditor->setValue(m_data.toInt()); -} - -// --- BoolEditor --- - -BoolEditor::BoolEditor(QWidget* parent) : CustomEditor(parent), m_checkBox(new QCheckBox) -{ - setAutoFillBackground(true); - auto* layout = new QHBoxLayout; - layout->setContentsMargins(4, 0, 0, 0); - layout->addWidget(m_checkBox); - setLayout(layout); - - connect(m_checkBox, &QCheckBox::toggled, this, &BoolEditor::onCheckBoxChange); - setFocusProxy(m_checkBox); - m_checkBox->setText(tr("True")); -} - -void BoolEditor::onCheckBoxChange(bool value) -{ - if (value != m_data.toBool()) - setDataIntern(QVariant(value)); -} - -void BoolEditor::initEditor() -{ - ASSERT(m_data.type() == QVariant::Bool); - bool value = m_data.toBool(); - - m_checkBox->blockSignals(true); - m_checkBox->setChecked(value); - m_checkBox->setText(value ? "True" : "False"); - m_checkBox->blockSignals(false); -} diff --git a/GUI/View/PropertyEditor/CustomEditors.h b/GUI/View/PropertyEditor/CustomEditors.h index f8a79b7a3e8052b0049addb50226101361225dcd..10620bb16a63ce1804cfc9b8ead87601ecf233c7 100644 --- a/GUI/View/PropertyEditor/CustomEditors.h +++ b/GUI/View/PropertyEditor/CustomEditors.h @@ -46,25 +46,6 @@ protected: QVariant m_data; }; -//! Editor to select a material - -class BA_CORE_API_ MaterialSelectionEditor : public CustomEditor { - Q_OBJECT -public: - explicit MaterialSelectionEditor(QWidget* parent = nullptr); - -private slots: - void buttonClicked(); - -protected: - void initEditor() override; - -private: - QLabel* m_textLabel; - QLabel* m_pixmapLabel; - LostFocusFilter* m_focusFilter; -}; - //! Editor for ComboProperty variant. class ComboPropertyEditor : public CustomEditor { @@ -88,46 +69,6 @@ protected: class WheelEventEater* m_wheel_event_filter; }; -//! Editor for ScientificDoubleProperty variant. - -class ScientificDoublePropertyEditor : public CustomEditor { - Q_OBJECT -public: - ScientificDoublePropertyEditor(QWidget* parent = nullptr); - - void setLimits(const RealLimits& limits); - -private slots: - void onEditingFinished(); - -protected: - void initEditor() override; - -private: - class QLineEdit* m_lineEdit; - class QDoubleValidator* m_validator; -}; - -//! Editor for Double variant. - -class DoubleEditor : public CustomEditor { - Q_OBJECT -public: - DoubleEditor(QWidget* parent = nullptr); - - void setLimits(const RealLimits& limits); - void setDecimals(int decimals); - -private slots: - void onEditingFinished(); - -protected: - void initEditor() override; - -private: - class QDoubleSpinBox* m_doubleEditor; -}; - //! Editor for Double variant using ScientificSpinBox. class ScientificSpinBoxEditor : public CustomEditor { @@ -149,42 +90,4 @@ private: class ScientificSpinBox* m_doubleEditor; }; -//! Editor for Int variant. - -class IntEditor : public CustomEditor { - Q_OBJECT -public: - IntEditor(QWidget* parent = nullptr); - - void setLimits(const RealLimits& limits); - -private slots: - void onEditingFinished(); - -protected: - void initEditor() override; - -private: - class QSpinBox* m_intEditor; -}; - -//! Editor for boolean. - -class QCheckBox; - -class BoolEditor : public CustomEditor { - Q_OBJECT -public: - BoolEditor(QWidget* parent = nullptr); - -private slots: - void onCheckBoxChange(bool value); - -protected: - void initEditor() override; - -private: - QCheckBox* m_checkBox; -}; - #endif // BORNAGAIN_GUI_VIEW_PROPERTYEDITOR_CUSTOMEDITORS_H diff --git a/GUI/View/PropertyEditor/MultiComboPropertyEditor.cpp b/GUI/View/PropertyEditor/MultiComboPropertyEditor.cpp deleted file mode 100644 index ae56ca3f49c7d674d44d37a3f423ae901b4cb2a3..0000000000000000000000000000000000000000 --- a/GUI/View/PropertyEditor/MultiComboPropertyEditor.cpp +++ /dev/null @@ -1,196 +0,0 @@ -// ************************************************************************************************ -// -// BornAgain: simulate and fit reflection and scattering -// -//! @file GUI/View/PropertyEditor/MultiComboPropertyEditor.cpp -//! @brief Defines MultiComboPropertyEditor class -//! -//! @homepage http://www.bornagainproject.org -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2018 -//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) -// -// ************************************************************************************************ - -#include "GUI/View/PropertyEditor/MultiComboPropertyEditor.h" -#include "GUI/Util/ComboProperty.h" -#include "GUI/View/PropertyEditor/CustomEventFilters.h" -#include <QComboBox> -#include <QEvent> -#include <QLineEdit> -#include <QListView> -#include <QMouseEvent> -#include <QStandardItem> -#include <QStandardItemModel> -#include <QVBoxLayout> - -QCheckListStyledItemDelegate::QCheckListStyledItemDelegate(QObject* parent) - : QStyledItemDelegate(parent) -{ -} - -void QCheckListStyledItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, - const QModelIndex& index) const -{ - auto& styleOption = const_cast<QStyleOptionViewItem&>(option); - styleOption.showDecorationSelected = false; - QStyledItemDelegate::paint(painter, styleOption, index); -} - -// ---------------------------------------------------------------------------- -// https://stackoverflow.com/questions/8422760/combobox-of-checkboxes -// https://stackoverflow.com/questions/21186779/catch-mouse-button-pressed-signal-from-qcombobox-popup-menu -// https://gist.github.com/mistic100/c3b7f3eabc65309687153fe3e0a9a720 -// ---------------------------------------------------------------------------- - -MultiComboPropertyEditor::MultiComboPropertyEditor(QWidget* parent) - : CustomEditor(parent) - , m_box(new QComboBox) - , m_wheel_event_filter(new WheelEventEater(this)) - , m_model(new QStandardItemModel(this)) -{ - setAutoFillBackground(true); - setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); - - m_box->installEventFilter(m_wheel_event_filter); - m_box->view()->viewport()->installEventFilter(this); - - // Editable mode will be used to have None/Multiple labels on top - m_box->setEditable(true); - m_box->lineEdit()->setReadOnly(true); - m_box->lineEdit()->installEventFilter(this); - connect(m_box->lineEdit(), &QLineEdit::selectionChanged, m_box->lineEdit(), - &QLineEdit::deselect); - - // transforms ordinary combo box into check list - m_box->setItemDelegate(new QCheckListStyledItemDelegate(this)); - m_box->setModel(m_model); - - auto* layout = new QVBoxLayout; - layout->setMargin(0); - layout->setSpacing(0); - layout->addWidget(m_box); - setLayout(layout); - setConnected(true); -} - -QSize MultiComboPropertyEditor::sizeHint() const -{ - return m_box->sizeHint(); -} - -QSize MultiComboPropertyEditor::minimumSizeHint() const -{ - return m_box->minimumSizeHint(); -} - -//! Propagate check state from the model to ComboProperty. - -void MultiComboPropertyEditor::onModelDataChanged(const QModelIndex& topLeft, const QModelIndex&, - const QVector<int>&) -{ - // on Qt 5.9 roles remains empty for checked state. It will stop working if uncomment. - // if (!roles.contains(Qt::CheckStateRole)) - // return; - - auto* item = m_model->itemFromIndex(topLeft); - if (!item) - return; - - auto comboProperty = m_data.value<ComboProperty>(); - auto state = item->checkState() == Qt::Checked; - comboProperty.setSelected(topLeft.row(), state); - - updateBoxLabel(); - setDataIntern(QVariant::fromValue<ComboProperty>(comboProperty)); -} - -//! Processes press event in QComboBox's underlying list view. - -void MultiComboPropertyEditor::onClickedList(const QModelIndex& index) -{ - if (auto* item = m_model->itemFromIndex(index)) { - auto state = item->checkState() == Qt::Checked ? Qt::Unchecked : Qt::Checked; - item->setCheckState(state); - } -} - -//! Handles mouse clicks on QComboBox elements. - -bool MultiComboPropertyEditor::eventFilter(QObject* obj, QEvent* event) -{ - if (isClickToSelect(obj, event)) { - // Handles mouse clicks on QListView when it is expanded from QComboBox - // 1) Prevents list from closing while selecting items. - // 2) Correctly calculates underlying model index when mouse is over check box style - // element. - const auto* const mouseEvent = dynamic_cast<const QMouseEvent*>(event); - auto index = m_box->view()->indexAt(mouseEvent->pos()); - onClickedList(index); - return true; - } - - if (isClickToExpand(obj, event)) { - // Expands box when clicking on None/Multiple label - m_box->showPopup(); - return true; - } - - // Propagate to the parent class. - return QObject::eventFilter(obj, event); -} - -void MultiComboPropertyEditor::initEditor() -{ - if (!m_data.canConvert<ComboProperty>()) - return; - - auto property = m_data.value<ComboProperty>(); - - setConnected(false); - m_model->clear(); - - auto labels = property.getValues(); - auto selectedIndices = property.selectedIndices(); - - for (int i = 0; i < labels.size(); ++i) { - auto* item = new QStandardItem(labels[i]); - m_model->invisibleRootItem()->appendRow(item); - item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); - item->setCheckable(true); - - auto state = selectedIndices.contains(i) ? Qt::Checked : Qt::Unchecked; - item->setData(state, Qt::CheckStateRole); - } - - setConnected(true); - updateBoxLabel(); -} - -void MultiComboPropertyEditor::setConnected(bool isConnected) -{ - if (isConnected) - connect(m_model, &QStandardItemModel::dataChanged, this, - &MultiComboPropertyEditor::onModelDataChanged); - else - disconnect(m_model, &QStandardItemModel::dataChanged, this, - &MultiComboPropertyEditor::onModelDataChanged); -} - -//! Update text on QComboBox with the label provided by combo property. - -void MultiComboPropertyEditor::updateBoxLabel() -{ - auto combo = m_data.value<ComboProperty>(); - m_box->setCurrentText(combo.label()); -} - -bool MultiComboPropertyEditor::isClickToSelect(QObject* obj, QEvent* event) const -{ - return obj == m_box->view()->viewport() && event->type() == QEvent::MouseButtonRelease; -} - -bool MultiComboPropertyEditor::isClickToExpand(QObject* obj, QEvent* event) const -{ - return obj == m_box->lineEdit() && event->type() == QEvent::MouseButtonRelease; -} diff --git a/GUI/View/PropertyEditor/MultiComboPropertyEditor.h b/GUI/View/PropertyEditor/MultiComboPropertyEditor.h deleted file mode 100644 index ee5eee0cf4e8e6ec0a6048461c4f897ca5629440..0000000000000000000000000000000000000000 --- a/GUI/View/PropertyEditor/MultiComboPropertyEditor.h +++ /dev/null @@ -1,67 +0,0 @@ -// ************************************************************************************************ -// -// BornAgain: simulate and fit reflection and scattering -// -//! @file GUI/View/PropertyEditor/MultiComboPropertyEditor.h -//! @brief Defines MultiComboPropertyEditor class -//! -//! @homepage http://www.bornagainproject.org -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2018 -//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) -// -// ************************************************************************************************ - -#ifndef BORNAGAIN_GUI_VIEW_PROPERTYEDITOR_MULTICOMBOPROPERTYEDITOR_H -#define BORNAGAIN_GUI_VIEW_PROPERTYEDITOR_MULTICOMBOPROPERTYEDITOR_H - -#include "GUI/View/PropertyEditor/CustomEditors.h" -#include <QStyledItemDelegate> -#include <memory> - -class QStandardItemModel; -class QModelIndex; -class QStyleOptionViewItem; - -//! Provides custom editor for ComboProperty with multi-select option. - -class MultiComboPropertyEditor : public CustomEditor { - Q_OBJECT -public: - explicit MultiComboPropertyEditor(QWidget* parent = nullptr); - - QSize sizeHint() const override; - QSize minimumSizeHint() const override; - -protected slots: - void onModelDataChanged(const QModelIndex&, const QModelIndex&, const QVector<int>&); - - void onClickedList(const QModelIndex& index); - -protected: - void initEditor() override; - -private: - bool eventFilter(QObject* obj, QEvent* event) override; - void setConnected(bool isConnected); - void updateBoxLabel(); - - bool isClickToSelect(QObject* obj, QEvent* event) const; - bool isClickToExpand(QObject* obj, QEvent* event) const; - - QComboBox* m_box; - class WheelEventEater* m_wheel_event_filter; - QStandardItemModel* m_model; -}; - -//! Provides custom style delegate for QComboBox to allow checkboxes. - -class QCheckListStyledItemDelegate : public QStyledItemDelegate { -public: - QCheckListStyledItemDelegate(QObject* parent = nullptr); - - void paint(QPainter* painter, const QStyleOptionViewItem& option, - const QModelIndex& index) const override; -}; - -#endif // BORNAGAIN_GUI_VIEW_PROPERTYEDITOR_MULTICOMBOPROPERTYEDITOR_H diff --git a/GUI/View/PropertyEditor/PropertyEditorFactory.cpp b/GUI/View/PropertyEditor/PropertyEditorFactory.cpp index 21d67a6744eb62d6ebbfbf168f81598706004493..f12d0391526b94142b6e6e02411869292708f0e6 100644 --- a/GUI/View/PropertyEditor/PropertyEditorFactory.cpp +++ b/GUI/View/PropertyEditor/PropertyEditorFactory.cpp @@ -13,33 +13,15 @@ // ************************************************************************************************ #include "GUI/View/PropertyEditor/PropertyEditorFactory.h" -#include "GUI/Model/Material/MaterialItem.h" -#include "GUI/Model/Material/MaterialItemUtils.h" -#include "GUI/Model/Sample/ItemWithMaterial.h" -#include "GUI/Model/Session/SessionFlags.h" +#include "GUI/Model/Session/SessionItem.h" #include "GUI/Util/ComboProperty.h" #include "GUI/View/Common/ScientificSpinBox.h" -#include "GUI/View/PropertyEditor/MultiComboPropertyEditor.h" -#include <QLabel> -#include <QLineEdit> +#include "GUI/View/PropertyEditor/CustomEditors.h" +#include <QModelIndex> #include <QSpinBox> -#include <limits> namespace { -QWidget* createCustomStringEditor(const SessionItem& item) -{ - if (item.isEditable()) { - auto* editor = new QLineEdit; - editor->setText(item.value().toString()); - return editor; - } - - auto* editor = new QLabel; - editor->setText(item.value().toString()); - return editor; -} - double getStep(double val) { return val == 0.0 ? 1.0 : val / 100.; @@ -50,44 +32,19 @@ bool isDoubleProperty(const QVariant& variant) return variant.type() == QVariant::Double; } -bool isIntProperty(const QVariant& variant) -{ - return variant.type() == QVariant::Int; -} - -bool isMaterialProperty(const QModelIndex& index) -{ - return index.data(SessionFlags::CustomEditorRole) == SessionItem::EDITOR_TYPE_MATERIAL - && index.column() == SessionFlags::ITEM_VALUE; -} - bool isComboProperty(const QVariant& variant) { return variant.canConvert<ComboProperty>(); } -bool isStringProperty(const QVariant& variant) -{ - return variant.type() == QVariant::String; -} - -bool isBoolProperty(const QVariant& variant) -{ - return variant.type() == QVariant::Bool; -} - } // namespace bool GUI::View::PropertyEditorFactory::hasStringRepresentation(const QModelIndex& index) { auto variant = index.data(); - if (isMaterialProperty(index)) - return true; if (isComboProperty(variant)) return true; - if (isBoolProperty(variant)) - return true; if (isDoubleProperty(variant) && index.internalPointer()) return true; @@ -97,24 +54,13 @@ bool GUI::View::PropertyEditorFactory::hasStringRepresentation(const QModelIndex QString GUI::View::PropertyEditorFactory::toString(const QModelIndex& index) { auto variant = index.data(); - if (isMaterialProperty(index)) { - const auto* materialItem = static_cast<SessionItem*>(index.internalPointer()); - const auto* itemWithMaterial = dynamic_cast<ItemWithMaterial*>(materialItem->parent()); - ASSERT(itemWithMaterial); - return itemWithMaterial->materialName(); - } if (isComboProperty(variant)) return variant.value<ComboProperty>().label(); - if (isBoolProperty(variant)) - return variant.toBool() ? "True" : "False"; if (isDoubleProperty(variant) && index.internalPointer()) { auto* item = static_cast<SessionItem*>(index.internalPointer()); - return item->editorType() == "ScientificDouble" - ? QString::number(item->value().toDouble(), 'g') - : item->editorType() == "ScientificSpinBox" - ? ScientificSpinBox::toString(item->value().toDouble(), item->decimals()) - : QString::number(item->value().toDouble(), 'f', item->decimals()); + // only "Scientific SpinBoxes" in Fit-Window + return ScientificSpinBox::toString(item->value().toDouble(), item->decimals()); } return ""; @@ -124,44 +70,16 @@ QWidget* GUI::View::PropertyEditorFactory::CreateEditor(const SessionItem& item, { QWidget* result(nullptr); - if (item.editorType() == SessionItem::EDITOR_TYPE_MATERIAL) { - // has to be checked first, because the property is a standard property and the following - // code would find a (wrong) editor - result = new MaterialSelectionEditor; - } else if (isDoubleProperty(item.value())) { - if (item.editorType() == "ScientificDouble") { - auto* editor = new ScientificDoublePropertyEditor; - auto limits = item.limits(); - editor->setLimits(limits); - result = editor; - } else if (item.editorType() == "ScientificSpinBox") { - auto* editor = new ScientificSpinBoxEditor; - auto limits = item.limits(); - editor->setLimits(limits); - editor->setDecimals(item.decimals()); - editor->setSingleStep(getStep(item.roleProperty(Qt::EditRole).toDouble())); - result = editor; - } else { - auto* editor = new DoubleEditor; - editor->setLimits(item.limits()); - editor->setDecimals(item.decimals()); - result = editor; - } - } else if (isIntProperty(item.value())) { - auto* editor = new IntEditor; + if (isDoubleProperty(item.value())) { + // only Scientific SpinBoxes in Fit-Window + auto* editor = new ScientificSpinBoxEditor; editor->setLimits(item.limits()); + editor->setDecimals(item.decimals()); + editor->setSingleStep(getStep(item.roleProperty(Qt::EditRole).toDouble())); result = editor; - } else if (isBoolProperty(item.value())) { - result = new BoolEditor; - } else if (isStringProperty(item.value())) { - result = createCustomStringEditor(item); - } else if (isComboProperty(item.value())) { - if (item.editorType() == "Default") { - result = new ComboPropertyEditor; - } else if (item.editorType() == "MultiSelectionComboEditor") { - result = new MultiComboPropertyEditor; - } - } + } else if (isComboProperty(item.value())) + result = new ComboPropertyEditor; + if (parent && result) result->setParent(parent);