diff --git a/ApplicationCode/WellPathImportSsihub/RimWellPathImport.cpp b/ApplicationCode/WellPathImportSsihub/RimWellPathImport.cpp index 73c11b7492..a5f17403e4 100644 --- a/ApplicationCode/WellPathImportSsihub/RimWellPathImport.cpp +++ b/ApplicationCode/WellPathImportSsihub/RimWellPathImport.cpp @@ -17,6 +17,7 @@ ///////////////////////////////////////////////////////////////////////////////// #include "RimWellPathImport.h" +#include "cafPdmUiTreeViewEditor.h" namespace caf { @@ -186,3 +187,19 @@ void RimWellPathImport::fieldChangedByUi(const caf::PdmFieldHandle* changedField } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimWellPathImport::defineObjectEditorAttribute(QString uiConfigName, caf::PdmUiEditorAttribute * attribute) +{ + caf::PdmUiTreeViewEditorAttribute* myAttr = dynamic_cast(attribute); + if (myAttr) + { + QStringList colHeaders; + colHeaders << "Region"; + myAttr->columnHeaders = colHeaders; + } +} + + + diff --git a/ApplicationCode/WellPathImportSsihub/RimWellPathImport.h b/ApplicationCode/WellPathImportSsihub/RimWellPathImport.h index 0cf24e0271..d74b055552 100644 --- a/ApplicationCode/WellPathImportSsihub/RimWellPathImport.h +++ b/ApplicationCode/WellPathImportSsihub/RimWellPathImport.h @@ -57,9 +57,11 @@ public: virtual void initAfterRead(); virtual void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ); + virtual void defineObjectEditorAttribute( QString uiConfigName, caf::PdmUiEditorAttribute * attribute ); -//private: void updateFieldVisibility(); + + }; diff --git a/ApplicationCode/WellPathImportSsihub/RiuWellImportWizard.cpp b/ApplicationCode/WellPathImportSsihub/RiuWellImportWizard.cpp index 56d3558d24..437ab248b5 100644 --- a/ApplicationCode/WellPathImportSsihub/RiuWellImportWizard.cpp +++ b/ApplicationCode/WellPathImportSsihub/RiuWellImportWizard.cpp @@ -32,6 +32,7 @@ #include "RimWellPathImport.h" #include "RifJsonEncodeDecode.h" +#include "cafPdmUiTreeViewEditor.h" //-------------------------------------------------------------------------------------------------- @@ -809,6 +810,31 @@ void FieldSelectionPage::initializePage() +//-------------------------------------------------------------------------------------------------- +/// Helper class used to define column headers +//-------------------------------------------------------------------------------------------------- +class ObjectGroupWithHeaders : public caf::PdmObjectGroup +{ +public: + ObjectGroupWithHeaders() : caf::PdmObjectGroup() + { + + } + + //-------------------------------------------------------------------------------------------------- + /// + //-------------------------------------------------------------------------------------------------- + virtual void defineObjectEditorAttribute(QString uiConfigName, caf::PdmUiEditorAttribute * attribute) + { + caf::PdmUiTreeViewEditorAttribute* myAttr = dynamic_cast(attribute); + if (myAttr) + { + QStringList colHeaders; + colHeaders << "Wells"; + myAttr->columnHeaders = colHeaders; + } + } +}; @@ -830,9 +856,7 @@ WellSelectionPage::WellSelectionPage(RimWellPathImport* wellPathImport, QWidget* m_wellPathImportObject = wellPathImport; - m_regionsWithVisibleWells = new caf::PdmObjectGroup; - - //m_wellSelectionTreeView->setPdmObject(wellPathImport); + m_regionsWithVisibleWells = new ObjectGroupWithHeaders; } //-------------------------------------------------------------------------------------------------- @@ -844,6 +868,8 @@ void WellSelectionPage::initializePage() if (!wiz) return; wiz->downloadWells(); + + setButtonText(QWizard::NextButton, "Download"); } //-------------------------------------------------------------------------------------------------- @@ -903,6 +929,8 @@ WellSummaryPage::WellSummaryPage(RimWellPathImport* wellPathImport, QWidget* par m_listView->hide(); m_objectGroup = new caf::PdmObjectGroup; + + setButtonText(QWizard::FinishButton, "Import"); } //-------------------------------------------------------------------------------------------------- @@ -942,17 +970,19 @@ void WellSummaryPage::updateSummaryPage() for (size_t wIdx = 0; wIdx < oilField->wells.size(); wIdx++) { RimWellPathEntry* wellPathEntry = oilField->wells[wIdx]; - - if (QFile::exists(oilField->wells[wIdx]->wellPathFilePath)) + if (wellPathEntry->selected) { - wellPathCount++; - } - else - { - errorString += QString("Failed to get file '%1' from well '%2'\n").arg(oilField->wells[wIdx]->wellPathFilePath).arg(oilField->wells[wIdx]->name); - } + if (QFile::exists(oilField->wells[wIdx]->wellPathFilePath)) + { + wellPathCount++; + } + else + { + errorString += QString("Failed to get file '%1' from well '%2'\n").arg(oilField->wells[wIdx]->wellPathFilePath).arg(oilField->wells[wIdx]->name); + } - m_objectGroup->objects.push_back(wellPathEntry); + m_objectGroup->objects.push_back(wellPathEntry); + } } } } @@ -960,7 +990,7 @@ void WellSummaryPage::updateSummaryPage() } - m_textEdit->setText(QString("Downloaded successfully %1 well paths.\nPlease push 'Finish' button to import well paths into ResInsight.\n\n").arg(wellPathCount)); + m_textEdit->setText(QString("Downloaded successfully %1 well paths.\nPlease push 'Import' button to import well paths into ResInsight.\n\n").arg(wellPathCount)); if (!errorString.isEmpty()) { m_textEdit->append("Detected following errors during well path download. See details below."); diff --git a/ApplicationCode/WellPathImportSsihub/RiuWellImportWizard.h b/ApplicationCode/WellPathImportSsihub/RiuWellImportWizard.h index d450acc3da..7beef558fb 100644 --- a/ApplicationCode/WellPathImportSsihub/RiuWellImportWizard.h +++ b/ApplicationCode/WellPathImportSsihub/RiuWellImportWizard.h @@ -72,6 +72,10 @@ public: }; + +class ObjectGroupWithHeaders; + + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -87,7 +91,7 @@ public: void buildWellTreeView(); private: - caf::PdmObjectGroup* m_regionsWithVisibleWells; + ObjectGroupWithHeaders* m_regionsWithVisibleWells; RimWellPathImport* m_wellPathImportObject; caf::PdmUiTreeView* m_wellSelectionTreeView; diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiTreeViewEditor.cpp b/Fwk/AppFwk/cafUserInterface/cafPdmUiTreeViewEditor.cpp index 1819c96305..c1f2c32702 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiTreeViewEditor.cpp +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiTreeViewEditor.cpp @@ -45,6 +45,29 @@ #include #include #include +#include + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +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(); } //-------------------------------------------------------------------------------------------------- diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiTreeViewEditor.h b/Fwk/AppFwk/cafUserInterface/cafPdmUiTreeViewEditor.h index ba675afb0f..04ae2f44f9 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiTreeViewEditor.h +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiTreeViewEditor.h @@ -43,6 +43,8 @@ #include #include +class MySortFilterProxyModel; + class QGridLayout; class QVBoxLayout; class QTreeView; @@ -66,6 +68,7 @@ public: } public: + QStringList columnHeaders; }; @@ -90,8 +93,9 @@ private: QPointer 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; diff --git a/Fwk/AppFwk/cafUserInterface/cafUiTreeModelPdm.cpp b/Fwk/AppFwk/cafUserInterface/cafUiTreeModelPdm.cpp index 9e321ff2de..03005d6698 100644 --- a/Fwk/AppFwk/cafUserInterface/cafUiTreeModelPdm.cpp +++ b/Fwk/AppFwk/cafUserInterface/cafUiTreeModelPdm.cpp @@ -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; +} + + + + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/Fwk/AppFwk/cafUserInterface/cafUiTreeModelPdm.h b/Fwk/AppFwk/cafUserInterface/cafUiTreeModelPdm.h index c5441e402b..2bba5d4210 100644 --- a/Fwk/AppFwk/cafUserInterface/cafUiTreeModelPdm.h +++ b/Fwk/AppFwk/cafUserInterface/cafUiTreeModelPdm.h @@ -40,6 +40,8 @@ #include "cafUiTreeItem.h" #include +#include + #include #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; };