mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-28 00:17:30 -05:00
Make style filter model search by word, not phrase
This allows matching of a filter string "hash line" to the symbol "hashed red lines"
This commit is contained in:
parent
31daa826c0
commit
57f89c999f
@ -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 @@ class TestQgsStyleModel(unittest.TestCase):
|
||||
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)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user