diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiOrdering.h b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiOrdering.h index 3719fb3863..0d395d0313 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiOrdering.h +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiOrdering.h @@ -81,12 +81,30 @@ private: }; //================================================================================================== -/// Class representing a group of fields +/// 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;} + + // Internal use + 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; }; diff --git a/Fwk/AppFwk/cafUserInterface/CMakeLists.txt b/Fwk/AppFwk/cafUserInterface/CMakeLists.txt index 4f62ae0f67..23148be42c 100644 --- a/Fwk/AppFwk/cafUserInterface/CMakeLists.txt +++ b/Fwk/AppFwk/cafUserInterface/CMakeLists.txt @@ -23,6 +23,7 @@ set( QOBJECT_HEADERS cafPdmUiCheckBoxTristateEditor.h cafPdmUiColorEditor.h cafPdmUiComboBoxEditor.h + cafPdmUiDefaultObjectEditor.h cafPdmUiDoubleSliderEditor.h cafPdmUiFilePathEditor.h cafPdmUiLineEditor.h diff --git a/Fwk/AppFwk/cafUserInterface/QMinimizePanel.cpp b/Fwk/AppFwk/cafUserInterface/QMinimizePanel.cpp index 2547762931..893fdb0c53 100644 --- a/Fwk/AppFwk/cafUserInterface/QMinimizePanel.cpp +++ b/Fwk/AppFwk/cafUserInterface/QMinimizePanel.cpp @@ -181,14 +181,26 @@ void QMinimizePanel::setTitle(const QString& title) m_titleLabel->setText(title); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString QMinimizePanel::title() const +{ + return m_titleLabel->text(); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void QMinimizePanel::setExpanded(bool isExpanded) { + if (m_contentFrame->isHidden() != isExpanded) return; + m_contentFrame->setVisible(isExpanded); isExpanded ? m_collapseButton->setIcon(expandUpIcon()) : m_collapseButton->setIcon(expandDownIcon()); this->QWidget::updateGeometry(); + + emit expandedChanged(isExpanded); } //-------------------------------------------------------------------------------------------------- @@ -196,7 +208,7 @@ void QMinimizePanel::setExpanded(bool isExpanded) //-------------------------------------------------------------------------------------------------- void QMinimizePanel::toggleExpanded() { - setExpanded(!m_contentFrame->isVisible()); + setExpanded(m_contentFrame->isHidden()); } //-------------------------------------------------------------------------------------------------- @@ -207,7 +219,7 @@ QSize QMinimizePanel::minimumSizeHint() const QSize labelSize = m_titleLabel->sizeHint(); QSize titleBarHint = labelSize + QSize(4 + labelSize.height() + 8 - 2 + 1, 8); - if (m_contentFrame->isVisible()) + if (!m_contentFrame->isHidden()) { QSize titleBarMin(0, labelSize.height() + 8 ); QSize contentsMin(m_contentFrame->minimumSizeHint()); @@ -236,10 +248,10 @@ void QMinimizePanel::resizeEvent(QResizeEvent *resizeEv ) int buttonSize = titleHeight - 2; m_titleFrame->setGeometry(0,0,width, titleHeight); - m_titleLabel->setGeometry( 4, titleHeight - labelHeight - 4, width - buttonSize - 1, labelHeight); + m_titleLabel->setGeometry( 4, titleHeight - labelHeight - 4, width - 4 - buttonSize - 1, labelHeight); m_collapseButton->setGeometry(width - buttonSize - 1, 1, buttonSize, buttonSize); - m_contentFrame->setGeometry(0, titleHeight-1, width, heigth - titleHeight-1); + m_contentFrame->setGeometry(0, titleHeight-1, width, heigth - (titleHeight-1)); } bool QMinimizePanel::event(QEvent* event) diff --git a/Fwk/AppFwk/cafUserInterface/QMinimizePanel.h b/Fwk/AppFwk/cafUserInterface/QMinimizePanel.h index 08d330139a..22d58c7069 100644 --- a/Fwk/AppFwk/cafUserInterface/QMinimizePanel.h +++ b/Fwk/AppFwk/cafUserInterface/QMinimizePanel.h @@ -52,10 +52,15 @@ public: QFrame * contentFrame() { return m_contentFrame; } void setTitle (const QString& title); + QString title() const; public slots: void setExpanded(bool isExpanded); void toggleExpanded(); + +signals: + void expandedChanged(bool isExpanded); + public: virtual QSize minimumSizeHint() const override; diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.cpp b/Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.cpp index f7638677f9..e1caef3c5a 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.cpp +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.cpp @@ -227,6 +227,7 @@ void PdmUiDefaultObjectEditor::recursiveSetupFieldsAndGroups(const std::vector

