@@ -24,25 +24,36 @@ class DummyAlgorithm : public QgsProcessingAlgorithm
24
24
public:
25
25
26
26
DummyAlgorithm ( const QString &name, const QString &group,
27
- QgsProcessingAlgorithm::Flags flags = 0 )
27
+ QgsProcessingAlgorithm::Flags flags = 0 ,
28
+ const QString &tags = QString(),
29
+ const QString &shortDescription = QString(),
30
+ const QString &displayName = QString() )
28
31
: mName ( name )
32
+ , mDisplayName ( displayName )
29
33
, mGroup ( group )
30
34
, mFlags ( flags )
35
+ , mTags ( tags.split( ' ,' ) )
36
+ , mShortDescription ( shortDescription )
31
37
{}
32
38
33
39
void initAlgorithm ( const QVariantMap & = QVariantMap() ) override {}
34
40
QgsProcessingAlgorithm::Flags flags () const override { return mFlags ; }
35
41
QString name () const override { return mName ; }
36
- QString displayName () const override { return mName ; }
42
+ QString displayName () const override { return mDisplayName . isEmpty () ? mName : mDisplayName ; }
37
43
QString group () const override { return mGroup ; }
38
44
QString groupId () const override { return mGroup ; }
45
+ QString shortDescription () const override { return mShortDescription ; }
46
+ QStringList tags () const override { return mTags ; }
39
47
QVariantMap processAlgorithm ( const QVariantMap &, QgsProcessingContext &, QgsProcessingFeedback * ) override { return QVariantMap (); }
40
48
41
- DummyAlgorithm *createInstance () const override { return new DummyAlgorithm ( mName , mGroup , mFlags ); }
49
+ DummyAlgorithm *createInstance () const override { return new DummyAlgorithm ( mName , mGroup , mFlags , mTags . join ( ' , ' ), mShortDescription , mDisplayName ); }
42
50
43
51
QString mName ;
52
+ QString mDisplayName ;
44
53
QString mGroup ;
45
- QgsProcessingAlgorithm::Flags mFlags = 0 ;
54
+ QgsProcessingAlgorithm::Flags mFlags = nullptr ;
55
+ QStringList mTags ;
56
+ QString mShortDescription ;
46
57
47
58
};
48
59
// dummy provider for testing
@@ -165,7 +176,7 @@ void TestQgsProcessingModel::testModel()
165
176
QVERIFY ( !model.data ( model.index ( 2 , 0 , QModelIndex () ), Qt::ToolTipRole ).isValid () );
166
177
167
178
// provider with algs and groups
168
- DummyAlgorithm *a1 = new DummyAlgorithm ( " a1" , " group1" , QgsProcessingAlgorithm::FlagHideFromModeler );
179
+ DummyAlgorithm *a1 = new DummyAlgorithm ( " a1" , " group1" , QgsProcessingAlgorithm::FlagHideFromModeler, QStringLiteral ( " tag1,tag2 " ), QStringLiteral ( " short desc a " ) );
169
180
DummyAlgorithm *a2 = new DummyAlgorithm ( " a2" , " group2" , QgsProcessingAlgorithm::FlagHideFromToolbox );
170
181
DummyProvider *p3 = new DummyProvider ( " p3" , " provider3" , QList< QgsProcessingAlgorithm * >() << a1 << a2 );
171
182
registry.addProvider ( p3 );
@@ -198,8 +209,13 @@ void TestQgsProcessingModel::testModel()
198
209
QModelIndex alg1Index = model.index ( 0 , 0 , group1Index );
199
210
QVERIFY ( !model.providerForIndex ( alg1Index ) );
200
211
QCOMPARE ( model.data ( alg1Index, Qt::DisplayRole ).toString (), QStringLiteral ( " a1" ) );
201
- QCOMPARE ( model.data ( alg1Index, Qt::ToolTipRole ).toString (), QStringLiteral ( " <p><b>a1</b></p><p>Algorithm ID: \u2018 <i>p3:a1</i>\u2019 </p>" ) );
212
+ QCOMPARE ( model.data ( alg1Index, Qt::ToolTipRole ).toString (), QStringLiteral ( " <p><b>a1</b></p><p>short desc a</p><p> Algorithm ID: \u2018 <i>p3:a1</i>\u2019 </p>" ) );
202
213
QCOMPARE ( model.data ( alg1Index, QgsProcessingToolboxModel::RoleAlgorithmFlags ).toInt (), static_cast < int >( QgsProcessingAlgorithm::FlagHideFromModeler ) );
214
+ QCOMPARE ( model.data ( alg1Index, QgsProcessingToolboxModel::RoleAlgorithmId ).toString (), QStringLiteral ( " p3:a1" ) );
215
+ QCOMPARE ( model.data ( alg1Index, QgsProcessingToolboxModel::RoleAlgorithmName ).toString (), QStringLiteral ( " a1" ) );
216
+ QCOMPARE ( model.data ( alg1Index, QgsProcessingToolboxModel::RoleAlgorithmTags ).toStringList ().join ( ' ,' ), QStringLiteral ( " tag1,tag2" ) );
217
+ QCOMPARE ( model.data ( alg1Index, QgsProcessingToolboxModel::RoleAlgorithmShortDescription ).toString (), QStringLiteral ( " short desc a" ) );
218
+
203
219
QCOMPARE ( model.algorithmForIndex ( alg1Index )->id (), QStringLiteral ( " p3:a1" ) );
204
220
205
221
QModelIndex group2Index = model.index ( 1 , 0 , providerIndex );
@@ -209,6 +225,10 @@ void TestQgsProcessingModel::testModel()
209
225
QCOMPARE ( model.data ( alg2Index, Qt::DisplayRole ).toString (), QStringLiteral ( " a2" ) );
210
226
QCOMPARE ( model.data ( alg2Index, Qt::ToolTipRole ).toString (), QStringLiteral ( " <p><b>a2</b></p><p>Algorithm ID: \u2018 <i>p3:a2</i>\u2019 </p>" ) );
211
227
QCOMPARE ( model.data ( alg2Index, QgsProcessingToolboxModel::RoleAlgorithmFlags ).toInt (), static_cast < int >( QgsProcessingAlgorithm::FlagHideFromToolbox ) );
228
+ QCOMPARE ( model.data ( alg2Index, QgsProcessingToolboxModel::RoleAlgorithmId ).toString (), QStringLiteral ( " p3:a2" ) );
229
+ QCOMPARE ( model.data ( alg2Index, QgsProcessingToolboxModel::RoleAlgorithmName ).toString (), QStringLiteral ( " a2" ) );
230
+ QCOMPARE ( model.data ( alg2Index, QgsProcessingToolboxModel::RoleAlgorithmTags ).toStringList ().join ( ' ,' ), QString () );
231
+ QCOMPARE ( model.data ( alg2Index, QgsProcessingToolboxModel::RoleAlgorithmShortDescription ).toString (), QString () );
212
232
QCOMPARE ( model.algorithmForIndex ( alg2Index )->id (), QStringLiteral ( " p3:a2" ) );
213
233
214
234
// combined groups
@@ -328,7 +348,8 @@ void TestQgsProcessingModel::testProxyModel()
328
348
DummyProvider *p1 = new DummyProvider ( " p2" , " provider2" , QList< QgsProcessingAlgorithm * >() << a1 );
329
349
registry.addProvider ( p1 );
330
350
// second provider
331
- DummyAlgorithm *a2 = new DummyAlgorithm ( " a2" , " group2" , QgsProcessingAlgorithm::FlagHideFromModeler );
351
+ DummyAlgorithm *a2 = new DummyAlgorithm ( " a2" , " group2" , QgsProcessingAlgorithm::FlagHideFromModeler,
352
+ QStringLiteral ( " buffer,vector" ), QStringLiteral ( " short desc" ), QStringLiteral ( " algorithm2" ) );
332
353
DummyProvider *p2 = new DummyProvider ( " p1" , " provider1" , QList< QgsProcessingAlgorithm * >() << a2 );
333
354
registry.addProvider ( p2 );
334
355
@@ -368,12 +389,93 @@ void TestQgsProcessingModel::testProxyModel()
368
389
QCOMPARE ( model.rowCount ( group2Index ), 1 );
369
390
QCOMPARE ( model.data ( model.index ( 0 , 0 , group1Index ), Qt::DisplayRole ).toString (), QStringLiteral ( " a1" ) );
370
391
392
+ // test filter strings
393
+ model.setFilters ( nullptr );
394
+ // filter by algorithm id
395
+ model.setFilterString ( " a1" );
396
+ QCOMPARE ( model.rowCount (), 2 );
397
+ group1Index = model.index ( 0 , 0 , QModelIndex () );
398
+ QModelIndex provider2Index = model.index ( 1 , 0 , QModelIndex () );
399
+ QCOMPARE ( model.rowCount ( group1Index ), 1 );
400
+ QCOMPARE ( model.data ( group1Index, Qt::DisplayRole ).toString (), QStringLiteral ( " group2" ) );
401
+ QCOMPARE ( model.data ( model.index ( 0 , 0 , group1Index ), QgsProcessingToolboxModel::RoleAlgorithmId ).toString (), QStringLiteral ( " qgis:a1" ) );
402
+ QCOMPARE ( model.rowCount ( group2Index ), 1 );
403
+ QCOMPARE ( model.data ( provider2Index, Qt::DisplayRole ).toString (), QStringLiteral ( " provider2" ) );
404
+ QCOMPARE ( model.rowCount ( provider2Index ), 1 );
405
+ group2Index = model.index ( 0 , 0 , provider2Index );
406
+ QCOMPARE ( model.rowCount ( group2Index ), 1 );
407
+ QCOMPARE ( model.data ( group2Index, Qt::DisplayRole ).toString (), QStringLiteral ( " group2" ) );
408
+ QCOMPARE ( model.data ( model.index ( 0 , 0 , group2Index ), QgsProcessingToolboxModel::RoleAlgorithmId ).toString (), QStringLiteral ( " p2:a1" ) );
409
+
410
+ // filter by algorithm display name
411
+ model.setFilterString ( QStringLiteral ( " ALGOR" ) );
412
+ QCOMPARE ( model.rowCount (), 1 );
413
+ QModelIndex provider1Index = model.index ( 0 , 0 , QModelIndex () );
414
+ QCOMPARE ( model.rowCount ( provider1Index ), 1 );
415
+ QCOMPARE ( model.data ( provider1Index, Qt::DisplayRole ).toString (), QStringLiteral ( " provider1" ) );
416
+ QCOMPARE ( model.rowCount ( provider1Index ), 1 );
417
+ group2Index = model.index ( 0 , 0 , provider1Index );
418
+ QCOMPARE ( model.data ( group2Index, Qt::DisplayRole ).toString (), QStringLiteral ( " group2" ) );
419
+ QCOMPARE ( model.rowCount ( group2Index ), 1 );
420
+ QCOMPARE ( model.data ( model.index ( 0 , 0 , group2Index ), QgsProcessingToolboxModel::RoleAlgorithmId ).toString (), QStringLiteral ( " p1:a2" ) );
421
+
422
+ // filter by algorithm tags
423
+ model.setFilterString ( QStringLiteral ( " buff CTOR" ) );
424
+ QCOMPARE ( model.rowCount (), 1 );
425
+ provider1Index = model.index ( 0 , 0 , QModelIndex () );
426
+ QCOMPARE ( model.rowCount ( provider1Index ), 1 );
427
+ QCOMPARE ( model.data ( provider1Index, Qt::DisplayRole ).toString (), QStringLiteral ( " provider1" ) );
428
+ QCOMPARE ( model.rowCount ( provider1Index ), 1 );
429
+ group2Index = model.index ( 0 , 0 , provider1Index );
430
+ QCOMPARE ( model.data ( group2Index, Qt::DisplayRole ).toString (), QStringLiteral ( " group2" ) );
431
+ QCOMPARE ( model.rowCount ( group2Index ), 1 );
432
+ QCOMPARE ( model.data ( model.index ( 0 , 0 , group2Index ), QgsProcessingToolboxModel::RoleAlgorithmId ).toString (), QStringLiteral ( " p1:a2" ) );
433
+
434
+ // filter by algorithm short desc
435
+ model.setFilterString ( QStringLiteral ( " buff CTOR desc" ) );
436
+ QCOMPARE ( model.rowCount (), 1 );
437
+ provider1Index = model.index ( 0 , 0 , QModelIndex () );
438
+ QCOMPARE ( model.rowCount ( provider1Index ), 1 );
439
+ QCOMPARE ( model.data ( provider1Index, Qt::DisplayRole ).toString (), QStringLiteral ( " provider1" ) );
440
+ QCOMPARE ( model.rowCount ( provider1Index ), 1 );
441
+ group2Index = model.index ( 0 , 0 , provider1Index );
442
+ QCOMPARE ( model.data ( group2Index, Qt::DisplayRole ).toString (), QStringLiteral ( " group2" ) );
443
+ QCOMPARE ( model.rowCount ( group2Index ), 1 );
444
+ QCOMPARE ( model.data ( model.index ( 0 , 0 , group2Index ), QgsProcessingToolboxModel::RoleAlgorithmId ).toString (), QStringLiteral ( " p1:a2" ) );
445
+
446
+ // filter by group
447
+ model.setFilterString ( QStringLiteral ( " group2" ) );
448
+ QCOMPARE ( model.rowCount (), 3 );
449
+ group2Index = model.index ( 0 , 0 , QModelIndex () );
450
+ QCOMPARE ( model.rowCount ( group2Index ), 1 );
451
+ QCOMPARE ( model.data ( group2Index, Qt::DisplayRole ).toString (), QStringLiteral ( " group2" ) );
452
+ alg1Index = model.index ( 0 , 0 , group2Index );
453
+ QCOMPARE ( model.data ( alg1Index, QgsProcessingToolboxModel::RoleAlgorithmId ).toString (), QStringLiteral ( " qgis:a1" ) );
454
+ provider1Index = model.index ( 1 , 0 , QModelIndex () );
455
+ QCOMPARE ( model.rowCount ( provider1Index ), 1 );
456
+ QCOMPARE ( model.data ( provider1Index, Qt::DisplayRole ).toString (), QStringLiteral ( " provider1" ) );
457
+ QCOMPARE ( model.rowCount ( provider1Index ), 1 );
458
+ group2Index = model.index ( 0 , 0 , provider1Index );
459
+ QCOMPARE ( model.data ( group2Index, Qt::DisplayRole ).toString (), QStringLiteral ( " group2" ) );
460
+ QCOMPARE ( model.rowCount ( group2Index ), 1 );
461
+ QCOMPARE ( model.data ( model.index ( 0 , 0 , group2Index ), QgsProcessingToolboxModel::RoleAlgorithmId ).toString (), QStringLiteral ( " p1:a2" ) );
462
+ provider2Index = model.index ( 2 , 0 , QModelIndex () );
463
+ QCOMPARE ( model.rowCount ( provider2Index ), 1 );
464
+ QCOMPARE ( model.data ( provider2Index, Qt::DisplayRole ).toString (), QStringLiteral ( " provider2" ) );
465
+ group2Index = model.index ( 0 , 0 , provider2Index );
466
+ QCOMPARE ( model.data ( group2Index, Qt::DisplayRole ).toString (), QStringLiteral ( " group2" ) );
467
+ QCOMPARE ( model.rowCount ( group2Index ), 1 );
468
+ QCOMPARE ( model.data ( model.index ( 0 , 0 , group2Index ), QgsProcessingToolboxModel::RoleAlgorithmId ).toString (), QStringLiteral ( " p2:a1" ) );
469
+
470
+ model.setFilterString ( QString () );
471
+
371
472
// inactive provider - should not be visible
473
+ QCOMPARE ( model.rowCount (), 4 );
372
474
DummyAlgorithm *qgisA31 = new DummyAlgorithm ( " a3" , " group1" );
373
475
DummyProvider *p3 = new DummyProvider ( " p3" , " provider3" , QList< QgsProcessingAlgorithm * >() << qgisA31 );
374
476
p3->mActive = false ;
375
477
registry.addProvider ( p3 );
376
- QCOMPARE ( model.rowCount (), 3 );
478
+ QCOMPARE ( model.rowCount (), 4 );
377
479
}
378
480
379
481
QGSTEST_MAIN ( TestQgsProcessingModel )
0 commit comments