mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Improved default parsing of visible items to establish root items in the tree view
This commit is contained in:
@@ -63,6 +63,7 @@ protected:
|
|||||||
/// Fill up the uiOrdering object with groups and field references to create the gui structure
|
/// Fill up the uiOrdering object with groups and field references to create the gui structure
|
||||||
/// If the uiOrdering is empty, it is interpreted as meaning all fields w/o grouping.
|
/// If the uiOrdering is empty, it is interpreted as meaning all fields w/o grouping.
|
||||||
virtual void defineUiOrdering(QString uiConfigName, PdmUiOrdering& uiOrdering) {}
|
virtual void defineUiOrdering(QString uiConfigName, PdmUiOrdering& uiOrdering) {}
|
||||||
|
friend class PdmUiTreeViewModel;
|
||||||
|
|
||||||
/// Override to customize the tree representations of the object hierarchy.
|
/// Override to customize the tree representations of the object hierarchy.
|
||||||
/// If the PdmUiTreeOrdering is empty, it is interpreted as meaning all fields containing child objects in order
|
/// If the PdmUiTreeOrdering is empty, it is interpreted as meaning all fields containing child objects in order
|
||||||
|
|||||||
@@ -37,6 +37,8 @@
|
|||||||
|
|
||||||
#include "cafPdmUiTreeViewModel.h"
|
#include "cafPdmUiTreeViewModel.h"
|
||||||
|
|
||||||
|
#include "cafPdmChildArrayField.h"
|
||||||
|
#include "cafPdmChildField.h"
|
||||||
#include "cafPdmField.h"
|
#include "cafPdmField.h"
|
||||||
#include "cafPdmObject.h"
|
#include "cafPdmObject.h"
|
||||||
#include "cafPdmUiTreeItemEditor.h"
|
#include "cafPdmUiTreeItemEditor.h"
|
||||||
@@ -70,28 +72,42 @@ void PdmUiTreeViewModel::setPdmItemRoot(PdmUiItem* rootItem)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PdmUiTreeOrdering* newRoot = NULL;
|
PdmUiTreeOrdering* invisibleRoot = NULL;
|
||||||
PdmUiFieldHandle* field = dynamic_cast<PdmUiFieldHandle*> (rootItem);
|
if (rootItem)
|
||||||
|
{
|
||||||
|
std::vector<PdmUiItem*> visibleItems;
|
||||||
|
findFirstVisibleUiItemInAllBranches(rootItem, visibleItems, m_uiConfigName);
|
||||||
|
|
||||||
|
if (visibleItems.size() > 0)
|
||||||
|
{
|
||||||
|
invisibleRoot = new PdmUiTreeOrdering("Invisible Tree Root", "");
|
||||||
|
|
||||||
|
for (size_t i = 0; i < visibleItems.size(); i++)
|
||||||
|
{
|
||||||
|
PdmUiTreeOrdering* nextTreeOrdering = NULL;
|
||||||
|
|
||||||
|
PdmUiFieldHandle* field = dynamic_cast<PdmUiFieldHandle*> (visibleItems[i]);
|
||||||
if (field)
|
if (field)
|
||||||
{
|
{
|
||||||
newRoot = new PdmUiTreeOrdering(field->fieldHandle());
|
nextTreeOrdering = new PdmUiTreeOrdering(field->fieldHandle());
|
||||||
PdmUiObjectHandle::expandUiTree(newRoot, m_uiConfigName);
|
PdmUiObjectHandle::expandUiTree(nextTreeOrdering, m_uiConfigName);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
PdmUiObjectHandle * obj = dynamic_cast<PdmUiObjectHandle*> (rootItem);
|
PdmUiObjectHandle * obj = dynamic_cast<PdmUiObjectHandle*> (visibleItems[i]);
|
||||||
if (obj)
|
if (obj)
|
||||||
{
|
{
|
||||||
newRoot = obj->uiTreeOrdering(m_uiConfigName);
|
nextTreeOrdering = obj->uiTreeOrdering(m_uiConfigName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert( newRoot || rootItem == NULL ); // Only fields, objects or NULL is allowed.
|
assert(nextTreeOrdering);
|
||||||
|
invisibleRoot->appendChild(nextTreeOrdering);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (newRoot) newRoot->debugDump(0);
|
this->resetTree(invisibleRoot);
|
||||||
|
|
||||||
this->resetTree(newRoot);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@@ -689,5 +705,78 @@ QVariant PdmUiTreeViewModel::headerData(int section, Qt::Orientation orientation
|
|||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
/// Do a search recursively to find the first visible object of all child branches
|
||||||
|
/// If the incoming object is visible, this is the only object returned
|
||||||
|
/// defineUiTreeOrdering is used to
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void PdmUiTreeViewModel::findFirstVisibleUiItemInAllBranches(PdmUiItem* uiItem, std::vector<PdmUiItem*>& visibleItems, const QString& uiConfigName)
|
||||||
|
{
|
||||||
|
if (!uiItem) return;
|
||||||
|
|
||||||
|
if (!uiItem->isUiHidden(uiConfigName))
|
||||||
|
{
|
||||||
|
visibleItems.push_back(uiItem);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Check if ui tree ordering is defined in the data model
|
||||||
|
PdmUiObjectHandle* uiObjectHandle = dynamic_cast<PdmUiObjectHandle*> (uiItem);
|
||||||
|
if (uiObjectHandle)
|
||||||
|
{
|
||||||
|
PdmUiTreeOrdering treeOrderingDefinedByApplication("", "");
|
||||||
|
uiObjectHandle->defineUiTreeOrdering(treeOrderingDefinedByApplication, uiConfigName);
|
||||||
|
if (treeOrderingDefinedByApplication.childCount() > 0)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < treeOrderingDefinedByApplication.childCount(); i++)
|
||||||
|
{
|
||||||
|
// The referenced objects in uiOrdering might be set as hidden
|
||||||
|
// Do a recursive search from the referenced objects to find first visible ui item
|
||||||
|
findFirstVisibleUiItemInAllBranches(treeOrderingDefinedByApplication.child(i)->activeItem(), visibleItems, uiConfigName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (uiItem->isUiChildrenHidden(uiConfigName))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PdmUiFieldHandle* field = dynamic_cast<PdmUiFieldHandle*> (uiItem);
|
||||||
|
if (field)
|
||||||
|
{
|
||||||
|
std::vector<caf::PdmObjectHandle*> children;
|
||||||
|
field->fieldHandle()->childObjects(&children);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < children.size(); i++)
|
||||||
|
{
|
||||||
|
findFirstVisibleUiItemInAllBranches(uiObj(children[i]), visibleItems, uiConfigName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (uiObjectHandle)
|
||||||
|
{
|
||||||
|
std::vector<PdmFieldHandle*> fields;
|
||||||
|
uiObjectHandle->owner()->fields(fields);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < fields.size(); i++)
|
||||||
|
{
|
||||||
|
if (dynamic_cast<PdmChildArrayFieldHandle*>(fields[i]))
|
||||||
|
{
|
||||||
|
// Always show a container object, even if the container is empty
|
||||||
|
findFirstVisibleUiItemInAllBranches(fields[i]->uiCapability(), visibleItems, uiConfigName);
|
||||||
|
}
|
||||||
|
else if (fields[i]->hasChildObjects())
|
||||||
|
{
|
||||||
|
// Show a child object only if an object is present
|
||||||
|
findFirstVisibleUiItemInAllBranches(fields[i]->uiCapability(), visibleItems, uiConfigName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // end namespace caf
|
} // end namespace caf
|
||||||
|
|||||||
@@ -83,6 +83,8 @@ private:
|
|||||||
void updateEditorsForSubTree(PdmUiTreeOrdering* root);
|
void updateEditorsForSubTree(PdmUiTreeOrdering* root);
|
||||||
static int findChildItemIndex(const PdmUiTreeOrdering * parent, const PdmUiItem* pdmItemToFindInChildren);
|
static int findChildItemIndex(const PdmUiTreeOrdering * parent, const PdmUiItem* pdmItemToFindInChildren);
|
||||||
|
|
||||||
|
static void findFirstVisibleUiItemInAllBranches(PdmUiItem* uiItem, std::vector<PdmUiItem*>& visibleItems, const QString& uiConfigName);
|
||||||
|
|
||||||
PdmUiTreeOrdering* m_treeOrderingRoot;
|
PdmUiTreeOrdering* m_treeOrderingRoot;
|
||||||
QStringList m_columnHeaders;
|
QStringList m_columnHeaders;
|
||||||
QString m_uiConfigName;
|
QString m_uiConfigName;
|
||||||
|
|||||||
Reference in New Issue
Block a user