cache few things, but it's still sloooooooooooow

svn path=/trunk/KDE/kdegraphics/okular/; revision=749261
remotes/origin/KDE/4.0
Pino Toscano 19 years ago
parent 034e8f9299
commit 18af83bcfc
  1. 18
      ui/ktreeviewsearchline.cpp

@ -185,16 +185,18 @@ void KTreeViewSearchLine::Private::checkItemParentsNotVisible( QTreeView *treeVi
bool KTreeViewSearchLine::Private::checkItemParentsVisible( QTreeView *treeView, const QModelIndex &index ) bool KTreeViewSearchLine::Private::checkItemParentsVisible( QTreeView *treeView, const QModelIndex &index )
{ {
bool childMatch = false; bool childMatch = false;
for ( int i = 0; i < treeView->model()->rowCount( index ); ++i ) const int rowcount = treeView->model()->rowCount( index );
for ( int i = 0; i < rowcount; ++i )
childMatch |= checkItemParentsVisible( treeView, treeView->model()->index( i, 0, index ) ); childMatch |= checkItemParentsVisible( treeView, treeView->model()->index( i, 0, index ) );
// Should this item be shown? It should if any children should be, or if it matches. // Should this item be shown? It should if any children should be, or if it matches.
if ( childMatch || parent->itemMatches( index.parent(), index.row(), search ) ) { const QModelIndex parentindex = index.parent();
treeView->setRowHidden( index.row(), index.parent(), false ); if ( childMatch || parent->itemMatches( parentindex, index.row(), search ) ) {
treeView->setRowHidden( index.row(), parentindex, false );
return true; return true;
} }
treeView->setRowHidden( index.row(), index.parent(), true ); treeView->setRowHidden( index.row(), parentindex, true );
return false; return false;
} }
@ -317,11 +319,14 @@ void KTreeViewSearchLine::updateSearch( QTreeView *treeView )
QModelIndex currentIndex = treeView->currentIndex(); QModelIndex currentIndex = treeView->currentIndex();
bool wasUpdateEnabled = treeView->updatesEnabled();
treeView->setUpdatesEnabled( false );
if ( d->keepParentsVisible ) if ( d->keepParentsVisible )
for ( int i = 0; i < treeView->model()->rowCount(); ++i ) for ( int i = 0; i < treeView->model()->rowCount(); ++i )
d->checkItemParentsVisible( treeView, treeView->rootIndex() ); d->checkItemParentsVisible( treeView, treeView->rootIndex() );
else else
d->checkItemParentsNotVisible( treeView ); d->checkItemParentsNotVisible( treeView );
treeView->setUpdatesEnabled( wasUpdateEnabled );
if ( currentIndex.isValid() ) if ( currentIndex.isValid() )
treeView->scrollTo( currentIndex ); treeView->scrollTo( currentIndex );
@ -385,15 +390,16 @@ bool KTreeViewSearchLine::itemMatches( const QModelIndex &index, int row, const
// If the search column list is populated, search just the columns // If the search column list is populated, search just the columns
// specifified. If it is empty default to searching all of the columns. // specifified. If it is empty default to searching all of the columns.
const int columncount = index.model()->columnCount( index );
if ( !d->searchColumns.isEmpty() ) { if ( !d->searchColumns.isEmpty() ) {
QList<int>::ConstIterator it = d->searchColumns.begin(); QList<int>::ConstIterator it = d->searchColumns.begin();
for ( ; it != d->searchColumns.end(); ++it ) { for ( ; it != d->searchColumns.end(); ++it ) {
if ( *it < index.model()->columnCount( index ) && if ( *it < columncount &&
index.child( row, *it ).data( Qt::DisplayRole ).toString().indexOf( pattern, 0, d->caseSensitive ) >= 0 ) index.child( row, *it ).data( Qt::DisplayRole ).toString().indexOf( pattern, 0, d->caseSensitive ) >= 0 )
return true; return true;
} }
} else { } else {
for ( int i = 0; i < index.model()->columnCount( index ); ++i) { for ( int i = 0; i < columncount; ++i) {
if ( index.child( row, i ).data( Qt::DisplayRole ).toString().indexOf( pattern, 0, d->caseSensitive ) >= 0 ) if ( index.child( row, i ).data( Qt::DisplayRole ).toString().indexOf( pattern, 0, d->caseSensitive ) >= 0 )
return true; return true;
} }

Loading…
Cancel
Save