From 06490c945c9f5a024530174654d853d7fda5d3d1 Mon Sep 17 00:00:00 2001 From: Gennady Pospelov <g.pospelov@fz-juelich.de> Date: Mon, 18 Apr 2016 14:37:07 +0200 Subject: [PATCH] All SessionItems switched to new addGroupProperty method --- GUI/coregui/Models/BeamItem.cpp | 6 +-- GUI/coregui/Models/GroupPropertyRegistry.cpp | 12 ++++- GUI/coregui/Models/GroupPropertyRegistry.h | 6 ++- GUI/coregui/Models/IntensityDataItem.cpp | 6 +-- GUI/coregui/Models/MaterialItem.cpp | 2 +- .../Models/ParticleCompositionItem.cpp | 2 +- GUI/coregui/Models/ParticleCoreShellItem.cpp | 2 +- GUI/coregui/Models/ParticleItem.cpp | 2 +- .../Models/RectangularDetectorItem.cpp | 8 ++-- GUI/coregui/Models/SessionItem.cpp | 48 +++++++++++-------- GUI/coregui/Models/SessionItem.h | 4 +- GUI/coregui/Models/SphericalDetectorItem.cpp | 4 +- .../DetectorMaskDelegate.cpp | 2 +- 13 files changed, 60 insertions(+), 44 deletions(-) diff --git a/GUI/coregui/Models/BeamItem.cpp b/GUI/coregui/Models/BeamItem.cpp index e01fd781be0..064e2bae440 100644 --- a/GUI/coregui/Models/BeamItem.cpp +++ b/GUI/coregui/Models/BeamItem.cpp @@ -36,9 +36,9 @@ BeamItem::BeamItem() : SessionItem(Constants::BeamType) { ScientificDoubleProperty intensity(1e+08); addProperty(P_INTENSITY, intensity.getVariant())->setLimits(AttLimits::limited(0.0, 1e+32)); - addGroupPropertyTmp(P_WAVELENGTH, Constants::BeamWavelengthType); - addGroupPropertyTmp(P_INCLINATION_ANGLE, Constants::BeamInclinationAngleType); - addGroupPropertyTmp(P_AZIMUTHAL_ANGLE, Constants::BeamAzimuthalAngleType); + addGroupProperty(P_WAVELENGTH, Constants::BeamWavelengthType); + addGroupProperty(P_INCLINATION_ANGLE, Constants::BeamInclinationAngleType); + addGroupProperty(P_AZIMUTHAL_ANGLE, Constants::BeamAzimuthalAngleType); } double BeamItem::getIntensity() const diff --git a/GUI/coregui/Models/GroupPropertyRegistry.cpp b/GUI/coregui/Models/GroupPropertyRegistry.cpp index 75fcfd01281..e746a11ce45 100644 --- a/GUI/coregui/Models/GroupPropertyRegistry.cpp +++ b/GUI/coregui/Models/GroupPropertyRegistry.cpp @@ -132,11 +132,19 @@ GroupPropertyRegistry::SelectableGroupMap_t initializeSelectableGroupMap() GroupPropertyRegistry::SelectableGroupMap_t GroupPropertyRegistry::m_selectable_group_map = initializeSelectableGroupMap(); +bool GroupPropertyRegistry::isValidGroup(const QString &group_type) +{ + auto it = m_selectable_group_map.find(group_type); + return it==m_selectable_group_map.end() ? false : true; +} + GroupProperty_t GroupPropertyRegistry::createGroupProperty(const QString &group_name, - const Constants::ModelType &group_model) + const Constants::ModelType &group_type) { - Constants::ModelType groupModelType = group_model; + Q_ASSERT(isValidGroup(group_type)); + + Constants::ModelType groupModelType = group_type; if (groupModelType.isEmpty()) groupModelType = group_name; diff --git a/GUI/coregui/Models/GroupPropertyRegistry.h b/GUI/coregui/Models/GroupPropertyRegistry.h index 75f87dfbf83..f213bcb834f 100644 --- a/GUI/coregui/Models/GroupPropertyRegistry.h +++ b/GUI/coregui/Models/GroupPropertyRegistry.h @@ -33,7 +33,11 @@ class BA_CORE_API_ GroupPropertyRegistry public: using SelectableGroupMap_t = std::map<QString, std::map<QString, QString>>; - static GroupProperty_t createGroupProperty(const QString &group_name, const Constants::ModelType &group_model = Constants::ModelType()); + static bool isValidGroup(const QString &group_type); + + static GroupProperty_t createGroupProperty(const QString &group_name, + const Constants::ModelType &group_type); + private: static SelectableGroupMap_t m_selectable_group_map; //!< Contains correspondance of selectable group names to their content, diff --git a/GUI/coregui/Models/IntensityDataItem.cpp b/GUI/coregui/Models/IntensityDataItem.cpp index c438f185e13..ad59b4efc20 100644 --- a/GUI/coregui/Models/IntensityDataItem.cpp +++ b/GUI/coregui/Models/IntensityDataItem.cpp @@ -62,13 +62,13 @@ IntensityDataItem::IntensityDataItem() addProperty(P_PROPERTY_PANEL_FLAG, false)->setVisible(false); - SessionItem *item = addGroupPropertyTmp(P_XAXIS, Constants::BasicAxisType); + SessionItem *item = addGroupProperty(P_XAXIS, Constants::BasicAxisType); item->getItem(BasicAxisItem::P_NBINS)->setVisible(false); - item = addGroupPropertyTmp(P_YAXIS, Constants::BasicAxisType); + item = addGroupProperty(P_YAXIS, Constants::BasicAxisType); item->getItem(BasicAxisItem::P_NBINS)->setVisible(false); - item = addGroupPropertyTmp(P_ZAXIS, Constants::AmplitudeAxisType); + item = addGroupProperty(P_ZAXIS, Constants::AmplitudeAxisType); item->getItem(BasicAxisItem::P_NBINS)->setVisible(false); registerTag(T_MASKS, 0, -1, QStringList() << Constants::MaskContainerType); diff --git a/GUI/coregui/Models/MaterialItem.cpp b/GUI/coregui/Models/MaterialItem.cpp index 2e0c73a6732..5aae28f3d48 100644 --- a/GUI/coregui/Models/MaterialItem.cpp +++ b/GUI/coregui/Models/MaterialItem.cpp @@ -37,7 +37,7 @@ MaterialItem::MaterialItem() ColorProperty color; addProperty(P_COLOR, color.getVariant()); - addGroupPropertyTmp(P_REFRACTIVE_INDEX, Constants::RefractiveIndexType); + addGroupProperty(P_REFRACTIVE_INDEX, Constants::RefractiveIndexType); addProperty(P_IDENTIFIER, QUuid::createUuid().toString()); getItem(P_IDENTIFIER)->setVisible(false); } diff --git a/GUI/coregui/Models/ParticleCompositionItem.cpp b/GUI/coregui/Models/ParticleCompositionItem.cpp index 3b41ad474a7..02a933d2d1f 100644 --- a/GUI/coregui/Models/ParticleCompositionItem.cpp +++ b/GUI/coregui/Models/ParticleCompositionItem.cpp @@ -29,7 +29,7 @@ ParticleCompositionItem::ParticleCompositionItem() addProperty(ParticleItem::P_ABUNDANCE, 1.0); getItem(ParticleItem::P_ABUNDANCE)->setLimits(AttLimits::limited(0.0, 1.0)); getItem(ParticleItem::P_ABUNDANCE)->setDecimals(3); - addGroupPropertyTmp(ParticleItem::P_POSITION, Constants::VectorType); + addGroupProperty(ParticleItem::P_POSITION, Constants::VectorType); PositionTranslator position_translator; ModelPath::addParameterTranslator(position_translator); diff --git a/GUI/coregui/Models/ParticleCoreShellItem.cpp b/GUI/coregui/Models/ParticleCoreShellItem.cpp index 9d2dd9a85a9..08bdddf2214 100644 --- a/GUI/coregui/Models/ParticleCoreShellItem.cpp +++ b/GUI/coregui/Models/ParticleCoreShellItem.cpp @@ -31,7 +31,7 @@ ParticleCoreShellItem::ParticleCoreShellItem() addProperty(ParticleItem::P_ABUNDANCE, 1.0); getItem(ParticleItem::P_ABUNDANCE)->setLimits(AttLimits::limited(0.0, 1.0)); getItem(ParticleItem::P_ABUNDANCE)->setDecimals(3); - addGroupPropertyTmp(ParticleItem::P_POSITION, Constants::VectorType); + addGroupProperty(ParticleItem::P_POSITION, Constants::VectorType); PositionTranslator position_translator; ModelPath::addParameterTranslator(position_translator); diff --git a/GUI/coregui/Models/ParticleItem.cpp b/GUI/coregui/Models/ParticleItem.cpp index bc33dbe2b4c..a653d35d95a 100644 --- a/GUI/coregui/Models/ParticleItem.cpp +++ b/GUI/coregui/Models/ParticleItem.cpp @@ -39,7 +39,7 @@ ParticleItem::ParticleItem() MaterialUtils::getDefaultMaterialProperty().getVariant()); addProperty(P_ABUNDANCE, 1.0)->setLimits(AttLimits::limited(0.0, 1.0)); getItem(P_ABUNDANCE)->setDecimals(3); - addGroupPropertyTmp(P_POSITION, Constants::VectorType); + addGroupProperty(P_POSITION, Constants::VectorType); PositionTranslator position_translator; ModelPath::addParameterTranslator(position_translator); diff --git a/GUI/coregui/Models/RectangularDetectorItem.cpp b/GUI/coregui/Models/RectangularDetectorItem.cpp index d3034e9c531..00570485796 100644 --- a/GUI/coregui/Models/RectangularDetectorItem.cpp +++ b/GUI/coregui/Models/RectangularDetectorItem.cpp @@ -66,14 +66,14 @@ RectangularDetectorItem::RectangularDetectorItem() , m_is_constructed(false) { // axes parameters - SessionItem *item = addGroupPropertyTmp(P_X_AXIS, Constants::BasicAxisType); + SessionItem *item = addGroupProperty(P_X_AXIS, Constants::BasicAxisType); item->getItem(BasicAxisItem::P_TITLE)->setVisible(false); item->getItem(BasicAxisItem::P_MIN)->setVisible(false); item->setItemValue(BasicAxisItem::P_MAX, default_detector_width); item->getItem(BasicAxisItem::P_MAX)->setDisplayName(QStringLiteral("Width")); item->getItem(BasicAxisItem::P_MAX)->setToolTip(QStringLiteral("Width of the detector in mm")); - item = addGroupPropertyTmp(P_Y_AXIS, Constants::BasicAxisType); + item = addGroupProperty(P_Y_AXIS, Constants::BasicAxisType); item->getItem(BasicAxisItem::P_TITLE)->setVisible(false); item->getItem(BasicAxisItem::P_MIN)->setVisible(false); item->setItemValue(BasicAxisItem::P_MAX, default_detector_height); @@ -93,11 +93,11 @@ RectangularDetectorItem::RectangularDetectorItem() addProperty(P_ALIGNMENT, alignment.getVariant()); // alignment parameters - item = addGroupPropertyTmp(P_NORMAL, Constants::VectorType); + item = addGroupProperty(P_NORMAL, Constants::VectorType); item->setItemValue(VectorItem::P_X, default_detector_distance); // direction - item = addGroupPropertyTmp(P_DIRECTION, Constants::VectorType); + item = addGroupProperty(P_DIRECTION, Constants::VectorType); item->setItemValue(VectorItem::P_Y, -1.0); addProperty(P_U0, default_detector_width/2.)->setToolTip(tooltip_u0); diff --git a/GUI/coregui/Models/SessionItem.cpp b/GUI/coregui/Models/SessionItem.cpp index 7016d02fa54..c24f93a759b 100644 --- a/GUI/coregui/Models/SessionItem.cpp +++ b/GUI/coregui/Models/SessionItem.cpp @@ -476,29 +476,35 @@ void SessionItem::setItemValue(const QString &tag, const QVariant &variant) /*! * \brief Creates new group item and register new tag. */ -SessionItem *SessionItem::addGroupProperty(const QString &groupName, const QString &groupModel) -{ - GroupProperty_t group_property - = GroupPropertyRegistry::createGroupProperty(groupName, groupModel); - GroupItem *groupItem = dynamic_cast<GroupItem *>(ItemFactory::createItem(Constants::GroupItemType)); - Q_ASSERT(groupItem); - groupItem->setGroup(group_property); - groupItem->setDisplayName(groupName); - registerTag(groupName, 1, 1, QStringList() << Constants::GroupItemType); - if(!insertItem(0, groupItem, groupName)) { - throw GUIHelpers::Error("SessionItem::addGroupProperty -> Error. Can't insert item"); +SessionItem *SessionItem::addGroupProperty(const QString &groupName, const QString &groupType) +{ + SessionItem *result(0); + + if(GroupPropertyRegistry::isValidGroup(groupType)) { + // create group item + GroupProperty_t group_property + = GroupPropertyRegistry::createGroupProperty(groupName, groupType); + GroupItem *groupItem = dynamic_cast<GroupItem *>( + ItemFactory::createItem(Constants::GroupItemType)); + Q_ASSERT(groupItem); + groupItem->setGroup(group_property); + registerTag(groupName, 1, 1, QStringList() << Constants::GroupItemType); + result = groupItem; } - return groupItem; -} -SessionItem *SessionItem::addGroupPropertyTmp(const QString &groupName, const QString &groupModel) -{ - registerTag(groupName, 1, 1, QStringList() << groupModel); - SessionItem *sessionItem = ItemFactory::createItem(groupModel); - sessionItem->setDisplayName(groupName); - insertItem(0, sessionItem, groupName); - Q_ASSERT(sessionItem); - return sessionItem; + else { + // create single item + registerTag(groupName, 1, 1, QStringList() << groupType); + result = ItemFactory::createItem(groupType); + } + + Q_ASSERT(result); + result->setDisplayName(groupName); + if(!insertItem(0, result, groupName)) { + throw GUIHelpers::Error("SessionItem::addGroupProperty -> Error. Can't insert group item"); + } + + return result; } /*! diff --git a/GUI/coregui/Models/SessionItem.h b/GUI/coregui/Models/SessionItem.h index b21ec713480..4379d4fd42a 100644 --- a/GUI/coregui/Models/SessionItem.h +++ b/GUI/coregui/Models/SessionItem.h @@ -95,9 +95,7 @@ public: SessionItem *addProperty(const QString &name, const QVariant &variant); QVariant getItemValue(const QString &tag) const; void setItemValue(const QString &tag, const QVariant &variant); - SessionItem *addGroupProperty(const QString &groupName, const QString &groupModel); - SessionItem *addGroupPropertyTmp(const QString &groupName, const QString &groupModel); - + SessionItem *addGroupProperty(const QString &groupName, const QString &groupType); SessionItem *setGroupProperty(const QString &name, const QString &value) const; SessionItem *getGroupItem(const QString &name, const QString &type = QString()) const; diff --git a/GUI/coregui/Models/SphericalDetectorItem.cpp b/GUI/coregui/Models/SphericalDetectorItem.cpp index fc02fe2be9c..e644690743f 100644 --- a/GUI/coregui/Models/SphericalDetectorItem.cpp +++ b/GUI/coregui/Models/SphericalDetectorItem.cpp @@ -29,12 +29,12 @@ const QString SphericalDetectorItem::P_RESOLUTION_FUNCTION = "Type"; SphericalDetectorItem::SphericalDetectorItem() : SessionItem(Constants::SphericalDetectorType) { - SessionItem *item = addGroupPropertyTmp(P_PHI_AXIS, Constants::BasicAxisType); + SessionItem *item = addGroupProperty(P_PHI_AXIS, Constants::BasicAxisType); item->getItem(BasicAxisItem::P_TITLE)->setVisible(false); item->setItemValue(BasicAxisItem::P_MIN, -1.0); item->setItemValue(BasicAxisItem::P_MAX, 1.0); - item = addGroupPropertyTmp(P_ALPHA_AXIS, Constants::BasicAxisType); + item = addGroupProperty(P_ALPHA_AXIS, Constants::BasicAxisType); item->getItem(BasicAxisItem::P_TITLE)->setVisible(false); item->setItemValue(BasicAxisItem::P_MIN, 0.0); item->setItemValue(BasicAxisItem::P_MAX, 2.0); diff --git a/GUI/coregui/Views/InstrumentWidgets/DetectorMaskDelegate.cpp b/GUI/coregui/Views/InstrumentWidgets/DetectorMaskDelegate.cpp index f3dc7e056f3..4438ccddc26 100644 --- a/GUI/coregui/Views/InstrumentWidgets/DetectorMaskDelegate.cpp +++ b/GUI/coregui/Views/InstrumentWidgets/DetectorMaskDelegate.cpp @@ -78,7 +78,7 @@ void DetectorMaskDelegate::createIntensityDataItem() // gradient.getVariant()); AmplitudeAxisItem *zAxisItem = dynamic_cast<AmplitudeAxisItem *>( - m_intensityItem->getGroupItem(IntensityDataItem::P_ZAXIS)); + m_intensityItem->getItem(IntensityDataItem::P_ZAXIS)); zAxisItem->setItemValue(BasicAxisItem::P_IS_VISIBLE, false); zAxisItem->setItemValue(BasicAxisItem::P_MIN, 0.0); -- GitLab