diff --git a/GUI/coregui/Models/GroupInfo.cpp b/GUI/coregui/Models/GroupInfo.cpp index 89be911f8fa6a1e3195c4e32a6b7343f8b2d3073..66877e8517b9f1182c2c07f6b2f739e8279b1a93 100644 --- a/GUI/coregui/Models/GroupInfo.cpp +++ b/GUI/coregui/Models/GroupInfo.cpp @@ -76,6 +76,11 @@ QStringList GroupInfo::itemLabels() const } +bool GroupInfo::isValid() +{ + return !m_groupType.isEmpty(); +} + bool GroupInfo::containsType(const QString& itemType) const { for (auto& pair : m_info) diff --git a/GUI/coregui/Models/GroupInfo.h b/GUI/coregui/Models/GroupInfo.h index 8e59cb3485d85db73daceed071b9076bdac2acc2..55b677957f73a60226c5e7d046129b0959a579e9 100644 --- a/GUI/coregui/Models/GroupInfo.h +++ b/GUI/coregui/Models/GroupInfo.h @@ -40,6 +40,8 @@ public: QStringList itemLabels() const; + bool isValid(); + private: struct TypeAndLabel { QString m_itemType; diff --git a/GUI/coregui/Models/GroupItem.cpp b/GUI/coregui/Models/GroupItem.cpp index bd5a66db178e9bbdc0c88375fd8cddc6dfe26c09..b908a350629e2fbbec6617fe6132605ae932b12c 100644 --- a/GUI/coregui/Models/GroupItem.cpp +++ b/GUI/coregui/Models/GroupItem.cpp @@ -34,9 +34,16 @@ void GroupItem::setGroup(GroupProperty_t group) setValue(QVariant::fromValue(group)); } -GroupProperty_t GroupItem::groupProperty() const +void GroupItem::setGroupInfo(const GroupInfo& groupInfo) { - return value().value<GroupProperty_t>(); + if (m_groupInfo.isValid()) + throw GUIHelpers::Error("GroupItem::setGroup() -> Error. Attempt to set GroupInfo twice."); + + m_groupInfo = groupInfo; + + GroupProperty_t groupProperty(new GroupProperty); + groupProperty->setGroupInfo(groupInfo); + setGroup(groupProperty); } SessionItem* GroupItem::currentItem() const @@ -62,3 +69,14 @@ QStringList GroupItem::translateList(const QStringList& list) const // we do not add here the name of itself return list; } + +GroupProperty_t GroupItem::groupProperty() const +{ + return value().value<GroupProperty_t>(); +} + +SessionItem* GroupItem::getItemOfType(const QString& type) +{ + return groupProperty()->getItemOfType(type); +} + diff --git a/GUI/coregui/Models/GroupItem.h b/GUI/coregui/Models/GroupItem.h index 4aec85c684cbd6c0489691691560a953c32e49a8..9ea19d3e589cba1cb43d93c01e2179e23d93ea11 100644 --- a/GUI/coregui/Models/GroupItem.h +++ b/GUI/coregui/Models/GroupItem.h @@ -19,6 +19,10 @@ #include "SessionItem.h" #include "GroupProperty.h" +#include "GroupInfo.h" +#include <memory> + +class GroupInfo; class BA_CORE_API_ GroupItem : public SessionItem { @@ -27,7 +31,7 @@ public: GroupItem(); void setGroup(GroupProperty_t groupProperty); - GroupProperty_t groupProperty() const; + void setGroupInfo(const GroupInfo& groupInfo); SessionItem* currentItem() const; QString currentType() const; @@ -35,6 +39,13 @@ public: SessionItem* setCurrentType(const QString& modelType); QStringList translateList(const QStringList& list) const; + + SessionItem* getItemOfType(const QString& type); + +private: + GroupProperty_t groupProperty() const; + + GroupInfo m_groupInfo; }; #endif // GROUPITEM_H diff --git a/GUI/coregui/Models/GroupProperty.h b/GUI/coregui/Models/GroupProperty.h index 5bccf99ba2cf62e682a20d08bc05421923c67ee5..ec044fb3294209748690f432d8024e5833cbd506 100644 --- a/GUI/coregui/Models/GroupProperty.h +++ b/GUI/coregui/Models/GroupProperty.h @@ -49,10 +49,11 @@ public: QStringList itemTypes() const; QStringList itemLabels() const; -private: GroupProperty(); - void setGroupInfo(GroupInfo groupInfo); + +private: + SessionItem* addItem(const QString& item_type); SessionItem* createCorrespondingItem(); int toIndex(const QString& type) const; diff --git a/GUI/coregui/Models/GroupPropertyRegistry.cpp b/GUI/coregui/Models/GroupPropertyRegistry.cpp index 7740d4b70b6b12204358c81df557ee6e700f468b..c21049240641feb3ec24e26cecd823ca7e106d56 100644 --- a/GUI/coregui/Models/GroupPropertyRegistry.cpp +++ b/GUI/coregui/Models/GroupPropertyRegistry.cpp @@ -29,6 +29,11 @@ GroupProperty_t GroupPropertyRegistry::createGroupProperty(const Constants::Mode return result; } +GroupInfo GroupPropertyRegistry::groupInfo(const Constants::ModelType& group_type) +{ + return catalogue().groupInfo(group_type); +} + const GroupInfoCatalogue& GroupPropertyRegistry::catalogue() { static GroupInfoCatalogue s_catalogue = GroupInfoCatalogue(); diff --git a/GUI/coregui/Models/GroupPropertyRegistry.h b/GUI/coregui/Models/GroupPropertyRegistry.h index 9c4f3230c8ffc3319bbd07f189e916b8967b7b36..9350aaa602c77f642835da2ecd8c8009b67cfbf8 100644 --- a/GUI/coregui/Models/GroupPropertyRegistry.h +++ b/GUI/coregui/Models/GroupPropertyRegistry.h @@ -30,6 +30,7 @@ public: static GroupProperty_t createGroupProperty(const Constants::ModelType& group_type); + static GroupInfo groupInfo(const Constants::ModelType& group_type); private: static const GroupInfoCatalogue& catalogue(); }; diff --git a/GUI/coregui/Models/SessionItem.cpp b/GUI/coregui/Models/SessionItem.cpp index e5d3ce22279d98b6fd63d8c5cfc92852c5e84ad0..fcac2af5e305cb13f523bff4b3ba2d525f71790a 100644 --- a/GUI/coregui/Models/SessionItem.cpp +++ b/GUI/coregui/Models/SessionItem.cpp @@ -352,37 +352,37 @@ void SessionItem::setItemValue(const QString& tag, const QVariant& variant) } //! Creates new group item and register new tag, returns GroupItem. -SessionItem* SessionItem::addGroupProperty(const QString& groupName, const QString& groupType) +SessionItem* SessionItem::addGroupProperty(const QString& groupTag, const QString& groupType) { SessionItem* result(0); if(GroupPropertyRegistry::isValidGroup(groupType)) { // create group item - GroupProperty_t group_property = GroupPropertyRegistry::createGroupProperty(groupType); + GroupInfo groupInfo = GroupPropertyRegistry::groupInfo(groupType); GroupItem* groupItem = dynamic_cast<GroupItem*>( ItemFactory::createItem(Constants::GroupItemType)); Q_ASSERT(groupItem); - groupItem->setGroup(group_property); - registerTag(groupName, 1, 1, QStringList() << Constants::GroupItemType); + groupItem->setGroupInfo(groupInfo); + registerTag(groupTag, 1, 1, QStringList() << Constants::GroupItemType); result = groupItem; } else { // create single item - registerTag(groupName, 1, 1, QStringList() << groupType); + registerTag(groupTag, 1, 1, QStringList() << groupType); result = ItemFactory::createItem(groupType); } Q_ASSERT(result); - result->setDisplayName(groupName); - if(!insertItem(0, result, groupName)) { + result->setDisplayName(groupTag); + if(!insertItem(0, result, groupTag)) { throw GUIHelpers::Error("SessionItem::addGroupProperty -> Error. Can't insert group item"); } return result; } //! Set the current type of group item. -SessionItem* SessionItem::setGroupProperty(const QString& groupName, const QString& value) const +SessionItem* SessionItem::setGroupProperty(const QString& groupTag, const QString& modelType) const { - return item<GroupItem>(groupName).setCurrentType(value); + return item<GroupItem>(groupTag).setCurrentType(modelType); } //! Access subitem of group item. diff --git a/GUI/coregui/Models/SessionItem.h b/GUI/coregui/Models/SessionItem.h index eb092673366de1fc3177443e7acdd9f391760d93..f7f0aa76967d38c6e548524062514b676d86c533 100644 --- a/GUI/coregui/Models/SessionItem.h +++ b/GUI/coregui/Models/SessionItem.h @@ -89,8 +89,8 @@ public: void setItemValue(const QString& tag, const QVariant& variant); // convenience functions for groups - SessionItem* addGroupProperty(const QString& groupName, const QString& groupType); - SessionItem* setGroupProperty(const QString& name, const QString& value) const; + SessionItem* addGroupProperty(const QString& groupTag, const QString& groupType); + SessionItem* setGroupProperty(const QString& groupTag, const QString& modelType) const; SessionItem* getGroupItem(const QString& groupName) const; template<typename T> T& groupItem(const QString& groupName) const; diff --git a/GUI/coregui/Models/SessionXML.cpp b/GUI/coregui/Models/SessionXML.cpp index e7971e92e19562ba369b4d248ce2e6639f424311..5a839b511081b6ece9de0463333ce92715014be8 100644 --- a/GUI/coregui/Models/SessionXML.cpp +++ b/GUI/coregui/Models/SessionXML.cpp @@ -281,8 +281,7 @@ SessionItem* createItem(SessionItem* parent, const QString& modelType, const QSt if (parent->modelType() == Constants::GroupItemType) { result = parent->parent() ->item<GroupItem>(parent->parent()->tagFromItem(parent)) - .groupProperty() - ->getItemOfType(modelType); + .getItemOfType(modelType); } else { SessionTagInfo info = parent->getTagInfo(tag); if (info.min == 1 && info.max == 1 && info.childCount == 1)