From 7c831a717f2aa08816f9d4058d26a44d1b7c068f Mon Sep 17 00:00:00 2001 From: san Date: Fri, 29 Oct 2010 13:55:37 +0000 Subject: [PATCH] QModelIndex comparation was corrected --- src/Qtx/QtxSearchTool.cxx | 29 +++++++++++++---------------- src/Qtx/QtxSearchTool.h | 4 ++-- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/Qtx/QtxSearchTool.cxx b/src/Qtx/QtxSearchTool.cxx index c1daf6415..b25bf8922 100644 --- a/src/Qtx/QtxSearchTool.cxx +++ b/src/Qtx/QtxSearchTool.cxx @@ -1873,17 +1873,16 @@ void QtxItemViewSearcher::showItem( const QModelIndex& index ) \param index model index \return item ID */ -QString QtxItemViewSearcher::getId( const QModelIndex& index ) +QModelIndexList QtxItemViewSearcher::getId( const QModelIndex& index ) const { - QStringList ids; + QModelIndexList idxList; QModelIndex p = index; while ( p.isValid() ) { - ids.prepend( QString::number( p.row() ) ); + idxList.prepend( p ); p = p.parent(); } - ids.prepend( "0" ); - return ids.join( ":" ); + return idxList; } /*! @@ -1895,20 +1894,18 @@ QString QtxItemViewSearcher::getId( const QModelIndex& index ) and positive value otherwise */ int QtxItemViewSearcher::compareIndices( const QModelIndex& left, - const QModelIndex& right ) + const QModelIndex& right ) const { - QString leftId = getId( left ); - QString rightId = getId( right ); - - QStringList idsLeft = leftId.split( ":", QString::SkipEmptyParts ); - QStringList idsRight = rightId.split( ":", QString::SkipEmptyParts ); - + QModelIndexList idsLeft = getId( left ); + QModelIndexList idsRight = getId( right ); for ( int i = 0; i < idsLeft.count() && i < idsRight.count(); i++ ) { - int lid = idsLeft[i].toInt(); - int rid = idsRight[i].toInt(); - if ( lid != rid ) - return lid - rid; + QModelIndex lid = idsLeft[i]; + QModelIndex rid = idsRight[i]; + if ( lid.row() != rid.row() ) + return lid.row() - rid.row(); + else if ( lid.column() != rid.column() ) + return lid.column() - rid.column(); } return idsLeft.count() < idsRight.count() ? -1 : ( idsLeft.count() == idsRight.count() ? 0 : 1 ); diff --git a/src/Qtx/QtxSearchTool.h b/src/Qtx/QtxSearchTool.h index 16e809c55..636e6e5b1 100644 --- a/src/Qtx/QtxSearchTool.h +++ b/src/Qtx/QtxSearchTool.h @@ -236,8 +236,8 @@ private: QModelIndexList findItems( const QString&, QtxSearchTool* ); QModelIndex findNearest( const QModelIndex&, const QModelIndexList&, bool ); void showItem( const QModelIndex& ); - QString getId( const QModelIndex& ); - int compareIndices( const QModelIndex&, const QModelIndex& ); + QModelIndexList getId( const QModelIndex& ) const; + int compareIndices( const QModelIndex&, const QModelIndex& ) const; private: QAbstractItemView* myView; -- 2.39.2