From c18e9c1293fde7117f4db480ed4c9a7f898e841b Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 28 Aug 2017 15:14:15 +0200 Subject: [PATCH] #1833 AppFwk: Add support for dynamic labels on group-boxes --- .../cafPdmUiCore/CMakeLists.txt | 2 + .../cafPdmUiCore/cafPdmUiGroup.cpp | 125 ++++++++++++++++++ .../cafPdmUiCore/cafPdmUiGroup.h | 80 +++++++++++ .../cafPdmUiCore/cafPdmUiOrdering.cpp | 14 +- .../cafPdmUiCore/cafPdmUiOrdering.h | 33 +---- .../cafTestApplication/MainWindow.cpp | 15 +++ .../cafPdmUiDefaultObjectEditor.cpp | 16 ++- 7 files changed, 248 insertions(+), 37 deletions(-) create mode 100644 Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiGroup.cpp create mode 100644 Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiGroup.h diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/CMakeLists.txt b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/CMakeLists.txt index bf64072d00..565920ac10 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/CMakeLists.txt +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/CMakeLists.txt @@ -41,6 +41,8 @@ set( PROJECT_FILES cafPdmUiTreeOrdering.cpp cafPdmUiTreeOrdering.h cafUiTreeItem.h + cafPdmUiGroup.cpp + cafPdmUiGroup.h cafSelectionManager.cpp cafSelectionManager.h diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiGroup.cpp b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiGroup.cpp new file mode 100644 index 0000000000..de3741dea8 --- /dev/null +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiGroup.cpp @@ -0,0 +1,125 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2017 Ceetron Solutions AS +// +// This library may be used under the terms of either the GNU General Public License or +// the GNU Lesser General Public License as follows: +// +// GNU General Public License Usage +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +// GNU Lesser General Public License Usage +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU Lesser General Public License at <> +// for more details. +// +//################################################################################################## + +#include "cafPdmUiGroup.h" + + +namespace caf +{ + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +PdmUiGroup::PdmUiGroup() +{ + m_isCollapsedByDefault = false; + m_hasForcedExpandedState = false; + m_forcedCollapseState = false; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiGroup::setKeyword(const QString& keyword) +{ + m_keyword = keyword; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString PdmUiGroup::keyword() const +{ + if (!m_keyword.isEmpty()) + { + return m_keyword; + } + + // Fallback to uiName with default uiConfigName + return uiName(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool PdmUiGroup::isUiGroup() +{ + return true; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiGroup::setCollapsedByDefault(bool doCollapse) +{ + m_isCollapsedByDefault = doCollapse; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiGroup::setCollapsed(bool doCollapse) +{ + m_hasForcedExpandedState = true; + m_forcedCollapseState = doCollapse; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool PdmUiGroup::isExpandedByDefault() const +{ + return !m_isCollapsedByDefault; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool PdmUiGroup::hasForcedExpandedState() const +{ + return m_hasForcedExpandedState; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool PdmUiGroup::forcedExpandedState() const +{ + return !m_forcedCollapseState; +} + +} //End of namespace caf + diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiGroup.h b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiGroup.h new file mode 100644 index 0000000000..b30e0fb34c --- /dev/null +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiGroup.h @@ -0,0 +1,80 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2017 Ceetron Solutions AS +// +// This library may be used under the terms of either the GNU General Public License or +// the GNU Lesser General Public License as follows: +// +// GNU General Public License Usage +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +// GNU Lesser General Public License Usage +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU Lesser General Public License at <> +// for more details. +// +//################################################################################################## + +#pragma once + +#include "cafPdmUiItem.h" +#include "cafPdmUiOrdering.h" + +namespace caf +{ + +//================================================================================================== +/// Class representing a group of fields communicated to the Gui +//================================================================================================== + +class PdmUiGroup : public PdmUiItem, public PdmUiOrdering +{ +public: + PdmUiGroup(); + + void setKeyword(const QString& keyword); + QString keyword() const; + + virtual bool isUiGroup(); + + /// Set this group to be collapsed by default. When the user expands the group, the default no longer has any effect. + void setCollapsedByDefault(bool doCollapse); + /// Forcifully set the collapsed state of the group, overriding the previous user actions and the default + void setCollapsed(bool doCollapse); + + // Pdm internal methods + bool isExpandedByDefault() const; + bool hasForcedExpandedState() const; + bool forcedExpandedState() const; + +private: + bool m_isCollapsedByDefault; + bool m_hasForcedExpandedState; + bool m_forcedCollapseState; + + QString m_keyword; +}; + + + +} // End of namespace caf + diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiOrdering.cpp b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiOrdering.cpp index bb828b39ef..6483f6f068 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiOrdering.cpp +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiOrdering.cpp @@ -60,7 +60,7 @@ PdmUiOrdering::~PdmUiOrdering() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -PdmUiGroup* PdmUiOrdering::addNewGroup(QString displayName) +PdmUiGroup* PdmUiOrdering::addNewGroup(const QString& displayName) { PdmUiGroup* group = new PdmUiGroup; group->setUiName(displayName); @@ -71,6 +71,18 @@ PdmUiGroup* PdmUiOrdering::addNewGroup(QString displayName) return group; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +caf::PdmUiGroup* PdmUiOrdering::addNewGroupWithKeyword(const QString& displayName, const QString& keyword) +{ + PdmUiGroup* group = addNewGroup(displayName); + + group->setKeyword(keyword); + + return group; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiOrdering.h b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiOrdering.h index 9ade4e1189..3e737bf553 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiOrdering.h +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiOrdering.h @@ -61,7 +61,8 @@ public: PdmUiOrdering(const PdmUiOrdering&) = delete; PdmUiOrdering& operator=(const PdmUiOrdering&) = delete; - PdmUiGroup* addNewGroup(QString displayName); + PdmUiGroup* addNewGroup(const QString& displayName); + PdmUiGroup* addNewGroupWithKeyword(const QString& displayName, const QString& keyword); void add(const PdmFieldHandle* field); void add(const PdmObjectHandle* obj); @@ -80,34 +81,6 @@ private: bool m_skipRemainingFields; }; -//================================================================================================== -/// Class representing a group of fields communicated to the Gui -//================================================================================================== - -class PdmUiGroup : public PdmUiItem, public PdmUiOrdering -{ -public: - PdmUiGroup() { m_isCollapsedByDefault = false; m_hasForcedExpandedState = false; m_forcedCollapseState = false;} - - virtual bool isUiGroup() { return true; } - - /// Set this group to be collapsed by default. When the user expands the group, the default no longer has any effect. - void setCollapsedByDefault(bool doCollapse) { m_isCollapsedByDefault = doCollapse;} - /// Forcifully set the collapsed state of the group, overriding the previous user actions and the default - void setCollapsed(bool doCollapse) { m_hasForcedExpandedState = true; m_forcedCollapseState = doCollapse;} - - // Pdm internal methods - bool isExpandedByDefault() const { return !m_isCollapsedByDefault;} - bool hasForcedExpandedState() const { return m_hasForcedExpandedState;} - bool forcedExpandedState() const { return !m_forcedCollapseState;} - -private: - bool m_isCollapsedByDefault; - bool m_hasForcedExpandedState; - bool m_forcedCollapseState; -}; - - - } // End of namespace caf +#include "cafPdmUiGroup.h" \ No newline at end of file diff --git a/Fwk/AppFwk/cafTests/cafTestApplication/MainWindow.cpp b/Fwk/AppFwk/cafTests/cafTestApplication/MainWindow.cpp index 8c38ff6ea9..0d9f048763 100644 --- a/Fwk/AppFwk/cafTests/cafTestApplication/MainWindow.cpp +++ b/Fwk/AppFwk/cafTests/cafTestApplication/MainWindow.cpp @@ -104,6 +104,21 @@ public: private: double m_doubleMember; +protected: + //-------------------------------------------------------------------------------------------------- + /// + //-------------------------------------------------------------------------------------------------- + virtual void defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering) override + { + uiOrdering.add(&m_doubleField); + uiOrdering.add(&m_intField); + + QString dynamicGroupName = QString("Dynamic Group Text (%1)").arg(m_intField); + + caf::PdmUiGroup* group = uiOrdering.addNewGroupWithKeyword(dynamicGroupName, "MyTest"); + group->add(&m_textField); + group->add(&m_proxyDoubleField); + } }; CAF_PDM_SOURCE_INIT(SmallDemoPdmObject, "SmallDemoPdmObject"); diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.cpp b/Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.cpp index 374988ce50..10a1166ad5 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.cpp +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.cpp @@ -218,7 +218,7 @@ void PdmUiDefaultObjectEditor::recursiveSetupFieldsAndGroups(const std::vector

