diff --git a/CHANGELOG b/CHANGELOG index 28c2a43d5c3b3e0ce2c096674c7f734dfcdc7e94..58b32a06e4c151bc77c830daa71872240dbee24e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -16,6 +16,7 @@ BornAgain-22.0, in preparation > GUI changes: * Examples DepthProfile, Transmission: flattened DepthProbeSimulation * In sample model, removed possibility to set lengths in angstrom instead of nm (#756) + * Removed unfinished undo/redo support (#757) > Examples and documentation: > Bug fixes: > Internal refactoring: diff --git a/GUI/View/FitObjective/ParameterTuningWidget.cpp b/GUI/View/FitObjective/ParameterTuningWidget.cpp index 0091910368c0bba663fc38a1d372aed913694530..0c593f35322957c53a0281afa71431e37d1082eb 100644 --- a/GUI/View/FitObjective/ParameterTuningWidget.cpp +++ b/GUI/View/FitObjective/ParameterTuningWidget.cpp @@ -42,7 +42,7 @@ ParameterTuningWidget::ParameterTuningWidget(QWidget* parent) m_treeView->setDragDropMode(QAbstractItemView::NoDragDrop); m_treeView->setAttribute(Qt::WA_MacShowFocusRect, false); - auto* resetValuesAction = new QAction(QIcon(":/images/undo-variant.svg"), "Reset values", this); + auto* resetValuesAction = new QAction(QIcon(":/images/undo.svg"), "Reset values", this); resetValuesAction->setToolTip("Reset parameter tree to initial values"); connect(resetValuesAction, &QAction::triggered, this, &ParameterTuningWidget::restoreModelsOfCurrentJobItem); diff --git a/GUI/View/Numeric/DoubleSpinBox.cpp b/GUI/View/Numeric/DoubleSpinBox.cpp index 0b7e600726323fb72dca28dd4d30a5b510b47f1f..eb6b067f54048e82c83e64ed17d5cf94e7178fb8 100644 --- a/GUI/View/Numeric/DoubleSpinBox.cpp +++ b/GUI/View/Numeric/DoubleSpinBox.cpp @@ -16,7 +16,7 @@ #include "GUI/View/Numeric/NumberUtil.h" #include <QWheelEvent> -DoubleSpinBox::DoubleSpinBox(DoubleProperty& d, bool easyScrollable, QWidget* parent) +DoubleSpinBox::DoubleSpinBox(const DoubleProperty& d, bool easyScrollable, QWidget* parent) : QDoubleSpinBox(parent) , m_valueProperty(d) , m_easyScrollable(easyScrollable) @@ -40,14 +40,6 @@ QString DoubleSpinBox::uid() const return m_valueProperty.uid(); } -// This method is only used in undo/redo functionality in SampleEditorController -// On its removal the input arguments of DoubleSpinbox and GUI::Util::createDoubleSpinBoxRow -// can be changed to "const DoubleProperty&" -void DoubleSpinBox::setPropertyValue(double value) -{ - m_valueProperty.setValue(value); -} - void DoubleSpinBox::setBaseValue(double value) { QDoubleSpinBox::setValue(value); diff --git a/GUI/View/Numeric/DoubleSpinBox.h b/GUI/View/Numeric/DoubleSpinBox.h index 52a12504d06e5961328fb9ce24f5381d0c06347e..d891e84a74b32bbc47c611ffd695e29833777a0d 100644 --- a/GUI/View/Numeric/DoubleSpinBox.h +++ b/GUI/View/Numeric/DoubleSpinBox.h @@ -27,11 +27,10 @@ public: //! policy). Furthermore, the spin box will prohibit accidental changes by the mouse wheel. //! Otherwise it would be dangerous if the spin box is on a scrollable form - unintended and //! unnoticed changes would take place when just scrolling through the form. - DoubleSpinBox(DoubleProperty& d, bool easyScrollable = false, QWidget* parent = nullptr); + DoubleSpinBox(const DoubleProperty& d, bool easyScrollable = false, QWidget* parent = nullptr); //! Set the value void setBaseValue(double value); - void setPropertyValue(double v); QString uid() const; @@ -48,7 +47,7 @@ private: void wheelEvent(QWheelEvent* event) override; void onDisplayValueChanged(double newDisplayValue); - DoubleProperty& m_valueProperty; + const DoubleProperty& m_valueProperty; bool m_easyScrollable; }; diff --git a/GUI/View/SampleDesigner/LayerOrientedSampleEditor.cpp b/GUI/View/SampleDesigner/SampleEditor.cpp similarity index 63% rename from GUI/View/SampleDesigner/LayerOrientedSampleEditor.cpp rename to GUI/View/SampleDesigner/SampleEditor.cpp index 70a0b9bdd081ff26e3c02396deeb047999aaf3e9..57d67d970e6c418413c39f9c6d3715b147cea5a5 100644 --- a/GUI/View/SampleDesigner/LayerOrientedSampleEditor.cpp +++ b/GUI/View/SampleDesigner/SampleEditor.cpp @@ -2,8 +2,8 @@ // // BornAgain: simulate and fit reflection and scattering // -//! @file GUI/View/SampleDesigner/LayerOrientedSampleEditor.cpp -//! @brief Implements class LayerOrientedSampleEditor +//! @file GUI/View/SampleDesigner/SampleEditor.cpp +//! @brief Implements class SampleEditor //! //! @homepage http://www.bornagainproject.org //! @license GNU General Public License v3 or higher (see COPYING) @@ -12,7 +12,7 @@ // // ************************************************************************************************ -#include "GUI/View/SampleDesigner/LayerOrientedSampleEditor.h" +#include "GUI/View/SampleDesigner/SampleEditor.h" #include "GUI/Model/Project/ProjectDocument.h" #include "GUI/Model/Sample/LayerItem.h" #include "GUI/Model/Sample/SampleItem.h" @@ -25,11 +25,9 @@ #include <QBoxLayout> #include <QPushButton> -LayerOrientedSampleEditor::LayerOrientedSampleEditor(QWidget* parent, ProjectDocument* document) +SampleEditor::SampleEditor(QWidget* parent, ProjectDocument* document) : QWidget(parent) , m_currentSampleWidget(nullptr) - , m_undoAction(nullptr) - , m_redoAction(nullptr) , m_currentSample(nullptr) , m_document(document) { @@ -37,21 +35,18 @@ LayerOrientedSampleEditor::LayerOrientedSampleEditor(QWidget* parent, ProjectDoc m_scrollArea->setWidgetResizable(true); m_scrollArea->setWidget(createEmptyWidget()); - m_toolbar = new StyledToolbar(this); - auto* mainLayout = new QVBoxLayout(this); mainLayout->setContentsMargins(0, 0, 0, 0); mainLayout->setSpacing(0); - mainLayout->addWidget(m_toolbar); mainLayout->addWidget(m_scrollArea); } -LayerOrientedSampleEditor::~LayerOrientedSampleEditor() +SampleEditor::~SampleEditor() { qDeleteAll(m_editControllers.values()); } -void LayerOrientedSampleEditor::setCurrentSample(SampleItem* sampleItem) +void SampleEditor::setCurrentSample(SampleItem* sampleItem) { if (m_currentSample != nullptr) m_editControllers[m_currentSample]->setSampleForm(nullptr); @@ -59,16 +54,9 @@ void LayerOrientedSampleEditor::setCurrentSample(SampleItem* sampleItem) m_currentSampleWidget = nullptr; delete m_scrollArea->takeWidget(); - // use the correct toolbar buttons (from correct undo stack) - delete m_undoAction; - m_undoAction = nullptr; - delete m_redoAction; - m_redoAction = nullptr; - m_currentSample = sampleItem; if (m_currentSample == nullptr) { m_scrollArea->setWidget(createEmptyWidget()); - updateActionEnabling(); return; } @@ -77,18 +65,9 @@ void LayerOrientedSampleEditor::setCurrentSample(SampleItem* sampleItem) new SampleEditorController(m_document, m_currentSample)); auto* ec = m_editControllers[m_currentSample]; connect(ec, &SampleEditorController::requestViewInRealspace, this, - &LayerOrientedSampleEditor::requestViewInRealspace); - connect(ec, &SampleEditorController::aboutToRemoveItem, this, - &LayerOrientedSampleEditor::aboutToRemoveItem); - connect(ec, &SampleEditorController::modified, this, &LayerOrientedSampleEditor::modified); - - m_undoAction = ec->undoStack()->createUndoAction(this); - m_redoAction = ec->undoStack()->createRedoAction(this); - m_undoAction->setIcon(QIcon(":/images/undo-variant.svg")); - m_redoAction->setIcon(QIcon(":/images/redo.svg")); - - m_toolbar->addAction(m_undoAction); - m_toolbar->addAction(m_redoAction); + &SampleEditor::requestViewInRealspace); + connect(ec, &SampleEditorController::aboutToRemoveItem, this, &SampleEditor::aboutToRemoveItem); + connect(ec, &SampleEditorController::modified, this, &SampleEditor::modified); createLayerColors(); @@ -96,20 +75,9 @@ void LayerOrientedSampleEditor::setCurrentSample(SampleItem* sampleItem) ec->setSampleForm(m_currentSampleWidget); m_currentSampleWidget->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); m_scrollArea->setWidget(m_currentSampleWidget); - - updateActionEnabling(); -} - -void LayerOrientedSampleEditor::updateActionEnabling() -{ - // Undo/Redo is not complete => hide the related buttons/actions - if (m_undoAction) - m_undoAction->setVisible(false); - if (m_redoAction) - m_redoAction->setVisible(false); } -void LayerOrientedSampleEditor::createLayerColors() // #baLayerEditor move to better place +void SampleEditor::createLayerColors() // #baLayerEditor move to better place { if (!m_currentSample) return; @@ -126,12 +94,12 @@ void LayerOrientedSampleEditor::createLayerColors() // #baLayerEditor move to be } } -QWidget* LayerOrientedSampleEditor::createEmptyWidget() +QWidget* SampleEditor::createEmptyWidget() { auto* emptyWidget = new QWidget(this); auto* btn = new QPushButton("Create sample", emptyWidget); - connect(btn, &QPushButton::clicked, this, &LayerOrientedSampleEditor::requestCreateNewSample); + connect(btn, &QPushButton::clicked, this, &SampleEditor::requestCreateNewSample); auto* layout = new QHBoxLayout(emptyWidget); layout->setContentsMargins(10, 20, 10, 20); diff --git a/GUI/View/SampleDesigner/LayerOrientedSampleEditor.h b/GUI/View/SampleDesigner/SampleEditor.h similarity index 67% rename from GUI/View/SampleDesigner/LayerOrientedSampleEditor.h rename to GUI/View/SampleDesigner/SampleEditor.h index cf32dc15da78895e65de242c3d4e538d9fdb2d52..25e1c321113ad67aac06529703922291fba4907a 100644 --- a/GUI/View/SampleDesigner/LayerOrientedSampleEditor.h +++ b/GUI/View/SampleDesigner/SampleEditor.h @@ -2,8 +2,8 @@ // // BornAgain: simulate and fit reflection and scattering // -//! @file GUI/View/SampleDesigner/LayerOrientedSampleEditor.h -//! @brief Defines class LayerOrientedSampleEditor +//! @file GUI/View/SampleDesigner/SampleEditor.h +//! @brief Defines class SampleEditor //! //! @homepage http://www.bornagainproject.org //! @license GNU General Public License v3 or higher (see COPYING) @@ -12,8 +12,8 @@ // // ************************************************************************************************ -#ifndef BORNAGAIN_GUI_VIEW_SAMPLEDESIGNER_LAYERORIENTEDSAMPLEEDITOR_H -#define BORNAGAIN_GUI_VIEW_SAMPLEDESIGNER_LAYERORIENTEDSAMPLEEDITOR_H +#ifndef BORNAGAIN_GUI_VIEW_SAMPLEDESIGNER_SAMPLEEDITOR_H +#define BORNAGAIN_GUI_VIEW_SAMPLEDESIGNER_SAMPLEEDITOR_H #include <QMap> #include <QScrollArea> @@ -27,11 +27,11 @@ class ProjectDocument; class SampleEditorController; //! Sample editor with layer oriented presentation of a sample -class LayerOrientedSampleEditor : public QWidget { +class SampleEditor : public QWidget { Q_OBJECT public: - LayerOrientedSampleEditor(QWidget* parent, ProjectDocument* document); - ~LayerOrientedSampleEditor() override; + SampleEditor(QWidget* parent, ProjectDocument* document); + ~SampleEditor() override; void setCurrentSample(SampleItem* sampleItem); @@ -42,23 +42,17 @@ signals: void modified(); private: - void updateActionEnabling(); - void createLayerColors(); //! Create empty widget with a button for sample creation QWidget* createEmptyWidget(); -private: SampleForm* m_currentSampleWidget; QScrollArea* m_scrollArea; - QToolBar* m_toolbar; - QAction* m_undoAction; // dedicated to the current sample - QAction* m_redoAction; SampleItem* m_currentSample = nullptr; QMap<SampleItem*, SampleEditorController*> m_editControllers; ProjectDocument* m_document; }; -#endif // BORNAGAIN_GUI_VIEW_SAMPLEDESIGNER_LAYERORIENTEDSAMPLEEDITOR_H +#endif // BORNAGAIN_GUI_VIEW_SAMPLEDESIGNER_SAMPLEEDITOR_H diff --git a/GUI/View/SampleDesigner/SampleEditorCommands.cpp b/GUI/View/SampleDesigner/SampleEditorCommands.cpp deleted file mode 100644 index f152d2a6ded6e23ea8c33219c7114e6e53291237..0000000000000000000000000000000000000000 --- a/GUI/View/SampleDesigner/SampleEditorCommands.cpp +++ /dev/null @@ -1,118 +0,0 @@ -// ************************************************************************************************ -// -// BornAgain: simulate and fit reflection and scattering -// -//! @file GUI/View/SampleDesigner/SampleEditorCommands.cpp -//! @brief Implements command classes for LayerOrientedSampleEditor -//! -//! @homepage http://www.bornagainproject.org -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2021 -//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) -// -// ************************************************************************************************ - -#include "GUI/View/SampleDesigner/SampleEditorCommands.h" -#include "GUI/Model/Sample/LayerItem.h" -#include "GUI/Model/Sample/SampleItem.h" -#include "GUI/Support/XML/Backup.h" -#include "GUI/View/SampleDesigner/SampleEditorController.h" -#include "GUI/View/SampleDesigner/SampleForm.h" -#include <utility> - -namespace { - -constexpr int COMMAND_ID_CHANGE_VALUE = 11; - -} // namespace - - -CommandRemoveLayer::CommandRemoveLayer(SampleEditorController* ec, LayerItem* layerItem, - QUndoCommand* parent /*= nullptr*/) - : QUndoCommand(parent) - , m_ec(ec) -{ - setText("Remove layer"); - m_indexOfLayer = ec->sampleItem()->layerItems().indexOf(layerItem); - m_layerItemBackup = GUI::Util::createBackup(layerItem); -} - -void CommandRemoveLayer::redo() -{ - m_ec->removeLayerItemFromUndo(m_indexOfLayer); -} - -void CommandRemoveLayer::undo() -{ - LayerItem* restoredLayer = m_ec->sampleItem()->createLayerItemAt(m_indexOfLayer); - GUI::Util::restoreBackup(restoredLayer, m_layerItemBackup); - m_ec->sampleForm()->onLayerAdded(restoredLayer); - emit m_ec->modified(); -} - -// --------------------------------------------------------------------------------------------- // - -CommandAddLayer::CommandAddLayer(SampleEditorController* ec, int atIndex, QUndoCommand* /*parent*/) - : m_ec(ec) - , m_atIndex(atIndex) -{ - setText("Add layer"); -} - -void CommandAddLayer::redo() -{ - m_ec->addLayerItemFromUndo(m_atIndex); -} - -void CommandAddLayer::undo() -{ - // no backup of the layer has to be stored, since redo always creates the layer - // from scratch - no contents required for this - m_ec->removeLayerItemFromUndo(m_atIndex); -} - -// --------------------------------------------------------------------------------------------- // - -CommandChangeValue::CommandChangeValue(const QString& label, SampleEditorController* ec, - double oldValue, double newValue, const QString& path, - QUndoCommand* parent /*= nullptr*/) - : QUndoCommand(parent) - , m_ec(ec) - , m_oldValue(oldValue) - , m_newValue(newValue) - , m_path(path) -{ - setText("change " + label + "\n"); -} - -int CommandChangeValue::id() const -{ - return COMMAND_ID_CHANGE_VALUE; -} - -bool CommandChangeValue::mergeWith(const QUndoCommand* command) -{ - if (command->id() != id()) // make sure other is also a changeValue command - return false; - - const auto* const other = dynamic_cast<const CommandChangeValue*>(command); - - if (m_path != other->m_path) - return false; - - m_newValue = other->m_newValue; - return true; -} - -void CommandChangeValue::redo() -{ - if (m_isFirst) - m_isFirst = false; - else - m_ec->setDoubleFromUndo(m_newValue, m_path); -} - -void CommandChangeValue::undo() -{ - m_ec->setDoubleFromUndo(m_oldValue, m_path); -} diff --git a/GUI/View/SampleDesigner/SampleEditorCommands.h b/GUI/View/SampleDesigner/SampleEditorCommands.h deleted file mode 100644 index 0a58d850da7235f26710dd427c49afa0ea85ff98..0000000000000000000000000000000000000000 --- a/GUI/View/SampleDesigner/SampleEditorCommands.h +++ /dev/null @@ -1,72 +0,0 @@ -// ************************************************************************************************ -// -// BornAgain: simulate and fit reflection and scattering -// -//! @file GUI/View/SampleDesigner/SampleEditorCommands.h -//! @brief Defines command classes for LayerOrientedSampleEditor -//! -//! @homepage http://www.bornagainproject.org -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2021 -//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) -// -// ************************************************************************************************ - -#ifndef BORNAGAIN_GUI_VIEW_SAMPLEDESIGNER_SAMPLEEDITORCOMMANDS_H -#define BORNAGAIN_GUI_VIEW_SAMPLEDESIGNER_SAMPLEEDITORCOMMANDS_H - -#include <QUndoCommand> - -class SampleEditorController; -class LayerItem; - -//! Command to change a double value -class CommandChangeValue : public QUndoCommand { -public: - CommandChangeValue(const QString& label, SampleEditorController* ec, double oldValue, - double newValue, const QString& path, QUndoCommand* parent = nullptr); - - int id() const override; - bool mergeWith(const QUndoCommand* command) override; - - void redo() override; - void undo() override; - -private: - SampleEditorController* m_ec; - double m_oldValue; - double m_newValue; - QString m_path; - bool m_isFirst = true; -}; - -//! Command to add a layer to a sample -class CommandAddLayer : public QUndoCommand { -public: - CommandAddLayer(SampleEditorController* ec, int atIndex, QUndoCommand* parent = nullptr); - - void redo() override; - void undo() override; - -private: - SampleEditorController* m_ec; - int m_atIndex; -}; - -//! Command to remove a layer from a sample -class CommandRemoveLayer : public QUndoCommand { -public: - CommandRemoveLayer(SampleEditorController* ec, LayerItem* layerItem, - QUndoCommand* parent = nullptr); - - void redo() override; - void undo() override; - -private: - SampleEditorController* m_ec; - QByteArray m_layerItemBackup; - int m_indexOfLayer; -}; - - -#endif // BORNAGAIN_GUI_VIEW_SAMPLEDESIGNER_SAMPLEEDITORCOMMANDS_H diff --git a/GUI/View/SampleDesigner/SampleEditorController.cpp b/GUI/View/SampleDesigner/SampleEditorController.cpp index 0020e2f6353c05e9721ff365682327f24fe3ae0f..951f1f9c80eabb20cf548ab67018a59c0d056f47 100644 --- a/GUI/View/SampleDesigner/SampleEditorController.cpp +++ b/GUI/View/SampleDesigner/SampleEditorController.cpp @@ -35,7 +35,6 @@ #include "GUI/View/SampleDesigner/MaterialInplaceForm.h" #include "GUI/View/SampleDesigner/MesocrystalForm.h" #include "GUI/View/SampleDesigner/ParticleLayoutForm.h" -#include "GUI/View/SampleDesigner/SampleEditorCommands.h" #include "GUI/View/SampleDesigner/SampleForm.h" #include "Sample/HardParticle/Cylinder.h" @@ -63,9 +62,14 @@ SampleItem* SampleEditorController::sampleItem() const void SampleEditorController::addLayerItem(LayerItem* before) { - const int newIndex = (before != nullptr) ? m_sampleItem->layerItems().indexOf(before) - : m_sampleItem->layerItems().size(); - m_undoStack.push(new CommandAddLayer(this, newIndex)); + const int i = (before != nullptr) ? m_sampleItem->layerItems().indexOf(before) + : m_sampleItem->layerItems().size(); + QColor color = findColor(i); // before adding layer + LayerItem* layer = m_sampleItem->createLayerItemAt(i); + layer->setMaterial(materialModel()->defaultMaterialItem()); + layer->setColor(color); + + onLayerAdded(layer); } QColor SampleEditorController::findColor(int atIndex) @@ -117,17 +121,6 @@ void SampleEditorController::onLayerAdded(LayerItem* layer) c->expand(); } -void SampleEditorController::addLayerItemFromUndo(int atIndex) -{ - QColor color = findColor(atIndex); // before adding layer - - LayerItem* layer = m_sampleItem->createLayerItemAt(atIndex); - layer->setMaterial(materialModel()->defaultMaterialItem()); - layer->setColor(color); - - onLayerAdded(layer); -} - void SampleEditorController::duplicateLayerItem(const LayerItem* layer) { int atIndex = m_sampleItem->layerItems().indexOf(layer) + 1; @@ -142,12 +135,6 @@ void SampleEditorController::duplicateLayerItem(const LayerItem* layer) void SampleEditorController::removeLayerItem(LayerItem* layer) { - m_undoStack.push(new CommandRemoveLayer(this, layer)); -} - -void SampleEditorController::removeLayerItemFromUndo(int atIndex) -{ - auto* layer = m_sampleItem->layerItems()[atIndex]; emit aboutToRemoveItem(layer); m_sampleForm->onAboutToRemoveLayer(layer); m_sampleItem->removeLayer(layer); @@ -359,20 +346,13 @@ void SampleEditorController::removeParticle(ItemWithParticles* itemToRemove) } } -void SampleEditorController::setDouble(double newValue, DoubleProperty& d) -{ - m_undoStack.push(new CommandChangeValue(d.label(), this, d.value(), newValue, d.uid())); - d.setValue(newValue); - emit modified(); -} - -void SampleEditorController::setDoubleFromUndo(double newValue, const QString& path) +void SampleEditorController::setDouble(double value, DoubleProperty& d) { ASSERT(m_sampleForm); DoubleSpinBox* spinBox = nullptr; for (auto* s : m_sampleForm->findChildren<DoubleSpinBox*>()) { - if (s->uid() == path) { + if (s->uid() == d.uid()) { spinBox = s; break; } @@ -381,13 +361,12 @@ void SampleEditorController::setDoubleFromUndo(double newValue, const QString& p if (!spinBox) return; - spinBox->setPropertyValue(newValue); + d.setValue(value); QSignalBlocker _(spinBox); - spinBox->setBaseValue(newValue); + spinBox->setBaseValue(value); spinBox->setFocus(); spinBox->selectAll(); - emit modified(); } @@ -399,11 +378,6 @@ void SampleEditorController::setCurrentIndex(ISelectionContainerForm* widget, in emit modified(); } -QUndoStack* SampleEditorController::undoStack() -{ - return &m_undoStack; -} - MaterialModel* SampleEditorController::materialModel() const { return &m_sampleItem->materialModel(); @@ -429,10 +403,10 @@ void SampleEditorController::selectMaterial(ItemWithMaterial* item, emit modified(); } -void SampleEditorController::setMaterialValue(ItemWithMaterial* item, double newValue, +void SampleEditorController::setMaterialValue(ItemWithMaterial* item, double value, DoubleProperty& d) { - setDouble(newValue, d); + setDouble(value, d); // -- notify all other users of this material (update values in the UI) ASSERT(m_sampleForm); @@ -444,9 +418,9 @@ void SampleEditorController::setMaterialValue(ItemWithMaterial* item, double new } void SampleEditorController::setDensityRelatedValue(InterferenceItem* interferenceItem, - double newValue, DoubleProperty& d) + double value, DoubleProperty& d) { - setDouble(newValue, d); + setDouble(value, d); // -- notify the containing particle layout UI about changed value ASSERT(m_sampleForm); @@ -523,9 +497,9 @@ void SampleEditorController::selectInterference(InterferenceForm* widget, int ne emit modified(); } -void SampleEditorController::setIntegrateOverXi(LatticeTypeSelectionForm* widget, bool newValue) +void SampleEditorController::setIntegrateOverXi(LatticeTypeSelectionForm* widget, bool value) { - widget->interferenceItem()->setXiIntegration(newValue); + widget->interferenceItem()->setXiIntegration(value); widget->onIntegrateOverXiChanged(); emit modified(); } diff --git a/GUI/View/SampleDesigner/SampleEditorController.h b/GUI/View/SampleDesigner/SampleEditorController.h index 2a2c6d3937fbb3427c3c78f52996256e4243e559..bc280a8312158ebf430adab5c6cf5674bec78688 100644 --- a/GUI/View/SampleDesigner/SampleEditorController.h +++ b/GUI/View/SampleDesigner/SampleEditorController.h @@ -17,13 +17,13 @@ #include "GUI/Model/Sample/FormFactorItemCatalog.h" #include "GUI/Model/Sample/ItemWithParticlesCatalog.h" -#include <QUndoStack> +#include <QObject> -class ISelectionContainerForm; -class ISelectionProperty; class CompoundItem; class CoreAndShellForm; class DoubleProperty; +class ISelectionContainerForm; +class ISelectionProperty; class InterferenceForm; class InterferenceItem; class Item3D; @@ -34,17 +34,19 @@ class LayerForm; class LayerItem; class MaterialModel; class MesocrystalForm; -class SampleForm; -class SampleItem; class ParticleLayoutItem; class ProjectDocument; +class SampleForm; +class SampleItem; class SelectionContainerForm; //! Class to modify a sample from the layer oriented sample editor. //! -//! Use this class to modify the sample model. It takes care of notifications and creating undo/redo -//! commands. +//! Use this class to modify the sample model. It takes care of notifications. //! It operates on one SampleItem. +//! +//! Originally, it also supported undo/redo (never completed, withdrawn in release 22). + class SampleEditorController : public QObject { Q_OBJECT public: @@ -62,9 +64,6 @@ public: //! The item on which this controller operates. SampleItem* sampleItem() const; - //! The contained undo stack. - QUndoStack* undoStack(); - //! The materials of the current document MaterialModel* materialModel() const; @@ -74,10 +73,8 @@ public: void addLayerItem(LayerItem* before); QColor findColor(int atIndex); void onLayerAdded(LayerItem* layer); - void addLayerItemFromUndo(int atIndex); void duplicateLayerItem(const LayerItem* layer); void removeLayerItem(LayerItem* layer); - void removeLayerItemFromUndo(int atIndex); void onLayoutAdded(LayerForm* layerForm, ParticleLayoutItem* layout); void addLayoutItem(LayerForm* layerForm); @@ -103,15 +100,14 @@ public: void setMesocrystalBasis(MesocrystalForm* widget, ItemWithParticlesCatalog::Type type); void setMesocrystalBasis(MesocrystalForm* widget, FormFactorItemCatalog::Type type); void selectInterference(InterferenceForm* widget, int newIndex); - void setIntegrateOverXi(LatticeTypeSelectionForm* widget, bool newValue); + void setIntegrateOverXi(LatticeTypeSelectionForm* widget, bool value); - void setDouble(double newValue, DoubleProperty& d); - void setDoubleFromUndo(double newValue, const QString& path); + void setDouble(double value, DoubleProperty& d); void setCurrentIndex(ISelectionContainerForm* widget, int index, ISelectionProperty& d); void selectMaterial(ItemWithMaterial* item, const QString& newMaterialIdentifier); - void setMaterialValue(ItemWithMaterial* item, double newValue, DoubleProperty& d); + void setMaterialValue(ItemWithMaterial* item, double value, DoubleProperty& d); //! Set an interference function's value which affects the total particle density of the //! containing particle layout. @@ -119,7 +115,7 @@ public: //! Some values in interference settings affect the total density in the particle layout which //! contains this interference function. Call this method to provide all the related updating //! (data & UI). - void setDensityRelatedValue(InterferenceItem* interferenceItem, double newValue, + void setDensityRelatedValue(InterferenceItem* interferenceItem, double value, DoubleProperty& d); void onStoppedToMoveLayer(QWidget* widgetToMove, QWidget* moveAboveThisWidget); @@ -136,8 +132,6 @@ private: ItemWithParticles* createAndInitItem(FormFactorItemCatalog::Type formFactorType) const; ItemWithParticles* createAndInitItem(ItemWithParticlesCatalog::Type itemType) const; -private: - QUndoStack m_undoStack; SampleItem* m_sampleItem; SampleForm* m_sampleForm; ProjectDocument* m_document; diff --git a/GUI/View/SampleDesigner/SampleView.cpp b/GUI/View/SampleDesigner/SampleView.cpp index 4b4e0f86d921fb30cd0ccce0f8d6cd0f9ce6dd23..20f32178d76184178956aea54db61993bc85a252 100644 --- a/GUI/View/SampleDesigner/SampleView.cpp +++ b/GUI/View/SampleDesigner/SampleView.cpp @@ -19,7 +19,7 @@ #include "GUI/Model/Sample/ParticleLayoutItem.h" #include "GUI/Model/Sample/SampleItem.h" #include "GUI/Support/Style/ApplicationSettings.h" -#include "GUI/View/SampleDesigner/LayerOrientedSampleEditor.h" +#include "GUI/View/SampleDesigner/SampleEditor.h" #include "GUI/View/SampleDesigner/SampleListView.h" #include "GUI/View/SampleDesigner/ScriptPanel.h" #include "GUI/View/SampleView/RealspacePanel.h" @@ -46,7 +46,7 @@ SampleView::SampleView(QWidget* parent, ProjectDocument* document) m_docks = new DocksController(this); - auto* editor = new LayerOrientedSampleEditor(this, document); + auto* editor = new SampleEditor(this, document); auto* sampleSelectionPane = new QWidget(this); auto* sampleSelectionLayout = new QVBoxLayout(sampleSelectionPane); @@ -80,7 +80,7 @@ SampleView::SampleView(QWidget* parent, ProjectDocument* document) m_docks->addWidget(PYTHONPANEL, scriptPanel, Qt::BottomDockWidgetArea); connect(m_sampleSelectionView, &SampleListView::currentSampleChanged, editor, - &LayerOrientedSampleEditor::setCurrentSample); + &SampleEditor::setCurrentSample); connect(m_sampleSelectionView, &SampleListView::currentSampleChanged, [&](SampleItem* m) { onRequestViewInRealspace(m); }); @@ -88,25 +88,23 @@ SampleView::SampleView(QWidget* parent, ProjectDocument* document) connect(m_sampleSelectionView, &SampleListView::currentSampleChanged, scriptPanel, &ScriptPanel::setCurrentSample); - connect(editor, &LayerOrientedSampleEditor::modified, scriptPanel, - &ScriptPanel::onSampleModified); + connect(editor, &SampleEditor::modified, scriptPanel, &ScriptPanel::onSampleModified); - connect(editor, &LayerOrientedSampleEditor::modified, m_sampleSelectionView, + connect(editor, &SampleEditor::modified, m_sampleSelectionView, &SampleListView::onSampleModified); - connect(editor, &LayerOrientedSampleEditor::requestViewInRealspace, this, + connect(editor, &SampleEditor::requestViewInRealspace, this, &SampleView::onRequestViewInRealspace); - connect(editor, &LayerOrientedSampleEditor::aboutToRemoveItem, this, - &SampleView::onAboutToRemoveItem); + connect(editor, &SampleEditor::aboutToRemoveItem, this, &SampleView::onAboutToRemoveItem); - connect(editor, &LayerOrientedSampleEditor::requestCreateNewSample, - m_sampleSelectionView->newSampleAction(), &QAction::trigger, Qt::QueuedConnection); + connect(editor, &SampleEditor::requestCreateNewSample, m_sampleSelectionView->newSampleAction(), + &QAction::trigger, Qt::QueuedConnection); - connect(editor, &LayerOrientedSampleEditor::modified, m_realspacePanel->widget(), + connect(editor, &SampleEditor::modified, m_realspacePanel->widget(), &RealspaceWidget::updateScene); - connect(editor, &LayerOrientedSampleEditor::modified, m_document, &ProjectDocument::setModified, + connect(editor, &SampleEditor::modified, m_document, &ProjectDocument::setModified, Qt::UniqueConnection); setCentralWidget(editor); diff --git a/GUI/gui.qrc b/GUI/gui.qrc index c65363c384c2c62f90e8cb8a0612bb9060b4a0c8..e61c21b021c1f611f5d28cff7240672f27c6f344 100644 --- a/GUI/gui.qrc +++ b/GUI/gui.qrc @@ -1,80 +1,79 @@ <RCC> <qresource prefix="/"> - <file>images/mode_script.png</file> - <file>images/reset.png</file> - <file>images/treeview-branch-closed.png</file> - <file>images/treeview-branch-end.png</file> - <file>images/treeview-branch-more.png</file> - <file>images/treeview-branch-open.png</file> - <file>images/treeview-vline.png</file> + <file>images/1D_Error.png</file> + <file>images/1D_OK.png</file> + <file>images/2D_OK.png</file> <file>images/BornAgain.ico</file> + <file>images/about_icon.awk</file> + <file>images/about_icon.png</file> + <file>images/alpha-f-box.svg</file> + <file>images/camera-metering-center.svg</file> + <file>images/caret-down.svg</file> + <file>images/caret-right.svg</file> + <file>images/caret-up.svg</file> + <file>images/checkbox-checked.svg</file> <file>images/collapse_arrow.png</file> - <file>images/library.svg</file> + <file>images/content-copy.svg</file> + <file>images/content-save-outline.svg</file> + <file>images/dark-angle-down.svg</file> + <file>images/dark-angle-up.svg</file> + <file>images/dark-close.svg</file> + <file>images/delete.svg</file> + <file>images/depth_instrument.svg</file> + <file>images/depth_instrument_new.svg</file> + <file>images/depth_instrument_shaded.svg</file> + <file>images/dock-close.svg</file> + <file>images/dock-float.svg</file> + <file>images/dock-right.svg</file> <file>images/expand_arrow.png</file> - <file>images/splashscreen.png</file> - <file>images/about_icon.png</file> - <file>images/warning@2x.png</file> + <file>images/gisas_instrument.svg</file> + <file>images/gisas_instrument_new.svg</file> + <file>images/gisas_instrument_shaded.svg</file> + <file>images/hand-right.svg</file> + <file>images/import.svg</file> + <file>images/library.svg</file> <file>images/magnifier.png</file> - <file>images/warning_64x64.png</file> - <file>images/statusbar_dockmenu.svg</file> - <file>images/statusbar_joblist.svg</file> - <file>images/main_sessionmodel.svg</file> - <file>images/toolbar_expand_collapse_tree.svg</file> <file>images/main_importview.svg</file> <file>images/main_instrumentview.svg</file> <file>images/main_jobview.svg</file> <file>images/main_sampleview.svg</file> + <file>images/main_sessionmodel.svg</file> <file>images/main_simulationview.svg</file> - <file>images/main_welcomeview.svg</file> <file>images/main_testview.svg</file> - <file>images/about_icon.awk</file> - <file>images/caret-down.svg</file> - <file>images/caret-up.svg</file> - <file>images/caret-right.svg</file> - <file>images/dock-close.svg</file> - <file>images/dock-float.svg</file> - <file>images/checkbox-checked.svg</file> - <file>images/radio-checked.svg</file> - <file>images/gisas_instrument.svg</file> - <file>images/gisas_instrument_new.svg</file> - <file>images/gisas_instrument_shaded.svg</file> + <file>images/main_welcomeview.svg</file> + <file>images/menu-open.svg</file> + <file>images/mode_script.png</file> + <file>images/move_up_down.svg</file> <file>images/offspec_instrument.svg</file> <file>images/offspec_instrument_new.svg</file> <file>images/offspec_instrument_shaded.svg</file> + <file>images/palette.svg</file> + <file>images/play.svg</file> + <file>images/radio-checked.svg</file> + <file>images/reset.png</file> + <file>images/rotate-left.svg</file> + <file>images/shape-square-plus.svg</file> <file>images/specular_instrument.svg</file> <file>images/specular_instrument_new.svg</file> <file>images/specular_instrument_shaded.svg</file> - <file>images/dark-angle-up.svg</file> - <file>images/dark-angle-down.svg</file> - <file>images/dark-close.svg</file> - <file>images/depth_instrument.svg</file> - <file>images/depth_instrument_new.svg</file> - <file>images/depth_instrument_shaded.svg</file> - <file>images/toolbar24dark_hambar.svg</file> - <file>images/import.svg</file> - <file>images/delete.svg</file> - <file>images/shape-square-plus.svg</file> - <file>images/content-copy.svg</file> - <file>images/palette.svg</file> - <file>images/play.svg</file> + <file>images/splashscreen.png</file> + <file>images/statusbar_dockmenu.svg</file> + <file>images/statusbar_joblist.svg</file> <file>images/stop.svg</file> - <file>images/alpha-f-box.svg</file> - <file>images/dock-right.svg</file> - <file>images/content-save-outline.svg</file> - <file>images/camera-metering-center.svg</file> - <file>images/hand-right.svg</file> - <file>images/menu-open.svg</file> - <file>images/move_up_down.svg</file> - <file>images/rotate-left.svg</file> - <file>images/undo-variant.svg</file> - <file>images/redo.svg</file> - <file>images/1D_Error.png</file> - <file>images/1D_OK.png</file> - <file>images/2D_OK.png</file> + <file>images/toolbar24dark_hambar.svg</file> + <file>images/toolbar_expand_collapse_tree.svg</file> + <file>images/treeview-branch-closed.png</file> + <file>images/treeview-branch-end.png</file> + <file>images/treeview-branch-more.png</file> + <file>images/treeview-branch-open.png</file> + <file>images/treeview-vline.png</file> + <file>images/undo.svg</file> + <file>images/warning@2x.png</file> <file>images/warning_16x16.png</file> - <file>styles/Native.stylesheet</file> + <file>images/warning_64x64.png</file> <file>styles/Base.stylesheet</file> <file>styles/Dark.stylesheet</file> <file>styles/Light.stylesheet</file> + <file>styles/Native.stylesheet</file> </qresource> </RCC> diff --git a/GUI/images/redo.svg b/GUI/images/redo.svg deleted file mode 100644 index 0a7eec2c9ca95c55d81b6d029236ef8b3e10f689..0000000000000000000000000000000000000000 --- a/GUI/images/redo.svg +++ /dev/null @@ -1,55 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<svg - inkscape:version="1.1 (c68e22c387, 2021-05-23)" - sodipodi:docname="redo.svg" - id="svg4" - viewBox="0 0 24 24" - height="24" - width="24" - version="1.1" - xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" - xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" - xmlns="http://www.w3.org/2000/svg" - xmlns:svg="http://www.w3.org/2000/svg" - xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" - xmlns:cc="http://creativecommons.org/ns#" - xmlns:dc="http://purl.org/dc/elements/1.1/"> - <metadata - id="metadata10"> - <rdf:RDF> - <cc:Work - rdf:about=""> - <dc:format>image/svg+xml</dc:format> - <dc:type - rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - </cc:Work> - </rdf:RDF> - </metadata> - <defs - id="defs8" /> - <sodipodi:namedview - inkscape:current-layer="svg4" - inkscape:window-maximized="0" - inkscape:window-y="28" - inkscape:window-x="938" - inkscape:cy="12" - inkscape:cx="12.033566" - inkscape:zoom="29.791667" - showgrid="false" - id="namedview6" - inkscape:window-height="1372" - inkscape:window-width="1796" - inkscape:pageshadow="2" - inkscape:pageopacity="0" - guidetolerance="10" - gridtolerance="10" - objecttolerance="10" - borderopacity="1" - bordercolor="#666666" - pagecolor="#ffffff" - inkscape:pagecheckerboard="0" /> - <path - style="fill:#838686;fill-opacity:1" - id="path2" - d="M 10.5,7 A -6.5,6.5 0 0 0 4,13.5 -6.5,6.5 0 0 0 10.5,20 H 14 V 18 H 10.5 C 8,18 6,16 6,13.5 6,11 8,9 10.5,9 h 5.67 L 13.09,12.09 14.5,13.5 20,8 14.5,2.5 13.08,3.91 16.17,7 H 10.5 M 18,18 h -2 v 2 h 2 z" /> -</svg> diff --git a/GUI/images/undo-variant.svg b/GUI/images/undo.svg similarity index 100% rename from GUI/images/undo-variant.svg rename to GUI/images/undo.svg