Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Also apply filter to geometry types in provider sublayer dialog
  • Loading branch information
nyalldawson committed Aug 6, 2021
1 parent 77b6e31 commit 415650e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/core/providers/qgsprovidersublayermodel.cpp
Expand Up @@ -406,6 +406,14 @@ bool QgsProviderSublayerProxyModel::filterAcceptsRow( int source_row, const QMod
if ( sourceModel()->data( sourceIndex, static_cast< int >( QgsProviderSublayerModel::Role::Description ) ).toString().contains( mFilterString, Qt::CaseInsensitive ) )
return true;

const QVariant wkbTypeVariant = sourceModel()->data( sourceIndex, static_cast< int >( QgsProviderSublayerModel::Role::WkbType ) );
if ( wkbTypeVariant.isValid() )
{
QgsWkbTypes::Type wkbType = static_cast< QgsWkbTypes::Type >( wkbTypeVariant.toInt() );
if ( QgsWkbTypes::displayString( wkbType ).contains( mFilterString, Qt::CaseInsensitive ) )
return true;
}

return false;
}

Expand Down
5 changes: 5 additions & 0 deletions tests/src/python/test_qgsprovidersublayermodel.py
Expand Up @@ -380,6 +380,11 @@ def test_proxy(self):
self.assertEqual(proxy.rowCount(QModelIndex()), 1)
self.assertEqual(proxy.data(proxy.index(0, 0), Qt.DisplayRole), 'item name 1')

# should also allow filtering by vector layer wkb type strings
proxy.setFilterString('LineSTRING')
self.assertEqual(proxy.rowCount(QModelIndex()), 1)
self.assertEqual(proxy.data(proxy.index(0, 0), Qt.DisplayRole), 'another layer 2')

proxy.setFilterString('')
self.assertEqual(proxy.rowCount(QModelIndex()), 3)
self.assertEqual(proxy.data(proxy.index(0, 0), Qt.DisplayRole), 'item name 1')
Expand Down

0 comments on commit 415650e

Please sign in to comment.