Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 16, 2018
1 parent 69ab3c9 commit 1235c35
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 54 deletions.
5 changes: 3 additions & 2 deletions src/gui/processing/qgsprocessingtoolboxmodel.cpp
Expand Up @@ -514,7 +514,8 @@ QModelIndex QgsProcessingToolboxModel::indexForProvider( const QString &provider
for ( int row = 0; row < rowCount( parent ); ++row )
{
QModelIndex current = index( row, 0, parent );
if ( providerIdForIndex( current ) == providerId )
const QString currentProviderId = providerIdForIndex( current );
if ( !currentProviderId.isEmpty() && currentProviderId == providerId )
return current;

QModelIndex checkChildren = findIndex( current, providerId );
Expand Down Expand Up @@ -649,7 +650,7 @@ bool QgsProcessingToolboxProxyModel::filterAcceptsRow( int sourceRow, const QMod
else
{
// group
return hasChildren || isRecentNode;
return hasChildren; // || isRecentNode;
}
}

Expand Down
107 changes: 55 additions & 52 deletions tests/src/gui/testqgsprocessingmodel.cpp
Expand Up @@ -129,72 +129,74 @@ void TestQgsProcessingModel::testModel()
QgsProcessingToolboxModel model( nullptr, &registry );

QCOMPARE( model.columnCount(), 1 );
QCOMPARE( model.rowCount(), 0 );
QVERIFY( !model.hasChildren() );
QCOMPARE( model.rowCount(), 1 );
QVERIFY( model.hasChildren() );
QCOMPARE( model.data( model.index( 0, 0, QModelIndex() ), Qt::DisplayRole ).toString(), QStringLiteral( "Recently used" ) );
QVERIFY( !model.providerForIndex( model.index( 0, 0, QModelIndex() ) ) );
QVERIFY( !model.providerForIndex( model.index( 1, 0, QModelIndex() ) ) );
QVERIFY( !model.indexForProvider( nullptr ).isValid() );

// add a provider
DummyProvider *p1 = new DummyProvider( "p1", "provider1" );
registry.addProvider( p1 );
QCOMPARE( model.rowCount(), 1 );
QCOMPARE( model.rowCount(), 2 );
QVERIFY( model.hasChildren() );

QVERIFY( model.index( 0, 0, QModelIndex() ).isValid() );
QCOMPARE( model.providerForIndex( model.index( 0, 0, QModelIndex() ) ), p1 );
QVERIFY( !model.providerForIndex( model.index( 1, 0, QModelIndex() ) ) );
QCOMPARE( model.indexForProvider( p1->id() ), model.index( 0, 0, QModelIndex() ) );
QCOMPARE( model.data( model.index( 0, 0, QModelIndex() ), Qt::DisplayRole ).toString(), QStringLiteral( "Recently used" ) );
QCOMPARE( model.providerForIndex( model.index( 1, 0, QModelIndex() ) ), p1 );
QVERIFY( !model.providerForIndex( model.index( 2, 0, QModelIndex() ) ) );
QCOMPARE( model.indexForProvider( p1->id() ), model.index( 1, 0, QModelIndex() ) );
QVERIFY( !model.indexForProvider( nullptr ).isValid() );
QCOMPARE( model.rowCount( model.index( 0, 0, QModelIndex() ) ), 0 );
QVERIFY( !model.hasChildren( model.index( 0, 0, QModelIndex() ) ) );
QCOMPARE( model.data( model.index( 0, 0, QModelIndex() ), Qt::DisplayRole ).toString(), QStringLiteral( "provider1" ) );
QCOMPARE( model.data( model.index( 0, 0, QModelIndex() ), Qt::ToolTipRole ).toString(), QStringLiteral( "long name provider1" ) );
QVERIFY( !model.data( model.index( 1, 0, QModelIndex() ), Qt::DisplayRole ).isValid() );
QVERIFY( !model.data( model.index( 1, 0, QModelIndex() ), Qt::ToolTipRole ).isValid() );
QCOMPARE( model.rowCount( model.index( 1, 0, QModelIndex() ) ), 0 );
QVERIFY( !model.hasChildren( model.index( 1, 0, QModelIndex() ) ) );
QCOMPARE( model.data( model.index( 1, 0, QModelIndex() ), Qt::DisplayRole ).toString(), QStringLiteral( "provider1" ) );
QCOMPARE( model.data( model.index( 1, 0, QModelIndex() ), Qt::ToolTipRole ).toString(), QStringLiteral( "long name provider1" ) );
QVERIFY( !model.data( model.index( 2, 0, QModelIndex() ), Qt::DisplayRole ).isValid() );
QVERIFY( !model.data( model.index( 2, 0, QModelIndex() ), Qt::ToolTipRole ).isValid() );

// second provider
DummyProvider *p2 = new DummyProvider( "p2", "provider2" );
registry.addProvider( p2 );
QCOMPARE( model.rowCount(), 2 );
QCOMPARE( model.rowCount(), 3 );
QVERIFY( model.hasChildren() );

QVERIFY( model.index( 1, 0, QModelIndex() ).isValid() );
QCOMPARE( model.providerForIndex( model.index( 0, 0, QModelIndex() ) ), p1 );
QCOMPARE( model.providerForIndex( model.index( 1, 0, QModelIndex() ) ), p2 );
QVERIFY( !model.providerForIndex( model.index( 2, 0, QModelIndex() ) ) );
QCOMPARE( model.indexForProvider( p1->id() ), model.index( 0, 0, QModelIndex() ) );
QCOMPARE( model.indexForProvider( p2->id() ), model.index( 1, 0, QModelIndex() ) );
QVERIFY( model.index( 2, 0, QModelIndex() ).isValid() );
QCOMPARE( model.providerForIndex( model.index( 1, 0, QModelIndex() ) ), p1 );
QCOMPARE( model.providerForIndex( model.index( 2, 0, QModelIndex() ) ), p2 );
QVERIFY( !model.providerForIndex( model.index( 3, 0, QModelIndex() ) ) );
QCOMPARE( model.indexForProvider( p1->id() ), model.index( 1, 0, QModelIndex() ) );
QCOMPARE( model.indexForProvider( p2->id() ), model.index( 2, 0, QModelIndex() ) );
QVERIFY( !model.indexForProvider( nullptr ).isValid() );
QVERIFY( !model.hasChildren( model.index( 1, 0, QModelIndex() ) ) );
QVERIFY( !model.hasChildren( model.index( 2, 0, QModelIndex() ) ) );

QCOMPARE( model.data( model.index( 0, 0, QModelIndex() ), Qt::DisplayRole ).toString(), QStringLiteral( "provider1" ) );
QCOMPARE( model.data( model.index( 0, 0, QModelIndex() ), Qt::ToolTipRole ).toString(), QStringLiteral( "long name provider1" ) );
QCOMPARE( model.data( model.index( 1, 0, QModelIndex() ), Qt::DisplayRole ).toString(), QStringLiteral( "provider2" ) );
QCOMPARE( model.data( model.index( 1, 0, QModelIndex() ), Qt::ToolTipRole ).toString(), QStringLiteral( "long name provider2" ) );
QVERIFY( !model.data( model.index( 2, 0, QModelIndex() ), Qt::DisplayRole ).isValid() );
QVERIFY( !model.data( model.index( 2, 0, QModelIndex() ), Qt::ToolTipRole ).isValid() );
QCOMPARE( model.data( model.index( 1, 0, QModelIndex() ), Qt::DisplayRole ).toString(), QStringLiteral( "provider1" ) );
QCOMPARE( model.data( model.index( 1, 0, QModelIndex() ), Qt::ToolTipRole ).toString(), QStringLiteral( "long name provider1" ) );
QCOMPARE( model.data( model.index( 2, 0, QModelIndex() ), Qt::DisplayRole ).toString(), QStringLiteral( "provider2" ) );
QCOMPARE( model.data( model.index( 2, 0, QModelIndex() ), Qt::ToolTipRole ).toString(), QStringLiteral( "long name provider2" ) );
QVERIFY( !model.data( model.index( 3, 0, QModelIndex() ), Qt::DisplayRole ).isValid() );
QVERIFY( !model.data( model.index( 3, 0, QModelIndex() ), Qt::ToolTipRole ).isValid() );

// provider with algs and groups
DummyAlgorithm *a1 = new DummyAlgorithm( "a1", "group1", QgsProcessingAlgorithm::FlagHideFromModeler, QStringLiteral( "tag1,tag2" ), QStringLiteral( "short desc a" ) );
DummyAlgorithm *a2 = new DummyAlgorithm( "a2", "group2", QgsProcessingAlgorithm::FlagHideFromToolbox );
DummyProvider *p3 = new DummyProvider( "p3", "provider3", QList< QgsProcessingAlgorithm * >() << a1 << a2 );
registry.addProvider( p3 );

QCOMPARE( model.rowCount(), 3 );
QCOMPARE( model.rowCount(), 4 );
QVERIFY( model.hasChildren() );
QVERIFY( model.index( 2, 0, QModelIndex() ).isValid() );
QCOMPARE( model.providerForIndex( model.index( 2, 0, QModelIndex() ) ), p3 );
QCOMPARE( model.indexForProvider( p1->id() ), model.index( 0, 0, QModelIndex() ) );
QCOMPARE( model.indexForProvider( p2->id() ), model.index( 1, 0, QModelIndex() ) );
QCOMPARE( model.indexForProvider( p3->id() ), model.index( 2, 0, QModelIndex() ) );
QCOMPARE( model.rowCount( model.index( 1, 0, QModelIndex() ) ), 0 );
QCOMPARE( model.rowCount( model.index( 2, 0, QModelIndex() ) ), 2 );
QVERIFY( !model.hasChildren( model.index( 1, 0, QModelIndex() ) ) );
QVERIFY( model.hasChildren( model.index( 2, 0, QModelIndex() ) ) );
QModelIndex providerIndex = model.index( 2, 0, QModelIndex() );
QVERIFY( !model.providerForIndex( model.index( 0, 0, providerIndex ) ) );
QVERIFY( model.index( 3, 0, QModelIndex() ).isValid() );
QCOMPARE( model.providerForIndex( model.index( 3, 0, QModelIndex() ) ), p3 );
QCOMPARE( model.indexForProvider( p1->id() ), model.index( 1, 0, QModelIndex() ) );
QCOMPARE( model.indexForProvider( p2->id() ), model.index( 2, 0, QModelIndex() ) );
QCOMPARE( model.indexForProvider( p3->id() ), model.index( 3, 0, QModelIndex() ) );
QCOMPARE( model.rowCount( model.index( 2, 0, QModelIndex() ) ), 0 );
QCOMPARE( model.rowCount( model.index( 3, 0, QModelIndex() ) ), 2 );
QVERIFY( !model.hasChildren( model.index( 2, 0, QModelIndex() ) ) );
QVERIFY( model.hasChildren( model.index( 3, 0, QModelIndex() ) ) );
QModelIndex providerIndex = model.index( 3, 0, QModelIndex() );
QVERIFY( !model.providerForIndex( model.index( 1, 0, providerIndex ) ) );
QVERIFY( !model.providerForIndex( model.index( 2, 0, providerIndex ) ) );

QCOMPARE( model.data( model.index( 0, 0, providerIndex ), Qt::DisplayRole ).toString(), QStringLiteral( "group1" ) );
QCOMPARE( model.data( model.index( 0, 0, providerIndex ), Qt::ToolTipRole ).toString(), QStringLiteral( "group1" ) );
Expand Down Expand Up @@ -248,7 +250,7 @@ void TestQgsProcessingModel::testModel()
DummyAlgorithm *a7 = new DummyAlgorithm( "a7", "group2" );
DummyProvider *p5 = new DummyProvider( "p5", "provider5", QList< QgsProcessingAlgorithm * >() << a5 << a6 << a7 );
registry.addProvider( p5 );
QCOMPARE( model.rowCount(), 5 );
QCOMPARE( model.rowCount(), 6 );
QModelIndex p5ProviderIndex = model.indexForProvider( p5->id() );
QCOMPARE( model.rowCount( p5ProviderIndex ), 3 );

Expand All @@ -266,7 +268,7 @@ void TestQgsProcessingModel::testModel()

// reload provider
p5->refreshAlgorithms();
QCOMPARE( model.rowCount(), 5 );
QCOMPARE( model.rowCount(), 6 );
p5ProviderIndex = model.indexForProvider( p5->id() );
QCOMPARE( model.rowCount( p5ProviderIndex ), 3 );

Expand All @@ -293,20 +295,21 @@ void TestQgsProcessingModel::testModel()

// remove a provider
registry.removeProvider( p1 );
QCOMPARE( model.rowCount(), 4 );
QCOMPARE( model.rowCount(), 5 );
QVERIFY( model.index( 0, 0, QModelIndex() ).isValid() );
QCOMPARE( model.providerForIndex( model.index( 0, 0, QModelIndex() ) ), p2 );
QCOMPARE( model.data( model.index( 0, 0, QModelIndex() ), Qt::DisplayRole ).toString(), QStringLiteral( "provider2" ) );
QCOMPARE( model.providerForIndex( model.index( 1, 0, QModelIndex() ) ), p2 );
QCOMPARE( model.data( model.index( 1, 0, QModelIndex() ), Qt::DisplayRole ).toString(), QStringLiteral( "provider2" ) );
registry.removeProvider( p5 );
QCOMPARE( model.rowCount(), 3 );
QCOMPARE( model.rowCount(), 4 );
registry.removeProvider( p2 );
QCOMPARE( model.rowCount(), 2 );
QCOMPARE( model.rowCount(), 3 );
registry.removeProvider( p3 );
QCOMPARE( model.rowCount(), 1 );
QCOMPARE( model.rowCount(), 2 );
registry.removeProvider( p4 );
QCOMPARE( model.rowCount(), 0 );
QCOMPARE( model.rowCount(), 1 );
QCOMPARE( model.columnCount(), 1 );
QVERIFY( !model.hasChildren() );
QVERIFY( model.hasChildren() );
QCOMPARE( model.data( model.index( 0, 0, QModelIndex() ), Qt::DisplayRole ).toString(), QStringLiteral( "Recently used" ) );
QVERIFY( !model.providerForIndex( model.index( 0, 0, QModelIndex() ) ) );
QVERIFY( !model.providerForIndex( model.index( 1, 0, QModelIndex() ) ) );
QVERIFY( !model.indexForProvider( nullptr ).isValid() );
Expand All @@ -321,10 +324,10 @@ void TestQgsProcessingModel::testModel()
DummyProvider *qgisP = new DummyProvider( "qgis", "qgis_provider", QList< QgsProcessingAlgorithm * >() << qgisA1 << qgisA2 << qgisA3 << qgisA4 );
registry2.addProvider( qgisP );

QCOMPARE( model2.rowCount(), 3 );
group1Index = model2.index( 0, 0 );
group2Index = model2.index( 1, 0 );
QModelIndex group3Index = model2.index( 2, 0 );
QCOMPARE( model2.rowCount(), 4 );
group1Index = model2.index( 1, 0 );
group2Index = model2.index( 2, 0 );
QModelIndex group3Index = model2.index( 3, 0 );
QCOMPARE( model2.data( group1Index, Qt::DisplayRole ).toString(), QStringLiteral( "group1" ) );
QCOMPARE( model2.data( group2Index, Qt::DisplayRole ).toString(), QStringLiteral( "group2" ) );
QCOMPARE( model2.data( group3Index, Qt::DisplayRole ).toString(), QStringLiteral( "group3" ) );
Expand Down

0 comments on commit 1235c35

Please sign in to comment.