mirror of
https://github.com/OPM/ResInsight.git
synced 2025-01-21 22:13:25 -06:00
#1833 AppFwk: Add support for dynamic labels on group-boxes
This commit is contained in:
parent
5f790273e9
commit
c18e9c1293
@ -41,6 +41,8 @@ set( PROJECT_FILES
|
||||
cafPdmUiTreeOrdering.cpp
|
||||
cafPdmUiTreeOrdering.h
|
||||
cafUiTreeItem.h
|
||||
cafPdmUiGroup.cpp
|
||||
cafPdmUiGroup.h
|
||||
|
||||
cafSelectionManager.cpp
|
||||
cafSelectionManager.h
|
||||
|
125
Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiGroup.cpp
Normal file
125
Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiGroup.cpp
Normal file
@ -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 <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// 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 <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// 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
|
||||
|
80
Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiGroup.h
Normal file
80
Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiGroup.h
Normal file
@ -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 <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// 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 <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// 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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -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"
|
@ -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");
|
||||
|
@ -218,7 +218,7 @@ void PdmUiDefaultObjectEditor::recursiveSetupFieldsAndGroups(const std::vector<P
|
||||
PdmUiGroup* group = static_cast<PdmUiGroup*>(uiItems[i]);
|
||||
const std::vector<PdmUiItem*>& 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<P
|
||||
if (it == m_groupBoxes.end())
|
||||
{
|
||||
groupBox = new QMinimizePanel( parent );
|
||||
groupBox->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<P
|
||||
bool isExpanded = isUiGroupExpanded(group);
|
||||
groupBox->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<PdmU
|
||||
PdmUiGroup* group = static_cast<PdmUiGroup*>(uiItems[i]);
|
||||
const std::vector<PdmUiItem*>& 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;
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user