#1337 Caf: Preserve the user collapse settings for each object type within session.

Provide means to set groups collapsed by default in the defineUiOrdering method, and to force the setting disregrding the user actions
This commit is contained in:
Jacob Støren 2017-03-20 22:12:07 +01:00
parent a1d14dc8a3
commit 888db49d6c
6 changed files with 99 additions and 11 deletions

View File

@ -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;
};

View File

@ -23,6 +23,7 @@ set( QOBJECT_HEADERS
cafPdmUiCheckBoxTristateEditor.h
cafPdmUiColorEditor.h
cafPdmUiComboBoxEditor.h
cafPdmUiDefaultObjectEditor.h
cafPdmUiDoubleSliderEditor.h
cafPdmUiFilePathEditor.h
cafPdmUiLineEditor.h

View File

@ -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)

View File

@ -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;

View File

@ -227,6 +227,7 @@ void PdmUiDefaultObjectEditor::recursiveSetupFieldsAndGroups(const std::vector<P
groupBox->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<P
/// Insert the group box at the correct position of the parent layout
parentLayout->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<P
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool PdmUiDefaultObjectEditor::isUiGroupExpanded(const PdmUiGroup* uiGroup)
{
if (uiGroup->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<QMinimizePanel*>(this->sender());
if (!panel) return;
m_objectKeywordGroupUiNameExpandedState[objKeyword][panel->title()] = isExpanded;
}
} // end namespace caf

View File

@ -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<PdmUiItem*>& uiItems, QWidget* parent, QGridLayout* parentLayout, const QString& uiConfigName);
void recursiveVerifyUniqueNames(const std::vector<PdmUiItem*>& uiItems, const QString& uiConfigName, std::set<QString>* fieldKeywordNames, std::set<QString>* groupNames);
void recursiveSetupFieldsAndGroups(const std::vector<PdmUiItem*>& uiItems, QWidget* parent, QGridLayout* parentLayout, const QString& uiConfigName);
bool isUiGroupExpanded(const PdmUiGroup* uiGroup);
void recursiveVerifyUniqueNames(const std::vector<PdmUiItem*>& uiItems, const QString& uiConfigName, std::set<QString>* fieldKeywordNames, std::set<QString>* groupNames);
std::map<PdmFieldHandle*, PdmUiFieldEditorHandle*> m_fieldViews;
std::map<QString, QPointer<QMinimizePanel> > m_groupBoxes;
std::map<QString, QPointer<QMinimizePanel> > m_newGroupBoxes; ///< used temporarily to store the new(complete) set of group boxes
std::map<QString, QPointer<QMinimizePanel> > m_groupBoxes;
std::map<QString, QPointer<QMinimizePanel> > m_newGroupBoxes; ///< used temporarily to store the new(complete) set of group boxes
QPointer<QWidget> m_mainWidget;
QPointer<QGridLayout> m_layout;
QPointer<QWidget> m_mainWidget;
QPointer<QGridLayout> m_layout;
std::map<QString, std::map<QString, bool> > m_objectKeywordGroupUiNameExpandedState;
};