mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Added sorting to tree items by clicking the header
Added names to header Renamed buttons to 'Download' and 'Import'
This commit is contained in:
@@ -45,6 +45,29 @@
|
||||
#include <QWidget>
|
||||
#include <QGridLayout>
|
||||
#include <QTreeView>
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
class MySortFilterProxyModel : public QSortFilterProxyModel
|
||||
{
|
||||
public:
|
||||
MySortFilterProxyModel(QObject *parent = 0)
|
||||
: QSortFilterProxyModel(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void notifyModelChanged()
|
||||
{
|
||||
QModelIndex startModelIdx = index(0,0);
|
||||
QModelIndex endModelIdx = index(rowCount(startModelIdx), 0);
|
||||
|
||||
emit dataChanged(startModelIdx, endModelIdx);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -84,8 +107,14 @@ QWidget* PdmUiTreeViewEditor::createWidget(QWidget* parent)
|
||||
|
||||
m_treeModelPdm = new caf::UiTreeModelPdm(m_mainWidget);
|
||||
m_treeView = new QTreeView(m_mainWidget);
|
||||
m_treeView->setHeaderHidden(true);
|
||||
m_treeView->setModel(m_treeModelPdm);
|
||||
|
||||
m_proxyTreeModelPdm = new MySortFilterProxyModel(m_mainWidget);
|
||||
m_proxyTreeModelPdm->setSourceModel(m_treeModelPdm);
|
||||
m_treeView->setModel(m_proxyTreeModelPdm);
|
||||
|
||||
m_treeView->setSortingEnabled(true);
|
||||
m_treeView->sortByColumn(1, Qt::AscendingOrder);
|
||||
|
||||
|
||||
m_layout->addWidget(m_treeView);
|
||||
|
||||
@@ -125,12 +154,11 @@ void PdmUiTreeViewEditor::configureAndUpdateUi(const QString& uiConfigName)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PdmUiTreeViewEditorAttribute leab;
|
||||
|
||||
m_treeModelPdm->setColumnHeaders(m_editorAttributes.columnHeaders);
|
||||
|
||||
// Notify all connected views that the complete model is updated
|
||||
m_treeModelPdm->notifyModelChanged();
|
||||
m_proxyTreeModelPdm->notifyModelChanged();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -43,6 +43,8 @@
|
||||
#include <QWidget>
|
||||
#include <QPointer>
|
||||
|
||||
class MySortFilterProxyModel;
|
||||
|
||||
class QGridLayout;
|
||||
class QVBoxLayout;
|
||||
class QTreeView;
|
||||
@@ -66,6 +68,7 @@ public:
|
||||
}
|
||||
|
||||
public:
|
||||
QStringList columnHeaders;
|
||||
};
|
||||
|
||||
|
||||
@@ -90,8 +93,9 @@ private:
|
||||
QPointer<QWidget> m_mainWidget;
|
||||
QVBoxLayout* m_layout;
|
||||
|
||||
QTreeView* m_treeView;
|
||||
UiTreeModelPdm* m_treeModelPdm;
|
||||
QTreeView* m_treeView;
|
||||
UiTreeModelPdm* m_treeModelPdm;
|
||||
MySortFilterProxyModel* m_proxyTreeModelPdm;
|
||||
|
||||
// Forward update events to the tree view editor connected to Pdm root object using a proxy editor
|
||||
PdmUiProxyEditorHandle* m_proxyEditor;
|
||||
|
||||
@@ -498,6 +498,33 @@ void UiTreeModelPdm::notifyModelChanged()
|
||||
emit dataChanged(startModelIdx, endModelIdx);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QVariant UiTreeModelPdm::headerData(int section, Qt::Orientation orientation, int role /*= Qt::DisplayRole */) const
|
||||
{
|
||||
if (role != Qt::DisplayRole)
|
||||
return QVariant();
|
||||
|
||||
if (section < m_columnHeaders.size())
|
||||
{
|
||||
return m_columnHeaders[section];
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void UiTreeModelPdm::setColumnHeaders(const QStringList& columnHeaders)
|
||||
{
|
||||
m_columnHeaders = columnHeaders;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -40,6 +40,8 @@
|
||||
#include "cafUiTreeItem.h"
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
#include <QStringList>
|
||||
|
||||
#include <assert.h>
|
||||
#include "cafPdmPointer.h"
|
||||
|
||||
@@ -71,6 +73,7 @@ public:
|
||||
void updateUiSubTree(PdmObject* root);
|
||||
|
||||
void notifyModelChanged();
|
||||
void setColumnHeaders(const QStringList& columnHeaders);
|
||||
|
||||
public:
|
||||
// Overrides from QAbstractItemModel
|
||||
@@ -79,10 +82,12 @@ public:
|
||||
virtual int rowCount(const QModelIndex &parentIndex = QModelIndex( ) ) const;
|
||||
virtual int columnCount(const QModelIndex &parentIndex = QModelIndex( ) ) const;
|
||||
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole ) const;
|
||||
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
|
||||
|
||||
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
||||
|
||||
|
||||
virtual bool removeRows_special(int position, int rows, const QModelIndex &parent = QModelIndex());
|
||||
|
||||
protected:
|
||||
@@ -91,6 +96,7 @@ private:
|
||||
void updateModelSubTree(const QModelIndex& uiSubTreeRootModelIdx, PdmUiTreeItem* uiModelSubTreeRoot, PdmUiTreeItem* updatedPdmSubTreeRoot);
|
||||
|
||||
PdmUiTreeItem* m_treeItemRoot;
|
||||
QStringList m_columnHeaders;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user