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..ec92c13c1205b622c20e5bc4720dcbc7af629eec 100644 --- a/GUI/coregui/Models/GroupItem.cpp +++ b/GUI/coregui/Models/GroupItem.cpp @@ -16,6 +16,9 @@ #include "GroupItem.h" #include "GUIHelpers.h" +#include "GroupItemController.h" +#include "ComboProperty.h" +#include "GUIHelpers.h" const QString GroupItem::T_ITEMS = "Item tag"; @@ -23,37 +26,35 @@ GroupItem::GroupItem() : SessionItem(Constants::GroupItemType) { registerTag(T_ITEMS); setDefaultTag(T_ITEMS); + + mapper()->setOnValueChange([this]() { onValueChange(); }); } -void GroupItem::setGroup(GroupProperty_t group) +GroupItem::~GroupItem() = default; + +void GroupItem::setGroupInfo(const GroupInfo& groupInfo) { - if (value().isValid()) + if (m_controller) throw GUIHelpers::Error("GroupItem::setGroup() -> Error. Attempt to set group twice."); - group->setGroupItem(this); - setValue(QVariant::fromValue(group)); -} - -GroupProperty_t GroupItem::groupProperty() const -{ - return value().value<GroupProperty_t>(); + m_controller = std::make_unique<GroupItemController>(this, groupInfo); + updateComboValue(); } SessionItem* GroupItem::currentItem() const { - return value().isValid() ? groupProperty()->currentItem() : nullptr; + return m_controller ? m_controller->currentItem() : nullptr; } QString GroupItem::currentType() const { - return groupProperty()->currentType(); + return m_controller->currentType(); } SessionItem* GroupItem::setCurrentType(const QString& modelType) { - GroupProperty_t group_property = groupProperty(); - group_property->setCurrentType(modelType); - + m_controller->setCurrentType(modelType); + updateComboValue(); return currentItem(); } @@ -62,3 +63,29 @@ QStringList GroupItem::translateList(const QStringList& list) const // we do not add here the name of itself return list; } + +SessionItem* GroupItem::getItemOfType(const QString& type) +{ + return m_controller->getItemOfType(type); +} + +void GroupItem::onValueChange() +{ + if (!value().canConvert<ComboProperty>()) + throw GUIHelpers::Error("GroupItem::onValueChange() -> Error. Wrong property type"); + + ComboProperty property = value().value<ComboProperty>(); + if (property.currentIndex() != m_controller->currentIndex()) { + m_controller->setCurrentIndex(property.currentIndex()); + // because of the delay between ComboProperty change and the change in GroupItem here, + // we have to emit signals once again to inform other views (i.e. views other than the view + // were property was changed) + emitDataChanged(Qt::DisplayRole | Qt::EditRole); + } +} + +void GroupItem::updateComboValue() +{ + setValue(m_controller->createCombo()); +} + diff --git a/GUI/coregui/Models/GroupItem.h b/GUI/coregui/Models/GroupItem.h index 4aec85c684cbd6c0489691691560a953c32e49a8..9aafb6b02607352216abb56db379aab363529287 100644 --- a/GUI/coregui/Models/GroupItem.h +++ b/GUI/coregui/Models/GroupItem.h @@ -18,16 +18,20 @@ #define GROUPITEM_H #include "SessionItem.h" -#include "GroupProperty.h" +#include "GroupInfo.h" +#include <memory> + +class GroupInfo; +class GroupItemController; class BA_CORE_API_ GroupItem : public SessionItem { public: static const QString T_ITEMS; GroupItem(); + ~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: + void onValueChange(); + void updateComboValue(); + std::unique_ptr<GroupItemController> m_controller; }; #endif // GROUPITEM_H diff --git a/GUI/coregui/Models/GroupProperty.cpp b/GUI/coregui/Models/GroupItemController.cpp similarity index 53% rename from GUI/coregui/Models/GroupProperty.cpp rename to GUI/coregui/Models/GroupItemController.cpp index dfa27c9e5b6c16ca03812bb02870f33939e921c6..42310cfba023e03df7ee381edab9c18bb66b981f 100644 --- a/GUI/coregui/Models/GroupProperty.cpp +++ b/GUI/coregui/Models/GroupItemController.cpp @@ -2,8 +2,8 @@ // // BornAgain: simulate and fit scattering at grazing incidence // -//! @file GUI/coregui/Models/GroupProperty.cpp -//! @brief Implements class GroupProperty +//! @file GUI/coregui/Models/GroupItemController.cpp +//! @brief Implements class GroupItemController //! //! @homepage http://www.bornagainproject.org //! @license GNU General Public License v3 or higher (see COPYING) @@ -14,38 +14,34 @@ // // ************************************************************************** // -#include "GroupProperty.h" +#include "GroupItemController.h" #include "ItemFactory.h" +#include "ComboProperty.h" -GroupProperty::GroupProperty() - : m_groupItem(nullptr) +GroupItemController::GroupItemController(SessionItem* groupItem, GroupInfo groupInfo) + : m_groupItem(groupItem) + , m_groupInfo(groupInfo) { + m_current_type = m_groupInfo.defaultType(); + m_groupItem->insertItem(-1, createCorrespondingItem()); } -SessionItem* GroupProperty::currentItem() +SessionItem* GroupItemController::currentItem() { return m_groupItem ? m_groupItem->getChildOfType(currentType()) : nullptr; } -void GroupProperty::setGroupItem(SessionItem* groupItem) -{ - Q_ASSERT(groupItem); - m_groupItem = groupItem; - SessionItem* item = createCorrespondingItem(); - m_groupItem->insertItem(-1, item); -} - -QString GroupProperty::currentType() const +QString GroupItemController::currentType() const { return m_current_type; } -void GroupProperty::setCurrentType(const QString& type) +void GroupItemController::setCurrentType(const QString& type) { if (type == currentType()) return; - SessionItem* prevItem = currentItem(); + auto prevItem = currentItem(); m_current_type = type; if (m_groupItem) { @@ -53,31 +49,19 @@ void GroupProperty::setCurrentType(const QString& type) item->setVisible(true); item->setEnabled(true); } else { - SessionItem* new_item = createCorrespondingItem(); - m_groupItem->insertItem(-1, new_item); + m_groupItem->insertItem(-1, createCorrespondingItem()); } if (prevItem) { prevItem->setVisible(false); prevItem->setEnabled(false); } - m_groupItem->emitDataChanged(); } } -void GroupProperty::setCurrentTypeName(const QString& type) -{ - if (type == currentType()) - return; - - SessionItem* prevItem = currentItem(); - m_current_type = type; - if (prevItem) { - prevItem->setVisible(false); - prevItem->setEnabled(false); - } -} +//! Returns item of give type. If it doesn't exist, it will be created. +//! Method do _not_ change current item. -SessionItem* GroupProperty::getItemOfType(const QString& type) +SessionItem* GroupItemController::getItemOfType(const QString& type) { if (m_groupItem) { if (auto item = m_groupItem->getChildOfType(type)) { @@ -89,60 +73,61 @@ SessionItem* GroupProperty::getItemOfType(const QString& type) new_item->setEnabled(false); } m_groupItem->insertItem(-1, new_item); - m_groupItem->emitDataChanged(); return new_item; } } return nullptr; } -int GroupProperty::currentIndex() const +int GroupItemController::currentIndex() const { return toIndex(m_current_type); } -void GroupProperty::setCurrentIndex(int index) +void GroupItemController::setCurrentIndex(int index) { setCurrentType(toString(index)); } -QString GroupProperty::currentLabel() const +QString GroupItemController::currentLabel() const { return itemLabels().at(currentIndex()); } -QStringList GroupProperty::itemTypes() const +QStringList GroupItemController::itemTypes() const { return m_groupInfo.itemTypes(); } -QStringList GroupProperty::itemLabels() const +QStringList GroupItemController::itemLabels() const { return m_groupInfo.itemLabels(); } -void GroupProperty::setGroupInfo(GroupInfo groupInfo) +QVariant GroupItemController::createCombo() const { - m_groupInfo = std::move(groupInfo); - setCurrentType(m_groupInfo.defaultType()); + ComboProperty result; + result.setValues(itemLabels()); + result.setCurrentIndex(currentIndex()); + return result.variant(); } -SessionItem* GroupProperty::addItem(const QString& item_type) +SessionItem* GroupItemController::addItem(const QString& item_type) { return ItemFactory::createItem(item_type); } -SessionItem* GroupProperty::createCorrespondingItem() +SessionItem* GroupItemController::createCorrespondingItem() { return addItem(currentType()); } -int GroupProperty::toIndex(const QString& type) const +int GroupItemController::toIndex(const QString& type) const { return itemTypes().indexOf(type); } -QString GroupProperty::toString(int index) const +QString GroupItemController::toString(int index) const { return itemTypes().at(index); } diff --git a/GUI/coregui/Models/GroupProperty.h b/GUI/coregui/Models/GroupItemController.h similarity index 67% rename from GUI/coregui/Models/GroupProperty.h rename to GUI/coregui/Models/GroupItemController.h index 5bccf99ba2cf62e682a20d08bc05421923c67ee5..b2055b688c8f36d9fbc5b18c104b1bc4d673f112 100644 --- a/GUI/coregui/Models/GroupProperty.h +++ b/GUI/coregui/Models/GroupItemController.h @@ -2,8 +2,8 @@ // // BornAgain: simulate and fit scattering at grazing incidence // -//! @file GUI/coregui/Models/GroupProperty.h -//! @brief Defines class GroupProperty +//! @file GUI/coregui/Models/GroupItemController.h +//! @brief Defines class GroupItemController //! //! @homepage http://www.bornagainproject.org //! @license GNU General Public License v3 or higher (see COPYING) @@ -14,45 +14,44 @@ // // ************************************************************************** // -#ifndef GROUPPROPERTY_H -#define GROUPPROPERTY_H +#ifndef GROUPITEMCONTROLLER_H +#define GROUPITEMCONTROLLER_H #include "GroupInfo.h" -#include <QSharedPointer> #include <QStringList> +#include <QVariant> class SessionItem; //! Provides logic for manipulating items belonging to GroupItem parent. -//! Its construction is handled by a GroupPropertyRegistry object. -class BA_CORE_API_ GroupProperty +class BA_CORE_API_ GroupItemController { public: - friend class GroupPropertyRegistry; - - void setGroupItem(SessionItem* groupItem); + GroupItemController(SessionItem* groupItem, GroupInfo groupInfo); SessionItem* currentItem(); QString currentType() const; void setCurrentType(const QString& type); - void setCurrentTypeName(const QString& type); SessionItem* getItemOfType(const QString& type); int currentIndex() const; void setCurrentIndex(int index); + // FIXME remove after qtpropertybrowserframework removal QString currentLabel() const; QStringList itemTypes() const; + + // FIXME make private after qtpropertybrowserframework removal QStringList itemLabels() const; + QVariant createCombo() const; + private: - GroupProperty(); - void setGroupInfo(GroupInfo groupInfo); SessionItem* addItem(const QString& item_type); SessionItem* createCorrespondingItem(); int toIndex(const QString& type) const; @@ -63,7 +62,9 @@ private: GroupInfo m_groupInfo; }; -typedef QSharedPointer<GroupProperty> GroupProperty_t; -Q_DECLARE_METATYPE(GroupProperty_t) +// TODO Remove simultaneously with qtpropertybrowserframework +#include <QSharedPointer> +typedef QSharedPointer<GroupItemController> ObsoleteGroupProperty_t; +Q_DECLARE_METATYPE(ObsoleteGroupProperty_t) -#endif // GROUPPROPERTY_H +#endif // GROUPITEMCONTROLLER_H diff --git a/GUI/coregui/Models/GroupPropertyRegistry.cpp b/GUI/coregui/Models/GroupPropertyRegistry.cpp deleted file mode 100644 index 7740d4b70b6b12204358c81df557ee6e700f468b..0000000000000000000000000000000000000000 --- a/GUI/coregui/Models/GroupPropertyRegistry.cpp +++ /dev/null @@ -1,36 +0,0 @@ -// ************************************************************************** // -// -// BornAgain: simulate and fit scattering at grazing incidence -// -//! @file GUI/coregui/Models/GroupPropertyRegistry.cpp -//! @brief Implements class GroupPropertyRegistry -//! -//! @homepage http://www.bornagainproject.org -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2016 -//! @authors Scientific Computing Group at MLZ Garching -//! @authors Céline Durniak, Marina Ganeva, David Li, Gennady Pospelov -//! @authors Walter Van Herck, Joachim Wuttke -// -// ************************************************************************** // - -#include "GroupPropertyRegistry.h" -#include "GroupInfoCatalogue.h" - -bool GroupPropertyRegistry::isValidGroup(const QString& group_type) -{ - return catalogue().containsGroup(group_type); -} - -GroupProperty_t GroupPropertyRegistry::createGroupProperty(const Constants::ModelType& group_type) -{ - GroupProperty_t result(new GroupProperty); - result->setGroupInfo(catalogue().groupInfo(group_type)); - return result; -} - -const GroupInfoCatalogue& GroupPropertyRegistry::catalogue() -{ - static GroupInfoCatalogue s_catalogue = GroupInfoCatalogue(); - return s_catalogue; -} diff --git a/GUI/coregui/Models/GroupPropertyRegistry.h b/GUI/coregui/Models/GroupPropertyRegistry.h deleted file mode 100644 index 9c4f3230c8ffc3319bbd07f189e916b8967b7b36..0000000000000000000000000000000000000000 --- a/GUI/coregui/Models/GroupPropertyRegistry.h +++ /dev/null @@ -1,37 +0,0 @@ -// ************************************************************************** // -// -// BornAgain: simulate and fit scattering at grazing incidence -// -//! @file GUI/coregui/Models/GroupPropertyRegistry.h -//! @brief Defines class GroupPropertyRegistry -//! -//! @homepage http://www.bornagainproject.org -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2016 -//! @authors Scientific Computing Group at MLZ Garching -//! @authors Céline Durniak, Marina Ganeva, David Li, Gennady Pospelov -//! @authors Walter Van Herck, Joachim Wuttke -// -// ************************************************************************** // - -#ifndef GROUPPROPERTYREGISTRY_H -#define GROUPPROPERTYREGISTRY_H - -#include "GroupProperty.h" -#include "GroupInfoCatalogue.h" -#include "item_constants.h" - -//! Constructs GroupProperty objects according to the given group type. - -class BA_CORE_API_ GroupPropertyRegistry -{ -public: - static bool isValidGroup(const QString& group_type); - - static GroupProperty_t createGroupProperty(const Constants::ModelType& group_type); - -private: - static const GroupInfoCatalogue& catalogue(); -}; - -#endif // GROUPPROPERTYREGISTRY_H diff --git a/GUI/coregui/Models/SessionDecorationModel.cpp b/GUI/coregui/Models/SessionDecorationModel.cpp index 5bbcc9679f0f9deb816d02a67d3264bd86efea8c..1018067c8eecd060b2b728c0f750aeb0b7a8a0db 100644 --- a/GUI/coregui/Models/SessionDecorationModel.cpp +++ b/GUI/coregui/Models/SessionDecorationModel.cpp @@ -67,12 +67,6 @@ QVariant SessionDecorationModel::data(const QModelIndex& index, int role) const return result; } -// FIXME Bigger font size is necessary for ComponentEditor. The recipe below does the trick -// but also affects InstrumentView. Find solution suitable for both QListView and QTreeView. -// if (role == Qt::SizeHintRole) { -// return QSize(28, 28); -// } - return QIdentityProxyModel::data(index, role); } diff --git a/GUI/coregui/Models/SessionItem.cpp b/GUI/coregui/Models/SessionItem.cpp index e5d3ce22279d98b6fd63d8c5cfc92852c5e84ad0..954c7c4ca1df99e4433bb6eb33b49221f5cbaa4c 100644 --- a/GUI/coregui/Models/SessionItem.cpp +++ b/GUI/coregui/Models/SessionItem.cpp @@ -16,11 +16,11 @@ #include "GUIHelpers.h" #include "GroupItem.h" -#include "GroupPropertyRegistry.h" #include "ItemFactory.h" #include "ParameterTranslators.h" #include "SessionModel.h" #include "VectorItem.h" +#include "SessionItemUtils.h" class SessionItemData { @@ -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)) { + if(SessionItemUtils::IsValidGroup(groupType)) { // create group item - GroupProperty_t group_property = GroupPropertyRegistry::createGroupProperty(groupType); + GroupInfo groupInfo = SessionItemUtils::GetGroupInfo(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/SessionItemUtils.cpp b/GUI/coregui/Models/SessionItemUtils.cpp index 581b049c85466e9d81b3c5d4fe8debb38bae4c36..7f30e2434d7120bfcf6760aedea8a4ab608e6700 100644 --- a/GUI/coregui/Models/SessionItemUtils.cpp +++ b/GUI/coregui/Models/SessionItemUtils.cpp @@ -19,10 +19,19 @@ #include "VectorItem.h" #include "MaterialItem.h" #include "ExternalProperty.h" +#include "GroupInfoCatalogue.h" #include <QColor> #include <QIcon> #include <QPixmap> +namespace { +const GroupInfoCatalogue& groupInfoCatalogue() +{ + static GroupInfoCatalogue s_catalogue = GroupInfoCatalogue(); + return s_catalogue; +} +} + int SessionItemUtils::ParentRow(const SessionItem& item) { if (item.parent()) @@ -98,3 +107,13 @@ QVariant SessionItemUtils::CheckStateRole(const SessionItem& item) return item.value().toBool() ? Qt::Checked : Qt::Unchecked; return QVariant(); } + +bool SessionItemUtils::IsValidGroup(const QString& group_type) +{ + return groupInfoCatalogue().containsGroup(group_type); +} + +GroupInfo SessionItemUtils::GetGroupInfo(const QString& group_type) +{ + return groupInfoCatalogue().groupInfo(group_type); +} diff --git a/GUI/coregui/Models/SessionItemUtils.h b/GUI/coregui/Models/SessionItemUtils.h index 345d615a460b2a60b2c494b88f69ef498d916c90..4741d9343c99e2676a9920c4fc7991ebdecb143e 100644 --- a/GUI/coregui/Models/SessionItemUtils.h +++ b/GUI/coregui/Models/SessionItemUtils.h @@ -23,6 +23,7 @@ #include <QVariant> class SessionItem; +class GroupInfo; namespace SessionItemUtils { @@ -51,6 +52,12 @@ BA_CORE_API_ QVariant DecorationRole(const SessionItem& item); //! Returns check state for given item. BA_CORE_API_ QVariant CheckStateRole(const SessionItem& item); +//! Returns true if there is registered group. +BA_CORE_API_ bool IsValidGroup(const QString& group_type); + +//! Returns GroupInfo for group property construction +BA_CORE_API_ GroupInfo GetGroupInfo(const QString& group_type); + } // namespace SessionItemUtils #endif // SESSIONITEMUTILS_H diff --git a/GUI/coregui/Models/SessionModelDelegate.h b/GUI/coregui/Models/SessionModelDelegate.h index ec02ac81fa17e9e6359f951b7185f6c7a863023f..82f68d149ae6954e13b3244bbbcb400a5c73f2fc 100644 --- a/GUI/coregui/Models/SessionModelDelegate.h +++ b/GUI/coregui/Models/SessionModelDelegate.h @@ -18,7 +18,6 @@ #define SESSIONMODELDELEGATE_H #include "WinDllMacros.h" -#include "GroupProperty.h" #include <QStyledItemDelegate> //! The SessionModelDelegate class presents the content of SessionModel items in diff --git a/GUI/coregui/Models/SessionXML.cpp b/GUI/coregui/Models/SessionXML.cpp index e7971e92e19562ba369b4d248ce2e6639f424311..6315bd32277dcfe715fc15cd79a4dc108f7172cf 100644 --- a/GUI/coregui/Models/SessionXML.cpp +++ b/GUI/coregui/Models/SessionXML.cpp @@ -20,6 +20,7 @@ #include "GroupItem.h" #include "ItemFactory.h" #include "ExternalProperty.h" +#include "GroupItemController.h" #include "SessionModel.h" #include "WarningMessageService.h" #include <QtCore/QXmlStreamWriter> @@ -37,7 +38,7 @@ const QString qstring_type_name = "QString"; void report_error(WarningMessageService* messageService, SessionItem* item, const QString& error_type, const QString& message); -SessionItem* createItem(SessionItem* parent, const QString& modelType, const QString& tag); +SessionItem* createItem(SessionItem* item, const QString& modelType, const QString& tag); } void SessionXML::writeTo(QXmlStreamWriter* writer, SessionItem* parent) @@ -117,11 +118,6 @@ void SessionXML::writeVariant(QXmlStreamWriter* writer, QVariant variant, int ro } - else if (type_name == Constants::GroupPropertyType) { - QString ff_name = variant.value<GroupProperty_t>()->currentType(); - writer->writeAttribute(SessionXML::ParameterValueAttribute, ff_name); - } - else { throw GUIHelpers::Error("SessionModel::writeProperty: Parameter type not supported " + type_name); @@ -234,21 +230,6 @@ QString SessionXML::readProperty(QXmlStreamReader* reader, SessionItem* item, variant = combo_property.variant(); } - else if (parameter_type == Constants::GroupPropertyType) { - QString parameter_value - = reader->attributes().value(SessionXML::ParameterValueAttribute).toString(); - - QVariant v = item->value(); - if (!v.canConvert<GroupProperty_t>()) { - report_error(messageService, item, SET_ITEM_PROPERTY_ERROR, - QStringLiteral("GroupProperty conversion failed")); - } else { - GroupProperty_t group_property = v.value<GroupProperty_t>(); - group_property->setCurrentTypeName(parameter_value); - variant = QVariant::fromValue<GroupProperty_t>(group_property); - } - } - else { throw GUIHelpers::Error("SessionModel::readProperty: " "Parameter type not supported" @@ -274,21 +255,19 @@ void report_error(WarningMessageService* messageService, SessionItem* item, } } -SessionItem* createItem(SessionItem* parent, const QString& modelType, const QString& tag) +SessionItem* createItem(SessionItem* item, const QString& modelType, const QString& tag) { SessionItem* result(nullptr); - if (parent->modelType() == Constants::GroupItemType) { - result = parent->parent() - ->item<GroupItem>(parent->parent()->tagFromItem(parent)) - .groupProperty() - ->getItemOfType(modelType); + if (item->modelType() == Constants::GroupItemType) { + if (auto groupItem = dynamic_cast<GroupItem*>(item)) + result = groupItem->getItemOfType(modelType); } else { - SessionTagInfo info = parent->getTagInfo(tag); + SessionTagInfo info = item->getTagInfo(tag); if (info.min == 1 && info.max == 1 && info.childCount == 1) - result = parent->getItem(tag); + result = item->getItem(tag); else - result = parent->model()->insertNewItem(modelType, parent->index(), -1, tag); + result = item->model()->insertNewItem(modelType, item->index(), -1, tag); } Q_ASSERT(result); return result; diff --git a/GUI/coregui/Models/item_constants.h b/GUI/coregui/Models/item_constants.h index 1ad245db42e9ff34f1780325acbc172ada07eb0d..c603af6f79c5b821933baa157a4482d1d5d16f39 100644 --- a/GUI/coregui/Models/item_constants.h +++ b/GUI/coregui/Models/item_constants.h @@ -270,7 +270,6 @@ const QString MaskEditorPresentation = "Mask Editor"; const ModelType ExternalPropertyType = "ExternalProperty"; const ModelType ComboPropertyType = "ComboProperty"; -const ModelType GroupPropertyType = "GroupProperty_t"; // --- Custom editors for variant propertues --- const ModelType DefaultEditorType = "Default"; diff --git a/GUI/coregui/Views/PropertyEditor/CustomEditors.cpp b/GUI/coregui/Views/PropertyEditor/CustomEditors.cpp index 6ca6d61ec9691d187c01eb6b824e48aa565f33ce..6393a9be6aef85ccf3c61f0f270e4bae37394c90 100644 --- a/GUI/coregui/Views/PropertyEditor/CustomEditors.cpp +++ b/GUI/coregui/Views/PropertyEditor/CustomEditors.cpp @@ -17,7 +17,7 @@ #include "CustomEditors.h" #include "CustomEventFilters.h" #include "ExternalProperty.h" -#include "GroupProperty.h" +#include "GroupItemController.h" #include "ComboProperty.h" #include "ObsoleteColorProperty.h" #include "MaterialItemUtils.h" @@ -120,7 +120,7 @@ void ExternalPropertyEditor::initEditor() // --- CustomComboEditor --- -CustomComboEditor::CustomComboEditor(QWidget* parent) +ComboPropertyEditor::ComboPropertyEditor(QWidget* parent) : CustomEditor(parent) , m_box(new QComboBox) , m_wheel_event_filter(new WheelEventEater(this)) @@ -139,21 +139,27 @@ CustomComboEditor::CustomComboEditor(QWidget* parent) setConnected(true); } -QSize CustomComboEditor::sizeHint() const +QSize ComboPropertyEditor::sizeHint() const { return m_box->sizeHint(); } -QSize CustomComboEditor::minimumSizeHint() const +QSize ComboPropertyEditor::minimumSizeHint() const { return m_box->minimumSizeHint(); } -void CustomComboEditor::onIndexChanged(int) +void ComboPropertyEditor::onIndexChanged(int index) { + ComboProperty comboProperty = m_data.value<ComboProperty>(); + + if (comboProperty.currentIndex() != index) { + comboProperty.setCurrentIndex(index); + setDataIntern(QVariant::fromValue<ComboProperty>(comboProperty)); + } } -void CustomComboEditor::initEditor() +void ComboPropertyEditor::initEditor() { setConnected(false); @@ -166,89 +172,30 @@ void CustomComboEditor::initEditor() //! Returns list of labels for QComboBox -QStringList CustomComboEditor::internLabels() +QStringList ComboPropertyEditor::internLabels() { - return QStringList(); + Q_ASSERT(m_data.canConvert<ComboProperty>()); + ComboProperty comboProperty = m_data.value<ComboProperty>(); + return comboProperty.getValues(); } //! Returns index for QComboBox. -int CustomComboEditor::internIndex() +int ComboPropertyEditor::internIndex() { - return -1; + Q_ASSERT(m_data.canConvert<ComboProperty>()); + ComboProperty comboProperty = m_data.value<ComboProperty>(); + return comboProperty.currentIndex(); } -void CustomComboEditor::setConnected(bool isConnected) +void ComboPropertyEditor::setConnected(bool isConnected) { if (isConnected) connect(m_box, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), - this, &CustomComboEditor::onIndexChanged, Qt::UniqueConnection); + this, &ComboPropertyEditor::onIndexChanged, Qt::UniqueConnection); else disconnect(m_box, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), - this, &CustomComboEditor::onIndexChanged); -} - -// --- GroupPropertyEditor --- - -GroupPropertyEditor::GroupPropertyEditor(QWidget* parent) - : CustomComboEditor(parent) -{ -} - -void GroupPropertyEditor::onIndexChanged(int index) -{ - GroupProperty_t groupProperty = m_data.value<GroupProperty_t>(); - - if (groupProperty->currentIndex() != index) { - groupProperty->setCurrentIndex(index); - setDataIntern(QVariant::fromValue<GroupProperty_t>(groupProperty)); - } -} - -QStringList GroupPropertyEditor::internLabels() -{ - Q_ASSERT(m_data.canConvert<GroupProperty_t>()); - GroupProperty_t groupProperty = m_data.value<GroupProperty_t>(); - return groupProperty->itemLabels(); -} - -int GroupPropertyEditor::internIndex() -{ - Q_ASSERT(m_data.canConvert<GroupProperty_t>()); - GroupProperty_t groupProperty = m_data.value<GroupProperty_t>(); - return groupProperty->currentIndex(); -} - -// --- ComboPropertyEditor --- - -ComboPropertyEditor::ComboPropertyEditor(QWidget* parent) - : CustomComboEditor(parent) -{ -} - -void ComboPropertyEditor::onIndexChanged(int index) -{ - ComboProperty comboProperty = m_data.value<ComboProperty>(); - - if (comboProperty.currentIndex() != index) { - comboProperty.setCurrentIndex(index); - setDataIntern(QVariant::fromValue<ComboProperty>(comboProperty)); - currentIndexChanged(index); - } -} - -QStringList ComboPropertyEditor::internLabels() -{ - Q_ASSERT(m_data.canConvert<ComboProperty>()); - ComboProperty comboProperty = m_data.value<ComboProperty>(); - return comboProperty.getValues(); -} - -int ComboPropertyEditor::internIndex() -{ - Q_ASSERT(m_data.canConvert<ComboProperty>()); - ComboProperty comboProperty = m_data.value<ComboProperty>(); - return comboProperty.currentIndex(); + this, &ComboPropertyEditor::onIndexChanged); } // --- ScientificDoublePropertyEditor --- diff --git a/GUI/coregui/Views/PropertyEditor/CustomEditors.h b/GUI/coregui/Views/PropertyEditor/CustomEditors.h index ff800133fdf2fb772be3c718b9d0618f6413cc87..d2a9bfeb0263ddee14ac65b75a2d086ff80d2c9a 100644 --- a/GUI/coregui/Views/PropertyEditor/CustomEditors.h +++ b/GUI/coregui/Views/PropertyEditor/CustomEditors.h @@ -71,13 +71,13 @@ private: QString m_extDialogType; //!< Type of the dialog which will be created on button click }; -//! Common editor for QComboBox-like custom editors. +//! Editor for ComboProperty variant. -class BA_CORE_API_ CustomComboEditor : public CustomEditor +class BA_CORE_API_ ComboPropertyEditor : public CustomEditor { Q_OBJECT public: - explicit CustomComboEditor(QWidget *parent = nullptr); + explicit ComboPropertyEditor(QWidget *parent = nullptr); QSize sizeHint() const; QSize minimumSizeHint() const; @@ -95,43 +95,6 @@ protected: class WheelEventEater* m_wheel_event_filter; }; -//! Editor for GroupProperty variant. - -class BA_CORE_API_ GroupPropertyEditor : public CustomComboEditor -{ - Q_OBJECT -public: - explicit GroupPropertyEditor(QWidget *parent = nullptr); - -protected slots: - virtual void onIndexChanged(int index); - -protected: - QStringList internLabels(); - int internIndex(); -}; - -//! Editor for ComboProperty variant. - -class BA_CORE_API_ ComboPropertyEditor : public CustomComboEditor -{ - Q_OBJECT -public: - explicit ComboPropertyEditor(QWidget *parent = nullptr); - - -signals: - //! Signal which is used only in the context of ComponentFlatView - void currentIndexChanged(int); - -protected slots: - void onIndexChanged(int index); - -protected: - QStringList internLabels(); - int internIndex(); -}; - //! Editor for ScientificDoubleProperty variant. class BA_CORE_API_ ScientificDoublePropertyEditor : public CustomEditor @@ -171,5 +134,4 @@ private: QCheckBox *m_checkBox; }; - #endif // CUSTOMEDITORS_H diff --git a/GUI/coregui/Views/PropertyEditor/ObsoleteComponentEditor.cpp b/GUI/coregui/Views/PropertyEditor/ObsoleteComponentEditor.cpp index 440e975566cda3c37021bcf6f26b9a9b491387cc..427d608dfd8a1aa292d23834e60960c46328dd8c 100644 --- a/GUI/coregui/Views/PropertyEditor/ObsoleteComponentEditor.cpp +++ b/GUI/coregui/Views/PropertyEditor/ObsoleteComponentEditor.cpp @@ -16,7 +16,7 @@ #include "ObsoleteComponentEditor.h" #include "ObsoleteComponentEditorPrivate.h" #include "GroupItem.h" -#include "GroupProperty.h" +#include "GroupItemController.h" #include "SessionItem.h" #include "SessionModel.h" #include "qtpropertybrowser.h" diff --git a/GUI/coregui/Views/PropertyEditor/ObsoletePropertyBrowserUtils.cpp b/GUI/coregui/Views/PropertyEditor/ObsoletePropertyBrowserUtils.cpp index b9a8698da19d17044e775952e166ecc4111fac4f..2127f8e0c8c3aed28f7e409a9c1063163761a963 100644 --- a/GUI/coregui/Views/PropertyEditor/ObsoletePropertyBrowserUtils.cpp +++ b/GUI/coregui/Views/PropertyEditor/ObsoletePropertyBrowserUtils.cpp @@ -118,7 +118,7 @@ ObsoleteGroupPropertyEdit::~ObsoleteGroupPropertyEdit() { } -void ObsoleteGroupPropertyEdit::setGroupProperty(GroupProperty_t groupProperty) +void ObsoleteGroupPropertyEdit::setGroupProperty(ObsoleteGroupProperty_t groupProperty) { if(groupProperty) { m_groupProperty = groupProperty; @@ -168,12 +168,12 @@ QSize ObsoleteGroupPropertyEdit::minimumSizeHint() const return QSize(100,10); } -GroupProperty_t ObsoleteGroupPropertyEdit::group() const +ObsoleteGroupProperty_t ObsoleteGroupPropertyEdit::group() const { return m_groupProperty; } -void ObsoleteGroupPropertyEdit::setGroup(GroupProperty_t group) +void ObsoleteGroupPropertyEdit::setGroup(ObsoleteGroupProperty_t group) { setGroupProperty(group); } diff --git a/GUI/coregui/Views/PropertyEditor/ObsoletePropertyBrowserUtils.h b/GUI/coregui/Views/PropertyEditor/ObsoletePropertyBrowserUtils.h index 970d8a24ed84707fe52bc1b939017d1e8fc6e419..9d082894770a93179282662dec55913cda2838a5 100644 --- a/GUI/coregui/Views/PropertyEditor/ObsoletePropertyBrowserUtils.h +++ b/GUI/coregui/Views/PropertyEditor/ObsoletePropertyBrowserUtils.h @@ -21,7 +21,7 @@ #include "ExternalProperty.h" #include "ObsoleteColorProperty.h" #include "ObsoleteScientificDoubleProperty.h" -#include "GroupProperty.h" +#include "GroupItemController.h" #include "ComboProperty.h" class QLabel; @@ -57,23 +57,23 @@ class BA_CORE_API_ ObsoleteGroupPropertyEdit : public QWidget { Q_OBJECT - Q_PROPERTY(GroupProperty_t group READ group WRITE setGroup USER true) + Q_PROPERTY(ObsoleteGroupProperty_t group READ group WRITE setGroup USER true) public: ObsoleteGroupPropertyEdit(QWidget *parent = 0); virtual ~ObsoleteGroupPropertyEdit(); - void setGroupProperty(GroupProperty_t groupProperty); - GroupProperty_t getGroupProperty() const; + void setGroupProperty(ObsoleteGroupProperty_t groupProperty); + ObsoleteGroupProperty_t getGroupProperty() const; virtual QSize sizeHint() const; virtual QSize minimumSizeHint() const; - GroupProperty_t group() const; - void setGroup(GroupProperty_t group); + ObsoleteGroupProperty_t group() const; + void setGroup(ObsoleteGroupProperty_t group); signals: - void groupPropertyChanged(const GroupProperty_t &group_property); + void groupPropertyChanged(const ObsoleteGroupProperty_t &group_property); private slots: void indexChanged(int index); @@ -82,10 +82,10 @@ private: void processGroup(); QComboBox *m_box; QLabel *m_label; - GroupProperty_t m_groupProperty; + ObsoleteGroupProperty_t m_groupProperty; }; -inline GroupProperty_t ObsoleteGroupPropertyEdit::getGroupProperty() const +inline ObsoleteGroupProperty_t ObsoleteGroupPropertyEdit::getGroupProperty() const { return m_groupProperty; } diff --git a/GUI/coregui/Views/PropertyEditor/ObsoletePropertyVariantFactory.cpp b/GUI/coregui/Views/PropertyEditor/ObsoletePropertyVariantFactory.cpp index eda3fe50570166dc3fc437cb4cbdd0cbec480f19..3c23860285b3a801cb3f44b0ee3673e3a1270a69 100644 --- a/GUI/coregui/Views/PropertyEditor/ObsoletePropertyVariantFactory.cpp +++ b/GUI/coregui/Views/PropertyEditor/ObsoletePropertyVariantFactory.cpp @@ -124,15 +124,15 @@ QWidget *ObsoletePropertyVariantFactory::createEditor(QtVariantPropertyManager * ObsoletePropertyVariantManager::fancyGroupTypeId()) { ObsoleteGroupPropertyEdit *editor = new ObsoleteGroupPropertyEdit(parent); QVariant var = manager->value(property); - GroupProperty_t ff = var.value<GroupProperty_t>(); + ObsoleteGroupProperty_t ff = var.value<ObsoleteGroupProperty_t>(); editor->setGroupProperty(ff); m_property_to_fancygroup_editors[property].append(editor); m_fancygroup_editor_to_property[editor] = property; connect(editor, - SIGNAL(groupPropertyChanged(GroupProperty_t)), - this, SLOT(slotSetValue(GroupProperty_t))); + SIGNAL(groupPropertyChanged(ObsoleteGroupProperty_t)), + this, SLOT(slotSetValue(ObsoleteGroupProperty_t))); connect(editor, SIGNAL(destroyed(QObject *)), this, SLOT(slotEditorDestroyed(QObject *))); @@ -209,7 +209,7 @@ void ObsoletePropertyVariantFactory::slotPropertyChanged(QtProperty *property, m_property_to_fancygroup_editors[property]; QListIterator<ObsoleteGroupPropertyEdit *> itEditor(editors); while (itEditor.hasNext()) { - GroupProperty_t mat = value.value<GroupProperty_t>(); + ObsoleteGroupProperty_t mat = value.value<ObsoleteGroupProperty_t>(); itEditor.next()->setGroupProperty(mat); } } @@ -282,7 +282,7 @@ void ObsoletePropertyVariantFactory::slotSetValue(const ObsoleteScientificDouble } } -void ObsoletePropertyVariantFactory::slotSetValue(const GroupProperty_t &value) +void ObsoletePropertyVariantFactory::slotSetValue(const ObsoleteGroupProperty_t &value) { QObject *object = sender(); QMap<ObsoleteGroupPropertyEdit *, QtProperty *>::ConstIterator itEditor = @@ -314,8 +314,6 @@ void ObsoletePropertyVariantFactory::slotSetValue(const ComboProperty &value) QVariant var; var.setValue(value); manager->setValue(property, var); - // FIXME g.p. Is it the right place to delete? Check other factories. - //object->deleteLater(); return; } itEditor++; diff --git a/GUI/coregui/Views/PropertyEditor/ObsoletePropertyVariantFactory.h b/GUI/coregui/Views/PropertyEditor/ObsoletePropertyVariantFactory.h index c45fdc4ceb434e4d307f44c427df5ae821b3da40..e37002e0da8dc31c8e1109769871dde2a8a0c6be 100644 --- a/GUI/coregui/Views/PropertyEditor/ObsoletePropertyVariantFactory.h +++ b/GUI/coregui/Views/PropertyEditor/ObsoletePropertyVariantFactory.h @@ -19,7 +19,7 @@ //! collection of classes extending QtPropertyBrowser functionality -#include "GroupProperty.h" +#include "GroupItemController.h" #include <QtVariantEditorFactory> class ObsoleteMaterialPropertyEdit; @@ -54,7 +54,7 @@ private slots: void slotSetValue(const ExternalProperty &value); void slotSetValue(const ObsoleteColorProperty &value); void slotSetValue(const ObsoleteScientificDoubleProperty &value); - void slotSetValue(const GroupProperty_t &value); + void slotSetValue(const ObsoleteGroupProperty_t &value); void slotSetValue(const ComboProperty &value); void slotEditorDestroyed(QObject *object); void slotPropertyAttributeChanged(QtProperty *, const QString &, const QVariant &); diff --git a/GUI/coregui/Views/PropertyEditor/ObsoletePropertyVariantManager.cpp b/GUI/coregui/Views/PropertyEditor/ObsoletePropertyVariantManager.cpp index 38e97a58c91bc23b10dadb91f6298248c5035977..782f0396e447793f3d834b322921b154a226f7dc 100644 --- a/GUI/coregui/Views/PropertyEditor/ObsoletePropertyVariantManager.cpp +++ b/GUI/coregui/Views/PropertyEditor/ObsoletePropertyVariantManager.cpp @@ -45,7 +45,7 @@ int ObsoletePropertyVariantManager::scientificDoubleTypeId() int ObsoletePropertyVariantManager::fancyGroupTypeId() { - int result = qMetaTypeId<GroupProperty_t>(); + int result = qMetaTypeId<ObsoleteGroupProperty_t>(); return result; } @@ -186,7 +186,7 @@ void ObsoletePropertyVariantManager::setValue(QtProperty *property, const QVaria } if (m_theFancyGroupValues.contains(property)) { if( val.userType() != fancyGroupTypeId() ) return; - GroupProperty_t group_prop = val.value<GroupProperty_t>(); + ObsoleteGroupProperty_t group_prop = val.value<ObsoleteGroupProperty_t>(); m_theFancyGroupValues[property] = group_prop; QVariant v2; v2.setValue(group_prop); @@ -224,7 +224,7 @@ void ObsoletePropertyVariantManager::initializeProperty(QtProperty *property) m_theScientificDoubleValues[property] = m; } if (propertyType(property) == fancyGroupTypeId()) { - GroupProperty_t m; + ObsoleteGroupProperty_t m; m_theFancyGroupValues[property] = m; } if (propertyType(property) == comboPropertyTypeId()) { diff --git a/GUI/coregui/Views/PropertyEditor/ObsoletePropertyVariantManager.h b/GUI/coregui/Views/PropertyEditor/ObsoletePropertyVariantManager.h index f3c54ffb1e3709ad727d47c664c544b99b0e083a..04c7b71aa40735e801e530126e7b067ad7b84fff 100644 --- a/GUI/coregui/Views/PropertyEditor/ObsoletePropertyVariantManager.h +++ b/GUI/coregui/Views/PropertyEditor/ObsoletePropertyVariantManager.h @@ -21,7 +21,7 @@ #include "ObsoleteColorProperty.h" #include "ComboProperty.h" -#include "GroupProperty.h" +#include "GroupItemController.h" #include "ExternalProperty.h" #include "ObsoleteScientificDoubleProperty.h" #include <QtVariantPropertyManager> @@ -59,7 +59,7 @@ private: QMap<const QtProperty *, ExternalProperty> m_theMaterialValues; QMap<const QtProperty *, ObsoleteColorProperty> m_theColorValues; QMap<const QtProperty *, ObsoleteScientificDoubleProperty> m_theScientificDoubleValues; - QMap<const QtProperty *, GroupProperty_t> m_theFancyGroupValues; + QMap<const QtProperty *, ObsoleteGroupProperty_t> m_theFancyGroupValues; QMap<const QtProperty *, ComboProperty> m_theComboValues; }; diff --git a/GUI/coregui/Views/PropertyEditor/PropertyEditorFactory.cpp b/GUI/coregui/Views/PropertyEditor/PropertyEditorFactory.cpp index 9e91c69a2b1894703581afa797029137a12516ca..6c301bdbff694102a24af5924a28f4bcf2b604e2 100644 --- a/GUI/coregui/Views/PropertyEditor/PropertyEditorFactory.cpp +++ b/GUI/coregui/Views/PropertyEditor/PropertyEditorFactory.cpp @@ -18,7 +18,7 @@ #include "SessionItem.h" #include "RealLimits.h" #include "ExternalProperty.h" -#include "GroupProperty.h" +#include "GroupItemController.h" #include "CustomEditors.h" #include "ComboProperty.h" #include "CustomEventFilters.h" @@ -55,11 +55,6 @@ bool isExternalProperty(const QVariant& variant) return variant.canConvert<ExternalProperty>(); } -bool isGroupProperty(const QVariant& variant) -{ - return variant.canConvert<GroupProperty_t>(); -} - bool isComboProperty(const QVariant& variant) { return variant.canConvert<ComboProperty>(); @@ -81,8 +76,6 @@ bool PropertyEditorFactory::IsCustomVariant(const QVariant& variant) { if (isExternalProperty(variant)) return true; - if (isGroupProperty(variant)) - return true; if (isComboProperty(variant)) return true; if (isBoolProperty(variant)) @@ -91,13 +84,10 @@ bool PropertyEditorFactory::IsCustomVariant(const QVariant& variant) return false; } -// TODO replace with template method when custom variants refactored QString PropertyEditorFactory::ToString(const QVariant& variant) { if (isExternalProperty(variant)) return variant.value<ExternalProperty>().text(); - if (isGroupProperty(variant)) - return variant.value<GroupProperty_t>()->currentLabel(); if (isComboProperty(variant)) return variant.value<ComboProperty>().getValue(); if (isBoolProperty(variant)) @@ -143,12 +133,6 @@ QWidget* PropertyEditorFactory::CreateEditor(const SessionItem& item, QWidget* p result = editor; } - else if(isGroupProperty(item.value())) { - auto editor = new GroupPropertyEditor; - editor->setData(item.value()); - result = editor; - } - else if(isComboProperty(item.value())) { auto editor = new ComboPropertyEditor; editor->setData(item.value()); diff --git a/GUI/coregui/Views/PropertyEditor/PropertyWidgetItem.cpp b/GUI/coregui/Views/PropertyEditor/PropertyWidgetItem.cpp index d2f7c65837cee1fdb8ba09913ecacc82aefd46a7..664e548afbb918630be097c195cbe61758180ed0 100644 --- a/GUI/coregui/Views/PropertyEditor/PropertyWidgetItem.cpp +++ b/GUI/coregui/Views/PropertyEditor/PropertyWidgetItem.cpp @@ -98,29 +98,20 @@ const SessionItem* PropertyWidgetItem::item() void PropertyWidgetItem::connectEditor(QWidget* editor) { if (auto combo = dynamic_cast<ComboPropertyEditor*>(editor)) { - // Hack: QDataWidgetMapper doesn't listen for the widget (QComboBox is somewhat special). - connect(combo, &ComboPropertyEditor::currentIndexChanged, + connect(combo, &ComboPropertyEditor::dataChanged, [=] { m_delegate->commitData(combo); }); - // TODO after merging GroupProperty and ComboProperty - // 1) cast to CustomEditor - // 2) switch to CustomEditor::dataChanged() - } else if (auto spinbox = dynamic_cast<QSpinBox*>(editor)) { - // To provide update of the model on valueChanged() and not only on editingFinished() connect(spinbox, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), [=] { m_delegate->commitData(spinbox); }); } else if (auto spinbox = dynamic_cast<QDoubleSpinBox*>(editor)) { - // To provide update of the model on valueChanged() and not only on editingFinished() connect(spinbox, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), [=] { m_delegate->commitData(spinbox); }); } else if (auto spinbox = dynamic_cast<ScientificDoublePropertyEditor*>(editor)) { - // To provide update of the model on valueChanged() and not only on editingFinished() connect(spinbox, &ScientificDoublePropertyEditor::dataChanged, [=] { m_delegate->commitData(spinbox); }); } - } diff --git a/GUI/coregui/Views/SampleDesigner/ParticleView.cpp b/GUI/coregui/Views/SampleDesigner/ParticleView.cpp index b5e40323699f61364061e48761f0acebf8971efa..99988fe0c04582c173484e7ce704713674ff75ef 100644 --- a/GUI/coregui/Views/SampleDesigner/ParticleView.cpp +++ b/GUI/coregui/Views/SampleDesigner/ParticleView.cpp @@ -17,7 +17,6 @@ #include "ParticleView.h" #include "GUIHelpers.h" #include "GroupItem.h" -#include "GroupProperty.h" #include "ParticleItem.h" #include "FormFactorItems.h" #include <QObject> diff --git a/Tests/UnitTests/GUI/TestGUI.cpp b/Tests/UnitTests/GUI/TestGUI.cpp index 8e407f5572cebbb59e6fa9b2449274f1540520a6..ef2881def66a5e95fda863276493a5bef54d5351 100644 --- a/Tests/UnitTests/GUI/TestGUI.cpp +++ b/Tests/UnitTests/GUI/TestGUI.cpp @@ -18,7 +18,7 @@ #include "TestMaterialModel.h" #include "TestComboProperty.h" #include "TestTranslations.h" -#include "TestGroupProperty.h" +#include "TestGroupItem.h" #include "TestParameterTreeUtils.h" #include "TestDetectorItems.h" #include "TestLinkInstrument.h" @@ -93,7 +93,7 @@ int main(int argc, char** argv) { tests.add<TestMaterialPropertyController>(); tests.add<TestComboProperty>(); tests.add<TestTranslations>(); - tests.add<TestGroupProperty>(); + tests.add<TestGroupItem>(); tests.add<TestParticleDistributionItem>(); tests.add<TestParameterTreeUtils>(); tests.add<TestDetectorItems>(); diff --git a/Tests/UnitTests/GUI/TestGroupItem.h b/Tests/UnitTests/GUI/TestGroupItem.h new file mode 100644 index 0000000000000000000000000000000000000000..0be51d2d2e2e0263845a8c19c350664fab74b438 --- /dev/null +++ b/Tests/UnitTests/GUI/TestGroupItem.h @@ -0,0 +1,116 @@ +#include <QtTest> +#include "test_utils.h" +#include "GroupInfo.h" +#include "GroupItem.h" +#include "ComboProperty.h" +#include "GUIHelpers.h" +#include "SessionModel.h" +#include "SessionItemUtils.h" + +class TestGroupItem : public QObject { + Q_OBJECT + +private slots: + void test_groupInfo(); + void test_CreateGroup(); + void test_groupPropertyWithDisplayNames(); +}; + +inline void TestGroupItem::test_groupInfo() +{ + GroupInfo info("Group"); + info.add("BBB", "b_label"); + info.add("AAA", "a_label"); + info.add("CCC", "c_label"); + info.setDefaultType("AAA"); + + // sorted group (default behavior) + QCOMPARE(info.groupType(), QString("Group")); + QCOMPARE(info.defaultType(), QString("AAA")); + QCOMPARE(info.itemTypes(), QStringList() << "AAA" << "BBB" << "CCC"); + QCOMPARE(info.itemLabels(), QStringList() << "a_label" << "b_label" << "c_label"); + + // unsorted group + info = GroupInfo("Group2", false); + info.add("BBB2", "b_label2"); + info.add("AAA2", "a_label2"); + info.add("CCC2", "c_label2"); + info.setDefaultType("AAA2"); + QCOMPARE(info.defaultType(), QString("AAA2")); + QCOMPARE(info.itemTypes(), QStringList() << "BBB2" << "AAA2" << "CCC2"); + QCOMPARE(info.itemLabels(), QStringList() << "b_label2" << "a_label2" << "c_label2"); + + // attempt to set non-existing default type + QVERIFY_THROW(info.setDefaultType("XXX"), GUIHelpers::Error); + + // attempt to add same info twice + QVERIFY_THROW(info.add("CCC2", "c_label2"), GUIHelpers::Error); +} + +inline void TestGroupItem::test_CreateGroup() +{ + SessionModel model("TestModel"); + + GroupInfo groupInfo = SessionItemUtils::GetGroupInfo(Constants::FormFactorGroup); + QCOMPARE(groupInfo.defaultType(), Constants::CylinderType); + + auto groupItem = dynamic_cast<GroupItem*>(model.insertNewItem(Constants::GroupItemType)); + QCOMPARE(groupItem->children().size(), 0); + QVERIFY(groupItem->currentItem() == nullptr); + QVERIFY(groupItem->value().isValid() == false); + + // setting group property and checking currentItem + groupItem->setGroupInfo(groupInfo); + + // setting group info twice + QVERIFY_THROW(groupItem->setGroupInfo(groupInfo), GUIHelpers::Error); + + // checking current item + QCOMPARE(groupItem->children().size(), 1); + QCOMPARE(groupItem->children()[0], groupItem->currentItem()); + SessionItem *ffItem = groupItem->currentItem(); + QCOMPARE(ffItem->modelType(), Constants::CylinderType); + + // checking current variant + QVariant value = groupItem->value(); + QVERIFY(value.canConvert<ComboProperty>() == true); + ComboProperty combo = value.value<ComboProperty>(); + QCOMPARE(combo.getValues(), groupInfo.itemLabels()); + int index = groupInfo.itemTypes().indexOf(groupInfo.defaultType()); + QCOMPARE(combo.currentIndex(), index); + QCOMPARE(combo.getValue(), groupInfo.itemLabels().at(index)); + + // changing current item + SessionItem *newItem = groupItem->setCurrentType(Constants::FullSphereType); + QCOMPARE(newItem, groupItem->currentItem()); + QCOMPARE(newItem->modelType(), Constants::FullSphereType); + QCOMPARE(groupItem->children().size(), 2); + + // checking current variant + combo = groupItem->value().value<ComboProperty>(); + QCOMPARE(combo.getValues(), groupInfo.itemLabels()); + index = groupInfo.itemTypes().indexOf(Constants::FullSphereType); + QCOMPARE(combo.currentIndex(), index); + QCOMPARE(combo.getValue(), groupInfo.itemLabels().at(index)); + + // returning back to previous item + QCOMPARE(groupItem->setCurrentType(Constants::CylinderType), ffItem); + QCOMPARE(groupItem->currentItem(), ffItem); + QCOMPARE(groupItem->children().size(), 2); +} + +//! Checking that GroupProperty stays functional if displayName of currentItem is changed. + +inline void TestGroupItem::test_groupPropertyWithDisplayNames() +{ + GroupInfo groupInfo = SessionItemUtils::GetGroupInfo(Constants::DistributionGroup); + + GroupItem groupItem; + groupItem.setGroupInfo(groupInfo); + + SessionItem *cosineItem = groupItem.currentItem(); + cosineItem->setDisplayName(Constants::DistributionCosineType+QString::number(0)); + + QCOMPARE(groupItem.currentItem(), cosineItem); +} + diff --git a/Tests/UnitTests/GUI/TestGroupProperty.h b/Tests/UnitTests/GUI/TestGroupProperty.h deleted file mode 100644 index 2887f87dffca9e46963bea46598c115be3454130..0000000000000000000000000000000000000000 --- a/Tests/UnitTests/GUI/TestGroupProperty.h +++ /dev/null @@ -1,109 +0,0 @@ -#include <QtTest> -#include "GroupInfo.h" -#include "GroupItem.h" -#include "GroupPropertyRegistry.h" -#include "GUIHelpers.h" -#include "verify_throw_macro.h" - -class TestGroupProperty : public QObject { - Q_OBJECT - -private slots: - void test_groupInfo(); - void test_groupProperty(); - void test_CreateGroup(); - void test_groupPropertyWithDisplayNames(); -}; - -inline void TestGroupProperty::test_groupInfo() -{ - GroupInfo info("Group"); - info.add("BBB", "b_label"); - info.add("AAA", "a_label"); - info.add("CCC", "c_label"); - info.setDefaultType("AAA"); - - // sorted group (default behavior) - QCOMPARE(info.groupType(), QString("Group")); - QCOMPARE(info.defaultType(), QString("AAA")); - QCOMPARE(info.itemTypes(), QStringList() << "AAA" << "BBB" << "CCC"); - QCOMPARE(info.itemLabels(), QStringList() << "a_label" << "b_label" << "c_label"); - - // unsorted group - info = GroupInfo("Group2", false); - info.add("BBB2", "b_label2"); - info.add("AAA2", "a_label2"); - info.add("CCC2", "c_label2"); - info.setDefaultType("AAA2"); - QCOMPARE(info.defaultType(), QString("AAA2")); - QCOMPARE(info.itemTypes(), QStringList() << "BBB2" << "AAA2" << "CCC2"); - QCOMPARE(info.itemLabels(), QStringList() << "b_label2" << "a_label2" << "c_label2"); - - // attempt to set non-existing default type - QVERIFY_THROW(info.setDefaultType("XXX"), GUIHelpers::Error); - - // attempt to add same info twice - QVERIFY_THROW(info.add("CCC2", "c_label2"), GUIHelpers::Error); -} - -inline void TestGroupProperty::test_groupProperty() -{ - GroupProperty_t property = GroupPropertyRegistry::createGroupProperty( - Constants::DistributionGroup); - - QCOMPARE(property->currentType(), Constants::DistributionGaussianType); - QVERIFY(property->currentItem() == nullptr); - -} - - -inline void TestGroupProperty::test_CreateGroup() -{ - GroupProperty_t property = GroupPropertyRegistry::createGroupProperty( - Constants::DistributionGroup); - - QCOMPARE(property->currentType(), Constants::DistributionGaussianType); - - GroupItem groupItem; - QCOMPARE(groupItem.children().size(), 0); - QVERIFY(groupItem.currentItem() == nullptr); - - // setting group property and checking currentItem - groupItem.setGroup(property); - QCOMPARE(groupItem.children().size(), 1); - QCOMPARE(groupItem.children()[0], groupItem.currentItem()); - SessionItem *cosineItem = groupItem.currentItem(); - QCOMPARE(cosineItem->modelType(), Constants::DistributionGaussianType); - QCOMPARE(property->currentItem(), cosineItem); - - // setting group property twice - QVERIFY_THROW(groupItem.setGroup(property), GUIHelpers::Error); - - // changing current item - SessionItem *newItem = groupItem.setCurrentType(Constants::DistributionNoneType); - QCOMPARE(newItem, groupItem.currentItem()); - QCOMPARE(newItem->modelType(), Constants::DistributionNoneType); - QCOMPARE(groupItem.children().size(), 2); - - // returning back to previous item - QCOMPARE(groupItem.setCurrentType(Constants::DistributionGaussianType), cosineItem); - QCOMPARE(groupItem.currentItem(), cosineItem); - QCOMPARE(groupItem.children().size(), 2); -} - -//! Checking that GroupProperty stays functional if displayName of currentItem is changed. - -inline void TestGroupProperty::test_groupPropertyWithDisplayNames() -{ - GroupProperty_t property = GroupPropertyRegistry::createGroupProperty( - Constants::DistributionGroup); - - GroupItem groupItem; - groupItem.setGroup(property); - - SessionItem *cosineItem = groupItem.currentItem(); - cosineItem->setDisplayName(Constants::DistributionCosineType+QString::number(0)); - - QCOMPARE(groupItem.currentItem(), cosineItem); -} - diff --git a/Tests/UnitTests/GUI/TestLayerItems.h b/Tests/UnitTests/GUI/TestLayerItems.h index 5b7ba517b352fc0967763bc7137151998bc07a8d..ecb99a56174661283fc9de525c8ae11d045a024f 100644 --- a/Tests/UnitTests/GUI/TestLayerItems.h +++ b/Tests/UnitTests/GUI/TestLayerItems.h @@ -14,7 +14,6 @@ class TestLayerItems : public QObject { private slots: void test_LayerDefaultMaterial(); -// void test_onMaterialChange(); }; //! Checking default material of the layer. @@ -30,26 +29,3 @@ inline void TestLayerItems::test_LayerDefaultMaterial() QCOMPARE(material.text(), QString("Default")); QCOMPARE(material.identifier(), defMaterial->getItemValue(MaterialItem::P_IDENTIFIER).toString()); } - -//! Checks that change of material in MaterialModel is propagated to the LayerItem. - -//inline void TestLayerItems::test_onMaterialChange() -//{ -// ApplicationModels models; -// auto layer = models.sampleModel()->insertNewItem(Constants::LayerType); -// auto materials = models.materialModel()->topItems(); -// auto defMaterial = materials.front(); - -// int property_changed(0); -// layer->mapper()->setOnPropertyChange([&property_changed](const QString& name) { -// if (name == LayerItem::P_MATERIAL) -// ++property_changed; -// }, this); - -// defMaterial->setItemName("NewName"); -// QCOMPARE(property_changed, 2); // should be ==1, Fixme after implementing MaterialPropertyController -// MaterialProperty material = layer->getItemValue(LayerItem::P_MATERIAL).value<MaterialProperty>(); - -// // FIXME reenable after MaterialPropertyController implementation -//// QCOMPARE(material.getName(), QString("NewName")); -//} diff --git a/Tests/UnitTests/GUI/TestParaCrystalItems.h b/Tests/UnitTests/GUI/TestParaCrystalItems.h index 19da58006203c71bd56c405f7fb3c73cc79e4dc3..c6afd0088033ee482644b8efe986b0f784706c96 100644 --- a/Tests/UnitTests/GUI/TestParaCrystalItems.h +++ b/Tests/UnitTests/GUI/TestParaCrystalItems.h @@ -1,6 +1,5 @@ #include <QtTest> #include "InterferenceFunctionItems.h" -#include "GroupProperty.h" #include "InterferenceFunction2DParaCrystal.h" #include "FTDistributions2D.h" #include "FTDistributionItems.h" @@ -9,6 +8,7 @@ #include "Lattice2DItems.h" #include "SampleModel.h" #include "Units.h" +#include "item_constants.h" class TestParaCrystalItems : public QObject { Q_OBJECT diff --git a/Tests/UnitTests/GUI/test_utils.h b/Tests/UnitTests/GUI/test_utils.h index 1516eee6e265d774827fcd196b51e8a0bed622bf..ce564f718b60f1c8d85640fc189b0519fabe7bed 100644 --- a/Tests/UnitTests/GUI/test_utils.h +++ b/Tests/UnitTests/GUI/test_utils.h @@ -20,6 +20,7 @@ #include "SessionXML.h" #include "PropertyItem.h" #include <QXmlStreamWriter> +#include "verify_throw_macro.h" namespace TestUtils { diff --git a/auto/Wrap/libBornAgainFit_wrap.cpp b/auto/Wrap/libBornAgainFit_wrap.cpp index 182abc5541c99f92f98a78439a7f630a79c6657c..980a19744c597e8ce4355eef1f3bbad544cc94ca 100644 --- a/auto/Wrap/libBornAgainFit_wrap.cpp +++ b/auto/Wrap/libBornAgainFit_wrap.cpp @@ -5627,7 +5627,7 @@ SWIG_AsVal_std_complex_Sl_double_Sg_ (PyObject *o, std::complex<double>* val) SWIGINTERNINLINE PyObject* -SWIG_From_std_complex_Sl_double_Sg_ (/*@SWIG:/usr/share/swig3.0/typemaps/swigmacros.swg,104,%ifcplusplus@*/ +SWIG_From_std_complex_Sl_double_Sg_ (/*@SWIG:/home/pospelov/software/local/share/swig/3.0.8/typemaps/swigmacros.swg,104,%ifcplusplus@*/ const std::complex<double>&