|
18 | 18 | #include "qgsprocessingregistry.h" |
19 | 19 | #include "qgsprocessingtoolboxmodel.h" |
20 | 20 | #include "qgsprocessingrecentalgorithmlog.h" |
| 21 | +#include "qgsprocessingtoolboxtreeview.h" |
21 | 22 | #include "qgssettings.h" |
22 | 23 |
|
23 | 24 | #include <QtTest/QSignalSpy> |
@@ -113,6 +114,7 @@ class TestQgsProcessingModel: public QObject |
113 | 114 | void cleanup() {} // will be called after every testfunction. |
114 | 115 | void testModel(); |
115 | 116 | void testProxyModel(); |
| 117 | + void testView(); |
116 | 118 | }; |
117 | 119 |
|
118 | 120 |
|
@@ -549,5 +551,90 @@ void TestQgsProcessingModel::testProxyModel() |
549 | 551 | QCOMPARE( model.rowCount(), 5 ); |
550 | 552 | } |
551 | 553 |
|
| 554 | +void TestQgsProcessingModel::testView() |
| 555 | +{ |
| 556 | + QgsSettings().clear(); |
| 557 | + QgsProcessingRegistry registry; |
| 558 | + QgsProcessingRecentAlgorithmLog recentLog; |
| 559 | + QgsProcessingToolboxTreeView view( nullptr, ®istry, &recentLog ); |
| 560 | + |
| 561 | + QVERIFY( !view.algorithmForIndex( QModelIndex() ) ); |
| 562 | + |
| 563 | + // add a provider |
| 564 | + DummyAlgorithm *a1 = new DummyAlgorithm( "a1", "group2", QgsProcessingAlgorithm::FlagHideFromToolbox ); |
| 565 | + DummyProvider *p1 = new DummyProvider( "p2", "provider2", QList< QgsProcessingAlgorithm * >() << a1 ); |
| 566 | + registry.addProvider( p1 ); |
| 567 | + // second provider |
| 568 | + DummyAlgorithm *a2 = new DummyAlgorithm( "a2", "group2", QgsProcessingAlgorithm::FlagHideFromModeler, |
| 569 | + QStringLiteral( "buffer,vector" ), QStringLiteral( "short desc" ), QStringLiteral( "algorithm2" ) ); |
| 570 | + DummyProvider *p2 = new DummyProvider( "p1", "provider1", QList< QgsProcessingAlgorithm * >() << a2 ); |
| 571 | + registry.addProvider( p2 ); |
| 572 | + |
| 573 | + QModelIndex provider1Index = view.model()->index( 0, 0, QModelIndex() ); |
| 574 | + QVERIFY( !view.algorithmForIndex( provider1Index ) ); |
| 575 | + QModelIndex group2Index = view.model()->index( 0, 0, provider1Index ); |
| 576 | + QCOMPARE( view.model()->data( group2Index, Qt::DisplayRole ).toString(), QStringLiteral( "group2" ) ); |
| 577 | + QVERIFY( !view.algorithmForIndex( group2Index ) ); |
| 578 | + QModelIndex alg2Index = view.model()->index( 0, 0, group2Index ); |
| 579 | + QCOMPARE( view.algorithmForIndex( alg2Index )->id(), QStringLiteral( "p1:a2" ) ); |
| 580 | + QModelIndex provider2Index = view.model()->index( 1, 0, QModelIndex() ); |
| 581 | + QVERIFY( !view.algorithmForIndex( provider2Index ) ); |
| 582 | + QCOMPARE( view.model()->data( provider2Index, Qt::DisplayRole ).toString(), QStringLiteral( "provider2" ) ); |
| 583 | + group2Index = view.model()->index( 0, 0, provider2Index ); |
| 584 | + QCOMPARE( view.model()->data( group2Index, Qt::DisplayRole ).toString(), QStringLiteral( "group2" ) ); |
| 585 | + QModelIndex alg1Index = view.model()->index( 0, 0, group2Index ); |
| 586 | + QCOMPARE( view.algorithmForIndex( alg1Index )->id(), QStringLiteral( "p2:a1" ) ); |
| 587 | + |
| 588 | + view.setFilters( QgsProcessingToolboxProxyModel::FilterModeler ); |
| 589 | + provider2Index = view.model()->index( 0, 0, QModelIndex() ); |
| 590 | + QCOMPARE( view.model()->data( provider2Index, Qt::DisplayRole ).toString(), QStringLiteral( "provider2" ) ); |
| 591 | + QCOMPARE( view.model()->rowCount(), 1 ); |
| 592 | + QCOMPARE( view.model()->rowCount( provider2Index ), 1 ); |
| 593 | + group2Index = view.model()->index( 0, 0, provider2Index ); |
| 594 | + QCOMPARE( view.model()->rowCount( group2Index ), 1 ); |
| 595 | + QCOMPARE( view.algorithmForIndex( view.model()->index( 0, 0, group2Index ) )->id(), QStringLiteral( "p2:a1" ) ); |
| 596 | + view.setFilters( QgsProcessingToolboxProxyModel::FilterToolbox ); |
| 597 | + provider1Index = view.model()->index( 0, 0, QModelIndex() ); |
| 598 | + QCOMPARE( view.model()->data( provider1Index, Qt::DisplayRole ).toString(), QStringLiteral( "provider1" ) ); |
| 599 | + QCOMPARE( view.model()->rowCount(), 1 ); |
| 600 | + QCOMPARE( view.model()->rowCount( provider1Index ), 1 ); |
| 601 | + group2Index = view.model()->index( 0, 0, provider1Index ); |
| 602 | + QCOMPARE( view.model()->rowCount( group2Index ), 1 ); |
| 603 | + QCOMPARE( view.algorithmForIndex( view.model()->index( 0, 0, group2Index ) )->id(), QStringLiteral( "p1:a2" ) ); |
| 604 | + |
| 605 | + view.setFilters( nullptr ); |
| 606 | + // test filter strings |
| 607 | + view.setFilterString( "a1" ); |
| 608 | + provider2Index = view.model()->index( 0, 0, QModelIndex() ); |
| 609 | + QCOMPARE( view.model()->data( provider2Index, Qt::DisplayRole ).toString(), QStringLiteral( "provider2" ) ); |
| 610 | + QCOMPARE( view.model()->rowCount(), 1 ); |
| 611 | + QCOMPARE( view.model()->rowCount( provider2Index ), 1 ); |
| 612 | + group2Index = view.model()->index( 0, 0, provider2Index ); |
| 613 | + QCOMPARE( view.model()->rowCount( group2Index ), 1 ); |
| 614 | + QCOMPARE( view.algorithmForIndex( view.model()->index( 0, 0, group2Index ) )->id(), QStringLiteral( "p2:a1" ) ); |
| 615 | + |
| 616 | + view.setFilterString( QString() ); |
| 617 | + |
| 618 | + // selected algorithm |
| 619 | + provider1Index = view.model()->index( 0, 0, QModelIndex() ); |
| 620 | + view.selectionModel()->clear(); |
| 621 | + QVERIFY( !view.selectedAlgorithm() ); |
| 622 | + view.selectionModel()->select( provider1Index, QItemSelectionModel::ClearAndSelect ); |
| 623 | + QVERIFY( !view.selectedAlgorithm() ); |
| 624 | + group2Index = view.model()->index( 0, 0, provider1Index ); |
| 625 | + view.selectionModel()->select( group2Index, QItemSelectionModel::ClearAndSelect ); |
| 626 | + QVERIFY( !view.selectedAlgorithm() ); |
| 627 | + alg2Index = view.model()->index( 0, 0, group2Index ); |
| 628 | + view.selectionModel()->select( alg2Index, QItemSelectionModel::ClearAndSelect ); |
| 629 | + QCOMPARE( view.selectedAlgorithm()->id(), QStringLiteral( "p1:a2" ) ); |
| 630 | + |
| 631 | + // when a filter string removes the selected algorithm, the next matching algorithm should be auto-selected |
| 632 | + view.setFilterString( QStringLiteral( "p2:a1" ) ); |
| 633 | + QCOMPARE( view.selectedAlgorithm()->id(), QStringLiteral( "p2:a1" ) ); |
| 634 | + // but if it doesn't remove the selected one, that algorithm should not be deselected |
| 635 | + view.setFilterString( QStringLiteral( "a" ) ); |
| 636 | + QCOMPARE( view.selectedAlgorithm()->id(), QStringLiteral( "p2:a1" ) ); |
| 637 | +} |
| 638 | + |
552 | 639 | QGSTEST_MAIN( TestQgsProcessingModel ) |
553 | 640 | #include "testqgsprocessingmodel.moc" |
0 commit comments