From d4b839dae2e952ed0e947a27e27f36b2f528066f Mon Sep 17 00:00:00 2001 From: Tobias Knopff <t.knopff@fz-juelich.de> Date: Wed, 30 Jun 2021 08:29:00 +0200 Subject: [PATCH] Use string constants for parameter item type names --- GUI/Models/ItemCatalog.cpp | 6 +++--- GUI/Models/JobItem.cpp | 2 +- GUI/Models/ParameterTreeItems.cpp | 25 ++++++++++++++++--------- GUI/Models/ParameterTreeItems.h | 7 +++++++ GUI/Models/ParameterTreeUtils.cpp | 6 +++--- GUI/Models/ParameterTuningModel.cpp | 2 +- GUI/Models/SessionItem.cpp | 5 +++-- 7 files changed, 34 insertions(+), 19 deletions(-) diff --git a/GUI/Models/ItemCatalog.cpp b/GUI/Models/ItemCatalog.cpp index 8bc37d7fb0c..5dcda8418a0 100644 --- a/GUI/Models/ItemCatalog.cpp +++ b/GUI/Models/ItemCatalog.cpp @@ -208,9 +208,9 @@ ItemCatalog::ItemCatalog() add("GroupProperty", create_new<GroupItem>); - add("Parameter Container", create_new<ParameterContainerItem>); - add("Parameter Label", create_new<ParameterLabelItem>); - add("Parameter", create_new<ParameterItem>); + addItem<ParameterContainerItem>(); + addItem<ParameterLabelItem>(); + addItem<ParameterItem>(); addItem<FitParameterContainerItem>(); addItem<FitParameterItem>(); diff --git a/GUI/Models/JobItem.cpp b/GUI/Models/JobItem.cpp index 2fd6c1c7f15..4d705c6aace 100644 --- a/GUI/Models/JobItem.cpp +++ b/GUI/Models/JobItem.cpp @@ -79,7 +79,7 @@ JobItem::JobItem() : SessionItem(M_TYPE) registerTag(T_OUTPUT, 1, 1, {IntensityDataItem::M_TYPE, SpecularDataItem::M_TYPE}); registerTag(T_REALDATA, 1, 1, {RealDataItem::M_TYPE}); registerTag(T_DATAVIEW, 1, 1, {Data1DViewItem::M_TYPE}); - registerTag(T_PARAMETER_TREE, 0, -1, QStringList() << "Parameter Container"); + registerTag(T_PARAMETER_TREE, 0, -1, {ParameterContainerItem::M_TYPE}); registerTag(T_SIMULATION_OPTIONS, 1, 1, {SimulationOptionsItem::M_TYPE}); diff --git a/GUI/Models/ParameterTreeItems.cpp b/GUI/Models/ParameterTreeItems.cpp index 620e8771fee..d9c97b57456 100644 --- a/GUI/Models/ParameterTreeItems.cpp +++ b/GUI/Models/ParameterTreeItems.cpp @@ -20,18 +20,23 @@ // ---------------------------------------------------------------------------- -ParameterLabelItem::ParameterLabelItem() : SessionItem("Parameter Label") +const QString ParameterLabelItem::M_TYPE = "Parameter Label"; + +ParameterLabelItem::ParameterLabelItem() : SessionItem(M_TYPE) { - const QString T_CHILDREN = "children tag"; - registerTag(T_CHILDREN, 0, -1, - QStringList() << "Parameter Label" - << "Parameter"); + static const QString T_CHILDREN = "children tag"; + registerTag(T_CHILDREN, 0, -1, {M_TYPE, ParameterItem::M_TYPE}); setDefaultTag(T_CHILDREN); } +// ---------------------------------------------------------------------------- + const QString ParameterItem::P_LINK = "Link"; const QString ParameterItem::P_BACKUP = "Backup"; -ParameterItem::ParameterItem() : SessionItem("Parameter") + +const QString ParameterItem::M_TYPE = "Parameter"; + +ParameterItem::ParameterItem() : SessionItem(M_TYPE) { // Link to original PropertyItem in one of components of MultiLayerItem or InstrumentItem addProperty(P_LINK, QString()); @@ -71,9 +76,11 @@ void ParameterItem::restoreFromBackup() // ---------------------------------------------------------------------------- -ParameterContainerItem::ParameterContainerItem() : SessionItem("Parameter Container") +const QString ParameterContainerItem::M_TYPE = "Parameter Container"; + +ParameterContainerItem::ParameterContainerItem() : SessionItem(M_TYPE) { - const QString T_CHILDREN = "children tag"; - registerTag(T_CHILDREN, 0, -1, QStringList() << "Parameter Label"); + static const QString T_CHILDREN = "children tag"; + registerTag(T_CHILDREN, 0, -1, {ParameterLabelItem::M_TYPE}); setDefaultTag(T_CHILDREN); } diff --git a/GUI/Models/ParameterTreeItems.h b/GUI/Models/ParameterTreeItems.h index 5f2a51f9c88..d8ca3ce393b 100644 --- a/GUI/Models/ParameterTreeItems.h +++ b/GUI/Models/ParameterTreeItems.h @@ -25,6 +25,8 @@ class BA_CORE_API_ ParameterLabelItem : public SessionItem { public: + static const QString M_TYPE; + ParameterLabelItem(); }; @@ -34,6 +36,9 @@ class BA_CORE_API_ ParameterItem : public SessionItem { public: static const QString P_LINK; static const QString P_BACKUP; + + static const QString M_TYPE; + ParameterItem(); void propagateValueToLink(double newValue); @@ -47,6 +52,8 @@ public: class BA_CORE_API_ ParameterContainerItem : public SessionItem { public: + static const QString M_TYPE; + ParameterContainerItem(); }; diff --git a/GUI/Models/ParameterTreeUtils.cpp b/GUI/Models/ParameterTreeUtils.cpp index 44be48f91a2..62f387b0be0 100644 --- a/GUI/Models/ParameterTreeUtils.cpp +++ b/GUI/Models/ParameterTreeUtils.cpp @@ -29,11 +29,11 @@ namespace { void handleItem(SessionItem* tree, const SessionItem* source) { - if (tree->modelType() == "Parameter Label") { + if (tree->hasModelType<ParameterLabelItem>()) { tree->setDisplayName(source->itemName()); } - else if (tree->modelType() == "Parameter") { + else if (tree->hasModelType<ParameterItem>()) { tree->setDisplayName(source->itemName()); double sourceValue = source->value().toDouble(); @@ -76,7 +76,7 @@ void handleItem(SessionItem* tree, const SessionItem* source) void populateParameterContainer(SessionItem* container, const SessionItem* source) { - if (container->modelType() != "Parameter Container") + if (!container->hasModelType<ParameterContainerItem>()) throw Error("GUI::Model::ParameterTreeUtils::populateParameterContainer() -> Error. " "Not a ParameterContainerType."); diff --git a/GUI/Models/ParameterTuningModel.cpp b/GUI/Models/ParameterTuningModel.cpp index 6a57ce8ec2e..72e0eb01643 100644 --- a/GUI/Models/ParameterTuningModel.cpp +++ b/GUI/Models/ParameterTuningModel.cpp @@ -30,7 +30,7 @@ Qt::ItemFlags ParameterTuningModel::flags(const QModelIndex& proxyIndex) const result |= Qt::ItemIsEditable; const QString modelType = sourceIndex.data(SessionFlags::ModelTypeRole).toString(); - if (modelType == "Parameter" && getParameterItem(proxyIndex)) + if (modelType == ParameterItem::M_TYPE && getParameterItem(proxyIndex)) result |= Qt::ItemIsDragEnabled; } return result; diff --git a/GUI/Models/SessionItem.cpp b/GUI/Models/SessionItem.cpp index 09672dce9e4..576343296d3 100644 --- a/GUI/Models/SessionItem.cpp +++ b/GUI/Models/SessionItem.cpp @@ -14,6 +14,7 @@ #include "GUI/Models/GroupItem.h" #include "GUI/Models/ItemFactory.h" +#include "GUI/Models/ParameterTreeItems.h" #include "GUI/Models/SessionItemData.h" #include "GUI/Models/SessionItemTags.h" #include "GUI/Models/SessionItemUtils.h" @@ -421,8 +422,8 @@ QString SessionItem::displayName() const { QString result = roleProperty(SessionFlags::DisplayNameRole).toString(); - if (modelType() == "Property" || modelType() == "GroupProperty" || modelType() == "Parameter" - || modelType() == "Parameter Label") + if (modelType() == "Property" || modelType() == "GroupProperty" || hasModelType<ParameterItem>() + || hasModelType<ParameterLabelItem>()) return result; if (m_parent) { -- GitLab