(uiItems[i]); const std::vector& groupChildren = group->uiItems(); - QString groupBoxKey = uiItems[i]->uiName(); + QString groupBoxKey = group->keyword(); QMinimizePanel* groupBox = NULL; QGridLayout* groupBoxLayout = NULL; @@ -229,7 +229,8 @@ void PdmUiDefaultObjectEditor::recursiveSetupFieldsAndGroups(const std::vector

setTitle(uiItems[i]->uiName()); + groupBox->setTitle(group->uiName(uiConfigName)); + groupBox->setObjectName(group->keyword()); groupBoxLayout = new QGridLayout(); groupBox->contentFrame()->setLayout(groupBoxLayout); connect(groupBox, SIGNAL(expandedChanged(bool)), this, SLOT(groupBoxExpandedStateToggled(bool))); @@ -255,6 +256,9 @@ void PdmUiDefaultObjectEditor::recursiveSetupFieldsAndGroups(const std::vector

setExpanded(isExpanded); + // Update the title to be able to support dynamic group names + groupBox->setTitle(group->uiName(uiConfigName)); + recursiveSetupFieldsAndGroups(groupChildren, groupBox->contentFrame(), groupBoxLayout, uiConfigName); currentRowIndex++; } @@ -379,9 +383,9 @@ bool PdmUiDefaultObjectEditor::isUiGroupExpanded(const PdmUiGroup* uiGroup) auto kwMapPair = m_objectKeywordGroupUiNameExpandedState.find(pdmObject()->xmlCapability()->classKeyword()); if ( kwMapPair != m_objectKeywordGroupUiNameExpandedState.end() ) { - QString uiName = uiGroup->uiName(); + QString keyword = uiGroup->keyword(); - auto uiNameExpStatePair = kwMapPair->second.find(uiName); + auto uiNameExpStatePair = kwMapPair->second.find(keyword); if ( uiNameExpStatePair != kwMapPair->second.end() ) { return uiNameExpStatePair->second; @@ -403,7 +407,7 @@ void PdmUiDefaultObjectEditor::recursiveVerifyUniqueNames(const std::vector(uiItems[i]); const std::vector& groupChildren = group->uiItems(); - QString groupBoxKey = uiItems[i]->uiName(); + QString groupBoxKey = group->keyword(); if (groupNames->find(groupBoxKey) != groupNames->end()) { @@ -492,7 +496,7 @@ void PdmUiDefaultObjectEditor::groupBoxExpandedStateToggled(bool isExpanded) if (!panel) return; - m_objectKeywordGroupUiNameExpandedState[objKeyword][panel->title()] = isExpanded; + m_objectKeywordGroupUiNameExpandedState[objKeyword][panel->objectName()] = isExpanded; }