setTitle(uiItems[i]->uiName()); groupBoxLayout = new QGridLayout(); groupBox->contentFrame()->setLayout(groupBoxLayout); + connect(groupBox, SIGNAL(expandedChanged(bool)), this, SLOT(groupBoxExpandedStateToggled(bool))); m_newGroupBoxes[groupBoxKey] = groupBox; } @@ -244,6 +245,11 @@ void PdmUiDefaultObjectEditor::recursiveSetupFieldsAndGroups(const std::vector

addWidget(groupBox, currentRowIndex, 0, 1, 2); + + // Set Expanded state + bool isExpanded = isUiGroupExpanded(group); + groupBox->setExpanded(isExpanded); + recursiveSetupFieldsAndGroups(groupChildren, groupBox->contentFrame(), groupBoxLayout, uiConfigName); currentRowIndex++; } @@ -358,6 +364,28 @@ void PdmUiDefaultObjectEditor::recursiveSetupFieldsAndGroups(const std::vector

hasForcedExpandedState()) return uiGroup->forcedExpandedState(); + + auto kwMapPair = m_objectKeywordGroupUiNameExpandedState.find(pdmObject()->xmlCapability()->classKeyword()); + if ( kwMapPair != m_objectKeywordGroupUiNameExpandedState.end() ) + { + QString uiName = uiGroup->uiName(); + + auto uiNameExpStatePair = kwMapPair->second.find(uiName); + if ( uiNameExpStatePair != kwMapPair->second.end() ) + { + return uiNameExpStatePair->second; + } + } + + return uiGroup->isExpandedByDefault(); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -447,4 +475,20 @@ caf::PdmUiFieldEditorHandle* PdmUiFieldEditorHelper::fieldEditorForField(PdmUiFi return fieldEditor; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiDefaultObjectEditor::groupBoxExpandedStateToggled(bool isExpanded) +{ + if (!this->pdmObject()->xmlCapability()) return; + + QString objKeyword = this->pdmObject()->xmlCapability()->classKeyword(); + QMinimizePanel* panel = dynamic_cast(this->sender()); + + if (!panel) return; + + m_objectKeywordGroupUiNameExpandedState[objKeyword][panel->title()] = isExpanded; + +} + } // end namespace caf diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.h b/Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.h index d982ff262f..332da51af7 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.h +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.h @@ -53,6 +53,7 @@ namespace caf { class PdmUiFieldEditorHandle; class PdmUiItem; +class PdmUiGroup; class PdmUiFieldEditorHelper @@ -68,6 +69,7 @@ public: class PdmUiDefaultObjectEditor : public PdmUiObjectEditorHandle { + Q_OBJECT public: PdmUiDefaultObjectEditor(); ~PdmUiDefaultObjectEditor(); @@ -77,16 +79,22 @@ protected: virtual void configureAndUpdateUi(const QString& uiConfigName) override; virtual void cleanupBeforeSettingPdmObject() override; +protected slots: + void groupBoxExpandedStateToggled(bool isExpanded); + private: - void recursiveSetupFieldsAndGroups(const std::vector& uiItems, QWidget* parent, QGridLayout* parentLayout, const QString& uiConfigName); - void recursiveVerifyUniqueNames(const std::vector& uiItems, const QString& uiConfigName, std::set* fieldKeywordNames, std::set* groupNames); + void recursiveSetupFieldsAndGroups(const std::vector& uiItems, QWidget* parent, QGridLayout* parentLayout, const QString& uiConfigName); + bool isUiGroupExpanded(const PdmUiGroup* uiGroup); + void recursiveVerifyUniqueNames(const std::vector& uiItems, const QString& uiConfigName, std::set* fieldKeywordNames, std::set* groupNames); std::map m_fieldViews; - std::map > m_groupBoxes; - std::map > m_newGroupBoxes; ///< used temporarily to store the new(complete) set of group boxes + std::map > m_groupBoxes; + std::map > m_newGroupBoxes; ///< used temporarily to store the new(complete) set of group boxes - QPointer m_mainWidget; - QPointer m_layout; + QPointer m_mainWidget; + QPointer m_layout; + + std::map > m_objectKeywordGroupUiNameExpandedState; };