Skip to content
Snippets Groups Projects
Commit d5cfaf06 authored by t.knopff's avatar t.knopff
Browse files

Use string constant for property item type name

parent 6bc7e559
No related branches found
No related tags found
1 merge request!213Refactor model: PropertyItem
Pipeline #41671 failed
......@@ -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>()) {
......
......@@ -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;
......
......@@ -92,7 +92,7 @@ ItemCatalog::ItemCatalog()
addItem<FootprintGaussianItem>();
addItem<FootprintSquareItem>();
addItem<VectorItem>();
add("Property", create_new<PropertyItem>);
addItem<PropertyItem>();
addItem<AnisoPyramidItem>();
addItem<BarGaussItem>();
......
......@@ -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);
......
......@@ -14,4 +14,6 @@
#include "GUI/Models/PropertyItem.h"
PropertyItem::PropertyItem() : SessionItem("Property") {}
const QString PropertyItem::M_TYPE = "Property";
PropertyItem::PropertyItem() : SessionItem(M_TYPE) {}
......@@ -20,6 +20,8 @@
class PropertyItem : public SessionItem {
public:
static const QString M_TYPE;
PropertyItem();
};
......
......@@ -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;
......
......@@ -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;
......
......@@ -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);
......
......@@ -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());
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment