Skip to content
Permalink
Browse files
Allow options filter to search in QTreeViews
Such as processing options. Quite basic - it just checks the item
text but does not filter or highlight items in the view
  • Loading branch information
nyalldawson committed Mar 24, 2017
1 parent 5f1a512 commit 109be1b0bbd9c008e7d17e44e52205461e6e141f
Showing with 17 additions and 4 deletions.
  1. +17 −4 src/gui/qgsoptionsdialogbase.cpp
@@ -31,7 +31,8 @@
#include <QSplitter>
#include <QStackedWidget>
#include <QTimer>

#include <QTreeView>
#include <QAbstractItemModel>

#include "qgsfilterlineedit.h"

@@ -423,6 +424,10 @@ QgsSearchHighlightOptionWidget::QgsSearchHighlightOptionWidget( QWidget *widget
mStyleSheet = "QGroupBox::title { background-color: yellow; color: blue;}";
mText = [ = ]() {return qobject_cast<QGroupBox *>( mWidget )->title();};
}
else if ( qobject_cast<QTreeView *>( widget ) )
{
// TODO - style individual matching items
}
else
{
mValid = false;
@@ -443,10 +448,18 @@ bool QgsSearchHighlightOptionWidget::searchHighlight( const QString &searchText

if ( !searchText.isEmpty() )
{
QString origText = mText();
if ( origText.contains( searchText, Qt::CaseInsensitive ) )
if ( QTreeView *tree = qobject_cast<QTreeView *>( mWidget ) )
{
QModelIndexList hits = tree->model()->match( tree->model()->index( 0, 0 ), Qt::DisplayRole, searchText, 1, Qt::MatchContains | Qt::MatchRecursive );
found = !hits.isEmpty();
}
else
{
found = true;
QString origText = mText();
if ( origText.contains( searchText, Qt::CaseInsensitive ) )
{
found = true;
}
}
}

0 comments on commit 109be1b

Please sign in to comment.