@@ -129,72 +129,74 @@ void TestQgsProcessingModel::testModel()
129
129
QgsProcessingToolboxModel model ( nullptr , ®istry );
130
130
131
131
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" ) );
134
135
QVERIFY ( !model.providerForIndex ( model.index ( 0 , 0 , QModelIndex () ) ) );
135
136
QVERIFY ( !model.providerForIndex ( model.index ( 1 , 0 , QModelIndex () ) ) );
136
137
QVERIFY ( !model.indexForProvider ( nullptr ).isValid () );
137
138
138
139
// add a provider
139
140
DummyProvider *p1 = new DummyProvider ( " p1" , " provider1" );
140
141
registry.addProvider ( p1 );
141
- QCOMPARE ( model.rowCount (), 1 );
142
+ QCOMPARE ( model.rowCount (), 2 );
142
143
QVERIFY ( model.hasChildren () );
143
144
144
145
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 () ) );
148
150
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 () );
155
157
156
158
// second provider
157
159
DummyProvider *p2 = new DummyProvider ( " p2" , " provider2" );
158
160
registry.addProvider ( p2 );
159
- QCOMPARE ( model.rowCount (), 2 );
161
+ QCOMPARE ( model.rowCount (), 3 );
160
162
QVERIFY ( model.hasChildren () );
161
163
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 () ) );
168
170
QVERIFY ( !model.indexForProvider ( nullptr ).isValid () );
169
- QVERIFY ( !model.hasChildren ( model.index ( 1 , 0 , QModelIndex () ) ) );
171
+ QVERIFY ( !model.hasChildren ( model.index ( 2 , 0 , QModelIndex () ) ) );
170
172
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 () );
177
179
178
180
// provider with algs and groups
179
181
DummyAlgorithm *a1 = new DummyAlgorithm ( " a1" , " group1" , QgsProcessingAlgorithm::FlagHideFromModeler, QStringLiteral ( " tag1,tag2" ), QStringLiteral ( " short desc a" ) );
180
182
DummyAlgorithm *a2 = new DummyAlgorithm ( " a2" , " group2" , QgsProcessingAlgorithm::FlagHideFromToolbox );
181
183
DummyProvider *p3 = new DummyProvider ( " p3" , " provider3" , QList< QgsProcessingAlgorithm * >() << a1 << a2 );
182
184
registry.addProvider ( p3 );
183
185
184
- QCOMPARE ( model.rowCount (), 3 );
186
+ QCOMPARE ( model.rowCount (), 4 );
185
187
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 () );
197
198
QVERIFY ( !model.providerForIndex ( model.index ( 1 , 0 , providerIndex ) ) );
199
+ QVERIFY ( !model.providerForIndex ( model.index ( 2 , 0 , providerIndex ) ) );
198
200
199
201
QCOMPARE ( model.data ( model.index ( 0 , 0 , providerIndex ), Qt::DisplayRole ).toString (), QStringLiteral ( " group1" ) );
200
202
QCOMPARE ( model.data ( model.index ( 0 , 0 , providerIndex ), Qt::ToolTipRole ).toString (), QStringLiteral ( " group1" ) );
@@ -248,7 +250,7 @@ void TestQgsProcessingModel::testModel()
248
250
DummyAlgorithm *a7 = new DummyAlgorithm ( " a7" , " group2" );
249
251
DummyProvider *p5 = new DummyProvider ( " p5" , " provider5" , QList< QgsProcessingAlgorithm * >() << a5 << a6 << a7 );
250
252
registry.addProvider ( p5 );
251
- QCOMPARE ( model.rowCount (), 5 );
253
+ QCOMPARE ( model.rowCount (), 6 );
252
254
QModelIndex p5ProviderIndex = model.indexForProvider ( p5->id () );
253
255
QCOMPARE ( model.rowCount ( p5ProviderIndex ), 3 );
254
256
@@ -266,7 +268,7 @@ void TestQgsProcessingModel::testModel()
266
268
267
269
// reload provider
268
270
p5->refreshAlgorithms ();
269
- QCOMPARE ( model.rowCount (), 5 );
271
+ QCOMPARE ( model.rowCount (), 6 );
270
272
p5ProviderIndex = model.indexForProvider ( p5->id () );
271
273
QCOMPARE ( model.rowCount ( p5ProviderIndex ), 3 );
272
274
@@ -293,20 +295,21 @@ void TestQgsProcessingModel::testModel()
293
295
294
296
// remove a provider
295
297
registry.removeProvider ( p1 );
296
- QCOMPARE ( model.rowCount (), 4 );
298
+ QCOMPARE ( model.rowCount (), 5 );
297
299
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" ) );
300
302
registry.removeProvider ( p5 );
301
- QCOMPARE ( model.rowCount (), 3 );
303
+ QCOMPARE ( model.rowCount (), 4 );
302
304
registry.removeProvider ( p2 );
303
- QCOMPARE ( model.rowCount (), 2 );
305
+ QCOMPARE ( model.rowCount (), 3 );
304
306
registry.removeProvider ( p3 );
305
- QCOMPARE ( model.rowCount (), 1 );
307
+ QCOMPARE ( model.rowCount (), 2 );
306
308
registry.removeProvider ( p4 );
307
- QCOMPARE ( model.rowCount (), 0 );
309
+ QCOMPARE ( model.rowCount (), 1 );
308
310
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" ) );
310
313
QVERIFY ( !model.providerForIndex ( model.index ( 0 , 0 , QModelIndex () ) ) );
311
314
QVERIFY ( !model.providerForIndex ( model.index ( 1 , 0 , QModelIndex () ) ) );
312
315
QVERIFY ( !model.indexForProvider ( nullptr ).isValid () );
@@ -321,10 +324,10 @@ void TestQgsProcessingModel::testModel()
321
324
DummyProvider *qgisP = new DummyProvider ( " qgis" , " qgis_provider" , QList< QgsProcessingAlgorithm * >() << qgisA1 << qgisA2 << qgisA3 << qgisA4 );
322
325
registry2.addProvider ( qgisP );
323
326
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 );
328
331
QCOMPARE ( model2.data ( group1Index, Qt::DisplayRole ).toString (), QStringLiteral ( " group1" ) );
329
332
QCOMPARE ( model2.data ( group2Index, Qt::DisplayRole ).toString (), QStringLiteral ( " group2" ) );
330
333
QCOMPARE ( model2.data ( group3Index, Qt::DisplayRole ).toString (), QStringLiteral ( " group3" ) );
0 commit comments