From c8f802c68e6dd3e0c7b41897fc45d812e4b523ed Mon Sep 17 00:00:00 2001 From: mzn Date: Thu, 20 Mar 2014 07:38:41 +0000 Subject: [PATCH] Start using HYDRO data objects. --- src/HYDROGUI/HYDROGUI_ZLevelsDlg.cxx | 41 ++++++++++++++++++-------- src/HYDROGUI/HYDROGUI_ZLevelsDlg.h | 8 ++++- src/HYDROGUI/HYDROGUI_ZLevelsModel.cxx | 25 +++++++++++----- src/HYDROGUI/HYDROGUI_ZLevelsModel.h | 13 ++++++-- 4 files changed, 63 insertions(+), 24 deletions(-) diff --git a/src/HYDROGUI/HYDROGUI_ZLevelsDlg.cxx b/src/HYDROGUI/HYDROGUI_ZLevelsDlg.cxx index bb899965..7055cd08 100644 --- a/src/HYDROGUI/HYDROGUI_ZLevelsDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_ZLevelsDlg.cxx @@ -102,21 +102,24 @@ HYDROGUI_ZLevelsDlg::~HYDROGUI_ZLevelsDlg() { } -void HYDROGUI_ZLevelsDlg::setObjects( const QList& theObjects ) +void HYDROGUI_ZLevelsDlg::setObjects( const HYDROGUI_ZLevelsModel::Object2VisibleList& theObjects ) { - QSortFilterProxyModel* aFilterModel = dynamic_cast( myList->model() ); - if( aFilterModel ) - { - HYDROGUI_ZLevelsModel* aModel = dynamic_cast( aFilterModel->sourceModel() ); - if( aModel ) { - // TODO: to be reimplemented - QList> anObjects; - for ( int i = 0; i < theObjects.count(); i++ ) { - anObjects << QPair( theObjects.at(i), i%2 == 0 ); - } - aModel->setObjects( anObjects ); - } + HYDROGUI_ZLevelsModel* aModel = getListSourceModel(); + if( aModel ) { + aModel->setObjects( theObjects ); + } +} + +QList HYDROGUI_ZLevelsDlg::getObjects() const +{ + QList anObjects; + + HYDROGUI_ZLevelsModel* aModel = getListSourceModel(); + if( aModel ) { + anObjects = aModel->getObjects(); } + + return anObjects; } void HYDROGUI_ZLevelsDlg::onMove( int theType ) @@ -144,3 +147,15 @@ void HYDROGUI_ZLevelsDlg::OnStateChanged() QString anExpr = isAll ? "true|false" : "true"; aFilterModel->setFilterRegExp( anExpr ); } + +HYDROGUI_ZLevelsModel* HYDROGUI_ZLevelsDlg::getListSourceModel() const +{ + HYDROGUI_ZLevelsModel* aSourceModel = 0; + + QSortFilterProxyModel* aFilterModel = dynamic_cast( myList->model() ); + if( aFilterModel ) { + aSourceModel = dynamic_cast( aFilterModel->sourceModel() ); + } + + return aSourceModel; +} \ No newline at end of file diff --git a/src/HYDROGUI/HYDROGUI_ZLevelsDlg.h b/src/HYDROGUI/HYDROGUI_ZLevelsDlg.h index 2ca17ef2..6d249784 100644 --- a/src/HYDROGUI/HYDROGUI_ZLevelsDlg.h +++ b/src/HYDROGUI/HYDROGUI_ZLevelsDlg.h @@ -23,6 +23,8 @@ #ifndef HYDROGUI_ZLEVELSPANEL_H #define HYDROGUI_ZLEVELSPANEL_H +#include "HYDROGUI_ZLevelsModel.h" + #include class QCheckBox; @@ -41,12 +43,16 @@ public: HYDROGUI_ZLevelsDlg( QWidget* theParent ); virtual ~HYDROGUI_ZLevelsDlg(); - void setObjects( const QList& theObjects ); + void setObjects( const HYDROGUI_ZLevelsModel::Object2VisibleList& theObjects ); + HYDROGUI_ZLevelsModel::ObjectList getObjects() const; private slots: void onMove( int theType ); void OnStateChanged(); +private: + HYDROGUI_ZLevelsModel* getListSourceModel() const; + private: QListView* myList; QPushButton* myTop; diff --git a/src/HYDROGUI/HYDROGUI_ZLevelsModel.cxx b/src/HYDROGUI/HYDROGUI_ZLevelsModel.cxx index f4ac8eae..320ea963 100644 --- a/src/HYDROGUI/HYDROGUI_ZLevelsModel.cxx +++ b/src/HYDROGUI/HYDROGUI_ZLevelsModel.cxx @@ -50,7 +50,7 @@ QVariant HYDROGUI_ZLevelsModel::data( const QModelIndex &theIndex, int theRole ) case Qt::DisplayRole: { if( aColumn==0 && aRow >=0 && aRow < myObjects.count() ) - return myObjects.at( aRow ).first; + return myObjects.at( aRow ).first->GetName(); else return QVariant(); } @@ -60,7 +60,7 @@ QVariant HYDROGUI_ZLevelsModel::data( const QModelIndex &theIndex, int theRole ) { if( aColumn==0 && aRow >=0 && aRow < myObjects.count() ) { - bool isVisible = IsObjectVisible( aRow ); + bool isVisible = isObjectVisible( aRow ); if( isVisible ) return myEye; else @@ -72,7 +72,7 @@ QVariant HYDROGUI_ZLevelsModel::data( const QModelIndex &theIndex, int theRole ) case HYDROGUI_VisibleRole: { - bool isVisible = IsObjectVisible( aRow ); + bool isVisible = isObjectVisible( aRow ); return QVariant( isVisible ).toString(); } break; @@ -86,14 +86,25 @@ int HYDROGUI_ZLevelsModel::rowCount( const QModelIndex &theParent ) const return myObjects.count(); } -void HYDROGUI_ZLevelsModel::setObjects( const QList>& theObjects ) +void HYDROGUI_ZLevelsModel::setObjects( const Object2VisibleList& theObjects ) { myObjects = theObjects; reset(); } -bool HYDROGUI_ZLevelsModel::IsObjectVisible( int theIndex ) const +HYDROGUI_ZLevelsModel::ObjectList HYDROGUI_ZLevelsModel::getObjects() const +{ + ObjectList anObjects; + + foreach( const Object2Visible& anItem, myObjects ) { + anObjects << anItem.first; + } + + return anObjects; +} + +bool HYDROGUI_ZLevelsModel::isObjectVisible( int theIndex ) const { bool isVisible = false; @@ -212,7 +223,7 @@ bool HYDROGUI_ZLevelsModel::move( const int theItem, const OpType theType, if ( theItem > 0 ) { aDestinationIndex = theItem - 1; if ( theIsVisibleOnly ) { - while ( aDestinationIndex >= 0 && !IsObjectVisible( aDestinationIndex ) ) { + while ( aDestinationIndex >= 0 && !isObjectVisible( aDestinationIndex ) ) { aDestinationIndex--; } } @@ -222,7 +233,7 @@ bool HYDROGUI_ZLevelsModel::move( const int theItem, const OpType theType, if ( theItem < myObjects.count() - 1 ) { aDestinationIndex = theItem + 1; if ( theIsVisibleOnly ) { - while ( aDestinationIndex < myObjects.count() && !IsObjectVisible( aDestinationIndex ) ) { + while ( aDestinationIndex < myObjects.count() && !isObjectVisible( aDestinationIndex ) ) { aDestinationIndex++; } } diff --git a/src/HYDROGUI/HYDROGUI_ZLevelsModel.h b/src/HYDROGUI/HYDROGUI_ZLevelsModel.h index 62c5f1b9..af30f458 100644 --- a/src/HYDROGUI/HYDROGUI_ZLevelsModel.h +++ b/src/HYDROGUI/HYDROGUI_ZLevelsModel.h @@ -23,6 +23,8 @@ #ifndef HYDROGUI_ZLEVELSMODEL_H #define HYDROGUI_ZLEVELSMODEL_H +#include + #include #include @@ -39,6 +41,10 @@ class HYDROGUI_ZLevelsModel : public QAbstractListModel public: enum OpType { Top, Up, Down, Bottom, DragAndDrop }; + typedef QPair Object2Visible; + typedef QList Object2VisibleList; + typedef QList ObjectList; + public: HYDROGUI_ZLevelsModel( QObject* theParent = 0 ); virtual ~HYDROGUI_ZLevelsModel(); @@ -59,7 +65,8 @@ public: QList getIds( const QModelIndexList& theIndexes, bool theIsToSort = true ) const; - void setObjects( const QList>& theObjects ); + void setObjects( const Object2VisibleList& theObjects ); + ObjectList getObjects() const; bool move( const int theItem, const OpType theType, bool theIsVisibleOnly, const int theDropItem = -1 ); @@ -67,10 +74,10 @@ public: const int theDropItem = -1 ); protected: - bool IsObjectVisible( int theIndex ) const; + bool isObjectVisible( int theIndex ) const; private: - QList> myObjects; + Object2VisibleList myObjects; QPixmap myEmpty, myEye; }; -- 2.39.2