if( aFilterModel )
{
HYDROGUI_ZLevelsModel* aModel = dynamic_cast<HYDROGUI_ZLevelsModel*>( aFilterModel->sourceModel() );
- if( aModel )
- aModel->setObjects( theObjects );
+ if( aModel ) {
+ // TODO: to be reimplemented
+ QList<QPair<QString, bool>> anObjects;
+ for ( int i = 0; i < theObjects.count(); i++ ) {
+ anObjects << QPair<QString, bool>( theObjects.at(i), i%2 == 0 );
+ }
+ aModel->setObjects( anObjects );
+ }
}
}
aSelectedSourceIndexes << aFilterModel->mapToSource( anIndex );
}
QList<int> aSelectedIds = aModel->getIds( aSelectedSourceIndexes );
- aModel->move( aSelectedIds, ( HYDROGUI_ZLevelsModel::OpType )theType );
+ aModel->move( aSelectedIds, ( HYDROGUI_ZLevelsModel::OpType )theType,
+ !myAllObjects->isChecked() );
}
}
}
case Qt::DisplayRole:
{
if( aColumn==0 && aRow >=0 && aRow < myObjects.count() )
- return myObjects.at( aRow );
+ return myObjects.at( aRow ).first;
else
return QVariant();
}
return myObjects.count();
}
-void HYDROGUI_ZLevelsModel::setObjects( const QList<QString>& theObjects )
+void HYDROGUI_ZLevelsModel::setObjects( const QList<QPair<QString, bool>>& theObjects )
{
myObjects = 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,
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;
}
bool HYDROGUI_ZLevelsModel::move( const QList<int>& theItems, const OpType theType,
- const int theDropItem )
+ bool theIsVisibleOnly, const int theDropItem )
{
bool aRes = true;
bool isReverse = theType == Top || theType == Down;
QListIterator<int> 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;
}
}
QList<int> getIds( const QModelIndexList& theIndexes, bool theIsToSort = true ) const;
- void setObjects( const QList<QString>& theObjects );
+ void setObjects( const QList<QPair<QString, bool>>& 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<int>& theItems, const OpType theType,
+ bool move( const QList<int>& theItems, const OpType theType, bool theIsVisibleOnly,
const int theDropItem = -1 );
protected:
bool IsObjectVisible( int theIndex ) const;
private:
- QList<QString> myObjects;
+ QList<QPair<QString, bool>> myObjects;
QPixmap myEmpty, myEye;
};