From 8fb9569fc3e2fb2915d4ed4cf8f2b70ac922247d Mon Sep 17 00:00:00 2001 From: caremoli Date: Mon, 10 Jan 2011 10:26:37 +0000 Subject: [PATCH] CCAR: optimize selection of large number of objects in object browser when entries are mostly contiguous: 1- order QModelIndex by increasing row (SUIT_DataBrowser.cxx) 2- select by range when indexes are contiguous (OB_Browser.cxx) --- src/ObjBrowser/OB_Browser.cxx | 24 +++++++++++++++++++++--- src/SUIT/SUIT_DataBrowser.cxx | 14 ++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/ObjBrowser/OB_Browser.cxx b/src/ObjBrowser/OB_Browser.cxx index b8c30eb3c..5e5d4a601 100755 --- a/src/ObjBrowser/OB_Browser.cxx +++ b/src/ObjBrowser/OB_Browser.cxx @@ -418,9 +418,27 @@ void OB_Browser::select( const QModelIndexList& indexes, const bool on, const bo if ( !indexes.isEmpty() ) { QItemSelection mysel; - foreach( idx, indexes ) { - mysel.select(idx,idx); - } + // select by range if indexes are contiguous + QModelIndex first=indexes.at(0); + QModelIndex last=first; + for (int i = 1; i < indexes.size(); ++i) + { + idx=indexes.at(i); + if(idx.parent().internalId()==last.parent().internalId() && idx.row()==last.row()+1 && idx.column()==last.column()) + { + // index is contiguous to last: extend the range + last=idx; + } + else + { + // index idx is not contiguous: create a new range + mysel.select(first,last); + first=idx; + last=idx; + } + } + mysel.select(first,last); + if ( myView->selectionModel() ) { QItemSelectionModel::SelectionFlags f = on ? QItemSelectionModel::Select : QItemSelectionModel::Deselect; f = f | QItemSelectionModel::Rows; diff --git a/src/SUIT/SUIT_DataBrowser.cxx b/src/SUIT/SUIT_DataBrowser.cxx index bae8d0ce8..e29194155 100644 --- a/src/SUIT/SUIT_DataBrowser.cxx +++ b/src/SUIT/SUIT_DataBrowser.cxx @@ -234,6 +234,18 @@ void SUIT_DataBrowser::setSelected( const SUIT_DataObject* obj, const bool appen } } +/*! + \brief function to sort QModelIndexList with qSort +*/ +bool modelIndexLessThan(const QModelIndex& lhs, const QModelIndex& rhs) +{ + QModelIndex lhs_parent=lhs.parent(); + QModelIndex rhs_parent=rhs.parent(); + if(lhs_parent < rhs_parent)return true; + if(lhs_parent == rhs_parent) return lhs < rhs; + return false; +} + /*! \brief Set list of selected data objects. \param lst list of the data object to set selected @@ -253,6 +265,8 @@ void SUIT_DataBrowser::setSelected( const DataObjectList& lst, const bool append if ( index.isValid() ) indexes.append( index ); } + qSort(indexes.begin(), indexes.end(), modelIndexLessThan); + select( indexes, true, append ); // if !indexes.isEmpty() ??? } } -- 2.39.2