Skip to content
Permalink
Browse files

[processing] Empty provider nodes should still be shown in toolbox,

unless a filter string is entered

This allows easier discoverability - e.g. without this, the model
and script nodes are hidden until models/scripts have already
been created.
  • Loading branch information
nyalldawson committed Jul 17, 2018
1 parent 3d20cfe commit 325f2a4622c20e44d3cb04a801e3eaffaf523045
Showing with 16 additions and 6 deletions.
  1. +3 −2 src/gui/processing/qgsprocessingtoolboxmodel.cpp
  2. +13 −4 tests/src/gui/testqgsprocessingmodel.cpp
@@ -722,7 +722,8 @@ bool QgsProcessingToolboxProxyModel::filterAcceptsRow( int sourceRow, const QMod
}

bool hasChildren = false;
// providers and groups are shown only if they have visible children
// groups are shown only if they have visible children
// but providers are shown if they have visible children, OR the filter string is empty
int count = sourceModel()->rowCount( sourceIndex );
for ( int i = 0; i < count; ++i )
{
@@ -735,7 +736,7 @@ bool QgsProcessingToolboxProxyModel::filterAcceptsRow( int sourceRow, const QMod

if ( QgsProcessingProvider *provider = mModel->providerForIndex( sourceIndex ) )
{
return hasChildren && provider->isActive();
return ( hasChildren || mFilterString.trimmed().isEmpty() ) && provider->isActive();
}
else
{
@@ -427,10 +427,15 @@ void TestQgsProcessingModel::testProxyModel()

model.setFilters( QgsProcessingToolboxProxyModel::FilterModeler );
group1Index = model.index( 0, 0, QModelIndex() );
QCOMPARE( model.rowCount(), 1 );
QCOMPARE( model.rowCount(), 3 );
QCOMPARE( model.rowCount( group1Index ), 1 );
QCOMPARE( model.data( group1Index, Qt::DisplayRole ).toString(), QStringLiteral( "group1" ) );
QCOMPARE( model.data( model.index( 0, 0, group1Index ), Qt::DisplayRole ).toString(), QStringLiteral( "a2" ) );
// no filter string, so empty providers should be shown
QCOMPARE( model.data( model.index( 1, 0, QModelIndex() ), Qt::DisplayRole ).toString(), QStringLiteral( "provider1" ) );
QCOMPARE( model.rowCount( model.index( 1, 0, QModelIndex() ) ), 0 );
QCOMPARE( model.data( model.index( 2, 0, QModelIndex() ), Qt::DisplayRole ).toString(), QStringLiteral( "provider2" ) );
QCOMPARE( model.rowCount( model.index( 2, 0, QModelIndex() ) ), 0 );
model.setFilters( QgsProcessingToolboxProxyModel::FilterToolbox );
group2Index = model.index( 0, 0, QModelIndex() );
QCOMPARE( model.rowCount(), 3 );
@@ -586,18 +591,22 @@ void TestQgsProcessingModel::testView()
QCOMPARE( view.algorithmForIndex( alg1Index )->id(), QStringLiteral( "p2:a1" ) );

view.setFilters( QgsProcessingToolboxProxyModel::FilterModeler );
provider2Index = view.model()->index( 0, 0, QModelIndex() );
QCOMPARE( view.model()->rowCount(), 2 );
QCOMPARE( view.model()->data( view.model()->index( 0, 0, QModelIndex() ), Qt::DisplayRole ).toString(), QStringLiteral( "provider1" ) );
QCOMPARE( view.model()->rowCount( view.model()->index( 0, 0, QModelIndex() ) ), 0 );
provider2Index = view.model()->index( 1, 0, QModelIndex() );
QCOMPARE( view.model()->data( provider2Index, Qt::DisplayRole ).toString(), QStringLiteral( "provider2" ) );
QCOMPARE( view.model()->rowCount(), 1 );
QCOMPARE( view.model()->rowCount( provider2Index ), 1 );
group2Index = view.model()->index( 0, 0, provider2Index );
QCOMPARE( view.model()->rowCount( group2Index ), 1 );
QCOMPARE( view.algorithmForIndex( view.model()->index( 0, 0, group2Index ) )->id(), QStringLiteral( "p2:a1" ) );
view.setFilters( QgsProcessingToolboxProxyModel::FilterToolbox );
QCOMPARE( view.model()->rowCount(), 2 );
provider1Index = view.model()->index( 0, 0, QModelIndex() );
QCOMPARE( view.model()->data( provider1Index, Qt::DisplayRole ).toString(), QStringLiteral( "provider1" ) );
QCOMPARE( view.model()->rowCount(), 1 );
QCOMPARE( view.model()->rowCount( provider1Index ), 1 );
QCOMPARE( view.model()->data( view.model()->index( 1, 0, QModelIndex() ), Qt::DisplayRole ).toString(), QStringLiteral( "provider2" ) );
QCOMPARE( view.model()->rowCount( view.model()->index( 1, 0, QModelIndex() ) ), 0 );
group2Index = view.model()->index( 0, 0, provider1Index );
QCOMPARE( view.model()->rowCount( group2Index ), 1 );
QCOMPARE( view.algorithmForIndex( view.model()->index( 0, 0, group2Index ) )->id(), QStringLiteral( "p1:a2" ) );

0 comments on commit 325f2a4

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