#3404 Side by side editors, first implementation.

This commit is contained in:
Gaute Lindkvist 2018-09-25 14:19:03 +02:00
parent 456903f2fa
commit e8a1d30f2d
19 changed files with 637 additions and 262 deletions

View File

@ -62,10 +62,12 @@ RicSummaryCurveCalculatorEditor::~RicSummaryCurveCalculatorEditor()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicSummaryCurveCalculatorEditor::recursivelyConfigureAndUpdateTopLevelUiItems(const std::vector<caf::PdmUiItem *>& topLevelUiItems, const QString& uiConfigName) void RicSummaryCurveCalculatorEditor::recursivelyConfigureAndUpdateTopLevelUiOrdering(const caf::PdmUiOrdering& topLevelUiOrdering, const QString& uiConfigName)
{ {
if (!m_firstRowLeftLayout || !m_firstRowRightLayout) return; if (!m_firstRowLeftLayout || !m_firstRowRightLayout) return;
const std::vector<caf::PdmUiItem *>& topLevelUiItems = topLevelUiOrdering.uiItems();
int layoutItemIndex = 0; int layoutItemIndex = 0;
for (size_t i = 0; i < topLevelUiItems.size(); ++i) for (size_t i = 0; i < topLevelUiItems.size(); ++i)
{ {
@ -185,8 +187,7 @@ QMinimizePanel* RicSummaryCurveCalculatorEditor::updateGroupBoxWithContent(caf::
{ {
QMinimizePanel* groupBox = findOrCreateGroupBox(this->widget(), group, uiConfigName); QMinimizePanel* groupBox = findOrCreateGroupBox(this->widget(), group, uiConfigName);
const std::vector<caf::PdmUiItem*>& groupChildren = group->uiItems(); recursivelyConfigureAndUpdateUiOrderingInGridLayoutColumn(*group, groupBox->contentFrame(), uiConfigName);
recursivelyConfigureAndUpdateUiItemsInGridLayoutColumn(groupChildren, groupBox->contentFrame(), uiConfigName);
return groupBox; return groupBox;
} }

View File

@ -52,8 +52,8 @@ public:
RicSummaryCurveCalculator* calculator() const; RicSummaryCurveCalculator* calculator() const;
private: private:
virtual void recursivelyConfigureAndUpdateTopLevelUiItems(const std::vector<caf::PdmUiItem *>& topLevelUiItems, virtual void recursivelyConfigureAndUpdateTopLevelUiOrdering(const caf::PdmUiOrdering& topLevelUiItems,
const QString& uiConfigName) override; const QString& uiConfigName) override;
virtual QWidget* createWidget(QWidget* parent) override; virtual QWidget* createWidget(QWidget* parent) override;

View File

@ -78,8 +78,9 @@ void RicSummaryCurveCreatorSplitterUi::updateFromDefaultSources(const std::vecto
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicSummaryCurveCreatorSplitterUi::recursivelyConfigureAndUpdateTopLevelUiItems(const std::vector<caf::PdmUiItem *>& topLevelUiItems, const QString& uiConfigName) void RicSummaryCurveCreatorSplitterUi::recursivelyConfigureAndUpdateTopLevelUiOrdering(const caf::PdmUiOrdering& topLevelUiOrdering, const QString& uiConfigName)
{ {
const std::vector<caf::PdmUiItem *>& topLevelUiItems = topLevelUiOrdering.uiItems();
if (m_summaryCurveCreator->isCloseButtonPressed()) if (m_summaryCurveCreator->isCloseButtonPressed())
{ {
m_summaryCurveCreator->clearCloseButton(); m_summaryCurveCreator->clearCloseButton();
@ -298,7 +299,6 @@ QMinimizePanel* RicSummaryCurveCreatorSplitterUi::createGroupBoxWithContent(caf:
{ {
QMinimizePanel* groupBox = findOrCreateGroupBox(this->widget(), group, uiConfigName); QMinimizePanel* groupBox = findOrCreateGroupBox(this->widget(), group, uiConfigName);
const std::vector<caf::PdmUiItem*>& groupChildren = group->uiItems(); recursivelyConfigureAndUpdateUiOrderingInGridLayoutColumn(*group, groupBox->contentFrame(), uiConfigName);
recursivelyConfigureAndUpdateUiItemsInGridLayoutColumn(groupChildren, groupBox->contentFrame(), uiConfigName);
return groupBox; return groupBox;
} }

View File

@ -57,8 +57,8 @@ public:
void updateFromDefaultSources(const std::vector<caf::PdmObject*> defaultSources); void updateFromDefaultSources(const std::vector<caf::PdmObject*> defaultSources);
private: private:
virtual void recursivelyConfigureAndUpdateTopLevelUiItems(const std::vector<caf::PdmUiItem *>& topLevelUiItems, virtual void recursivelyConfigureAndUpdateTopLevelUiOrdering(const caf::PdmUiOrdering& topLevelUiOrdering,
const QString& uiConfigName) override; const QString& uiConfigName) override;
virtual QWidget* createWidget(QWidget* parent) override; virtual QWidget* createWidget(QWidget* parent) override;

View File

@ -59,10 +59,12 @@ RiuSummaryCurveDefSelection* RiuSummaryCurveDefSelectionEditor::summaryAddressSe
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiuSummaryCurveDefSelectionEditor::recursivelyConfigureAndUpdateTopLevelUiItems(const std::vector<caf::PdmUiItem *>& topLevelUiItems, const QString& uiConfigName) void RiuSummaryCurveDefSelectionEditor::recursivelyConfigureAndUpdateTopLevelUiOrdering(const caf::PdmUiOrdering& topLevelUiOrdering, const QString& uiConfigName)
{ {
if (!m_firstRowLeftLayout || !m_firstRowRightLayout) return; if (!m_firstRowLeftLayout || !m_firstRowRightLayout) return;
const std::vector<caf::PdmUiItem *>& topLevelUiItems = topLevelUiOrdering.uiItems();
for (size_t i = 0; i < topLevelUiItems.size(); ++i) for (size_t i = 0; i < topLevelUiItems.size(); ++i)
{ {
if (topLevelUiItems[i]->isUiHidden(uiConfigName)) continue; if (topLevelUiItems[i]->isUiHidden(uiConfigName)) continue;
@ -214,7 +216,6 @@ QMinimizePanel* RiuSummaryCurveDefSelectionEditor::createGroupBoxWithContent(caf
{ {
QMinimizePanel* groupBox = findOrCreateGroupBox(this->widget(), group, uiConfigName); QMinimizePanel* groupBox = findOrCreateGroupBox(this->widget(), group, uiConfigName);
const std::vector<caf::PdmUiItem*>& groupChildren = group->uiItems(); recursivelyConfigureAndUpdateUiOrderingInGridLayoutColumn(*group, groupBox->contentFrame(), uiConfigName);
recursivelyConfigureAndUpdateUiItemsInGridLayoutColumn(groupChildren, groupBox->contentFrame(), uiConfigName);
return groupBox; return groupBox;
} }

View File

@ -52,8 +52,8 @@ public:
RiuSummaryCurveDefSelection* summaryAddressSelection() const; RiuSummaryCurveDefSelection* summaryAddressSelection() const;
private: private:
virtual void recursivelyConfigureAndUpdateTopLevelUiItems(const std::vector<caf::PdmUiItem *>& topLevelUiItems, virtual void recursivelyConfigureAndUpdateTopLevelUiOrdering(const caf::PdmUiOrdering& topLevelUiOrdering,
const QString& uiConfigName) override; const QString& uiConfigName) override;
virtual QWidget* createWidget(QWidget* parent) override; virtual QWidget* createWidget(QWidget* parent) override;

View File

@ -48,6 +48,7 @@ PdmUiGroup::PdmUiGroup()
m_isCollapsedByDefault = false; m_isCollapsedByDefault = false;
m_hasForcedExpandedState = false; m_hasForcedExpandedState = false;
m_forcedCollapseState = false; m_forcedCollapseState = false;
m_enableFrame = true;
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -97,6 +98,14 @@ void PdmUiGroup::setCollapsed(bool doCollapse)
m_forcedCollapseState = doCollapse; m_forcedCollapseState = doCollapse;
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PdmUiGroup::setEnableFrame(bool enableFrame)
{
m_enableFrame = enableFrame;
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -121,5 +130,13 @@ bool PdmUiGroup::forcedExpandedState() const
return !m_forcedCollapseState; return !m_forcedCollapseState;
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool PdmUiGroup::enableFrame() const
{
return m_enableFrame;
}
} //End of namespace caf } //End of namespace caf

View File

@ -57,21 +57,24 @@ public:
bool isUiGroup() const override; bool isUiGroup() const override;
/// Set this group to be collapsed by default. When the user expands the group, the default no longer has any effect. /// 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); void setCollapsedByDefault(bool doCollapse);
/// Forcifully set the collapsed state of the group, overriding the previous user actions and the default /// Forcifully set the collapsed state of the group, overriding the previous user actions and the default
void setCollapsed(bool doCollapse); void setCollapsed(bool doCollapse);
void setEnableFrame(bool enableFrame);
// Pdm internal methods // Pdm internal methods
bool isExpandedByDefault() const; bool isExpandedByDefault() const;
bool hasForcedExpandedState() const; bool hasForcedExpandedState() const;
bool forcedExpandedState() const; bool forcedExpandedState() const;
bool enableFrame() const;
private: private:
bool m_isCollapsedByDefault; bool m_isCollapsedByDefault;
bool m_hasForcedExpandedState; bool m_hasForcedExpandedState;
bool m_forcedCollapseState; bool m_forcedCollapseState;
bool m_enableFrame;
QString m_keyword; QString m_keyword;
}; };

View File

@ -60,13 +60,13 @@ PdmUiOrdering::~PdmUiOrdering()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
PdmUiGroup* PdmUiOrdering::addNewGroup(const QString& displayName) PdmUiGroup* PdmUiOrdering::addNewGroup(const QString& displayName, LayoutOptions layout)
{ {
PdmUiGroup* group = new PdmUiGroup; PdmUiGroup* group = new PdmUiGroup;
group->setUiName(displayName); group->setUiName(displayName);
m_createdGroups.push_back(group); m_createdGroups.push_back(group);
m_ordering.push_back(group); m_ordering.push_back(std::make_pair(group, layout));
return group; return group;
} }
@ -74,9 +74,9 @@ PdmUiGroup* PdmUiOrdering::addNewGroup(const QString& displayName)
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
caf::PdmUiGroup* PdmUiOrdering::addNewGroupWithKeyword(const QString& displayName, const QString& keyword) caf::PdmUiGroup* PdmUiOrdering::addNewGroupWithKeyword(const QString& displayName, const QString& keyword, LayoutOptions layout)
{ {
PdmUiGroup* group = addNewGroup(displayName); PdmUiGroup* group = addNewGroup(displayName, layout);
group->setKeyword(keyword); group->setKeyword(keyword);
@ -86,12 +86,12 @@ caf::PdmUiGroup* PdmUiOrdering::addNewGroupWithKeyword(const QString& displayNam
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
bool PdmUiOrdering::insertBeforeGroup(const QString& groupId, const PdmFieldHandle* field) bool PdmUiOrdering::insertBeforeGroup(const QString& groupId, const PdmFieldHandle* field, LayoutOptions layout)
{ {
PositionFound pos = findGroupPosition(groupId); PositionFound pos = findGroupPosition(groupId);
if (pos.parent) if (pos.parent)
{ {
pos.parent->insert(pos.indexInParent, field); pos.parent->insert(pos.indexInParent, field, layout);
return true; return true;
} }
else else
@ -104,12 +104,12 @@ bool PdmUiOrdering::insertBeforeGroup(const QString& groupId, const PdmFieldHand
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
bool PdmUiOrdering::insertBeforeItem(const PdmUiItem* item, const PdmFieldHandle* field) bool PdmUiOrdering::insertBeforeItem(const PdmUiItem* item, const PdmFieldHandle* field, LayoutOptions layout)
{ {
PositionFound pos = findItemPosition(item); PositionFound pos = findItemPosition(item);
if (pos.parent) if (pos.parent)
{ {
pos.parent->insert(pos.indexInParent, field); pos.parent->insert(pos.indexInParent, field, layout);
return true; return true;
} }
else else
@ -121,28 +121,28 @@ bool PdmUiOrdering::insertBeforeItem(const PdmUiItem* item, const PdmFieldHandle
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
caf::PdmUiGroup* PdmUiOrdering::createGroupBeforeGroup(const QString& groupId, const QString& displayName) caf::PdmUiGroup* PdmUiOrdering::createGroupBeforeGroup(const QString& groupId, const QString& displayName, LayoutOptions layout)
{ {
return createGroupWithIdBeforeGroup(groupId, displayName, ""); return createGroupWithIdBeforeGroup(groupId, displayName, "", layout);
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
caf::PdmUiGroup* PdmUiOrdering::createGroupBeforeItem(const PdmUiItem* item, const QString& displayName) caf::PdmUiGroup* PdmUiOrdering::createGroupBeforeItem(const PdmUiItem* item, const QString& displayName, LayoutOptions layout)
{ {
return createGroupWithIdBeforeItem(item, displayName, ""); return createGroupWithIdBeforeItem(item, displayName, "", layout);
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
caf::PdmUiGroup* PdmUiOrdering::createGroupWithIdBeforeGroup(const QString& groupId, const QString& displayName, const QString& newGroupId) caf::PdmUiGroup* PdmUiOrdering::createGroupWithIdBeforeGroup(const QString& groupId, const QString& displayName, const QString& newGroupId, LayoutOptions layout)
{ {
PositionFound pos = findGroupPosition(groupId); PositionFound pos = findGroupPosition(groupId);
if (pos.parent) if (pos.parent)
{ {
return pos.parent->insertNewGroupWithKeyword(pos.indexInParent, displayName, newGroupId); return pos.parent->insertNewGroupWithKeyword(pos.indexInParent, displayName, newGroupId, layout);
} }
return nullptr; return nullptr;
@ -151,12 +151,12 @@ caf::PdmUiGroup* PdmUiOrdering::createGroupWithIdBeforeGroup(const QString& grou
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
caf::PdmUiGroup* PdmUiOrdering::createGroupWithIdBeforeItem(const PdmUiItem* item, const QString& displayName, const QString& newGroupId) caf::PdmUiGroup* PdmUiOrdering::createGroupWithIdBeforeItem(const PdmUiItem* item, const QString& displayName, const QString& newGroupId, LayoutOptions layout)
{ {
PositionFound pos = findItemPosition(item); PositionFound pos = findItemPosition(item);
if (pos.parent) if (pos.parent)
{ {
return pos.parent->insertNewGroupWithKeyword(pos.indexInParent, displayName, newGroupId); return pos.parent->insertNewGroupWithKeyword(pos.indexInParent, displayName, newGroupId, layout);
} }
return nullptr; return nullptr;
@ -175,14 +175,15 @@ caf::PdmUiGroup* PdmUiOrdering::findGroup(const QString& groupId) const
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
caf::PdmUiGroup* PdmUiOrdering::insertNewGroupWithKeyword(size_t index, caf::PdmUiGroup* PdmUiOrdering::insertNewGroupWithKeyword(size_t index,
const QString& displayName, const QString& displayName,
const QString& groupKeyword) const QString& groupKeyword,
LayoutOptions layout)
{ {
PdmUiGroup* group = new PdmUiGroup; PdmUiGroup* group = new PdmUiGroup;
group->setUiName(displayName); group->setUiName(displayName);
m_createdGroups.push_back(group); m_createdGroups.push_back(group);
m_ordering.insert(m_ordering.begin() + index, group); m_ordering.insert(m_ordering.begin() + index, std::make_pair(group, layout));
group->setKeyword(groupKeyword); group->setKeyword(groupKeyword);
@ -204,10 +205,10 @@ caf::PdmUiOrdering::PositionFound PdmUiOrdering::findItemPosition(const PdmUiIte
{ {
for (size_t i = 0; i < m_ordering.size(); ++i) for (size_t i = 0; i < m_ordering.size(); ++i)
{ {
if (m_ordering[i] == item) return { const_cast<PdmUiOrdering*>(this), i}; if (m_ordering[i].first == item) return { const_cast<PdmUiOrdering*>(this), i};
if (m_ordering[i] && m_ordering[i]->isUiGroup()) if (m_ordering[i].first && m_ordering[i].first->isUiGroup())
{ {
PositionFound result = static_cast<PdmUiGroup*>(m_ordering[i])->findItemPosition(item); PositionFound result = static_cast<PdmUiGroup*>(m_ordering[i].first)->findItemPosition(item);
if (result.parent ) return result; if (result.parent ) return result;
} }
} }
@ -221,10 +222,10 @@ caf::PdmUiOrdering::PositionFound PdmUiOrdering::findGroupPosition(const QString
{ {
for (size_t i = 0; i < m_ordering.size(); ++i) for (size_t i = 0; i < m_ordering.size(); ++i)
{ {
if (m_ordering[i] && m_ordering[i]->isUiGroup()) if (m_ordering[i].first && m_ordering[i].first->isUiGroup())
{ {
if (static_cast<PdmUiGroup*>(m_ordering[i])->keyword() == groupKeyword) return { const_cast<PdmUiOrdering*>(this), i}; if (static_cast<PdmUiGroup*>(m_ordering[i].first)->keyword() == groupKeyword) return { const_cast<PdmUiOrdering*>(this), i};
PositionFound result = static_cast<PdmUiGroup*>(m_ordering[i])->findGroupPosition(groupKeyword); PositionFound result = static_cast<PdmUiGroup*>(m_ordering[i].first)->findGroupPosition(groupKeyword);
if (result.parent ) return result; if (result.parent ) return result;
} }
} }
@ -235,37 +236,37 @@ caf::PdmUiOrdering::PositionFound PdmUiOrdering::findGroupPosition(const QString
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void PdmUiOrdering::add(const PdmFieldHandle* field) void PdmUiOrdering::add(const PdmFieldHandle* field, LayoutOptions layout)
{ {
PdmUiFieldHandle* uiItem = const_cast<PdmFieldHandle*>(field)->uiCapability(); PdmUiFieldHandle* uiItem = const_cast<PdmFieldHandle*>(field)->uiCapability();
CAF_ASSERT(uiItem); CAF_ASSERT(uiItem);
CAF_ASSERT(!this->contains(uiItem)); CAF_ASSERT(!this->contains(uiItem));
m_ordering.push_back(uiItem); m_ordering.push_back(std::make_pair(uiItem, layout));
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void PdmUiOrdering::add(const PdmObjectHandle* obj) void PdmUiOrdering::add(const PdmObjectHandle* obj, LayoutOptions layout)
{ {
PdmUiObjectHandle* uiItem = uiObj(const_cast<PdmObjectHandle*>(obj)); PdmUiObjectHandle* uiItem = uiObj(const_cast<PdmObjectHandle*>(obj));
CAF_ASSERT(uiItem); CAF_ASSERT(uiItem);
CAF_ASSERT(!this->contains(uiItem)); CAF_ASSERT(!this->contains(uiItem));
m_ordering.push_back(std::make_pair(uiItem, layout));
m_ordering.push_back(uiItem);
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void PdmUiOrdering::insert(size_t index, const PdmFieldHandle* field) void PdmUiOrdering::insert(size_t index, const PdmFieldHandle* field, LayoutOptions layout)
{ {
PdmUiFieldHandle* uiItem = const_cast<PdmFieldHandle*>(field)->uiCapability(); PdmUiFieldHandle* uiItem = const_cast<PdmFieldHandle*>(field)->uiCapability();
CAF_ASSERT(uiItem); CAF_ASSERT(uiItem);
CAF_ASSERT(!this->contains(uiItem)); CAF_ASSERT(!this->contains(uiItem));
m_ordering.insert(m_ordering.begin() + index, uiItem); m_ordering.insert(m_ordering.begin() + index, std::make_pair(uiItem, layout));
} }
@ -288,11 +289,59 @@ void PdmUiOrdering::skipRemainingFields(bool doSkip /*= true*/)
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
const std::vector<PdmUiItem*>& PdmUiOrdering::uiItems() const const std::vector<PdmUiItem*> PdmUiOrdering::uiItems() const
{
std::vector<PdmUiItem*> justUiItems;
justUiItems.reserve(m_ordering.size());
for (const FieldAndLayout& itemAndLayout : m_ordering)
{
justUiItems.push_back(itemAndLayout.first);
}
return justUiItems;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const std::vector<PdmUiOrdering::FieldAndLayout>& PdmUiOrdering::uiItemsWithLayout() const
{ {
return m_ordering; return m_ordering;
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int PdmUiOrdering::nrOfColumns() const
{
int maxColumns = 0;
int currentRowColumns = 0;
for (const FieldAndLayout& itemAndLayout : m_ordering)
{
int currentColumnSpan = itemAndLayout.second.totalColumnSpan;
if (currentColumnSpan == LayoutOptions::MAX_COLUMN_SPAN)
{
int minimumFieldColumnSpan = 1;
int minimumLabelColumnSpan = 0;
if (itemAndLayout.first->uiLabelPosition() == PdmUiItemInfo::LEFT)
{
minimumLabelColumnSpan = 1;
}
currentColumnSpan = minimumLabelColumnSpan + minimumFieldColumnSpan;
}
if (itemAndLayout.second.newRow)
{
currentRowColumns = currentColumnSpan;
}
else
{
currentRowColumns += currentColumnSpan;
}
maxColumns = std::max(maxColumns, currentRowColumns);
}
return maxColumns;
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------

View File

@ -55,24 +55,37 @@ class PdmObjectHandle;
class PdmUiOrdering class PdmUiOrdering
{ {
public: public:
struct LayoutOptions
{
static const int MAX_COLUMN_SPAN = -1;
LayoutOptions(bool newRow = true, int totalColumnSpan = MAX_COLUMN_SPAN, int leftLabelColumnSpan = MAX_COLUMN_SPAN)
: newRow(newRow), totalColumnSpan(totalColumnSpan), leftLabelColumnSpan(leftLabelColumnSpan)
{}
bool newRow;
int totalColumnSpan;
int leftLabelColumnSpan;
};
typedef std::pair<PdmUiItem*, LayoutOptions> FieldAndLayout;
PdmUiOrdering(): m_skipRemainingFields(false) { }; PdmUiOrdering(): m_skipRemainingFields(false) { };
virtual ~PdmUiOrdering(); virtual ~PdmUiOrdering();
PdmUiOrdering(const PdmUiOrdering&) = delete; PdmUiOrdering(const PdmUiOrdering&) = delete;
PdmUiOrdering& operator=(const PdmUiOrdering&) = delete; PdmUiOrdering& operator=(const PdmUiOrdering&) = delete;
void add(const PdmFieldHandle* field); void add(const PdmFieldHandle* field, LayoutOptions layout = LayoutOptions());
void add(const PdmObjectHandle* obj); void add(const PdmObjectHandle* obj, LayoutOptions layout = LayoutOptions());
bool insertBeforeGroup(const QString& groupId, const PdmFieldHandle* fieldToInsert); bool insertBeforeGroup(const QString& groupId, const PdmFieldHandle* fieldToInsert, LayoutOptions layout = LayoutOptions());
bool insertBeforeItem(const PdmUiItem* item, const PdmFieldHandle* fieldToInsert); bool insertBeforeItem(const PdmUiItem* item, const PdmFieldHandle* fieldToInsert, LayoutOptions layout = LayoutOptions());
PdmUiGroup* addNewGroup(const QString& displayName); PdmUiGroup* addNewGroup(const QString& displayName, LayoutOptions layout = LayoutOptions());
PdmUiGroup* createGroupBeforeGroup(const QString& groupId, const QString& displayName); PdmUiGroup* createGroupBeforeGroup(const QString& groupId, const QString& displayName, LayoutOptions layout = LayoutOptions());
PdmUiGroup* createGroupBeforeItem(const PdmUiItem* item, const QString& displayName); PdmUiGroup* createGroupBeforeItem(const PdmUiItem* item, const QString& displayName, LayoutOptions layout = LayoutOptions());
PdmUiGroup* addNewGroupWithKeyword(const QString& displayName, const QString& groupKeyword); PdmUiGroup* addNewGroupWithKeyword(const QString& displayName, const QString& groupKeyword, LayoutOptions layout = LayoutOptions());
PdmUiGroup* createGroupWithIdBeforeGroup(const QString& groupId, const QString& displayName, const QString& newGroupId); PdmUiGroup* createGroupWithIdBeforeGroup(const QString& groupId, const QString& displayName, const QString& newGroupId, LayoutOptions layout = LayoutOptions());
PdmUiGroup* createGroupWithIdBeforeItem(const PdmUiItem* item, const QString& displayName, const QString& newGroupId); PdmUiGroup* createGroupWithIdBeforeItem(const PdmUiItem* item, const QString& displayName, const QString& newGroupId, LayoutOptions layout = LayoutOptions());
PdmUiGroup* findGroup(const QString& groupId) const; PdmUiGroup* findGroup(const QString& groupId) const;
@ -80,9 +93,11 @@ public:
// Pdm internal methods // Pdm internal methods
const std::vector<PdmUiItem*>& uiItems() const; const std::vector<PdmUiItem*> uiItems() const;
bool contains(const PdmUiItem* item) const; const std::vector<FieldAndLayout>& uiItemsWithLayout() const;
bool isIncludingRemainingFields() const; int nrOfColumns() const;
bool contains(const PdmUiItem* item) const;
bool isIncludingRemainingFields() const;
protected: protected:
@ -98,10 +113,10 @@ protected:
PositionFound findItemPosition(const PdmUiItem* item) const; PositionFound findItemPosition(const PdmUiItem* item) const;
private: private:
void insert(size_t index, const PdmFieldHandle* field); void insert(size_t index, const PdmFieldHandle* field, LayoutOptions layout = LayoutOptions());
PdmUiGroup* insertNewGroupWithKeyword(size_t index, const QString& displayName, const QString& groupKeyword); PdmUiGroup* insertNewGroupWithKeyword(size_t index, const QString& displayName, const QString& groupKeyword, LayoutOptions layout = LayoutOptions());
std::vector<PdmUiItem*> m_ordering; ///< The order of groups and fields std::vector<FieldAndLayout> m_ordering; ///< The order of groups and fields
std::vector<PdmUiGroup*> m_createdGroups; ///< Owned PdmUiGroups, for memory management only std::vector<PdmUiGroup*> m_createdGroups; ///< Owned PdmUiGroups, for memory management only
bool m_skipRemainingFields; bool m_skipRemainingFields;
}; };

View File

@ -151,19 +151,21 @@ QWidget* CustomObjectEditor::createWidget(QWidget* parent)
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void CustomObjectEditor::recursivelyConfigureAndUpdateTopLevelUiItems(const std::vector<PdmUiItem*>& topLevelUiItems, const QString& uiConfigName) void CustomObjectEditor::recursivelyConfigureAndUpdateTopLevelUiOrdering(const PdmUiOrdering& topLevelUiOrdering, const QString& uiConfigName)
{ {
resetCellId(); resetCellId();
QWidget* previousTabOrderWidget = nullptr; QWidget* previousTabOrderWidget = nullptr;
const std::vector<PdmUiOrdering::FieldAndLayout>& topLevelUiItems = topLevelUiOrdering.uiItemsWithLayout();
for (size_t i = 0; i < topLevelUiItems.size(); ++i) for (size_t i = 0; i < topLevelUiItems.size(); ++i)
{ {
if (topLevelUiItems[i]->isUiHidden(uiConfigName)) continue; if (topLevelUiItems[i].first->isUiHidden(uiConfigName)) continue;
if (topLevelUiItems[i]->isUiGroup()) if (topLevelUiItems[i].first->isUiGroup())
{ {
PdmUiGroup* group = static_cast<PdmUiGroup*>(topLevelUiItems[i]); PdmUiGroup* group = static_cast<PdmUiGroup*>(topLevelUiItems[i].first);
QMinimizePanel* groupBox = findOrCreateGroupBox(this->widget(), group, uiConfigName); QMinimizePanel* groupBox = findOrCreateGroupBox(this->widget(), group, uiConfigName);
/// Insert the group box at the correct position of the parent layout /// Insert the group box at the correct position of the parent layout
@ -171,8 +173,7 @@ void CustomObjectEditor::recursivelyConfigureAndUpdateTopLevelUiItems(const std:
std::pair<int, int> rowCol = rowAndColumn(nextCellId); std::pair<int, int> rowCol = rowAndColumn(nextCellId);
m_layout->addWidget(groupBox, rowCol.first, rowCol.second, 1, 1); m_layout->addWidget(groupBox, rowCol.first, rowCol.second, 1, 1);
const std::vector<PdmUiItem*>& groupChildren = group->uiItems(); recursivelyConfigureAndUpdateUiOrderingInGridLayoutColumn(*group, groupBox->contentFrame(), uiConfigName);
recursivelyConfigureAndUpdateUiItemsInGridLayoutColumn(groupChildren, groupBox->contentFrame(), uiConfigName);
} }
// NB! Only groups at top level are handled, fields at top level are not added to layout // NB! Only groups at top level are handled, fields at top level are not added to layout

View File

@ -78,8 +78,8 @@ public:
private: private:
virtual QWidget* createWidget(QWidget* parent) override; virtual QWidget* createWidget(QWidget* parent) override;
virtual void recursivelyConfigureAndUpdateTopLevelUiItems(const std::vector<PdmUiItem*>& topLevelUiItems, virtual void recursivelyConfigureAndUpdateTopLevelUiOrdering(const PdmUiOrdering& topLevelUiOrdering,
const QString& uiConfigName) override; const QString& uiConfigName) override;
bool isAreaAvailable(int row, int column, int rowSpan, int columnSpan) const; bool isAreaAvailable(int row, int column, int rowSpan, int columnSpan) const;
bool isCellIdAvailable(int cellId) const; bool isCellIdAvailable(int cellId) const;

View File

@ -27,6 +27,7 @@
#include "cafPdmReferenceHelper.h" #include "cafPdmReferenceHelper.h"
#include "cafPdmUiComboBoxEditor.h" #include "cafPdmUiComboBoxEditor.h"
#include "cafPdmUiFilePathEditor.h" #include "cafPdmUiFilePathEditor.h"
#include "cafPdmUiOrdering.h"
#include "cafPdmUiItem.h" #include "cafPdmUiItem.h"
#include "cafPdmUiListEditor.h" #include "cafPdmUiListEditor.h"
#include "cafPdmUiPropertyView.h" #include "cafPdmUiPropertyView.h"
@ -106,6 +107,7 @@ public:
caf::PdmField<double> m_doubleField; caf::PdmField<double> m_doubleField;
caf::PdmField<int> m_intField; caf::PdmField<int> m_intField;
caf::PdmField<QString> m_textField; caf::PdmField<QString> m_textField;
caf::PdmProxyValueField<double> m_proxyDoubleField; caf::PdmProxyValueField<double> m_proxyDoubleField;
caf::PdmField<caf::FilePath> m_fileName; caf::PdmField<caf::FilePath> m_fileName;
caf::PdmField<std::vector<caf::FilePath>> m_fileNameList; caf::PdmField<std::vector<caf::FilePath>> m_fileNameList;
@ -218,7 +220,6 @@ protected:
{ {
uiOrdering.add(&m_doubleField); uiOrdering.add(&m_doubleField);
uiOrdering.add(&m_intField); uiOrdering.add(&m_intField);
QString dynamicGroupName = QString("Dynamic Group Text (%1)").arg(m_intField); QString dynamicGroupName = QString("Dynamic Group Text (%1)").arg(m_intField);
caf::PdmUiGroup* group = uiOrdering.addNewGroupWithKeyword(dynamicGroupName, "MyTest"); caf::PdmUiGroup* group = uiOrdering.addNewGroupWithKeyword(dynamicGroupName, "MyTest");
@ -230,6 +231,151 @@ protected:
CAF_PDM_SOURCE_INIT(SmallDemoPdmObject, "SmallDemoPdmObject"); CAF_PDM_SOURCE_INIT(SmallDemoPdmObject, "SmallDemoPdmObject");
class SmallGridDemoPdmObject : public caf::PdmObject
{
CAF_PDM_HEADER_INIT;
public:
SmallGridDemoPdmObject()
{
CAF_PDM_InitObject("Small Grid Demo Object", "", "This object is a demo of the CAF framework", "This object is a demo of the CAF framework");
CAF_PDM_InitField(&m_intFieldStandard, "Standard", 0, "Standard", "", "Enter some small number here", "This is a place you can enter a small integer value if you want");
CAF_PDM_InitField(&m_intFieldUseFullSpace, "FullSpace", 0, "Use Full Space For Both", "", "Enter some small number here", "This is a place you can enter a small integer value if you want");
CAF_PDM_InitField(&m_intFieldUseFullSpaceLabel, "FullSpaceLabel", 0, "Total 3, Label MAX", "", "Enter some small number here", "This is a place you can enter a small integer value if you want");
CAF_PDM_InitField(&m_intFieldUseFullSpaceField, "FullSpaceField", 0, "Total MAX, Label 1", "", "Enter some small number here", "This is a place you can enter a small integer value if you want");
CAF_PDM_InitField(&m_intFieldWideLabel,"WideLabel", 0, "Wide Label", "", "Enter some small number here", "This is a place you can enter a small integer value if you want");
CAF_PDM_InitField(&m_intFieldWideField,"WideField", 0, "Wide Field", "", "Enter some small number here", "This is a place you can enter a small integer value if you want");
CAF_PDM_InitField(&m_intFieldLeft, "LeftField", 0, "Left Field", "", "Enter some small number here", "This is a place you can enter a small integer value if you want");
CAF_PDM_InitField(&m_intFieldRight, "RightField", 0, "Right Field With More Text", "", "Enter some small number here", "This is a place you can enter a small integer value if you want");
CAF_PDM_InitField(&m_intFieldWideBoth, "WideBoth", 0, "Wide Both", "", "Enter some small number here", "This is a place you can enter a small integer value if you want");
CAF_PDM_InitField(&m_intFieldWideBoth2, "WideBoth2", 0, "Wide Both", "", "Enter some small number here", "This is a place you can enter a small integer value if you want");
CAF_PDM_InitField(&m_intFieldLeft2, "LeftFieldInGrp", 0, "Left Field", "", "Enter some small number here", "This is a place you can enter a small integer value if you want");
CAF_PDM_InitField(&m_intFieldCenter, "CenterFieldInGrp", 0, "Center Field", "", "Enter some small number here", "This is a place you can enter a small integer value if you want");
CAF_PDM_InitField(&m_intFieldRight2, "RightFieldInGrp", 0, "Right Field", "", "Enter some small number here", "This is a place you can enter a small integer value if you want");
CAF_PDM_InitField(&m_intFieldLabelTop, "FieldLabelTop", 0, "Field Label Top", "", "Enter some small number here", "This is a place you can enter a small integer value if you want");
m_intFieldLabelTop.uiCapability()->setUiLabelPosition(caf::PdmUiItemInfo::TOP);
CAF_PDM_InitField(&m_stringFieldLabelHidden, "FieldLabelHidden", QString("Hidden Label Field"), "Field Label Hidden", "", "Enter some small number here", "This is a place you can enter a small integer value if you want");
m_stringFieldLabelHidden.uiCapability()->setUiLabelPosition(caf::PdmUiItemInfo::HIDDEN);
CAF_PDM_InitField(&m_intFieldWideBothAuto, "WideBothAuto", 0, "Wide ", "", "Enter some small number here", "This is a place you can enter a small integer value if you want");
CAF_PDM_InitField(&m_intFieldLeftAuto, "LeftFieldInGrpAuto", 0, "Left Field", "", "Enter some small number here", "This is a place you can enter a small integer value if you want");
CAF_PDM_InitField(&m_intFieldCenterAuto, "CenterFieldInGrpAuto", 0, "Center Field", "", "Enter some small number here", "This is a place you can enter a small integer value if you want");
CAF_PDM_InitField(&m_intFieldRightAuto, "RightFieldInGrpAuto", 0, "Right Field", "", "Enter some small number here", "This is a place you can enter a small integer value if you want");
CAF_PDM_InitField(&m_intFieldLabelTopAuto, "FieldLabelTopAuto", 0, "Field Label Top", "", "Enter some small number here", "This is a place you can enter a small integer value if you want");
m_intFieldLabelTopAuto.uiCapability()->setUiLabelPosition(caf::PdmUiItemInfo::TOP);
CAF_PDM_InitField(&m_stringFieldLabelHiddenAuto, "FieldLabelHiddenAuto", QString("Hidden Label Field"), "Field Label Hidden", "", "Enter some small number here", "This is a place you can enter a small integer value if you want");
m_stringFieldLabelHiddenAuto.uiCapability()->setUiLabelPosition(caf::PdmUiItemInfo::HIDDEN);
CAF_PDM_InitField(&m_intFieldLeftOfGroup, "FieldLeftOfGrp", 0, "Left of group", "", "Enter some small number here", "This is a place you can enter a small integer value if you want");
CAF_PDM_InitField(&m_intFieldRightOfGroup, "FieldRightOfGrp", 0, "Right of group wide label", "", "Enter some small number here", "This is a place you can enter a small integer value if you want");
CAF_PDM_InitField(&m_intFieldInsideGroup1, "FieldInGrp1", 0, "Inside Group", "", "Enter some small number here", "This is a place you can enter a small integer value if you want");
CAF_PDM_InitField(&m_intFieldInsideGroup2, "FieldInGrp2", 0, "Inside Group", "", "Enter some small number here", "This is a place you can enter a small integer value if you want");
CAF_PDM_InitField(&m_intFieldInsideGroup3, "FieldInGrp3", 0, "Inside Group", "", "Enter some small number here", "This is a place you can enter a small integer value if you want");
CAF_PDM_InitField(&m_intFieldInsideGroup4, "FieldInGrp4", 0, "Inside Group", "", "Enter some small number here", "This is a place you can enter a small integer value if you want");
CAF_PDM_InitField(&m_intFieldInsideGroup5, "FieldInGrp5", 0, "Inside Group", "", "Enter some small number here", "This is a place you can enter a small integer value if you want");
CAF_PDM_InitField(&m_intFieldInsideGroup6, "FieldInGrp6", 0, "Inside Group", "", "Enter some small number here", "This is a place you can enter a small integer value if you want");
}
// Outside group
caf::PdmField<int> m_intFieldStandard;
caf::PdmField<int> m_intFieldUseFullSpace;
caf::PdmField<int> m_intFieldUseFullSpaceLabel;
caf::PdmField<int> m_intFieldUseFullSpaceField;
caf::PdmField<int> m_intFieldWideLabel;
caf::PdmField<int> m_intFieldWideField;
caf::PdmField<int> m_intFieldWideBoth;
caf::PdmField<int> m_intFieldLeft;
caf::PdmField<int> m_intFieldRight;
// First group
caf::PdmField<int> m_intFieldWideBoth2;
caf::PdmField<int> m_intFieldLeft2;
caf::PdmField<int> m_intFieldCenter;
caf::PdmField<int> m_intFieldRight2;
caf::PdmField<int> m_intFieldLabelTop;
caf::PdmField<QString> m_stringFieldLabelHidden;
// Auto group
caf::PdmField<int> m_intFieldWideBothAuto;
caf::PdmField<int> m_intFieldLeftAuto;
caf::PdmField<int> m_intFieldCenterAuto;
caf::PdmField<int> m_intFieldRightAuto;
caf::PdmField<int> m_intFieldLabelTopAuto;
caf::PdmField<QString> m_stringFieldLabelHiddenAuto;
// Combination with groups
caf::PdmField<int> m_intFieldLeftOfGroup;
caf::PdmField<int> m_intFieldRightOfGroup;
caf::PdmField<int> m_intFieldInsideGroup1;
caf::PdmField<int> m_intFieldInsideGroup2;
// Side-by-side groups
caf::PdmField<int> m_intFieldInsideGroup3;
caf::PdmField<int> m_intFieldInsideGroup4;
caf::PdmField<int> m_intFieldInsideGroup5;
caf::PdmField<int> m_intFieldInsideGroup6;
protected:
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
virtual void defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering) override
{
uiOrdering.add(&m_intFieldStandard);
uiOrdering.add(&m_intFieldUseFullSpace, caf::PdmUiOrdering::LayoutOptions(true, caf::PdmUiOrdering::LayoutOptions::MAX_COLUMN_SPAN, caf::PdmUiOrdering::LayoutOptions::MAX_COLUMN_SPAN));
uiOrdering.add(&m_intFieldUseFullSpaceLabel, caf::PdmUiOrdering::LayoutOptions(true, 3, caf::PdmUiOrdering::LayoutOptions::MAX_COLUMN_SPAN));
uiOrdering.add(&m_intFieldUseFullSpaceField, caf::PdmUiOrdering::LayoutOptions(true, caf::PdmUiOrdering::LayoutOptions::MAX_COLUMN_SPAN, 1));
uiOrdering.add(&m_intFieldWideLabel, caf::PdmUiOrdering::LayoutOptions(true, 4, 3));
uiOrdering.add(&m_intFieldWideField, caf::PdmUiOrdering::LayoutOptions(true, 4, 1));
uiOrdering.add(&m_intFieldLeft, caf::PdmUiOrdering::LayoutOptions(true));
uiOrdering.add(&m_intFieldRight, caf::PdmUiOrdering::LayoutOptions(false));
uiOrdering.add(&m_intFieldWideBoth, caf::PdmUiOrdering::LayoutOptions(true, 4, 2));
QString dynamicGroupName = QString("Dynamic Group Text (%1)").arg(m_intFieldStandard);
caf::PdmUiGroup* group = uiOrdering.addNewGroup("Wide Group", { true, 4 });
group->add(&m_intFieldWideBoth2, caf::PdmUiOrdering::LayoutOptions(true, 6, 3));
group->add(&m_intFieldLeft2, caf::PdmUiOrdering::LayoutOptions(true));
group->add(&m_intFieldCenter, caf::PdmUiOrdering::LayoutOptions(false));
group->add(&m_intFieldRight2, caf::PdmUiOrdering::LayoutOptions(false));
group->add(&m_intFieldLabelTop, caf::PdmUiOrdering::LayoutOptions(true, 6));
group->add(&m_stringFieldLabelHidden, caf::PdmUiOrdering::LayoutOptions(true, 6));
caf::PdmUiGroup* autoGroup = uiOrdering.addNewGroup("Automatic Full Width Group", caf::PdmUiOrdering::LayoutOptions(true));
autoGroup->add(&m_intFieldWideBothAuto, caf::PdmUiOrdering::LayoutOptions(true));
autoGroup->add(&m_intFieldLeftAuto, caf::PdmUiOrdering::LayoutOptions(true));
autoGroup->add(&m_intFieldCenterAuto, false);
autoGroup->add(&m_intFieldRightAuto, caf::PdmUiOrdering::LayoutOptions(false));
autoGroup->add(&m_intFieldLabelTopAuto, true);
autoGroup->add(&m_stringFieldLabelHiddenAuto, true);
uiOrdering.add(&m_intFieldLeftOfGroup);
caf::PdmUiGroup* group2 = uiOrdering.addNewGroup("Right Group", caf::PdmUiOrdering::LayoutOptions(false, 2, 0));
group2->setEnableFrame(false);
group2->add(&m_intFieldInsideGroup1);
caf::PdmUiGroup* group3 = uiOrdering.addNewGroup("Narrow L", caf::PdmUiOrdering::LayoutOptions(true, 1));
group3->add(&m_intFieldInsideGroup2);
uiOrdering.add(&m_intFieldRightOfGroup, caf::PdmUiOrdering::LayoutOptions(false, 3, 2));
caf::PdmUiGroup* groupL = uiOrdering.addNewGroup("Left Group", caf::PdmUiOrdering::LayoutOptions(true, 1));
groupL->add(&m_intFieldInsideGroup3);
groupL->add(&m_intFieldInsideGroup5);
caf::PdmUiGroup* groupR = uiOrdering.addNewGroup("Right Wide Group", caf::PdmUiOrdering::LayoutOptions(false, 3));
groupR->setEnableFrame(false);
groupR->add(&m_intFieldInsideGroup4);
groupR->add(&m_intFieldInsideGroup6);
}
};
CAF_PDM_SOURCE_INIT(SmallGridDemoPdmObject, "SmallGridDemoPdmObject");
class SmallDemoPdmObjectA: public caf::PdmObject class SmallDemoPdmObjectA: public caf::PdmObject
{ {
CAF_PDM_HEADER_INIT; CAF_PDM_HEADER_INIT;
@ -724,6 +870,9 @@ void MainWindow::buildTestModel()
SmallDemoPdmObjectA* smallObj2 = new SmallDemoPdmObjectA; SmallDemoPdmObjectA* smallObj2 = new SmallDemoPdmObjectA;
m_testRoot->objects.push_back(smallObj2); m_testRoot->objects.push_back(smallObj2);
SmallGridDemoPdmObject* smallGridObj = new SmallGridDemoPdmObject;
m_testRoot->objects.push_back(smallGridObj);
DemoPdmObject* demoObj2 = new DemoPdmObject; DemoPdmObject* demoObj2 = new DemoPdmObject;
demoObject->m_textField = "Mitt Demo Obj"; demoObject->m_textField = "Mitt Demo Obj";

View File

@ -44,6 +44,10 @@
#include <QPixmap> #include <QPixmap>
#include <QPushButton> #include <QPushButton>
#include <QResizeEvent> #include <QResizeEvent>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <algorithm>
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
@ -119,6 +123,7 @@ static const QIcon& expandUpIcon()
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
QMinimizePanel::QMinimizePanel(QWidget* parent/*=0*/) QMinimizePanel::QMinimizePanel(QWidget* parent/*=0*/)
: QWidget(parent)
{ {
this->initialize(""); this->initialize("");
} }
@ -127,10 +132,149 @@ QMinimizePanel::QMinimizePanel(QWidget* parent/*=0*/)
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
QMinimizePanel::QMinimizePanel(const QString &title, QWidget* parent/*=0*/) QMinimizePanel::QMinimizePanel(const QString &title, QWidget* parent/*=0*/)
: QWidget(parent)
{ {
this->initialize(title); this->initialize(title);
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QMinimizePanel::~QMinimizePanel()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QFrame* QMinimizePanel::contentFrame()
{
return m_contentFrame;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void QMinimizePanel::setTitle(const QString& title)
{
m_titleLabel->setText(title);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString QMinimizePanel::title() const
{
return m_titleLabel->text();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void QMinimizePanel::enableFrame(bool showFrame)
{
if (showFrame)
{
m_titleFrame->show();
m_titleLabel->show();
m_collapseButton->show();
m_contentFrame->setFrameStyle(QFrame::StyledPanel | QFrame::Plain);
m_contentFrame->setPalette(m_contentPalette);
m_contentFrame->setAttribute(Qt::WA_SetPalette, true);
}
else
{
m_titleFrame->hide();
m_titleLabel->hide();
m_collapseButton->hide();
m_contentFrame->setFrameStyle(QFrame::NoFrame);
if (parentWidget())
{
m_contentFrame->setPalette(parentWidget()->palette());
}
m_contentFrame->setAttribute(Qt::WA_SetPalette, false);
}
QWidget::update();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QSize QMinimizePanel::minimumSizeHint() const
{
return calculateSizeHint(true);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QSize QMinimizePanel::sizeHint() const
{
return calculateSizeHint(false);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
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);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void QMinimizePanel::toggleExpanded()
{
setExpanded(m_contentFrame->isHidden());
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void QMinimizePanel::resizeEvent(QResizeEvent *resizeEv )
{
QWidget::updateGeometry();
int width = resizeEv->size().width();
int heigth = resizeEv->size().height();
int labelHeight = m_titleLabel->sizeHint().height();
int titleHeight = labelHeight + 8;
int buttonSize = titleHeight - 2;
int contentHeightOffset = 0;
if (!m_titleFrame->isHidden())
{
m_titleFrame->setGeometry(0, 0, width, titleHeight);
m_titleLabel->setGeometry(4, titleHeight - labelHeight - 4, width - 4 - buttonSize - 1, labelHeight);
m_collapseButton->setGeometry(width - buttonSize - 1, 1, buttonSize, buttonSize);
contentHeightOffset = titleHeight - 1;
}
m_contentFrame->setGeometry(0, contentHeightOffset, width, heigth - contentHeightOffset);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool QMinimizePanel::event(QEvent* event)
{
if (event->type() == QEvent::LayoutRequest)
{
this->QWidget::updateGeometry();
}
return this->QWidget::event(event);
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -158,7 +302,7 @@ void QMinimizePanel::initialize(const QString &title)
m_titleLabel->setPalette(titleLabelPalette); m_titleLabel->setPalette(titleLabelPalette);
m_collapseButton = new QPushButton( m_titleFrame); m_collapseButton = new QPushButton(m_titleFrame);
m_collapseButton->setFlat(true); m_collapseButton->setFlat(true);
m_collapseButton->setIcon(expandUpIcon()); m_collapseButton->setIcon(expandUpIcon());
m_collapseButton->setDefault(false); m_collapseButton->setDefault(false);
@ -168,49 +312,30 @@ void QMinimizePanel::initialize(const QString &title)
m_contentFrame->setFrameStyle(QFrame::StyledPanel | QFrame::Plain); m_contentFrame->setFrameStyle(QFrame::StyledPanel | QFrame::Plain);
m_contentFrame->setAutoFillBackground(true); m_contentFrame->setAutoFillBackground(true);
QPalette contentFramePalette = m_contentFrame->palette(); m_contentPalette = m_contentFrame->palette();
contentFramePalette.setBrush(QPalette::Window, QColor(255,250,250,85)); m_contentPalette.setBrush(QPalette::Window, QColor(255, 250, 250, 85));
m_contentFrame->setPalette(contentFramePalette); m_contentFrame->setPalette(m_contentPalette);
connect(m_collapseButton, SIGNAL(clicked()),this, SLOT(toggleExpanded()) ); connect(m_collapseButton, SIGNAL(clicked()), this, SLOT(toggleExpanded()));
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
QMinimizePanel::~QMinimizePanel() QSize QMinimizePanel::calculateSizeHint(bool minimumSizeHint) const
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void QMinimizePanel::setTitle(const QString& title)
{
m_titleLabel->setText(title);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString QMinimizePanel::title() const
{
return m_titleLabel->text();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QSize QMinimizePanel::sizeHint() 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->isHidden()) if (!m_contentFrame->isHidden())
{ {
QSize titleBarMin(0, labelSize.height() + 8); int titleHeight = 0;
QSize contentsMin(m_contentFrame->sizeHint()); if (!m_titleFrame->isHidden())
{
titleHeight = labelSize.height() + 8;
}
QSize titleBarMin(0, titleHeight);
QSize contentsMin(minimumSizeHint ? m_contentFrame->minimumSizeHint() : m_contentFrame->sizeHint());
QSize total = contentsMin.expandedTo(titleBarMin); QSize total = contentsMin.expandedTo(titleBarMin);
total.rheight() += titleBarMin.height(); total.rheight() += titleBarMin.height();
@ -218,85 +343,9 @@ QSize QMinimizePanel::sizeHint() const
} }
else else
{ {
// Retain width when collapsing the field
QSize contentsMin(minimumSizeHint ? m_contentFrame->minimumSizeHint() : m_contentFrame->sizeHint());
titleBarHint.rwidth() = std::max(titleBarHint.width(), contentsMin.width());
return titleBarHint; return titleBarHint;
} }
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
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);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void QMinimizePanel::toggleExpanded()
{
setExpanded(m_contentFrame->isHidden());
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QSize QMinimizePanel::minimumSizeHint() const
{
QSize labelSize = m_titleLabel->sizeHint();
QSize titleBarHint = labelSize + QSize(4 + labelSize.height() + 8 - 2 + 1, 8);
if (!m_contentFrame->isHidden())
{
QSize titleBarMin(0, labelSize.height() + 8 );
QSize contentsMin(m_contentFrame->minimumSizeHint());
QSize total = contentsMin.expandedTo(titleBarMin);
total.rheight() += titleBarMin.height();
return total;
}
else
{
return titleBarHint;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void QMinimizePanel::resizeEvent(QResizeEvent *resizeEv )
{
QWidget::updateGeometry();
int width = resizeEv->size().width();
int heigth = resizeEv->size().height();
int labelHeight = m_titleLabel->sizeHint().height();
int titleHeight = labelHeight + 8;
int buttonSize = titleHeight - 2;
m_titleFrame->setGeometry(0,0,width, titleHeight);
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));
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool QMinimizePanel::event(QEvent* event)
{
if (event->type() == QEvent::LayoutRequest)
{
this->QWidget::updateGeometry();
}
return this->QWidget::event(event);
}

View File

@ -40,6 +40,7 @@
class QFrame; class QFrame;
class QLabel; class QLabel;
class QPalette;
class QPushButton; class QPushButton;
//================================================================================================== //==================================================================================================
@ -55,10 +56,12 @@ public:
explicit QMinimizePanel(const QString &title, QWidget* parent=nullptr); explicit QMinimizePanel(const QString &title, QWidget* parent=nullptr);
~QMinimizePanel(); ~QMinimizePanel();
QFrame* contentFrame() { return m_contentFrame; } QFrame* contentFrame();
void setTitle (const QString& title); void setTitle (const QString& title);
QString title() const; QString title() const;
void enableFrame(bool showFrame);
virtual QSize minimumSizeHint() const override;
virtual QSize sizeHint() const override; virtual QSize sizeHint() const override;
public slots: public slots:
@ -69,17 +72,19 @@ signals:
void expandedChanged(bool isExpanded); void expandedChanged(bool isExpanded);
public: public:
virtual QSize minimumSizeHint() const override;
protected: protected:
QFrame* m_titleFrame; QFrame* m_titleFrame;
QLabel* m_titleLabel; QLabel* m_titleLabel;
QPushButton* m_collapseButton; QPushButton* m_collapseButton;
QFrame* m_contentFrame; QFrame* m_contentFrame;
QPalette m_contentPalette;
virtual void resizeEvent(QResizeEvent *) override; virtual void resizeEvent(QResizeEvent *) override;
virtual bool event(QEvent* event) override; // To catch QEvent::LayoutRequest virtual bool event(QEvent* event) override; // To catch QEvent::LayoutRequest
private: private:
void initialize(const QString &title); void initialize(const QString &title);
QSize calculateSizeHint(bool minimumSizeHint) const;
}; };

View File

@ -101,11 +101,11 @@ QWidget* PdmUiDefaultObjectEditor::createWidget(QWidget* parent)
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void PdmUiDefaultObjectEditor::recursivelyConfigureAndUpdateTopLevelUiItems(const std::vector<PdmUiItem*>& topLevelUiItems, const QString& uiConfigName) void PdmUiDefaultObjectEditor::recursivelyConfigureAndUpdateTopLevelUiOrdering(const PdmUiOrdering& topLevelUiOrdering, const QString& uiConfigName)
{ {
CAF_ASSERT(this->widget()); CAF_ASSERT(this->widget());
recursivelyConfigureAndUpdateUiItemsInGridLayoutColumn(topLevelUiItems, this->widget(), uiConfigName); recursivelyConfigureAndUpdateUiOrderingInGridLayoutColumn(topLevelUiOrdering, this->widget(), uiConfigName);
} }
} // end namespace caf } // end namespace caf

View File

@ -64,8 +64,8 @@ public:
private: private:
virtual QWidget* createWidget(QWidget* parent) override; virtual QWidget* createWidget(QWidget* parent) override;
virtual void recursivelyConfigureAndUpdateTopLevelUiItems(const std::vector<PdmUiItem*>& topLevelUiItems, virtual void recursivelyConfigureAndUpdateTopLevelUiOrdering(const PdmUiOrdering& topLevelUiItems,
const QString& uiConfigName) override; const QString& uiConfigName) override;
}; };

View File

@ -45,6 +45,8 @@
#include "cafPdmUiOrdering.h" #include "cafPdmUiOrdering.h"
#include "cafPdmXmlObjectHandle.h" #include "cafPdmXmlObjectHandle.h"
#include "cafAssert.h"
#include "QMinimizePanel.h" #include "QMinimizePanel.h"
#include <QGridLayout> #include <QGridLayout>
@ -71,38 +73,69 @@ caf::PdmUiFormLayoutObjectEditor::~PdmUiFormLayoutObjectEditor()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void caf::PdmUiFormLayoutObjectEditor::recursivelyConfigureAndUpdateUiItemsInGridLayoutColumn(const std::vector<PdmUiItem*>& uiItems, QWidget* containerWidgetWithGridLayout, const QString& uiConfigName) void caf::PdmUiFormLayoutObjectEditor::recursivelyConfigureAndUpdateUiOrderingInGridLayoutColumn(
const PdmUiOrdering& uiOrdering,
QWidget* containerWidgetWithGridLayout,
const QString& uiConfigName)
{ {
CAF_ASSERT(containerWidgetWithGridLayout); CAF_ASSERT(containerWidgetWithGridLayout);
int currentRowIndex = 0; int currentRowIndex = -1;
QWidget* previousTabOrderWidget = nullptr; QWidget* previousTabOrderWidget = nullptr;
// Currently, only QGridLayout is supported // Currently, only QGridLayout is supported
QGridLayout* parentLayout = dynamic_cast<QGridLayout*>(containerWidgetWithGridLayout->layout()); QGridLayout* parentLayout = dynamic_cast<QGridLayout*>(containerWidgetWithGridLayout->layout());
CAF_ASSERT(parentLayout); CAF_ASSERT(parentLayout);
const std::vector<PdmUiOrdering::FieldAndLayout>& uiItems = uiOrdering.uiItemsWithLayout();
int columnsPerRow = uiOrdering.nrOfColumns();
int currentColumn = 0;
int itemsInCurrentRow = 1;
for (size_t i = 0; i < uiItems.size(); ++i) for (size_t i = 0; i < uiItems.size(); ++i)
{ {
if (uiItems[i]->isUiHidden(uiConfigName)) continue; PdmUiItem* currentItem = uiItems[i].first;
PdmUiOrdering::LayoutOptions currentLayout = uiItems[i].second;
int itemColumnSpan = currentLayout.totalColumnSpan;
if (uiItems[i]->isUiGroup()) if (currentRowIndex == -1 || currentLayout.newRow)
{ {
PdmUiGroup* group = static_cast<PdmUiGroup*>(uiItems[i]); currentRowIndex++;
parentLayout->setRowStretch(currentRowIndex, 0);
currentColumn = 0;
itemsInCurrentRow = 1;
for (size_t j = i+1; j < uiItems.size(); ++j)
{
if (uiItems[j].second.newRow) break;
itemsInCurrentRow++;
}
}
if (itemColumnSpan == PdmUiOrdering::LayoutOptions::MAX_COLUMN_SPAN)
{
itemColumnSpan = columnsPerRow / itemsInCurrentRow;
}
if (currentItem->isUiHidden(uiConfigName)) continue;
if (currentItem->isUiGroup())
{
PdmUiGroup* group = static_cast<PdmUiGroup*>(currentItem);
QMinimizePanel* groupBox = findOrCreateGroupBox(containerWidgetWithGridLayout, group, uiConfigName); QMinimizePanel* groupBox = findOrCreateGroupBox(containerWidgetWithGridLayout, group, uiConfigName);
/// 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, currentColumn, 1, itemColumnSpan);
const std::vector<PdmUiItem*>& groupChildren = group->uiItems(); recursivelyConfigureAndUpdateUiOrderingInGridLayoutColumn(*group, groupBox->contentFrame(), uiConfigName);
recursivelyConfigureAndUpdateUiItemsInGridLayoutColumn(groupChildren, groupBox->contentFrame(), uiConfigName);
currentRowIndex++; currentColumn += itemColumnSpan;
} }
else else
{ {
PdmUiFieldHandle* field = dynamic_cast<PdmUiFieldHandle*>(uiItems[i]); PdmUiFieldHandle* field = dynamic_cast<PdmUiFieldHandle*>(currentItem);
PdmUiFieldEditorHandle* fieldEditor = findOrCreateFieldEditor(containerWidgetWithGridLayout, field, uiConfigName); PdmUiFieldEditorHandle* fieldEditor = findOrCreateFieldEditor(containerWidgetWithGridLayout, field, uiConfigName);
@ -116,64 +149,109 @@ void caf::PdmUiFormLayoutObjectEditor::recursivelyConfigureAndUpdateUiItemsInGri
if (fieldCombinedWidget) if (fieldCombinedWidget)
{ {
fieldCombinedWidget->setParent(containerWidgetWithGridLayout); fieldCombinedWidget->setParent(containerWidgetWithGridLayout);
parentLayout->addWidget(fieldCombinedWidget, currentRowIndex, 0, 1, 2); parentLayout->addWidget(fieldCombinedWidget, currentRowIndex, currentColumn, 1, itemColumnSpan);
} }
else else
{ {
PdmUiItemInfo::LabelPosType labelPos = field->uiLabelPosition(uiConfigName); PdmUiItemInfo::LabelPosType labelPos = field->uiLabelPosition(uiConfigName);
bool labelOnTop = (labelPos == PdmUiItemInfo::TOP);
bool editorSpanBoth = labelOnTop;
QWidget* fieldEditorWidget = fieldEditor->editorWidget(); QWidget* fieldEditorWidget = fieldEditor->editorWidget();
if (labelPos != PdmUiItemInfo::HIDDEN)
{
QWidget* fieldLabelWidget = fieldEditor->labelWidget();
if (fieldLabelWidget)
{
fieldLabelWidget->setParent(containerWidgetWithGridLayout);
// Label widget will span two columns if aligned on top
int colSpan = labelOnTop ? 2 : 1;
// If the label is on the side, and the editor can expand vertically, allign the label with the top edge of the editor
if (!labelOnTop && (fieldEditorWidget->sizePolicy().verticalPolicy() & QSizePolicy::ExpandFlag))
parentLayout->addWidget(fieldLabelWidget, currentRowIndex, 0, 1, colSpan, Qt::AlignTop);
else
parentLayout->addWidget(fieldLabelWidget, currentRowIndex, 0, 1, colSpan, Qt::AlignVCenter);
fieldLabelWidget->show();
if (labelOnTop) currentRowIndex++;
}
}
else
{
QWidget* fieldLabelWidget = fieldEditor->labelWidget();
if (fieldLabelWidget) fieldLabelWidget->hide();
editorSpanBoth = true; // To span both columns when there is no label
}
if (fieldEditorWidget) if (fieldEditorWidget)
{ {
fieldEditorWidget->setParent(containerWidgetWithGridLayout); // To make sure this widget has the current group box as parent. // Hide label
if (labelPos == PdmUiItemInfo::HIDDEN)
{
QWidget* fieldLabelWidget = fieldEditor->labelWidget();
if (fieldLabelWidget)
{
fieldLabelWidget->hide();
}
// Label widget will span two columns if aligned on top fieldEditorWidget->setParent(containerWidgetWithGridLayout); // To make sure this widget has the current group box as parent.
int colSpan = editorSpanBoth ? 2 : 1; parentLayout->addWidget(fieldEditorWidget, currentRowIndex, currentColumn, 1, itemColumnSpan, Qt::AlignTop);
int colIndex = editorSpanBoth ? 0 : 1;
parentLayout->addWidget(fieldEditorWidget, currentRowIndex, colIndex, 1, colSpan, Qt::AlignTop);
if (previousTabOrderWidget) QWidget::setTabOrder(previousTabOrderWidget, fieldEditorWidget); currentColumn += itemColumnSpan;
}
else // Add label
{
QWidget* fieldLabelWidget = fieldEditor->labelWidget();
previousTabOrderWidget = fieldEditorWidget; // For label on top we add another layer of QLayouts to avoid messing with the global rows.
if (labelPos == PdmUiItemInfo::TOP)
{
QVBoxLayout* labelAndFieldVLayout = new QVBoxLayout();
parentLayout->addLayout(labelAndFieldVLayout, currentRowIndex, currentColumn, 1, itemColumnSpan, Qt::AlignTop);
if (fieldLabelWidget)
{
labelAndFieldVLayout->addWidget(fieldLabelWidget, 0, Qt::AlignTop);
}
labelAndFieldVLayout->addWidget(fieldEditorWidget, 1, Qt::AlignTop);
currentColumn += itemColumnSpan;
}
else
{
int fieldColumnSpan = currentLayout.totalColumnSpan;
int leftLabelColumnSpan = 0;
if (fieldLabelWidget)
{
leftLabelColumnSpan = currentLayout.leftLabelColumnSpan;
if (fieldColumnSpan == PdmUiOrdering::LayoutOptions::MAX_COLUMN_SPAN &&
leftLabelColumnSpan == PdmUiOrdering::LayoutOptions::MAX_COLUMN_SPAN)
{
// Rounded up half for field. Rest for left label.
fieldColumnSpan = itemColumnSpan / 2 + itemColumnSpan % 2;
leftLabelColumnSpan = itemColumnSpan - fieldColumnSpan;
}
else if (fieldColumnSpan == PdmUiOrdering::LayoutOptions::MAX_COLUMN_SPAN)
{
fieldColumnSpan = itemColumnSpan - leftLabelColumnSpan;
}
else if (leftLabelColumnSpan == PdmUiOrdering::LayoutOptions::MAX_COLUMN_SPAN)
{
fieldColumnSpan = 1;
leftLabelColumnSpan = itemColumnSpan - fieldColumnSpan;
}
else
{
fieldColumnSpan = itemColumnSpan - leftLabelColumnSpan;
}
CAF_ASSERT(fieldColumnSpan >= 1 && "Need at least one column for the field");
fieldColumnSpan = std::max(1, fieldColumnSpan);
fieldLabelWidget->setParent(containerWidgetWithGridLayout);
parentLayout->addWidget(fieldLabelWidget, currentRowIndex, currentColumn, 1, leftLabelColumnSpan, Qt::AlignTop);
// Shift label a bit to make it appear centered on the field. Using Qt::AlignVCenter will
// cause both label and field to appear in the vertical centre of the row.
// That isn't the intention.
int labelHeight = fieldLabelWidget->sizeHint().height();
int fieldHeight = fieldEditorWidget->sizeHint().height();
int heightDiff = std::max(0, fieldHeight - labelHeight);
QMargins contentMargins = fieldLabelWidget->contentsMargins();
contentMargins.setTop(heightDiff / 2);
contentMargins.setBottom(heightDiff / 2);
fieldLabelWidget->setContentsMargins(contentMargins);
}
fieldEditorWidget->setParent(containerWidgetWithGridLayout); // To make sure this widget has the current group box as parent.
parentLayout->addWidget(fieldEditorWidget, currentRowIndex, currentColumn + leftLabelColumnSpan, 1, fieldColumnSpan, Qt::AlignTop);
currentColumn += itemColumnSpan;
}
}
if (previousTabOrderWidget)
{
QWidget::setTabOrder(previousTabOrderWidget, fieldEditorWidget);
}
} }
} }
fieldEditor->updateUi(uiConfigName); fieldEditor->updateUi(uiConfigName);
currentRowIndex++;
} }
} }
} }
// Set last row to stretch
parentLayout->setRowStretch(currentRowIndex, 10);
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -214,9 +292,15 @@ QMinimizePanel* caf::PdmUiFormLayoutObjectEditor::findOrCreateGroupBox(QWidget*
if (it == m_groupBoxes.end()) if (it == m_groupBoxes.end())
{ {
groupBox = new QMinimizePanel(parent); groupBox = new QMinimizePanel(parent);
groupBox->enableFrame(group->enableFrame());
groupBox->setTitle(group->uiName(uiConfigName)); groupBox->setTitle(group->uiName(uiConfigName));
groupBox->setObjectName(group->keyword()); groupBox->setObjectName(group->keyword());
groupBoxLayout = new QGridLayout(); groupBoxLayout = new QGridLayout();
if (!group->enableFrame())
{
groupBoxLayout->setContentsMargins(0, 0, 0, 0);
groupBoxLayout->setHorizontalSpacing(0);
}
groupBox->contentFrame()->setLayout(groupBoxLayout); groupBox->contentFrame()->setLayout(groupBoxLayout);
connect(groupBox, SIGNAL(expandedChanged(bool)), this, SLOT(groupBoxExpandedStateToggled(bool))); connect(groupBox, SIGNAL(expandedChanged(bool)), this, SLOT(groupBoxExpandedStateToggled(bool)));
@ -344,8 +428,7 @@ void caf::PdmUiFormLayoutObjectEditor::configureAndUpdateUi(const QString& uiCon
// Set all group Boxes to be unvisited // Set all group Boxes to be unvisited
m_newGroupBoxes.clear(); m_newGroupBoxes.clear();
const std::vector<PdmUiItem*>& uiItems = config.uiItems(); recursivelyConfigureAndUpdateTopLevelUiOrdering(config, uiConfigName);
recursivelyConfigureAndUpdateTopLevelUiItems(uiItems, uiConfigName);
// Remove all fieldViews not mentioned by the configuration from the layout // Remove all fieldViews not mentioned by the configuration from the layout

View File

@ -38,6 +38,7 @@
#pragma once #pragma once
#include "cafPdmUiObjectEditorHandle.h" #include "cafPdmUiObjectEditorHandle.h"
#include "cafPdmUiOrdering.h"
#include <QPointer> #include <QPointer>
#include <QString> #include <QString>
@ -51,6 +52,7 @@ namespace caf {
class PdmUiFieldEditorHandle; class PdmUiFieldEditorHandle;
class PdmUiGroup; class PdmUiGroup;
class PdmUiOrdering;
//================================================================================================== //==================================================================================================
@ -66,12 +68,12 @@ public:
protected: protected:
/// When overriding this function, use findOrCreateGroupBox() or findOrCreateFieldEditor() for detailed control /// When overriding this function, use findOrCreateGroupBox() or findOrCreateFieldEditor() for detailed control
/// Use recursivelyConfigureAndUpdateUiItemsInGridLayoutColumn() for automatic layout of group and field widgets /// Use recursivelyConfigureAndUpdateUiItemsInGridLayoutColumn() for automatic layout of group and field widgets
virtual void recursivelyConfigureAndUpdateTopLevelUiItems(const std::vector<PdmUiItem*>& topLevelUiItems, virtual void recursivelyConfigureAndUpdateTopLevelUiOrdering(const PdmUiOrdering& topLevelUiOrdering,
const QString& uiConfigName) = 0; const QString& uiConfigName) = 0;
void recursivelyConfigureAndUpdateUiItemsInGridLayoutColumn(const std::vector<PdmUiItem*>& uiItems, void recursivelyConfigureAndUpdateUiOrderingInGridLayoutColumn(const PdmUiOrdering& uiOrdering,
QWidget* containerWidgetWithGridLayout, QWidget* containerWidgetWithGridLayout,
const QString& uiConfigName); const QString& uiConfigName);
QMinimizePanel* findOrCreateGroupBox(QWidget* parent, PdmUiGroup* group, const QString& uiConfigName); QMinimizePanel* findOrCreateGroupBox(QWidget* parent, PdmUiGroup* group, const QString& uiConfigName);
PdmUiFieldEditorHandle* findOrCreateFieldEditor(QWidget* parent, PdmUiFieldHandle* field, const QString& uiConfigName); PdmUiFieldEditorHandle* findOrCreateFieldEditor(QWidget* parent, PdmUiFieldHandle* field, const QString& uiConfigName);