Skip to content

Commit 1235c35

Browse files
committedJul 16, 2018
Fix test
1 parent 69ab3c9 commit 1235c35

File tree

2 files changed

+58
-54
lines changed

2 files changed

+58
-54
lines changed
 

‎src/gui/processing/qgsprocessingtoolboxmodel.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,8 @@ QModelIndex QgsProcessingToolboxModel::indexForProvider( const QString &provider
514514
for ( int row = 0; row < rowCount( parent ); ++row )
515515
{
516516
QModelIndex current = index( row, 0, parent );
517-
if ( providerIdForIndex( current ) == providerId )
517+
const QString currentProviderId = providerIdForIndex( current );
518+
if ( !currentProviderId.isEmpty() && currentProviderId == providerId )
518519
return current;
519520

520521
QModelIndex checkChildren = findIndex( current, providerId );
@@ -649,7 +650,7 @@ bool QgsProcessingToolboxProxyModel::filterAcceptsRow( int sourceRow, const QMod
649650
else
650651
{
651652
// group
652-
return hasChildren || isRecentNode;
653+
return hasChildren; // || isRecentNode;
653654
}
654655
}
655656

‎tests/src/gui/testqgsprocessingmodel.cpp

Lines changed: 55 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -129,72 +129,74 @@ void TestQgsProcessingModel::testModel()
129129
QgsProcessingToolboxModel model( nullptr, &registry );
130130

131131
QCOMPARE( model.columnCount(), 1 );
132-
QCOMPARE( model.rowCount(), 0 );
133-
QVERIFY( !model.hasChildren() );
132+
QCOMPARE( model.rowCount(), 1 );
133+
QVERIFY( model.hasChildren() );
134+
QCOMPARE( model.data( model.index( 0, 0, QModelIndex() ), Qt::DisplayRole ).toString(), QStringLiteral( "Recently used" ) );
134135
QVERIFY( !model.providerForIndex( model.index( 0, 0, QModelIndex() ) ) );
135136
QVERIFY( !model.providerForIndex( model.index( 1, 0, QModelIndex() ) ) );
136137
QVERIFY( !model.indexForProvider( nullptr ).isValid() );
137138

138139
// add a provider
139140
DummyProvider *p1 = new DummyProvider( "p1", "provider1" );
140141
registry.addProvider( p1 );
141-
QCOMPARE( model.rowCount(), 1 );
142+
QCOMPARE( model.rowCount(), 2 );
142143
QVERIFY( model.hasChildren() );
143144

144145
QVERIFY( model.index( 0, 0, QModelIndex() ).isValid() );
145-
QCOMPARE( model.providerForIndex( model.index( 0, 0, QModelIndex() ) ), p1 );
146-
QVERIFY( !model.providerForIndex( model.index( 1, 0, QModelIndex() ) ) );
147-
QCOMPARE( model.indexForProvider( p1->id() ), model.index( 0, 0, QModelIndex() ) );
146+
QCOMPARE( model.data( model.index( 0, 0, QModelIndex() ), Qt::DisplayRole ).toString(), QStringLiteral( "Recently used" ) );
147+
QCOMPARE( model.providerForIndex( model.index( 1, 0, QModelIndex() ) ), p1 );
148+
QVERIFY( !model.providerForIndex( model.index( 2, 0, QModelIndex() ) ) );
149+
QCOMPARE( model.indexForProvider( p1->id() ), model.index( 1, 0, QModelIndex() ) );
148150
QVERIFY( !model.indexForProvider( nullptr ).isValid() );
149-
QCOMPARE( model.rowCount( model.index( 0, 0, QModelIndex() ) ), 0 );
150-
QVERIFY( !model.hasChildren( model.index( 0, 0, QModelIndex() ) ) );
151-
QCOMPARE( model.data( model.index( 0, 0, QModelIndex() ), Qt::DisplayRole ).toString(), QStringLiteral( "provider1" ) );
152-
QCOMPARE( model.data( model.index( 0, 0, QModelIndex() ), Qt::ToolTipRole ).toString(), QStringLiteral( "long name provider1" ) );
153-
QVERIFY( !model.data( model.index( 1, 0, QModelIndex() ), Qt::DisplayRole ).isValid() );
154-
QVERIFY( !model.data( model.index( 1, 0, QModelIndex() ), Qt::ToolTipRole ).isValid() );
151+
QCOMPARE( model.rowCount( model.index( 1, 0, QModelIndex() ) ), 0 );
152+
QVERIFY( !model.hasChildren( model.index( 1, 0, QModelIndex() ) ) );
153+
QCOMPARE( model.data( model.index( 1, 0, QModelIndex() ), Qt::DisplayRole ).toString(), QStringLiteral( "provider1" ) );
154+
QCOMPARE( model.data( model.index( 1, 0, QModelIndex() ), Qt::ToolTipRole ).toString(), QStringLiteral( "long name provider1" ) );
155+
QVERIFY( !model.data( model.index( 2, 0, QModelIndex() ), Qt::DisplayRole ).isValid() );
156+
QVERIFY( !model.data( model.index( 2, 0, QModelIndex() ), Qt::ToolTipRole ).isValid() );
155157

156158
// second provider
157159
DummyProvider *p2 = new DummyProvider( "p2", "provider2" );
158160
registry.addProvider( p2 );
159-
QCOMPARE( model.rowCount(), 2 );
161+
QCOMPARE( model.rowCount(), 3 );
160162
QVERIFY( model.hasChildren() );
161163

162-
QVERIFY( model.index( 1, 0, QModelIndex() ).isValid() );
163-
QCOMPARE( model.providerForIndex( model.index( 0, 0, QModelIndex() ) ), p1 );
164-
QCOMPARE( model.providerForIndex( model.index( 1, 0, QModelIndex() ) ), p2 );
165-
QVERIFY( !model.providerForIndex( model.index( 2, 0, QModelIndex() ) ) );
166-
QCOMPARE( model.indexForProvider( p1->id() ), model.index( 0, 0, QModelIndex() ) );
167-
QCOMPARE( model.indexForProvider( p2->id() ), model.index( 1, 0, QModelIndex() ) );
164+
QVERIFY( model.index( 2, 0, QModelIndex() ).isValid() );
165+
QCOMPARE( model.providerForIndex( model.index( 1, 0, QModelIndex() ) ), p1 );
166+
QCOMPARE( model.providerForIndex( model.index( 2, 0, QModelIndex() ) ), p2 );
167+
QVERIFY( !model.providerForIndex( model.index( 3, 0, QModelIndex() ) ) );
168+
QCOMPARE( model.indexForProvider( p1->id() ), model.index( 1, 0, QModelIndex() ) );
169+
QCOMPARE( model.indexForProvider( p2->id() ), model.index( 2, 0, QModelIndex() ) );
168170
QVERIFY( !model.indexForProvider( nullptr ).isValid() );
169-
QVERIFY( !model.hasChildren( model.index( 1, 0, QModelIndex() ) ) );
171+
QVERIFY( !model.hasChildren( model.index( 2, 0, QModelIndex() ) ) );
170172

171-
QCOMPARE( model.data( model.index( 0, 0, QModelIndex() ), Qt::DisplayRole ).toString(), QStringLiteral( "provider1" ) );
172-
QCOMPARE( model.data( model.index( 0, 0, QModelIndex() ), Qt::ToolTipRole ).toString(), QStringLiteral( "long name provider1" ) );
173-
QCOMPARE( model.data( model.index( 1, 0, QModelIndex() ), Qt::DisplayRole ).toString(), QStringLiteral( "provider2" ) );
174-
QCOMPARE( model.data( model.index( 1, 0, QModelIndex() ), Qt::ToolTipRole ).toString(), QStringLiteral( "long name provider2" ) );
175-
QVERIFY( !model.data( model.index( 2, 0, QModelIndex() ), Qt::DisplayRole ).isValid() );
176-
QVERIFY( !model.data( model.index( 2, 0, QModelIndex() ), Qt::ToolTipRole ).isValid() );
173+
QCOMPARE( model.data( model.index( 1, 0, QModelIndex() ), Qt::DisplayRole ).toString(), QStringLiteral( "provider1" ) );
174+
QCOMPARE( model.data( model.index( 1, 0, QModelIndex() ), Qt::ToolTipRole ).toString(), QStringLiteral( "long name provider1" ) );
175+
QCOMPARE( model.data( model.index( 2, 0, QModelIndex() ), Qt::DisplayRole ).toString(), QStringLiteral( "provider2" ) );
176+
QCOMPARE( model.data( model.index( 2, 0, QModelIndex() ), Qt::ToolTipRole ).toString(), QStringLiteral( "long name provider2" ) );
177+
QVERIFY( !model.data( model.index( 3, 0, QModelIndex() ), Qt::DisplayRole ).isValid() );
178+
QVERIFY( !model.data( model.index( 3, 0, QModelIndex() ), Qt::ToolTipRole ).isValid() );
177179

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

184-
QCOMPARE( model.rowCount(), 3 );
186+
QCOMPARE( model.rowCount(), 4 );
185187
QVERIFY( model.hasChildren() );
186-
QVERIFY( model.index( 2, 0, QModelIndex() ).isValid() );
187-
QCOMPARE( model.providerForIndex( model.index( 2, 0, QModelIndex() ) ), p3 );
188-
QCOMPARE( model.indexForProvider( p1->id() ), model.index( 0, 0, QModelIndex() ) );
189-
QCOMPARE( model.indexForProvider( p2->id() ), model.index( 1, 0, QModelIndex() ) );
190-
QCOMPARE( model.indexForProvider( p3->id() ), model.index( 2, 0, QModelIndex() ) );
191-
QCOMPARE( model.rowCount( model.index( 1, 0, QModelIndex() ) ), 0 );
192-
QCOMPARE( model.rowCount( model.index( 2, 0, QModelIndex() ) ), 2 );
193-
QVERIFY( !model.hasChildren( model.index( 1, 0, QModelIndex() ) ) );
194-
QVERIFY( model.hasChildren( model.index( 2, 0, QModelIndex() ) ) );
195-
QModelIndex providerIndex = model.index( 2, 0, QModelIndex() );
196-
QVERIFY( !model.providerForIndex( model.index( 0, 0, providerIndex ) ) );
188+
QVERIFY( model.index( 3, 0, QModelIndex() ).isValid() );
189+
QCOMPARE( model.providerForIndex( model.index( 3, 0, QModelIndex() ) ), p3 );
190+
QCOMPARE( model.indexForProvider( p1->id() ), model.index( 1, 0, QModelIndex() ) );
191+
QCOMPARE( model.indexForProvider( p2->id() ), model.index( 2, 0, QModelIndex() ) );
192+
QCOMPARE( model.indexForProvider( p3->id() ), model.index( 3, 0, QModelIndex() ) );
193+
QCOMPARE( model.rowCount( model.index( 2, 0, QModelIndex() ) ), 0 );
194+
QCOMPARE( model.rowCount( model.index( 3, 0, QModelIndex() ) ), 2 );
195+
QVERIFY( !model.hasChildren( model.index( 2, 0, QModelIndex() ) ) );
196+
QVERIFY( model.hasChildren( model.index( 3, 0, QModelIndex() ) ) );
197+
QModelIndex providerIndex = model.index( 3, 0, QModelIndex() );
197198
QVERIFY( !model.providerForIndex( model.index( 1, 0, providerIndex ) ) );
199+
QVERIFY( !model.providerForIndex( model.index( 2, 0, providerIndex ) ) );
198200

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

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

267269
// reload provider
268270
p5->refreshAlgorithms();
269-
QCOMPARE( model.rowCount(), 5 );
271+
QCOMPARE( model.rowCount(), 6 );
270272
p5ProviderIndex = model.indexForProvider( p5->id() );
271273
QCOMPARE( model.rowCount( p5ProviderIndex ), 3 );
272274

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

294296
// remove a provider
295297
registry.removeProvider( p1 );
296-
QCOMPARE( model.rowCount(), 4 );
298+
QCOMPARE( model.rowCount(), 5 );
297299
QVERIFY( model.index( 0, 0, QModelIndex() ).isValid() );
298-
QCOMPARE( model.providerForIndex( model.index( 0, 0, QModelIndex() ) ), p2 );
299-
QCOMPARE( model.data( model.index( 0, 0, QModelIndex() ), Qt::DisplayRole ).toString(), QStringLiteral( "provider2" ) );
300+
QCOMPARE( model.providerForIndex( model.index( 1, 0, QModelIndex() ) ), p2 );
301+
QCOMPARE( model.data( model.index( 1, 0, QModelIndex() ), Qt::DisplayRole ).toString(), QStringLiteral( "provider2" ) );
300302
registry.removeProvider( p5 );
301-
QCOMPARE( model.rowCount(), 3 );
303+
QCOMPARE( model.rowCount(), 4 );
302304
registry.removeProvider( p2 );
303-
QCOMPARE( model.rowCount(), 2 );
305+
QCOMPARE( model.rowCount(), 3 );
304306
registry.removeProvider( p3 );
305-
QCOMPARE( model.rowCount(), 1 );
307+
QCOMPARE( model.rowCount(), 2 );
306308
registry.removeProvider( p4 );
307-
QCOMPARE( model.rowCount(), 0 );
309+
QCOMPARE( model.rowCount(), 1 );
308310
QCOMPARE( model.columnCount(), 1 );
309-
QVERIFY( !model.hasChildren() );
311+
QVERIFY( model.hasChildren() );
312+
QCOMPARE( model.data( model.index( 0, 0, QModelIndex() ), Qt::DisplayRole ).toString(), QStringLiteral( "Recently used" ) );
310313
QVERIFY( !model.providerForIndex( model.index( 0, 0, QModelIndex() ) ) );
311314
QVERIFY( !model.providerForIndex( model.index( 1, 0, QModelIndex() ) ) );
312315
QVERIFY( !model.indexForProvider( nullptr ).isValid() );
@@ -321,10 +324,10 @@ void TestQgsProcessingModel::testModel()
321324
DummyProvider *qgisP = new DummyProvider( "qgis", "qgis_provider", QList< QgsProcessingAlgorithm * >() << qgisA1 << qgisA2 << qgisA3 << qgisA4 );
322325
registry2.addProvider( qgisP );
323326

324-
QCOMPARE( model2.rowCount(), 3 );
325-
group1Index = model2.index( 0, 0 );
326-
group2Index = model2.index( 1, 0 );
327-
QModelIndex group3Index = model2.index( 2, 0 );
327+
QCOMPARE( model2.rowCount(), 4 );
328+
group1Index = model2.index( 1, 0 );
329+
group2Index = model2.index( 2, 0 );
330+
QModelIndex group3Index = model2.index( 3, 0 );
328331
QCOMPARE( model2.data( group1Index, Qt::DisplayRole ).toString(), QStringLiteral( "group1" ) );
329332
QCOMPARE( model2.data( group2Index, Qt::DisplayRole ).toString(), QStringLiteral( "group2" ) );
330333
QCOMPARE( model2.data( group3Index, Qt::DisplayRole ).toString(), QStringLiteral( "group3" ) );

0 commit comments

Comments
 (0)
Please sign in to comment.