diff --git a/GUI/coregui/Models/MesoCrystalItem.cpp b/GUI/coregui/Models/MesoCrystalItem.cpp index 660e58681b7783c15263c53881f5c64bc33ff665..ba02c14eb2ac9bd2477494dffc3ac1fd59d9e487 100644 --- a/GUI/coregui/Models/MesoCrystalItem.cpp +++ b/GUI/coregui/Models/MesoCrystalItem.cpp @@ -55,11 +55,6 @@ const QString density_tooltip = bool IsIParticleName(QString name); -QStringList parents_with_abundance() { - return QStringList() << Constants::ParticleCoreShellType << Constants::ParticleCompositionType - << Constants::ParticleDistributionType << Constants::MesoCrystalType; -} - } const QString MesoCrystalItem::P_FORM_FACTOR = "Outer Shape"; @@ -107,7 +102,7 @@ MesoCrystalItem::MesoCrystalItem() : SessionGraphicsItem(Constants::MesoCrystalT mapper()->setOnParentChange( [this](SessionItem *parent) { - if (parentHasOwnAbundance(parent)) { + if (SessionItemUtils::HasOwnAbundance(parent)) { setItemValue(ParticleItem::P_ABUNDANCE, 1.0); getItem(ParticleItem::P_ABUNDANCE)->setEnabled(false); } else { @@ -188,12 +183,6 @@ std::unique_ptr<IFormFactor> MesoCrystalItem::getOuterShape() const return ff_item.createFormFactor(); } -bool MesoCrystalItem::parentHasOwnAbundance(SessionItem* parent) const -{ - static QStringList special_parent = parents_with_abundance(); - return parent ? special_parent.contains(parent->modelType()) : false; -} - namespace { bool IsIParticleName(QString name) { return (name.startsWith(Constants::ParticleType) diff --git a/GUI/coregui/Models/MesoCrystalItem.h b/GUI/coregui/Models/MesoCrystalItem.h index 0fca4e459108142ba711b8c2b4b030decf0a7391..bfafa510598cc38b2915defaa97c76cd20f68a31 100644 --- a/GUI/coregui/Models/MesoCrystalItem.h +++ b/GUI/coregui/Models/MesoCrystalItem.h @@ -41,7 +41,6 @@ public: Lattice getLattice() const; std::unique_ptr<IParticle> getBasis() const; std::unique_ptr<IFormFactor> getOuterShape() const; - bool parentHasOwnAbundance(SessionItem* parent) const; }; #endif // MESOCRYSTALITEM_H diff --git a/GUI/coregui/Models/ParticleCompositionItem.cpp b/GUI/coregui/Models/ParticleCompositionItem.cpp index 61cb50f73898e04430659c3e3c6a65fd65e835c8..5e1ad7e4621e87fad039ed8d4f2effd9e4958c5b 100644 --- a/GUI/coregui/Models/ParticleCompositionItem.cpp +++ b/GUI/coregui/Models/ParticleCompositionItem.cpp @@ -21,6 +21,7 @@ #include "Particle.h" #include "TransformToDomain.h" #include "ParticleCoreShell.h" +#include "SessionItemUtils.h" namespace { const QString abundance_tooltip = @@ -59,7 +60,7 @@ ParticleCompositionItem::ParticleCompositionItem() mapper()->setOnParentChange( [this](SessionItem *parent) { - if (parent && parent->modelType() != Constants::ParticleLayoutType) { + if (SessionItemUtils::HasOwnAbundance(parent)) { setItemValue(ParticleItem::P_ABUNDANCE, 1.0); getItem(ParticleItem::P_ABUNDANCE)->setEnabled(false); } else { diff --git a/GUI/coregui/Models/ParticleCoreShellItem.cpp b/GUI/coregui/Models/ParticleCoreShellItem.cpp index 2f9f643eac8db9b9989f9d2c24b354b2721232e2..674452b446d0ef146a5c013749e2ad1daec32752 100644 --- a/GUI/coregui/Models/ParticleCoreShellItem.cpp +++ b/GUI/coregui/Models/ParticleCoreShellItem.cpp @@ -19,6 +19,7 @@ #include "TransformToDomain.h" #include "Particle.h" #include "ParticleCoreShell.h" +#include "SessionItemUtils.h" namespace { const QString abundance_tooltip = @@ -29,11 +30,6 @@ const QString position_tooltip = "Relative position of the particle's reference point \n" "in the coordinate system of the parent (nm)"; -QStringList parents_with_abundance() { - return QStringList() << Constants::ParticleCoreShellType << Constants::ParticleCompositionType - << Constants::ParticleDistributionType << Constants::MesoCrystalType; -} - } const QString ParticleCoreShellItem::T_CORE = "Core Tag"; @@ -62,7 +58,7 @@ ParticleCoreShellItem::ParticleCoreShellItem() mapper()->setOnParentChange( [this](SessionItem* parent) { - if (parentHasOwnAbundance(parent)) { + if (SessionItemUtils::HasOwnAbundance(parent)) { setItemValue(ParticleItem::P_ABUNDANCE, 1.0); getItem(ParticleItem::P_ABUNDANCE)->setEnabled(false); } else { @@ -103,8 +99,3 @@ QVector<SessionItem*> ParticleCoreShellItem::materialPropertyItems() return result; } -bool ParticleCoreShellItem::parentHasOwnAbundance(SessionItem* parent) const -{ - static QStringList special_parent = parents_with_abundance(); - return parent ? special_parent.contains(parent->modelType()) : false; -} diff --git a/GUI/coregui/Models/ParticleCoreShellItem.h b/GUI/coregui/Models/ParticleCoreShellItem.h index a80f5ab063b2b1c40c3d4fbee3782ba41140a975..00cab30f884fb85ccb14bfabfe048dd0f58cf775 100644 --- a/GUI/coregui/Models/ParticleCoreShellItem.h +++ b/GUI/coregui/Models/ParticleCoreShellItem.h @@ -27,7 +27,6 @@ public: ParticleCoreShellItem(); std::unique_ptr<ParticleCoreShell> createParticleCoreShell() const; QVector<SessionItem*> materialPropertyItems(); - bool parentHasOwnAbundance(SessionItem* parent) const; }; #endif // PARTICLECORESHELLITEM_H diff --git a/GUI/coregui/Models/ParticleItem.cpp b/GUI/coregui/Models/ParticleItem.cpp index 1a53bfe1843b1f773e542205a86e7f785a45aaf5..a3b1cbe32bffeb1a35e943da23ed6d45639bcc66 100644 --- a/GUI/coregui/Models/ParticleItem.cpp +++ b/GUI/coregui/Models/ParticleItem.cpp @@ -23,6 +23,7 @@ #include "TransformToDomain.h" #include "VectorItem.h" #include "SessionModel.h" +#include "SessionItemUtils.h" using SessionItemUtils::SetVectorItem; @@ -35,10 +36,6 @@ const QString position_tooltip = "Relative position of the particle's reference point \n" "in the coordinate system of the parent (nm)"; -QStringList parents_with_abundance() { - return QStringList() << Constants::ParticleCoreShellType << Constants::ParticleCompositionType - << Constants::ParticleDistributionType << Constants::MesoCrystalType; -} } const QString ParticleItem::P_FORM_FACTOR = "Form Factor"; @@ -98,7 +95,7 @@ QVector<SessionItem*> ParticleItem::materialPropertyItems() void ParticleItem::updatePropertiesAppearance(SessionItem* newParent) { - if (parentHasOwnAbundance(newParent)) { + if (SessionItemUtils::HasOwnAbundance(newParent)) { setItemValue(ParticleItem::P_ABUNDANCE, 1.0); getItem(ParticleItem::P_ABUNDANCE)->setEnabled(false); if (isShellParticle()) { @@ -133,12 +130,3 @@ bool ParticleItem::parentIsParticleLayout() const return parent()->modelType() == Constants::ParticleLayoutType; } - -//! Returns true if parent has own abundance. -//! For rootItem and for ParticleLayout will return false. - -bool ParticleItem::parentHasOwnAbundance(SessionItem* parent) const -{ - static QStringList special_parent = parents_with_abundance(); - return parent ? special_parent.contains(parent->modelType()) : false; -} diff --git a/GUI/coregui/Models/ParticleItem.h b/GUI/coregui/Models/ParticleItem.h index eb2b48d4a0b73e73f9d46d03d1232b782d34018e..26aaf1402a28f398ff345de2fc20f029ec42e13e 100644 --- a/GUI/coregui/Models/ParticleItem.h +++ b/GUI/coregui/Models/ParticleItem.h @@ -37,7 +37,6 @@ private: void updatePropertiesAppearance(SessionItem*); bool isShellParticle() const; bool parentIsParticleLayout() const; - bool parentHasOwnAbundance(SessionItem* parent) const; }; #endif // PARTICLEITEM_H diff --git a/GUI/coregui/Models/SessionItemUtils.cpp b/GUI/coregui/Models/SessionItemUtils.cpp index b5fbc41fd45f0807ddbaf4431da48ea7c996e30e..d3fd44329c1e3bc1f509af7f7c9d66437525da50 100644 --- a/GUI/coregui/Models/SessionItemUtils.cpp +++ b/GUI/coregui/Models/SessionItemUtils.cpp @@ -30,6 +30,12 @@ const GroupInfoCatalogue& groupInfoCatalogue() static GroupInfoCatalogue s_catalogue = GroupInfoCatalogue(); return s_catalogue; } + +QStringList parents_with_abundance() { + return QStringList() << Constants::ParticleCoreShellType << Constants::ParticleCompositionType + << Constants::ParticleDistributionType << Constants::MesoCrystalType; +} + } int SessionItemUtils::ParentRow(const SessionItem& item) @@ -163,3 +169,9 @@ bool SessionItemUtils::IsPositionRelated(const SessionItem& item) return false; } + +bool SessionItemUtils::HasOwnAbundance(const SessionItem* item) +{ + static QStringList special_parent = parents_with_abundance(); + return item ? special_parent.contains(item->modelType()) : false; +} diff --git a/GUI/coregui/Models/SessionItemUtils.h b/GUI/coregui/Models/SessionItemUtils.h index abe78b81d39c0f49dc68287e2eabbfcd9f644b23..8af8f976185605c74b489796cd547f96ae8b0edf 100644 --- a/GUI/coregui/Models/SessionItemUtils.h +++ b/GUI/coregui/Models/SessionItemUtils.h @@ -71,6 +71,8 @@ BA_CORE_API_ bool IsTheSame(const QVariant& var1, const QVariant& var2); //! Returns true if current item is related to the position on sample editor canvas. BA_CORE_API_ bool IsPositionRelated(const SessionItem& item); +BA_CORE_API_ bool HasOwnAbundance(const SessionItem* item); + } // namespace SessionItemUtils #endif // SESSIONITEMUTILS_H