mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Added TreeView and TreeViewEditor using the same pattern as cafPdmUiDefaultObjectEditor
p4#: 22264
This commit is contained in:
parent
1e7c4a385a
commit
f260092d3c
@ -70,6 +70,33 @@ private:
|
||||
};
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
/// Proxy editor handle used to propagate updates to the editor responsible for the UI for this object
|
||||
///
|
||||
/// A tree view control is connected to the root item, and all nodes in the tree will have a proxy editor
|
||||
/// pointing to the root node editor controlling the UI for the whole tree
|
||||
//==================================================================================================
|
||||
class PdmUiProxyEditorHandle: public PdmUiEditorHandle
|
||||
{
|
||||
public:
|
||||
PdmUiProxyEditorHandle(PdmUiEditorHandle* mainEditorHandle) : PdmUiEditorHandle() { m_mainEditorHandle = mainEditorHandle; }
|
||||
virtual ~PdmUiProxyEditorHandle() {};
|
||||
|
||||
protected: // Interface to override:
|
||||
|
||||
/// Supposed to update all parts of the widgets, both visibility, sensitivity, decorations and field data
|
||||
virtual void configureAndUpdateUi(const QString& uiConfigName)
|
||||
{
|
||||
if (m_mainEditorHandle)
|
||||
{
|
||||
m_mainEditorHandle->updateUi(uiConfigName);
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
PdmUiEditorHandle* m_mainEditorHandle;
|
||||
};
|
||||
|
||||
|
||||
} // End of namespace caf
|
||||
|
||||
|
@ -25,6 +25,7 @@ set( QOBJECT_HEADERS
|
||||
cafPdmUiColorEditor.h
|
||||
|
||||
cafPdmUiPropertyView.h
|
||||
cafPdmUiTreeView.h
|
||||
)
|
||||
|
||||
if ( (${CMAKE_VERSION} VERSION_LESS 2.8.6) OR (NOT CMAKE_AUTOMOC) )
|
||||
@ -59,6 +60,8 @@ add_library( ${PROJECT_NAME}
|
||||
cafPdmUiSliderEditor.h
|
||||
cafPdmUiTextEditor.cpp
|
||||
cafPdmUiTextEditor.h
|
||||
cafPdmUiTreeViewEditor.cpp
|
||||
cafPdmUiTreeViewEditor.h
|
||||
cafProgressInfo.cpp
|
||||
cafProgressInfo.h
|
||||
cafUiProcess.cpp
|
||||
@ -66,6 +69,7 @@ add_library( ${PROJECT_NAME}
|
||||
cafUiTreeItem.h
|
||||
cafUiTreeModelPdm.cpp
|
||||
cafUiTreeModelPdm.h
|
||||
cafPdmUiTreeView.cpp
|
||||
|
||||
${MOC_FILES_CPP}
|
||||
)
|
||||
|
141
cafUserInterface/cafPdmUiTreeView.cpp
Normal file
141
cafUserInterface/cafPdmUiTreeView.cpp
Normal file
@ -0,0 +1,141 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
#include "cafPdmUiTreeView.h"
|
||||
|
||||
#include "cafPdmObject.h"
|
||||
#include "cafPdmUiDefaultObjectEditor.h"
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include "cafPdmUiTreeViewEditor.h"
|
||||
|
||||
|
||||
namespace caf
|
||||
{
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
PdmUiTreeView::PdmUiTreeView(QWidget* parent, Qt::WindowFlags f)
|
||||
: QWidget (parent, f)
|
||||
{
|
||||
m_layout = new QVBoxLayout(this);
|
||||
m_layout->insertStretch(1, 1);
|
||||
m_layout->setContentsMargins(0, 0, 0, 0);
|
||||
m_layout->setSpacing(0);
|
||||
|
||||
setLayout(m_layout);
|
||||
|
||||
m_treeViewEditor = NULL;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
PdmUiTreeView::~PdmUiTreeView()
|
||||
{
|
||||
if (m_treeViewEditor) delete m_treeViewEditor;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiTreeView::setUiConfigurationName(QString uiConfigName)
|
||||
{
|
||||
// Reset everything, and possibly create widgets etc afresh
|
||||
if (m_uiConfigName != uiConfigName)
|
||||
{
|
||||
m_uiConfigName = uiConfigName;
|
||||
|
||||
if (m_treeViewEditor)
|
||||
{
|
||||
PdmObject* object = m_treeViewEditor->pdmObject();
|
||||
delete m_treeViewEditor;
|
||||
m_treeViewEditor = NULL;
|
||||
this->showTree(object);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiTreeView::showTree(caf::PdmObject* object)
|
||||
{
|
||||
// Find specialized object view handle
|
||||
|
||||
// If the current ObjectView has the same type as the one to view, reuse, with Widget etc.
|
||||
|
||||
bool rebuildWidget = false;
|
||||
|
||||
if (!m_treeViewEditor) rebuildWidget = true;
|
||||
|
||||
if (m_treeViewEditor && m_treeViewEditor->pdmObject())
|
||||
{
|
||||
if (object)
|
||||
{
|
||||
if (m_treeViewEditor->pdmObject()->uiEditorTypeName(m_uiConfigName) != object->uiEditorTypeName(m_uiConfigName))
|
||||
{
|
||||
rebuildWidget = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (rebuildWidget)
|
||||
{
|
||||
// Remove Widget from layout
|
||||
if (m_treeViewEditor)
|
||||
{
|
||||
layout()->removeWidget(m_treeViewEditor->widget());
|
||||
delete m_treeViewEditor;
|
||||
m_treeViewEditor = NULL;
|
||||
}
|
||||
|
||||
//m_currentObjectView = PdmObjViewFactory::instance()->create(object->editorType(m_uiConfigName));
|
||||
if (!m_treeViewEditor)
|
||||
{
|
||||
m_treeViewEditor = new PdmUiTreeViewEditor();
|
||||
}
|
||||
|
||||
// Create widget to handle this
|
||||
QWidget * widget = NULL;
|
||||
widget = m_treeViewEditor->getOrCreateWidget(this);
|
||||
|
||||
assert(widget);
|
||||
|
||||
this->m_layout->insertWidget(0, widget);
|
||||
}
|
||||
|
||||
m_treeViewEditor->setPdmObject(object);
|
||||
m_treeViewEditor->updateUi(m_uiConfigName);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
caf::PdmObject* PdmUiTreeView::currentObject()
|
||||
{
|
||||
if (!m_treeViewEditor) return NULL;
|
||||
return m_treeViewEditor->pdmObject();
|
||||
}
|
||||
|
||||
|
||||
} //End of namespace caf
|
||||
|
57
cafUserInterface/cafPdmUiTreeView.h
Normal file
57
cafUserInterface/cafPdmUiTreeView.h
Normal file
@ -0,0 +1,57 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
#pragma once
|
||||
#include <QString>
|
||||
#include <QWidget>
|
||||
|
||||
class QVBoxLayout;
|
||||
|
||||
namespace caf
|
||||
{
|
||||
|
||||
class PdmObject;
|
||||
class PdmUiTreeViewEditor;
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
|
||||
class PdmUiTreeView : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
PdmUiTreeView(QWidget* parent = 0, Qt::WindowFlags f = 0);
|
||||
~PdmUiTreeView();
|
||||
|
||||
void setUiConfigurationName(QString uiConfigName);
|
||||
caf::PdmObject* currentObject();
|
||||
public slots:
|
||||
void showTree(caf::PdmObject* object);
|
||||
|
||||
private:
|
||||
PdmUiTreeViewEditor* m_treeViewEditor;
|
||||
QString m_uiConfigName;
|
||||
QVBoxLayout* m_layout;
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // End of namespace caf
|
||||
|
142
cafUserInterface/cafPdmUiTreeViewEditor.cpp
Normal file
142
cafUserInterface/cafPdmUiTreeViewEditor.cpp
Normal file
@ -0,0 +1,142 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
#include "cafPdmUiTreeViewEditor.h"
|
||||
|
||||
#include "cafPdmObject.h"
|
||||
#include "cafPdmField.h"
|
||||
#include "cafPdmUiEditorHandle.h"
|
||||
#include "cafUiTreeModelPdm.h"
|
||||
|
||||
#include <QWidget>
|
||||
#include <QGridLayout>
|
||||
#include <QTreeView>
|
||||
|
||||
|
||||
|
||||
namespace caf
|
||||
{
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
PdmUiTreeViewEditor::PdmUiTreeViewEditor()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
PdmUiTreeViewEditor::~PdmUiTreeViewEditor()
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QWidget* PdmUiTreeViewEditor::createWidget(QWidget* parent)
|
||||
{
|
||||
m_mainWidget = new QWidget(parent);
|
||||
m_layout = new QGridLayout();
|
||||
m_layout->setContentsMargins(0, 0, 0, 0);
|
||||
m_mainWidget->setLayout(m_layout);
|
||||
|
||||
m_treeModelPdm = new caf::UiTreeModelPdm(m_mainWidget);
|
||||
m_treeView = new QTreeView(m_mainWidget);
|
||||
m_treeView->setHeaderHidden(true);
|
||||
m_treeView->setModel(m_treeModelPdm);
|
||||
|
||||
m_layout->addWidget(m_treeView);
|
||||
|
||||
m_proxyEditor = new PdmUiProxyEditorHandle(this);
|
||||
|
||||
return m_mainWidget;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiTreeViewEditor::configureAndUpdateUi(const QString& uiConfigName)
|
||||
{
|
||||
if (!m_treeModelPdm->treeItemRoot() || m_treeModelPdm->treeItemRoot()->dataObject() != this->pdmObject())
|
||||
{
|
||||
caf::PdmUiTreeItem* treeItemRoot = caf::UiTreeItemBuilderPdm::buildViewItems(NULL, -1, this->pdmObject());
|
||||
m_treeModelPdm->setTreeItemRoot(treeItemRoot);
|
||||
}
|
||||
|
||||
// Update tree model, and set the proxy editor for all Pdm child objects
|
||||
if (m_treeModelPdm->treeItemRoot() && m_treeModelPdm->treeItemRoot()->dataObject())
|
||||
{
|
||||
m_treeModelPdm->updateUiSubTree(m_treeModelPdm->treeItemRoot()->dataObject());
|
||||
|
||||
std::vector<PdmObject*> children;
|
||||
childObjects(m_treeModelPdm->treeItemRoot()->dataObject(), children);
|
||||
|
||||
size_t cIdx;
|
||||
for (cIdx = 0; cIdx < children.size(); ++cIdx)
|
||||
{
|
||||
addEditorRecursively(children[cIdx], m_proxyEditor);
|
||||
}
|
||||
}
|
||||
|
||||
// Notify all connected views that the complete model is updated
|
||||
m_treeModelPdm->notifyModelChanged();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiTreeViewEditor::addEditorRecursively(PdmObject* pdmObject, PdmUiEditorHandle* editorHandle)
|
||||
{
|
||||
if (!pdmObject) return;
|
||||
|
||||
std::vector<PdmObject*> children;
|
||||
childObjects(pdmObject, children);
|
||||
|
||||
size_t cIdx;
|
||||
for (cIdx = 0; cIdx < children.size(); ++cIdx)
|
||||
{
|
||||
addEditorRecursively(children[cIdx], editorHandle);
|
||||
}
|
||||
|
||||
pdmObject->addFieldEditor(editorHandle);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiTreeViewEditor::childObjects(PdmObject* pdmObject, std::vector<PdmObject*>& children)
|
||||
{
|
||||
if (!pdmObject) return;
|
||||
|
||||
std::vector<PdmFieldHandle*> fields;
|
||||
pdmObject->fields(fields);
|
||||
|
||||
size_t fIdx;
|
||||
for (fIdx = 0; fIdx < fields.size(); ++fIdx)
|
||||
{
|
||||
if (fields[fIdx]) fields[fIdx]->childObjects(&children);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // end namespace caf
|
66
cafUserInterface/cafPdmUiTreeViewEditor.h
Normal file
66
cafUserInterface/cafPdmUiTreeViewEditor.h
Normal file
@ -0,0 +1,66 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cafPdmUiObjectEditorHandle.h"
|
||||
|
||||
#include <QWidget>
|
||||
#include <QPointer>
|
||||
|
||||
class QGridLayout;
|
||||
class QTreeView;
|
||||
|
||||
namespace caf
|
||||
{
|
||||
class PdmUiFieldEditorHandle;
|
||||
class PdmUiItem;
|
||||
class UiTreeModelPdm;
|
||||
class PdmUiProxyEditorHandle;
|
||||
|
||||
|
||||
class PdmUiTreeViewEditor : public PdmUiObjectEditorHandle
|
||||
{
|
||||
public:
|
||||
PdmUiTreeViewEditor();
|
||||
~PdmUiTreeViewEditor();
|
||||
|
||||
protected:
|
||||
virtual QWidget* createWidget(QWidget* parent);
|
||||
virtual void configureAndUpdateUi(const QString& uiConfigName);
|
||||
|
||||
private:
|
||||
void addEditorRecursively(PdmObject* pdmObject, PdmUiEditorHandle* editorHandle);
|
||||
|
||||
static void childObjects(PdmObject* pdmObject, std::vector<PdmObject*>& children);
|
||||
|
||||
private:
|
||||
QPointer<QWidget> m_mainWidget;
|
||||
QGridLayout* m_layout;
|
||||
|
||||
QTreeView* m_treeView;
|
||||
UiTreeModelPdm* m_treeModelPdm;
|
||||
|
||||
// Forward update events to the tree view editor connected to Pdm root object using a proxy editor
|
||||
PdmUiProxyEditorHandle* m_proxyEditor;
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // end namespace caf
|
@ -460,6 +460,17 @@ PdmUiTreeItem* UiTreeModelPdm::treeItemRoot()
|
||||
return m_treeItemRoot;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void UiTreeModelPdm::notifyModelChanged()
|
||||
{
|
||||
QModelIndex startModelIdx = index(0,0);
|
||||
QModelIndex endModelIdx = index(rowCount(startModelIdx), 0);
|
||||
|
||||
emit dataChanged(startModelIdx, endModelIdx);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -52,6 +52,8 @@ public:
|
||||
QModelIndex getModelIndexFromPdmObject(const PdmObject* object) const;
|
||||
void updateUiSubTree(PdmObject* root);
|
||||
|
||||
void notifyModelChanged();
|
||||
|
||||
public:
|
||||
// Overrides from QAbstractItemModel
|
||||
virtual QModelIndex index(int row, int column, const QModelIndex &parentIndex = QModelIndex( )) const;
|
||||
|
Loading…
Reference in New Issue
Block a user