mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#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:
@@ -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
|
class PdmUiGroup : public PdmUiItem, public PdmUiOrdering
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
PdmUiGroup() { m_isCollapsedByDefault = false; m_hasForcedExpandedState = false; m_forcedCollapseState = false;}
|
||||||
|
|
||||||
virtual bool isUiGroup() { return true; }
|
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ set( QOBJECT_HEADERS
|
|||||||
cafPdmUiCheckBoxTristateEditor.h
|
cafPdmUiCheckBoxTristateEditor.h
|
||||||
cafPdmUiColorEditor.h
|
cafPdmUiColorEditor.h
|
||||||
cafPdmUiComboBoxEditor.h
|
cafPdmUiComboBoxEditor.h
|
||||||
|
cafPdmUiDefaultObjectEditor.h
|
||||||
cafPdmUiDoubleSliderEditor.h
|
cafPdmUiDoubleSliderEditor.h
|
||||||
cafPdmUiFilePathEditor.h
|
cafPdmUiFilePathEditor.h
|
||||||
cafPdmUiLineEditor.h
|
cafPdmUiLineEditor.h
|
||||||
|
|||||||
@@ -181,14 +181,26 @@ void QMinimizePanel::setTitle(const QString& title)
|
|||||||
m_titleLabel->setText(title);
|
m_titleLabel->setText(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
QString QMinimizePanel::title() const
|
||||||
|
{
|
||||||
|
return m_titleLabel->text();
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void QMinimizePanel::setExpanded(bool isExpanded)
|
void QMinimizePanel::setExpanded(bool isExpanded)
|
||||||
{
|
{
|
||||||
|
if (m_contentFrame->isHidden() != isExpanded) return;
|
||||||
|
|
||||||
m_contentFrame->setVisible(isExpanded);
|
m_contentFrame->setVisible(isExpanded);
|
||||||
isExpanded ? m_collapseButton->setIcon(expandUpIcon()) : m_collapseButton->setIcon(expandDownIcon());
|
isExpanded ? m_collapseButton->setIcon(expandUpIcon()) : m_collapseButton->setIcon(expandDownIcon());
|
||||||
this->QWidget::updateGeometry();
|
this->QWidget::updateGeometry();
|
||||||
|
|
||||||
|
emit expandedChanged(isExpanded);
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@@ -196,7 +208,7 @@ void QMinimizePanel::setExpanded(bool isExpanded)
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void QMinimizePanel::toggleExpanded()
|
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 labelSize = m_titleLabel->sizeHint();
|
||||||
QSize titleBarHint = labelSize + QSize(4 + labelSize.height() + 8 - 2 + 1, 8);
|
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 titleBarMin(0, labelSize.height() + 8 );
|
||||||
QSize contentsMin(m_contentFrame->minimumSizeHint());
|
QSize contentsMin(m_contentFrame->minimumSizeHint());
|
||||||
@@ -236,10 +248,10 @@ void QMinimizePanel::resizeEvent(QResizeEvent *resizeEv )
|
|||||||
int buttonSize = titleHeight - 2;
|
int buttonSize = titleHeight - 2;
|
||||||
|
|
||||||
m_titleFrame->setGeometry(0,0,width, titleHeight);
|
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_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)
|
bool QMinimizePanel::event(QEvent* event)
|
||||||
|
|||||||
@@ -52,10 +52,15 @@ public:
|
|||||||
|
|
||||||
QFrame * contentFrame() { return m_contentFrame; }
|
QFrame * contentFrame() { return m_contentFrame; }
|
||||||
void setTitle (const QString& title);
|
void setTitle (const QString& title);
|
||||||
|
QString title() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setExpanded(bool isExpanded);
|
void setExpanded(bool isExpanded);
|
||||||
void toggleExpanded();
|
void toggleExpanded();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void expandedChanged(bool isExpanded);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual QSize minimumSizeHint() const override;
|
virtual QSize minimumSizeHint() const override;
|
||||||
|
|
||||||
|
|||||||
@@ -227,6 +227,7 @@ void PdmUiDefaultObjectEditor::recursiveSetupFieldsAndGroups(const std::vector<P
|
|||||||
groupBox->setTitle(uiItems[i]->uiName());
|
groupBox->setTitle(uiItems[i]->uiName());
|
||||||
groupBoxLayout = new QGridLayout();
|
groupBoxLayout = new QGridLayout();
|
||||||
groupBox->contentFrame()->setLayout(groupBoxLayout);
|
groupBox->contentFrame()->setLayout(groupBoxLayout);
|
||||||
|
connect(groupBox, SIGNAL(expandedChanged(bool)), this, SLOT(groupBoxExpandedStateToggled(bool)));
|
||||||
|
|
||||||
m_newGroupBoxes[groupBoxKey] = groupBox;
|
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
|
/// Insert the group box at the correct position of the parent layout
|
||||||
|
|
||||||
parentLayout->addWidget(groupBox, currentRowIndex, 0, 1, 2);
|
parentLayout->addWidget(groupBox, currentRowIndex, 0, 1, 2);
|
||||||
|
|
||||||
|
// Set Expanded state
|
||||||
|
bool isExpanded = isUiGroupExpanded(group);
|
||||||
|
groupBox->setExpanded(isExpanded);
|
||||||
|
|
||||||
recursiveSetupFieldsAndGroups(groupChildren, groupBox->contentFrame(), groupBoxLayout, uiConfigName);
|
recursiveSetupFieldsAndGroups(groupChildren, groupBox->contentFrame(), groupBoxLayout, uiConfigName);
|
||||||
currentRowIndex++;
|
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;
|
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
|
} // end namespace caf
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ namespace caf
|
|||||||
{
|
{
|
||||||
class PdmUiFieldEditorHandle;
|
class PdmUiFieldEditorHandle;
|
||||||
class PdmUiItem;
|
class PdmUiItem;
|
||||||
|
class PdmUiGroup;
|
||||||
|
|
||||||
|
|
||||||
class PdmUiFieldEditorHelper
|
class PdmUiFieldEditorHelper
|
||||||
@@ -68,6 +69,7 @@ public:
|
|||||||
|
|
||||||
class PdmUiDefaultObjectEditor : public PdmUiObjectEditorHandle
|
class PdmUiDefaultObjectEditor : public PdmUiObjectEditorHandle
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
PdmUiDefaultObjectEditor();
|
PdmUiDefaultObjectEditor();
|
||||||
~PdmUiDefaultObjectEditor();
|
~PdmUiDefaultObjectEditor();
|
||||||
@@ -77,16 +79,22 @@ protected:
|
|||||||
virtual void configureAndUpdateUi(const QString& uiConfigName) override;
|
virtual void configureAndUpdateUi(const QString& uiConfigName) override;
|
||||||
virtual void cleanupBeforeSettingPdmObject() override;
|
virtual void cleanupBeforeSettingPdmObject() override;
|
||||||
|
|
||||||
|
protected slots:
|
||||||
|
void groupBoxExpandedStateToggled(bool isExpanded);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void recursiveSetupFieldsAndGroups(const std::vector<PdmUiItem*>& uiItems, QWidget* parent, QGridLayout* parentLayout, const QString& uiConfigName);
|
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);
|
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<PdmFieldHandle*, PdmUiFieldEditorHandle*> m_fieldViews;
|
||||||
std::map<QString, QPointer<QMinimizePanel> > m_groupBoxes;
|
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_newGroupBoxes; ///< used temporarily to store the new(complete) set of group boxes
|
||||||
|
|
||||||
QPointer<QWidget> m_mainWidget;
|
QPointer<QWidget> m_mainWidget;
|
||||||
QPointer<QGridLayout> m_layout;
|
QPointer<QGridLayout> m_layout;
|
||||||
|
|
||||||
|
std::map<QString, std::map<QString, bool> > m_objectKeywordGroupUiNameExpandedState;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user