Skip to content

Commit 325f2a4

Browse files
committedJul 17, 2018
[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.
1 parent 3d20cfe commit 325f2a4

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed
 

‎src/gui/processing/qgsprocessingtoolboxmodel.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,8 @@ bool QgsProcessingToolboxProxyModel::filterAcceptsRow( int sourceRow, const QMod
722722
}
723723

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

736737
if ( QgsProcessingProvider *provider = mModel->providerForIndex( sourceIndex ) )
737738
{
738-
return hasChildren && provider->isActive();
739+
return ( hasChildren || mFilterString.trimmed().isEmpty() ) && provider->isActive();
739740
}
740741
else
741742
{

‎tests/src/gui/testqgsprocessingmodel.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -427,10 +427,15 @@ void TestQgsProcessingModel::testProxyModel()
427427

428428
model.setFilters( QgsProcessingToolboxProxyModel::FilterModeler );
429429
group1Index = model.index( 0, 0, QModelIndex() );
430-
QCOMPARE( model.rowCount(), 1 );
430+
QCOMPARE( model.rowCount(), 3 );
431431
QCOMPARE( model.rowCount( group1Index ), 1 );
432432
QCOMPARE( model.data( group1Index, Qt::DisplayRole ).toString(), QStringLiteral( "group1" ) );
433433
QCOMPARE( model.data( model.index( 0, 0, group1Index ), Qt::DisplayRole ).toString(), QStringLiteral( "a2" ) );
434+
// no filter string, so empty providers should be shown
435+
QCOMPARE( model.data( model.index( 1, 0, QModelIndex() ), Qt::DisplayRole ).toString(), QStringLiteral( "provider1" ) );
436+
QCOMPARE( model.rowCount( model.index( 1, 0, QModelIndex() ) ), 0 );
437+
QCOMPARE( model.data( model.index( 2, 0, QModelIndex() ), Qt::DisplayRole ).toString(), QStringLiteral( "provider2" ) );
438+
QCOMPARE( model.rowCount( model.index( 2, 0, QModelIndex() ) ), 0 );
434439
model.setFilters( QgsProcessingToolboxProxyModel::FilterToolbox );
435440
group2Index = model.index( 0, 0, QModelIndex() );
436441
QCOMPARE( model.rowCount(), 3 );
@@ -586,18 +591,22 @@ void TestQgsProcessingModel::testView()
586591
QCOMPARE( view.algorithmForIndex( alg1Index )->id(), QStringLiteral( "p2:a1" ) );
587592

588593
view.setFilters( QgsProcessingToolboxProxyModel::FilterModeler );
589-
provider2Index = view.model()->index( 0, 0, QModelIndex() );
594+
QCOMPARE( view.model()->rowCount(), 2 );
595+
QCOMPARE( view.model()->data( view.model()->index( 0, 0, QModelIndex() ), Qt::DisplayRole ).toString(), QStringLiteral( "provider1" ) );
596+
QCOMPARE( view.model()->rowCount( view.model()->index( 0, 0, QModelIndex() ) ), 0 );
597+
provider2Index = view.model()->index( 1, 0, QModelIndex() );
590598
QCOMPARE( view.model()->data( provider2Index, Qt::DisplayRole ).toString(), QStringLiteral( "provider2" ) );
591-
QCOMPARE( view.model()->rowCount(), 1 );
592599
QCOMPARE( view.model()->rowCount( provider2Index ), 1 );
593600
group2Index = view.model()->index( 0, 0, provider2Index );
594601
QCOMPARE( view.model()->rowCount( group2Index ), 1 );
595602
QCOMPARE( view.algorithmForIndex( view.model()->index( 0, 0, group2Index ) )->id(), QStringLiteral( "p2:a1" ) );
596603
view.setFilters( QgsProcessingToolboxProxyModel::FilterToolbox );
604+
QCOMPARE( view.model()->rowCount(), 2 );
597605
provider1Index = view.model()->index( 0, 0, QModelIndex() );
598606
QCOMPARE( view.model()->data( provider1Index, Qt::DisplayRole ).toString(), QStringLiteral( "provider1" ) );
599-
QCOMPARE( view.model()->rowCount(), 1 );
600607
QCOMPARE( view.model()->rowCount( provider1Index ), 1 );
608+
QCOMPARE( view.model()->data( view.model()->index( 1, 0, QModelIndex() ), Qt::DisplayRole ).toString(), QStringLiteral( "provider2" ) );
609+
QCOMPARE( view.model()->rowCount( view.model()->index( 1, 0, QModelIndex() ) ), 0 );
601610
group2Index = view.model()->index( 0, 0, provider1Index );
602611
QCOMPARE( view.model()->rowCount( group2Index ), 1 );
603612
QCOMPARE( view.algorithmForIndex( view.model()->index( 0, 0, group2Index ) )->id(), QStringLiteral( "p1:a2" ) );

0 commit comments

Comments
 (0)
Please sign in to comment.