Skip to content

Commit

Permalink
When searching for options pages, we should also show those
Browse files Browse the repository at this point in the history
where the page name matches the search term

Otherwise searching for eg "python" won't show the python console
settings page.
  • Loading branch information
nyalldawson committed Jul 29, 2021
1 parent 011a8d2 commit dc6b97c
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/gui/qgsoptionsdialogbase.cpp
Expand Up @@ -514,7 +514,14 @@ void QgsOptionsDialogBase::searchText( const QString &text )
{
for ( int r = 0; r < mOptStackedWidget->count(); ++r )
{
mOptListWidget->setRowHidden( r, text.length() >= minimumTextLength );
if ( mOptListWidget->item( r )->text().contains( text, Qt::CaseInsensitive ) )
{
mOptListWidget->setRowHidden( r, false );
}
else
{
mOptListWidget->setRowHidden( r, text.length() >= minimumTextLength );
}
}

for ( const QPair< QgsOptionsDialogHighlightWidget *, int > &rsw : std::as_const( mRegisteredSearchWidgets ) )
Expand All @@ -533,6 +540,22 @@ void QgsOptionsDialogBase::searchText( const QString &text )
hiddenPages.insert( r, text.length() >= minimumTextLength );
}

std::function<void( const QModelIndex & )> traverseModel;
// traverse through the model, showing pages which match by page name
traverseModel = [&]( const QModelIndex & parent )
{
for ( int row = 0; row < mOptTreeModel->rowCount( parent ); ++row )
{
const QModelIndex currentIndex = mOptTreeModel->index( row, 0, parent );
if ( currentIndex.data().toString().contains( text, Qt::CaseInsensitive ) )
{
hiddenPages.insert( mTreeProxyModel->sourceIndexToPageNumber( currentIndex ), false );
}
traverseModel( currentIndex );
}
};
traverseModel( QModelIndex() );

for ( const QPair< QgsOptionsDialogHighlightWidget *, int > &rsw : std::as_const( mRegisteredSearchWidgets ) )
{
if ( rsw.first->searchHighlight( text.length() >= minimumTextLength ? text : QString() ) )
Expand Down

0 comments on commit dc6b97c

Please sign in to comment.