Skip to content
Permalink
Browse files

Make style filter model search by word, not phrase

This allows matching of a filter string "hash line" to the symbol
 "hashed red lines"
  • Loading branch information
nyalldawson committed Sep 14, 2018
1 parent 31daa82 commit 57f89c999f1a1eda2f5fc12323587a7e2168eda6
Showing with 33 additions and 2 deletions.
  1. +27 −2 src/core/symbology/qgsstylemodel.cpp
  2. +6 −0 tests/src/python/test_qgsstylemodel.py
@@ -472,8 +472,33 @@ bool QgsStyleProxyModel::filterAcceptsRow( int source_row, const QModelIndex &so
if ( mFavoritesOnly && !mFavoritedSymbolNames.contains( name ) )
return false;

if ( !name.contains( mFilterString, Qt::CaseInsensitive ) && !tags.join( ';' ).contains( mFilterString, Qt::CaseInsensitive ) )
return false;
if ( !mFilterString.isEmpty() )
{
// filter by word, in both filter string and style entity name/tags
// this allows matching of a filter string "hash line" to the symbol "hashed red lines"
const QStringList partsToMatch = mFilterString.trimmed().split( ' ' );

QStringList partsToSearch = name.split( ' ' );
for ( const QString &tag : tags )
{
partsToSearch.append( tag.split( ' ' ) );
}

for ( const QString &part : partsToMatch )
{
bool found = false;
for ( const QString &partToSearch : qgis::as_const( partsToSearch ) )
{
if ( partToSearch.contains( part, Qt::CaseInsensitive ) )
{
found = true;
break;
}
}
if ( !found )
return false; // couldn't find a match for this word, so hide entity
}
}

return true;
}
@@ -548,6 +548,12 @@ def test_filter_proxy(self):
self.assertEqual(model.rowCount(), 2)
self.assertEqual(model.data(model.index(0, 0)), 'a')
self.assertEqual(model.data(model.index(1, 0)), 'ramp a')
model.setFilterString('ram b')
self.assertEqual(model.rowCount(), 1)
self.assertEqual(model.data(model.index(0, 0)), 'ramp BB')
model.setFilterString('ta ram') # match ta -> "tag 1", ram -> "ramp a"
self.assertEqual(model.rowCount(), 1)
self.assertEqual(model.data(model.index(0, 0)), 'ramp a')
model.setFilterString('')
self.assertEqual(model.rowCount(), 8)

0 comments on commit 57f89c9

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