Skip to content
Permalink
Browse files

[options search] use lambda method to search text in widgets

  • Loading branch information
3nids committed Jan 25, 2018
1 parent 34c2d32 commit 3b143805d8dfe5fa2fbe104501caf44ef6a75bfe
Showing with 14 additions and 19 deletions.
  1. +13 −18 src/gui/qgsoptionsdialogbase.cpp
  2. +1 −1 src/gui/qgsoptionsdialogbase.h
@@ -398,31 +398,38 @@ void QgsOptionsDialogBase::warnAboutMissingObjects()
QgsSearchHighlightOptionWidget::QgsSearchHighlightOptionWidget( QWidget *widget )
: QObject( widget )
, mWidget( widget )
, mText( [ = ]() {return QString();} )
{
if ( qobject_cast<QLabel *>( widget ) )
{
mStyleSheet = QStringLiteral( "QLabel { background-color: yellow; color: blue;}" );
mText = [ = ]() {return qobject_cast<QLabel *>( mWidget )->text();};
mTextFound = [ = ]( QString searchText ) {return qobject_cast<QLabel *>( mWidget )->text().contains( searchText, Qt::CaseInsensitive );};
}
else if ( qobject_cast<QCheckBox *>( widget ) )
{
mStyleSheet = QStringLiteral( "QCheckBox { background-color: yellow; color: blue;}" );
mText = [ = ]() {return qobject_cast<QCheckBox *>( mWidget )->text();};
mTextFound = [ = ]( QString searchText ) {return qobject_cast<QCheckBox *>( mWidget )->text().contains( searchText, Qt::CaseInsensitive );};
}
else if ( qobject_cast<QAbstractButton *>( widget ) )
{
mStyleSheet = QStringLiteral( "QAbstractButton { background-color: yellow; color: blue;}" );
mText = [ = ]() {return qobject_cast<QAbstractButton *>( mWidget )->text();};
mTextFound = [ = ]( QString searchText ) {return qobject_cast<QAbstractButton *>( mWidget )->text().contains( searchText, Qt::CaseInsensitive );};
}
else if ( qobject_cast<QGroupBox *>( widget ) )
{
mStyleSheet = QStringLiteral( "QGroupBox::title { background-color: yellow; color: blue;}" );
mText = [ = ]() {return qobject_cast<QGroupBox *>( mWidget )->title();};
mTextFound = [ = ]( QString searchText ) {return qobject_cast<QGroupBox *>( mWidget )->title().contains( searchText, Qt::CaseInsensitive );};
}
else if ( qobject_cast<QTreeView *>( widget ) )
{
// TODO - style individual matching items
mTextFound = [ = ]( QString searchText )
{
QTreeView *tree = qobject_cast<QTreeView *>( mWidget );
if ( !tree )
return false;
QModelIndexList hits = tree->model()->match( tree->model()->index( 0, 0 ), Qt::DisplayRole, searchText, 1, Qt::MatchContains | Qt::MatchRecursive );
return !hits.isEmpty();
};
}
else
{
@@ -444,19 +451,7 @@ bool QgsSearchHighlightOptionWidget::searchHighlight( const QString &searchText

if ( !searchText.isEmpty() )
{
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
{
QString origText = mText();
if ( origText.contains( searchText, Qt::CaseInsensitive ) )
{
found = true;
}
}
found = mTextFound( searchText );
}

if ( found && !mChangedStyle )
@@ -90,7 +90,7 @@ class GUI_EXPORT QgsSearchHighlightOptionWidget : public QObject
QString mStyleSheet;
bool mValid = true;
bool mChangedStyle = false;
std::function < QString() > mText;
std::function < bool( QString )> mTextFound = []( QString searchText ) {Q_UNUSED( searchText ); return false;};
bool mInstalledFilter = false;
};

0 comments on commit 3b14380

Please sign in to comment.
You can’t perform that action at this time.