From b6b16e4ac3903f6e79ee2a3335e84bed3ad47939 Mon Sep 17 00:00:00 2001 From: Matthias Puchner <github@mpuchner.de> Date: Tue, 16 Nov 2021 09:15:15 +0100 Subject: [PATCH] remove class SessionGraphicsItem ...which held the position of an item in the GraphicsScene of the net oriented sample editor --- GUI/Model/Sample/InterferenceItems.cpp | 2 +- GUI/Model/Sample/InterferenceItems.h | 4 +- GUI/Model/Sample/ItemWithMaterial.cpp | 2 +- GUI/Model/Sample/ItemWithMaterial.h | 4 +- GUI/Model/Sample/ItemWithParticles.cpp | 2 +- GUI/Model/Sample/ItemWithParticles.h | 4 +- GUI/Model/Sample/LayerItem.cpp | 2 +- GUI/Model/Sample/MesoCrystalItem.cpp | 2 +- GUI/Model/Sample/MultiLayerItem.cpp | 2 +- GUI/Model/Sample/MultiLayerItem.h | 4 +- GUI/Model/Sample/ParticleCompositionItem.cpp | 2 +- GUI/Model/Sample/ParticleCoreShellItem.cpp | 2 +- GUI/Model/Sample/ParticleItem.cpp | 2 +- GUI/Model/Sample/ParticleLayoutItem.cpp | 2 +- GUI/Model/Sample/ParticleLayoutItem.h | 3 +- GUI/Model/Sample/SampleModel.cpp | 14 ++---- GUI/Model/Sample/SampleModel.h | 7 +-- GUI/Model/Session/SessionGraphicsItem.cpp | 51 -------------------- GUI/Model/Session/SessionGraphicsItem.h | 39 --------------- GUI/Model/Session/SessionItemUtils.cpp | 1 - GUI/Model/Trafo/TransformationItem.cpp | 2 +- GUI/Model/Trafo/TransformationItem.h | 4 +- GUI/View/Realspace/RealSpaceCanvas.cpp | 4 +- GUI/View/SampleDesigner/ScriptPanel.cpp | 2 +- 24 files changed, 32 insertions(+), 131 deletions(-) delete mode 100644 GUI/Model/Session/SessionGraphicsItem.cpp delete mode 100644 GUI/Model/Session/SessionGraphicsItem.h diff --git a/GUI/Model/Sample/InterferenceItems.cpp b/GUI/Model/Sample/InterferenceItems.cpp index a593c2476a9..7ca2ffbc259 100644 --- a/GUI/Model/Sample/InterferenceItems.cpp +++ b/GUI/Model/Sample/InterferenceItems.cpp @@ -33,7 +33,7 @@ DoubleDescriptor InterferenceItem::positionVariance() const return d; } -InterferenceItem::InterferenceItem(const QString& modelType) : SessionGraphicsItem(modelType) +InterferenceItem::InterferenceItem(const QString& modelType) : SessionItem(modelType) { addProperty(P_POSITION_VARIANCE, 0.0) ->setToolTip("Variance of the position in each dimension (nm^2)"); diff --git a/GUI/Model/Sample/InterferenceItems.h b/GUI/Model/Sample/InterferenceItems.h index 05235fa26ea..e5914d40092 100644 --- a/GUI/Model/Sample/InterferenceItems.h +++ b/GUI/Model/Sample/InterferenceItems.h @@ -16,7 +16,7 @@ #define BORNAGAIN_GUI_MODEL_SAMPLE_INTERFERENCEITEMS_H #include "GUI/Model/Group/SelectionDescriptor.h" -#include "GUI/Model/Session/SessionGraphicsItem.h" +#include "GUI/Model/Session/SessionItem.h" class FTDecayFunction1DItem; class FTDecayFunction2DItem; @@ -27,7 +27,7 @@ class Lattice2DItem; class DoubleDescriptor; class UIntDescriptor; -class InterferenceItem : public SessionGraphicsItem { +class InterferenceItem : public SessionItem { private: static constexpr auto P_POSITION_VARIANCE{"PositionVariance"}; diff --git a/GUI/Model/Sample/ItemWithMaterial.cpp b/GUI/Model/Sample/ItemWithMaterial.cpp index 8dbb8faa5cb..45522d5b998 100644 --- a/GUI/Model/Sample/ItemWithMaterial.cpp +++ b/GUI/Model/Sample/ItemWithMaterial.cpp @@ -65,7 +65,7 @@ QString ItemWithMaterial::materialIdentifier() const return getItemValue(P_MATERIAL).toString(); } -ItemWithMaterial::ItemWithMaterial(const QString& model_type) : SessionGraphicsItem(model_type) +ItemWithMaterial::ItemWithMaterial(const QString& model_type) : SessionItem(model_type) { addProperty(P_MATERIAL, GUI::MaterialUtil::defaultMaterialIdentifier()) ->setToolTip("Material this item is made of") diff --git a/GUI/Model/Sample/ItemWithMaterial.h b/GUI/Model/Sample/ItemWithMaterial.h index 99b89c8be3a..1dc94440131 100644 --- a/GUI/Model/Sample/ItemWithMaterial.h +++ b/GUI/Model/Sample/ItemWithMaterial.h @@ -15,13 +15,13 @@ #ifndef BORNAGAIN_GUI_MODEL_SAMPLE_ITEMWITHMATERIAL_H #define BORNAGAIN_GUI_MODEL_SAMPLE_ITEMWITHMATERIAL_H -#include "GUI/Model/Session/SessionGraphicsItem.h" +#include "GUI/Model/Session/SessionItem.h" #include <memory> class Material; class MaterialItem; -class ItemWithMaterial : public virtual SessionGraphicsItem { +class ItemWithMaterial : public virtual SessionItem { private: static constexpr auto P_MATERIAL{"Material"}; diff --git a/GUI/Model/Sample/ItemWithParticles.cpp b/GUI/Model/Sample/ItemWithParticles.cpp index 0be860e8de8..3cdfa0fdc13 100644 --- a/GUI/Model/Sample/ItemWithParticles.cpp +++ b/GUI/Model/Sample/ItemWithParticles.cpp @@ -127,7 +127,7 @@ SelectionDescriptor<RotationItem*> ItemWithParticles::rotationMethod() ItemWithParticles::ItemWithParticles(const QString& model_type, const QString& abundance_tooltip, const QString& position_tooltip) - : SessionGraphicsItem(model_type) + : SessionItem(model_type) { addProperty(P_ABUNDANCE, 1.0) ->setLimits(RealLimits::limited(0.0, 1.0)) diff --git a/GUI/Model/Sample/ItemWithParticles.h b/GUI/Model/Sample/ItemWithParticles.h index 5e91a54efe0..91745cf0640 100644 --- a/GUI/Model/Sample/ItemWithParticles.h +++ b/GUI/Model/Sample/ItemWithParticles.h @@ -17,7 +17,7 @@ #include "Base/Vector/Vectors3D.h" #include "GUI/Model/Group/SelectionDescriptor.h" -#include "GUI/Model/Session/SessionGraphicsItem.h" +#include "GUI/Model/Session/SessionItem.h" class DoubleDescriptor; class IParticle; @@ -28,7 +28,7 @@ class TransformationItem; class VectorDescriptor; class VectorItem; -class ItemWithParticles : public virtual SessionGraphicsItem { +class ItemWithParticles : public virtual SessionItem { private: static constexpr auto P_ABUNDANCE{"Abundance"}; static constexpr auto P_POSITION{"Position Offset"}; diff --git a/GUI/Model/Sample/LayerItem.cpp b/GUI/Model/Sample/LayerItem.cpp index 4af5b030232..c3574dcb0db 100644 --- a/GUI/Model/Sample/LayerItem.cpp +++ b/GUI/Model/Sample/LayerItem.cpp @@ -66,7 +66,7 @@ QVector<ItemWithMaterial*> layoutItemsWithMaterial(ParticleLayoutItem* item) } // namespace -LayerItem::LayerItem() : SessionGraphicsItem(M_TYPE), ItemWithMaterial(M_TYPE) +LayerItem::LayerItem() : SessionItem(M_TYPE), ItemWithMaterial(M_TYPE) { setToolTip("A layer with thickness and material"); addProperty(P_THICKNESS, 0.0) diff --git a/GUI/Model/Sample/MesoCrystalItem.cpp b/GUI/Model/Sample/MesoCrystalItem.cpp index 9b036b46db1..8bee38cdbfb 100644 --- a/GUI/Model/Sample/MesoCrystalItem.cpp +++ b/GUI/Model/Sample/MesoCrystalItem.cpp @@ -46,7 +46,7 @@ const QString density_tooltip = } // namespace MesoCrystalItem::MesoCrystalItem() - : SessionGraphicsItem(M_TYPE), ItemWithParticles(M_TYPE, abundance_tooltip, position_tooltip) + : SessionItem(M_TYPE), ItemWithParticles(M_TYPE, abundance_tooltip, position_tooltip) { setToolTip("A 3D crystal structure of nanoparticles"); diff --git a/GUI/Model/Sample/MultiLayerItem.cpp b/GUI/Model/Sample/MultiLayerItem.cpp index 4b7cd0d3f0b..7aab8dc9453 100644 --- a/GUI/Model/Sample/MultiLayerItem.cpp +++ b/GUI/Model/Sample/MultiLayerItem.cpp @@ -21,7 +21,7 @@ namespace { const QString external_field_tooltip = "External field (A/m)"; } -MultiLayerItem::MultiLayerItem() : SessionGraphicsItem(M_TYPE) +MultiLayerItem::MultiLayerItem() : SessionItem(M_TYPE) { setToolTip("A multilayer to hold stack of layers"); setItemName(M_TYPE); diff --git a/GUI/Model/Sample/MultiLayerItem.h b/GUI/Model/Sample/MultiLayerItem.h index 29dec2597ec..b92d94b3691 100644 --- a/GUI/Model/Sample/MultiLayerItem.h +++ b/GUI/Model/Sample/MultiLayerItem.h @@ -16,14 +16,14 @@ #define BORNAGAIN_GUI_MODEL_SAMPLE_MULTILAYERITEM_H #include "Base/Vector/Vectors3D.h" -#include "GUI/Model/Session/SessionGraphicsItem.h" +#include "GUI/Model/Session/SessionItem.h" class LayerItem; class ItemWithMaterial; class DoubleDescriptor; class VectorDescriptor; -class BA_CORE_API_ MultiLayerItem : public SessionGraphicsItem { +class BA_CORE_API_ MultiLayerItem : public SessionItem { private: static constexpr auto P_CROSS_CORR_LENGTH{"CrossCorrelationLength"}; static constexpr auto P_EXTERNAL_FIELD{"ExternalField"}; diff --git a/GUI/Model/Sample/ParticleCompositionItem.cpp b/GUI/Model/Sample/ParticleCompositionItem.cpp index bdc8b4461bb..f610cd54430 100644 --- a/GUI/Model/Sample/ParticleCompositionItem.cpp +++ b/GUI/Model/Sample/ParticleCompositionItem.cpp @@ -35,7 +35,7 @@ const QString position_tooltip = "Relative position of the particle's reference ParticleCompositionItem::ParticleCompositionItem() - : SessionGraphicsItem(M_TYPE), ItemWithParticles(M_TYPE, abundance_tooltip, position_tooltip) + : SessionItem(M_TYPE), ItemWithParticles(M_TYPE, abundance_tooltip, position_tooltip) { setToolTip("Composition of particles with fixed positions"); diff --git a/GUI/Model/Sample/ParticleCoreShellItem.cpp b/GUI/Model/Sample/ParticleCoreShellItem.cpp index 244dc1fc546..ff0f96bd694 100644 --- a/GUI/Model/Sample/ParticleCoreShellItem.cpp +++ b/GUI/Model/Sample/ParticleCoreShellItem.cpp @@ -32,7 +32,7 @@ const QString position_tooltip = "Relative position of the particle's reference } // namespace ParticleCoreShellItem::ParticleCoreShellItem() - : SessionGraphicsItem(M_TYPE), ItemWithParticles(M_TYPE, abundance_tooltip, position_tooltip) + : SessionItem(M_TYPE), ItemWithParticles(M_TYPE, abundance_tooltip, position_tooltip) { setToolTip("A particle with a core/shell geometry"); diff --git a/GUI/Model/Sample/ParticleItem.cpp b/GUI/Model/Sample/ParticleItem.cpp index 6e20f7865e9..1da8af4c55b 100644 --- a/GUI/Model/Sample/ParticleItem.cpp +++ b/GUI/Model/Sample/ParticleItem.cpp @@ -36,7 +36,7 @@ const QString position_tooltip = "Relative position of the particle's reference } // namespace ParticleItem::ParticleItem() - : SessionGraphicsItem(M_TYPE) + : SessionItem(M_TYPE) , ItemWithMaterial(M_TYPE) , ItemWithParticles(M_TYPE, abundance_tooltip, position_tooltip) { diff --git a/GUI/Model/Sample/ParticleLayoutItem.cpp b/GUI/Model/Sample/ParticleLayoutItem.cpp index 256e40ce5e1..4ea90c9ce90 100644 --- a/GUI/Model/Sample/ParticleLayoutItem.cpp +++ b/GUI/Model/Sample/ParticleLayoutItem.cpp @@ -46,7 +46,7 @@ const QString weight_tooltip = "Should be used when multiple layouts define different domains in the sample."; } // namespace -ParticleLayoutItem::ParticleLayoutItem() : SessionGraphicsItem(M_TYPE) +ParticleLayoutItem::ParticleLayoutItem() : SessionItem(M_TYPE) { setToolTip("A layout of particles"); diff --git a/GUI/Model/Sample/ParticleLayoutItem.h b/GUI/Model/Sample/ParticleLayoutItem.h index 85a193db159..703c3b673d1 100644 --- a/GUI/Model/Sample/ParticleLayoutItem.h +++ b/GUI/Model/Sample/ParticleLayoutItem.h @@ -16,14 +16,13 @@ #define BORNAGAIN_GUI_MODEL_SAMPLE_PARTICLELAYOUTITEM_H #include "GUI/Model/Group/SelectionDescriptor.h" -#include "GUI/Model/Session/SessionGraphicsItem.h" #include "GUI/Model/Session/SessionModel.h" class InterferenceItem; class ItemWithParticles; class DoubleDescriptor; -class BA_CORE_API_ ParticleLayoutItem : public SessionGraphicsItem { +class BA_CORE_API_ ParticleLayoutItem : public SessionItem { private: static constexpr auto P_TOTAL_DENSITY{"TotalParticleDensity"}; static constexpr auto P_WEIGHT{"Weight"}; diff --git a/GUI/Model/Sample/SampleModel.cpp b/GUI/Model/Sample/SampleModel.cpp index e550a9c6347..4f89486f06d 100644 --- a/GUI/Model/Sample/SampleModel.cpp +++ b/GUI/Model/Sample/SampleModel.cpp @@ -86,16 +86,8 @@ void SampleModel::removeMultiLayer(MultiLayerItem* item) void SampleModel::onDataChanged(const QModelIndex& index, const QModelIndex&) { - // check whether it's an item and not a position related item, then emit - // the relevant signal + // check whether it's an item, then emit the relevant signal auto* const item = itemForIndex(index); - if (item) { - const bool isPositionRelated = - item->hasModelType<PropertyItem>() - && (SessionGraphicsItem::isXPosPropertyName(item->displayName()) - || SessionGraphicsItem::isYPosPropertyName(item->displayName())); - - if (!isPositionRelated) - emit nonPositionRelatedDataChanged(item); - } + if (item) + emit itemDataChanged(item); } diff --git a/GUI/Model/Sample/SampleModel.h b/GUI/Model/Sample/SampleModel.h index 430c0b72033..e923341fc2a 100644 --- a/GUI/Model/Sample/SampleModel.h +++ b/GUI/Model/Sample/SampleModel.h @@ -41,10 +41,11 @@ public: void removeMultiLayer(MultiLayerItem* item); signals: - //! This signal is emitted if any data changed (compare to dataChanged), but only if the - //! change is not about position changes (i.e. moving an item in the sample editor). + //! This signal is emitted if any item data changed (compare to + //! QAbstractItemModel::dataChanged). + //! //! item is the one given in the first index of dataChanged(idx1,idx2) - void nonPositionRelatedDataChanged(const SessionItem* item); + void itemDataChanged(const SessionItem* item); private: void onDataChanged(const QModelIndex& index, const QModelIndex&); diff --git a/GUI/Model/Session/SessionGraphicsItem.cpp b/GUI/Model/Session/SessionGraphicsItem.cpp deleted file mode 100644 index 0432e63f3d8..00000000000 --- a/GUI/Model/Session/SessionGraphicsItem.cpp +++ /dev/null @@ -1,51 +0,0 @@ -// ************************************************************************************************ -// -// BornAgain: simulate and fit reflection and scattering -// -//! @file GUI/Model/Session/SessionGraphicsItem.cpp -//! @brief Implements class SessionGraphicsItem -//! -//! @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/Model/Session/SessionGraphicsItem.h" - -SessionGraphicsItem::SessionGraphicsItem(const QString& model_type) : SessionItem(model_type) -{ - addProperty(P_XPOS, qreal(0.0))->setVisible(false); - addProperty(P_YPOS, qreal(0.0))->setVisible(false); -} - -double SessionGraphicsItem::xPos() const -{ - return getItemValue(P_XPOS).toDouble(); -} - -void SessionGraphicsItem::setXPos(double x_pos) -{ - setItemValue(P_XPOS, x_pos); -} - -bool SessionGraphicsItem::isXPosPropertyName(const QString& name) -{ - return name == P_XPOS; -} - -double SessionGraphicsItem::yPos() const -{ - return getItemValue(P_YPOS).toDouble(); -} - -void SessionGraphicsItem::setYPos(double y_pos) -{ - setItemValue(P_YPOS, y_pos); -} - -bool SessionGraphicsItem::isYPosPropertyName(const QString& name) -{ - return name == P_YPOS; -} diff --git a/GUI/Model/Session/SessionGraphicsItem.h b/GUI/Model/Session/SessionGraphicsItem.h deleted file mode 100644 index 28ce7cda63b..00000000000 --- a/GUI/Model/Session/SessionGraphicsItem.h +++ /dev/null @@ -1,39 +0,0 @@ -// ************************************************************************************************ -// -// BornAgain: simulate and fit reflection and scattering -// -//! @file GUI/Model/Session/SessionGraphicsItem.h -//! @brief Defines class SessionGraphicsItem -//! -//! @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_MODEL_SESSION_SESSIONGRAPHICSITEM_H -#define BORNAGAIN_GUI_MODEL_SESSION_SESSIONGRAPHICSITEM_H - -#include "GUI/Model/Session/SessionItem.h" - -class BA_CORE_API_ SessionGraphicsItem : public SessionItem { - -private: - static constexpr auto P_XPOS{"xpos"}; - static constexpr auto P_YPOS{"ypos"}; - -public: - double xPos() const; - void setXPos(double x_pos); - static bool isXPosPropertyName(const QString& name); - - double yPos() const; - void setYPos(double y_pos); - static bool isYPosPropertyName(const QString& name); - -protected: - explicit SessionGraphicsItem(const QString& model_type); -}; - -#endif // BORNAGAIN_GUI_MODEL_SESSION_SESSIONGRAPHICSITEM_H diff --git a/GUI/Model/Session/SessionItemUtils.cpp b/GUI/Model/Session/SessionItemUtils.cpp index b90237a17fe..399e83dff47 100644 --- a/GUI/Model/Session/SessionItemUtils.cpp +++ b/GUI/Model/Session/SessionItemUtils.cpp @@ -17,7 +17,6 @@ #include "GUI/Model/Sample/MesoCrystalItem.h" #include "GUI/Model/Sample/ParticleCompositionItem.h" #include "GUI/Model/Sample/ParticleCoreShellItem.h" -#include "GUI/Model/Session/SessionGraphicsItem.h" #include <QColor> #include <QIcon> #include <QPixmap> diff --git a/GUI/Model/Trafo/TransformationItem.cpp b/GUI/Model/Trafo/TransformationItem.cpp index d2aa65bb006..3b26a3487de 100644 --- a/GUI/Model/Trafo/TransformationItem.cpp +++ b/GUI/Model/Trafo/TransformationItem.cpp @@ -16,7 +16,7 @@ #include "GUI/Model/Group/GroupInfo.h" #include "GUI/Model/Trafo/RotationItems.h" -TransformationItem::TransformationItem() : SessionGraphicsItem(M_TYPE) +TransformationItem::TransformationItem() : SessionItem(M_TYPE) { setToolTip("Rotation applied to particles"); diff --git a/GUI/Model/Trafo/TransformationItem.h b/GUI/Model/Trafo/TransformationItem.h index bb35832943f..7df8ac011df 100644 --- a/GUI/Model/Trafo/TransformationItem.h +++ b/GUI/Model/Trafo/TransformationItem.h @@ -15,11 +15,11 @@ #ifndef BORNAGAIN_GUI_MODEL_TRAFO_TRANSFORMATIONITEM_H #define BORNAGAIN_GUI_MODEL_TRAFO_TRANSFORMATIONITEM_H -#include "GUI/Model/Session/SessionGraphicsItem.h" +#include "GUI/Model/Session/SessionItem.h" class RotationItem; -class BA_CORE_API_ TransformationItem : public SessionGraphicsItem { +class BA_CORE_API_ TransformationItem : public SessionItem { private: static constexpr auto P_ROT{"Rotation type"}; diff --git a/GUI/View/Realspace/RealSpaceCanvas.cpp b/GUI/View/Realspace/RealSpaceCanvas.cpp index f7009e090d5..5c5420750c7 100644 --- a/GUI/View/Realspace/RealSpaceCanvas.cpp +++ b/GUI/View/Realspace/RealSpaceCanvas.cpp @@ -178,8 +178,8 @@ void RealSpaceCanvas::setConnected(SampleModel* model, bool makeConnected) Qt::UniqueConnection); connect(model, &SampleModel::rowsAboutToBeRemoved, this, &RealSpaceCanvas::onRowsAboutToBeRemoved, Qt::UniqueConnection); - connect(model, &SampleModel::nonPositionRelatedDataChanged, this, - &RealSpaceCanvas::updateScene, Qt::UniqueConnection); + connect(model, &SampleModel::itemDataChanged, this, &RealSpaceCanvas::updateScene, + Qt::UniqueConnection); connect(model, &SampleModel::modelReset, this, &RealSpaceCanvas::resetScene, Qt::UniqueConnection); connect( diff --git a/GUI/View/SampleDesigner/ScriptPanel.cpp b/GUI/View/SampleDesigner/ScriptPanel.cpp index d2c73e0c8c7..6bb6a78db56 100644 --- a/GUI/View/SampleDesigner/ScriptPanel.cpp +++ b/GUI/View/SampleDesigner/ScriptPanel.cpp @@ -88,7 +88,7 @@ void ScriptPanel::setEditorConnected(bool isConnected) &UpdateTimer::scheduleUpdate); connect(m_sampleModel, &SampleModel::rowsRemoved, m_updateTimer, &UpdateTimer::scheduleUpdate); - connect(m_sampleModel, &SampleModel::nonPositionRelatedDataChanged, m_updateTimer, + connect(m_sampleModel, &SampleModel::itemDataChanged, m_updateTimer, &UpdateTimer::scheduleUpdate); connect(m_sampleModel, &SampleModel::modelReset, this, &ScriptPanel::updateEditor, Qt::UniqueConnection); -- GitLab