From: mzn Date: Wed, 19 Mar 2014 14:02:37 +0000 (+0000) Subject: The first implementation of Top/Bottom functionality. X-Git-Tag: BR_hydro_v1_0_1~47 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=83ee47a70dabc7398a823dc06984d6db70e49a58;p=modules%2Fhydro.git The first implementation of Top/Bottom functionality. --- diff --git a/src/ZLEVEL/HYDROGUI_ZLevelsDlg.cxx b/src/ZLEVEL/HYDROGUI_ZLevelsDlg.cxx index 0808a2a5..bb899965 100644 --- a/src/ZLEVEL/HYDROGUI_ZLevelsDlg.cxx +++ b/src/ZLEVEL/HYDROGUI_ZLevelsDlg.cxx @@ -108,8 +108,14 @@ void HYDROGUI_ZLevelsDlg::setObjects( const QList& theObjects ) if( aFilterModel ) { HYDROGUI_ZLevelsModel* aModel = dynamic_cast( aFilterModel->sourceModel() ); - if( aModel ) - aModel->setObjects( theObjects ); + 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 ); + } } } @@ -125,7 +131,8 @@ void HYDROGUI_ZLevelsDlg::onMove( int theType ) aSelectedSourceIndexes << aFilterModel->mapToSource( anIndex ); } QList aSelectedIds = aModel->getIds( aSelectedSourceIndexes ); - aModel->move( aSelectedIds, ( HYDROGUI_ZLevelsModel::OpType )theType ); + aModel->move( aSelectedIds, ( HYDROGUI_ZLevelsModel::OpType )theType, + !myAllObjects->isChecked() ); } } } diff --git a/src/ZLEVEL/HYDROGUI_ZLevelsModel.cxx b/src/ZLEVEL/HYDROGUI_ZLevelsModel.cxx index 70d575b3..e36287c8 100644 --- a/src/ZLEVEL/HYDROGUI_ZLevelsModel.cxx +++ b/src/ZLEVEL/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 ); + return myObjects.at( aRow ).first; else return QVariant(); } @@ -86,7 +86,7 @@ int HYDROGUI_ZLevelsModel::rowCount( const QModelIndex &theParent ) const return myObjects.count(); } -void HYDROGUI_ZLevelsModel::setObjects( const QList& theObjects ) +void HYDROGUI_ZLevelsModel::setObjects( const QList>& theObjects ) { myObjects = theObjects; @@ -95,11 +95,13 @@ void HYDROGUI_ZLevelsModel::setObjects( const QList& theObjects ) bool HYDROGUI_ZLevelsModel::IsObjectVisible( int theIndex ) const { - //TODO: reimplement - return myObjects[ theIndex ] == "A" || - myObjects[ theIndex ] == "C" || - myObjects[ theIndex ] == "E" || - myObjects[ theIndex ] == "G"; + bool isVisible = false; + + if ( theIndex >= 0 && theIndex < myObjects.count() ) { + isVisible = myObjects.at( theIndex ).second; + } + + return isVisible; } QVariant HYDROGUI_ZLevelsModel::headerData( int theSection, @@ -195,21 +197,54 @@ QList HYDROGUI_ZLevelsModel::getIds( const QModelIndexList& theIndexes, boo return anIds; } -bool HYDROGUI_ZLevelsModel::move( const int theItem, const OpType theType, - const int theDropItem ) +bool HYDROGUI_ZLevelsModel::move( const int theItem, const OpType theType, + bool theIsVisibleOnly, const int theDropItem ) { bool aRes = false; + if ( theItem < 0 || theItem >= myObjects.count() ) { + return aRes; + } switch ( theType ) { case Up: + { + if ( theItem > 0 ) { + int aSwapItem = theItem - 1; + if ( theIsVisibleOnly ) { + while ( aSwapItem >= 0 && !myObjects.at( aSwapItem ).second ) { + aSwapItem--; + } + } + if ( aSwapItem >= 0 ) { + myObjects.move( theItem, aSwapItem ); + aRes = true; + } + } + } + break; + case Down: + if ( theItem < myObjects.count() - 1 ) { + int aSwapItem = theItem + 1; + if ( theIsVisibleOnly ) { + while ( aSwapItem < myObjects.count() && !myObjects.at( aSwapItem ).second ) { + aSwapItem++; + } + } + if ( aSwapItem < myObjects.count() ) { + myObjects.move( theItem, aSwapItem ); + aRes = true; + } + } + break; + case Top: if ( theItem > 0 ) { - myObjects.swap( theItem, theItem - 1 ); + myObjects.move( theItem, 0 ); aRes = true; } break; - case Down: + case Bottom: if ( theItem < myObjects.count() - 1 ) { - myObjects.swap( theItem, theItem + 1 ); + myObjects.move( theItem, myObjects.count() - 1 ); aRes = true; } break; @@ -219,26 +254,37 @@ bool HYDROGUI_ZLevelsModel::move( const int theItem, const OpType theType, } bool HYDROGUI_ZLevelsModel::move( const QList& theItems, const OpType theType, - const int theDropItem ) + bool theIsVisibleOnly, const int theDropItem ) { bool aRes = true; bool isReverse = theType == Top || theType == Down; QListIterator anIt( theItems ); + bool isFirst = true; if ( isReverse ) { anIt.toBack(); while ( anIt.hasPrevious() ) { - if ( !move( anIt.previous(), theType, theDropItem ) ) { + int anId = anIt.previous(); + if ( theType == Top && !isFirst ) { + anId++; + } + if ( !move( anId, theType, theIsVisibleOnly, theDropItem ) ) { aRes = false; break; } + isFirst = false; } } else { while ( anIt.hasNext() ) { - if ( !move( anIt.next(), theType, theDropItem ) ) { + int anId = anIt.next(); + if ( theType == Bottom && !isFirst ) { + anId--; + } + if ( !move( anId, theType, theIsVisibleOnly, theDropItem ) ) { aRes = false; break; } + isFirst = false; } } diff --git a/src/ZLEVEL/HYDROGUI_ZLevelsModel.h b/src/ZLEVEL/HYDROGUI_ZLevelsModel.h index 028b6584..62c5f1b9 100644 --- a/src/ZLEVEL/HYDROGUI_ZLevelsModel.h +++ b/src/ZLEVEL/HYDROGUI_ZLevelsModel.h @@ -59,18 +59,18 @@ public: QList getIds( const QModelIndexList& theIndexes, bool theIsToSort = true ) const; - void setObjects( const QList& theObjects ); + void setObjects( const QList>& theObjects ); - bool move( const int theItem, const OpType theType, + bool move( const int theItem, const OpType theType, bool theIsVisibleOnly, const int theDropItem = -1 ); - bool move( const QList& theItems, const OpType theType, + bool move( const QList& theItems, const OpType theType, bool theIsVisibleOnly, const int theDropItem = -1 ); protected: bool IsObjectVisible( int theIndex ) const; private: - QList myObjects; + QList> myObjects; QPixmap myEmpty, myEye; };