Skip to content

Commit

Permalink
[options search] use lambda method to search text in widgets
Browse files Browse the repository at this point in the history
3nids committed Jan 25, 2018
1 parent 34c2d32 commit 3b14380
Showing 2 changed files with 14 additions and 19 deletions.
31 changes: 13 additions & 18 deletions src/gui/qgsoptionsdialogbase.cpp
Original file line number Diff line number Diff line change
@@ -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 )
2 changes: 1 addition & 1 deletion src/gui/qgsoptionsdialogbase.h
Original file line number Diff line number Diff line change
@@ -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.