diff --git a/GUI/Models/ComponentUtils.cpp b/GUI/Models/ComponentUtils.cpp index 3d61fc1d8f9fee5733b6864b31e439eafd16308e..c670417b7c28f516ed1671fdb85b0d1a19a09794 100644 --- a/GUI/Models/ComponentUtils.cpp +++ b/GUI/Models/ComponentUtils.cpp @@ -16,6 +16,7 @@ #include "GUI/Models/AxesItems.h" #include "GUI/Models/GroupItem.h" #include "GUI/Models/MaterialDataItems.h" +#include "GUI/Models/PropertyItem.h" #include "GUI/Models/VectorItem.h" namespace { @@ -24,7 +25,7 @@ QList<const SessionItem*> groupItems(const GroupItem& item); const QStringList& GUI::Model::ComponentUtils::propertyRelatedTypes() { - static const QStringList result = {"Property", + static const QStringList result = {PropertyItem::M_TYPE, GroupItem::M_TYPE, VectorItem::M_TYPE, BasicAxisItem::M_TYPE, @@ -39,7 +40,7 @@ QList<const SessionItem*> GUI::Model::ComponentUtils::componentItems(const Sessi QList<const SessionItem*> result; - if (item.modelType() == "Property") { + if (item.hasModelType<PropertyItem>()) { result.push_back(&item); } else if (item.hasModelType<GroupItem>()) { diff --git a/GUI/Models/FilterPropertyProxy.cpp b/GUI/Models/FilterPropertyProxy.cpp index 9d21d06904ad271de13aa902f8cb382378a8e61b..b31fc9e1d1cd132d487f0524484696bb6cb3497a 100644 --- a/GUI/Models/FilterPropertyProxy.cpp +++ b/GUI/Models/FilterPropertyProxy.cpp @@ -14,6 +14,7 @@ #include "GUI/Models/FilterPropertyProxy.h" #include "GUI/Models/GroupItem.h" +#include "GUI/Models/PropertyItem.h" #include "GUI/Models/SessionModel.h" #include "GUI/Models/VectorItem.h" @@ -38,7 +39,7 @@ bool FilterPropertyProxy::filterAcceptsRow(int sourceRow, const QModelIndex& sou if (!sourceParent.isValid()) return true; const QString modelType = index.data(SessionFlags::ModelTypeRole).toString(); - if (modelType == "Property" || modelType == GroupItem::M_TYPE + if (modelType == PropertyItem::M_TYPE || modelType == GroupItem::M_TYPE || modelType == VectorItem::M_TYPE) return false; diff --git a/GUI/Models/ItemCatalog.cpp b/GUI/Models/ItemCatalog.cpp index 1c6692f2d70418989603c7da311cdfec1cd5d6e5..532b9f4fd3bf0280bfcf51a39c4030d463bbe6cb 100644 --- a/GUI/Models/ItemCatalog.cpp +++ b/GUI/Models/ItemCatalog.cpp @@ -92,7 +92,7 @@ ItemCatalog::ItemCatalog() addItem<FootprintGaussianItem>(); addItem<FootprintSquareItem>(); addItem<VectorItem>(); - add("Property", create_new<PropertyItem>); + addItem<PropertyItem>(); addItem<AnisoPyramidItem>(); addItem<BarGaussItem>(); diff --git a/GUI/Models/ParameterTreeUtils.cpp b/GUI/Models/ParameterTreeUtils.cpp index 4a4ee45004642f2e12477ea52bb53a3e70a1ec10..f29de29771c7600f62dc0b093c760cc7e53b038e 100644 --- a/GUI/Models/ParameterTreeUtils.cpp +++ b/GUI/Models/ParameterTreeUtils.cpp @@ -22,6 +22,7 @@ #include "GUI/Models/ModelPath.h" #include "GUI/Models/MultiLayerItem.h" #include "GUI/Models/ParameterTreeItems.h" +#include "GUI/Models/PropertyItem.h" #include "GUI/Models/SampleModel.h" #include <QStack> @@ -55,7 +56,7 @@ void handleItem(SessionItem* tree, const SessionItem* source) for (SessionItem* child : source->children()) { if (child->isVisible() && child->isEnabled()) { - if (child->modelType() == "Property") { + if (child->hasModelType<PropertyItem>()) { if (child->value().type() == QVariant::Double) { auto branch = tree->model()->insertItem<ParameterItem>(tree); handleItem(branch, child); diff --git a/GUI/Models/PropertyItem.cpp b/GUI/Models/PropertyItem.cpp index 224cf6f5e76d97f43a5fe25b38e84d465c07bc99..904f2648b2ec2a9950baa8c1cab15a9f61b153ad 100644 --- a/GUI/Models/PropertyItem.cpp +++ b/GUI/Models/PropertyItem.cpp @@ -14,4 +14,6 @@ #include "GUI/Models/PropertyItem.h" -PropertyItem::PropertyItem() : SessionItem("Property") {} +const QString PropertyItem::M_TYPE = "Property"; + +PropertyItem::PropertyItem() : SessionItem(M_TYPE) {} diff --git a/GUI/Models/PropertyItem.h b/GUI/Models/PropertyItem.h index c428a67e47acecc2ba0ad30a0989a2168a96c3e0..3655bce5169327ca7572bf8b547864e3847aba64 100644 --- a/GUI/Models/PropertyItem.h +++ b/GUI/Models/PropertyItem.h @@ -20,6 +20,8 @@ class PropertyItem : public SessionItem { public: + static const QString M_TYPE; + PropertyItem(); }; diff --git a/GUI/Models/SessionItem.cpp b/GUI/Models/SessionItem.cpp index 46ac702fe7372ef07b7df86ed487a421996597b5..ad6d52f27cce13906f9768d998c158314c0be37a 100644 --- a/GUI/Models/SessionItem.cpp +++ b/GUI/Models/SessionItem.cpp @@ -15,6 +15,7 @@ #include "GUI/Models/GroupItem.h" #include "GUI/Models/ItemFactory.h" #include "GUI/Models/ParameterTreeItems.h" +#include "GUI/Models/PropertyItem.h" #include "GUI/Models/SessionItemData.h" #include "GUI/Models/SessionItemTags.h" #include "GUI/Models/SessionItemUtils.h" @@ -274,9 +275,9 @@ SessionItem* SessionItem::addProperty(const QString& name, const QVariant& varia { ASSERT(!isTag(name)); - SessionItem* property = GUI::Model::ItemFactory::CreateItem("Property"); + SessionItem* property = GUI::Model::ItemFactory::CreateItem(PropertyItem::M_TYPE); property->setDisplayName(name); - registerTag(name, 1, 1, QStringList() << "Property"); + registerTag(name, 1, 1, {PropertyItem::M_TYPE}); bool success = insertItem(0, property, name); ASSERT(success); @@ -422,7 +423,7 @@ QString SessionItem::displayName() const { QString result = roleProperty(SessionFlags::DisplayNameRole).toString(); - if (modelType() == "Property" || hasModelType<GroupItem>() || hasModelType<ParameterItem>() + if (hasModelType<PropertyItem>() || hasModelType<GroupItem>() || hasModelType<ParameterItem>() || hasModelType<ParameterLabelItem>()) return result; diff --git a/GUI/Models/SessionItemUtils.cpp b/GUI/Models/SessionItemUtils.cpp index 869fe1a244288c5c75202069f3be41c9e3e116db..533f85d0cddfcef5f902a23f542dc826da1673a8 100644 --- a/GUI/Models/SessionItemUtils.cpp +++ b/GUI/Models/SessionItemUtils.cpp @@ -18,6 +18,7 @@ #include "GUI/Models/MesoCrystalItem.h" #include "GUI/Models/ParticleCompositionItem.h" #include "GUI/Models/ParticleCoreShellItem.h" +#include "GUI/Models/PropertyItem.h" #include "GUI/Models/SessionGraphicsItem.h" #include <QColor> #include <QIcon> @@ -145,7 +146,7 @@ bool GUI::Session::ItemUtils::IsTheSame(const QVariant& var1, const QVariant& va bool GUI::Session::ItemUtils::IsPositionRelated(const SessionItem& item) { - if (item.modelType() == "Property" + if (item.hasModelType<PropertyItem>() && (SessionGraphicsItem::isXPosPropertyName(item.displayName()) || SessionGraphicsItem::isYPosPropertyName(item.displayName()))) return true; diff --git a/GUI/Views/MaskWidgets/MaskGraphicsScene.cpp b/GUI/Views/MaskWidgets/MaskGraphicsScene.cpp index ec1765d3c604f90c66d37c5348a4b68687b191c4..918043196a8606ea6975c10f65762890b1841f94 100644 --- a/GUI/Views/MaskWidgets/MaskGraphicsScene.cpp +++ b/GUI/Views/MaskWidgets/MaskGraphicsScene.cpp @@ -17,6 +17,7 @@ #include "GUI/Models/GroupItem.h" #include "GUI/Models/MaskItems.h" #include "GUI/Models/ProjectionItems.h" +#include "GUI/Models/PropertyItem.h" #include "GUI/Models/SessionModel.h" #include "GUI/Views/MaskWidgets/ColorMapSceneAdaptor.h" #include "GUI/Views/MaskWidgets/MaskGraphicsProxy.h" @@ -387,7 +388,7 @@ void MaskGraphicsScene::updateViews(const QModelIndex& parentIndex, IShape2DView for (int i_row = 0; i_row < m_maskModel->rowCount(parentIndex); ++i_row) { QModelIndex itemIndex = m_maskModel->index(i_row, 0, parentIndex); if (SessionItem* item = m_maskModel->itemForIndex(itemIndex)) { - if (item->hasModelType<GroupItem>() || item->modelType() == "Property") + if (item->hasModelType<GroupItem>() || item->hasModelType<PropertyItem>()) continue; childView = addViewForItem(item); diff --git a/Tests/UnitTests/GUI/TestSessionXML.cpp b/Tests/UnitTests/GUI/TestSessionXML.cpp index dca2e744d1d39e14d2dc71584c8fa0561ea45fe5..673ecf8fb45faf6f10d09c974a97ad2e758bafde 100644 --- a/Tests/UnitTests/GUI/TestSessionXML.cpp +++ b/Tests/UnitTests/GUI/TestSessionXML.cpp @@ -47,7 +47,7 @@ TEST_F(TestSessionXML, test_sessionItem) EXPECT_EQ(target.rowCount(QModelIndex()), 1); SessionItem* newItem = target.itemForIndex(target.index(0, 0, QModelIndex())); - EXPECT_EQ(newItem->modelType(), "Property"); + EXPECT_TRUE(newItem->hasModelType<PropertyItem>()); EXPECT_EQ(newItem->displayName(), "Property"); EXPECT_FALSE(newItem->value().isValid()); }