|
37 | 37 | #include "processing/models/qgsprocessingmodelalgorithm.h"
|
38 | 38 | #include "qgsxmlutils.h"
|
39 | 39 | #include "qgspropertyoverridebutton.h"
|
| 40 | +#include "qgsprojectionselectionwidget.h" |
40 | 41 |
|
41 | 42 | class TestParamType : public QgsProcessingParameterDefinition
|
42 | 43 | {
|
@@ -141,6 +142,7 @@ class TestProcessingGui : public QObject
|
141 | 142 | void testModelerWrapper();
|
142 | 143 | void testBooleanWrapper();
|
143 | 144 | void testStringWrapper();
|
| 145 | + void testCrsWrapper(); |
144 | 146 | };
|
145 | 147 |
|
146 | 148 | void TestProcessingGui::initTestCase()
|
@@ -737,5 +739,104 @@ void TestProcessingGui::testStringWrapper()
|
737 | 739 | delete l;
|
738 | 740 | }
|
739 | 741 |
|
| 742 | +void TestProcessingGui::testCrsWrapper() |
| 743 | +{ |
| 744 | + QgsProcessingParameterCrs param( QStringLiteral( "crs" ), QStringLiteral( "crs" ) ); |
| 745 | + |
| 746 | + // standard wrapper |
| 747 | + QgsProcessingCrsWidgetWrapper wrapper( ¶m ); |
| 748 | + |
| 749 | + QgsProcessingContext context; |
| 750 | + QWidget *w = wrapper.createWrappedWidget( context ); |
| 751 | + |
| 752 | + QSignalSpy spy( &wrapper, &QgsProcessingCrsWidgetWrapper::widgetValueHasChanged ); |
| 753 | + wrapper.setWidgetValue( QStringLiteral( "epsg:3111" ), context ); |
| 754 | + QCOMPARE( spy.count(), 1 ); |
| 755 | + QCOMPARE( wrapper.widgetValue().value< QgsCoordinateReferenceSystem >().authid(), QStringLiteral( "EPSG:3111" ) ); |
| 756 | + QCOMPARE( static_cast< QgsProjectionSelectionWidget * >( wrapper.wrappedWidget() )->crs().authid(), QStringLiteral( "EPSG:3111" ) ); |
| 757 | + wrapper.setWidgetValue( QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:28356" ) ), context ); |
| 758 | + QCOMPARE( spy.count(), 2 ); |
| 759 | + QCOMPARE( wrapper.widgetValue().value< QgsCoordinateReferenceSystem >().authid(), QStringLiteral( "EPSG:28356" ) ); |
| 760 | + QCOMPARE( static_cast< QgsProjectionSelectionWidget * >( wrapper.wrappedWidget() )->crs().authid(), QStringLiteral( "EPSG:28356" ) ); |
| 761 | + wrapper.setWidgetValue( QString(), context ); |
| 762 | + QCOMPARE( spy.count(), 3 ); |
| 763 | + QVERIFY( !wrapper.widgetValue().value< QgsCoordinateReferenceSystem >().isValid() ); |
| 764 | + QVERIFY( !static_cast< QgsProjectionSelectionWidget * >( wrapper.wrappedWidget() )->crs().isValid() ); |
| 765 | + |
| 766 | + QLabel *l = wrapper.createWrappedLabel(); |
| 767 | + QVERIFY( l ); |
| 768 | + QCOMPARE( l->text(), QStringLiteral( "crs" ) ); |
| 769 | + QCOMPARE( l->toolTip(), param.toolTip() ); |
| 770 | + delete l; |
| 771 | + |
| 772 | + // check signal |
| 773 | + static_cast< QgsProjectionSelectionWidget * >( wrapper.wrappedWidget() )->setCrs( QgsCoordinateReferenceSystem( "EPSG:3857" ) ); |
| 774 | + QCOMPARE( spy.count(), 4 ); |
| 775 | + static_cast< QgsProjectionSelectionWidget * >( wrapper.wrappedWidget() )->setCrs( QgsCoordinateReferenceSystem() ); |
| 776 | + QCOMPARE( spy.count(), 5 ); |
| 777 | + |
| 778 | + delete w; |
| 779 | + |
| 780 | + // batch wrapper |
| 781 | + QgsProcessingCrsWidgetWrapper wrapperB( ¶m, QgsProcessingGui::Batch ); |
| 782 | + |
| 783 | + w = wrapperB.createWrappedWidget( context ); |
| 784 | + QSignalSpy spy2( &wrapperB, &QgsProcessingCrsWidgetWrapper::widgetValueHasChanged ); |
| 785 | + wrapperB.setWidgetValue( QStringLiteral( "epsg:3111" ), context ); |
| 786 | + QCOMPARE( spy2.count(), 1 ); |
| 787 | + QCOMPARE( wrapperB.widgetValue().value< QgsCoordinateReferenceSystem >().authid(), QStringLiteral( "EPSG:3111" ) ); |
| 788 | + QCOMPARE( static_cast< QgsProjectionSelectionWidget * >( wrapperB.wrappedWidget() )->crs().authid(), QStringLiteral( "EPSG:3111" ) ); |
| 789 | + wrapperB.setWidgetValue( QgsCoordinateReferenceSystem(), context ); |
| 790 | + QCOMPARE( spy2.count(), 2 ); |
| 791 | + QVERIFY( !wrapperB.widgetValue().value< QgsCoordinateReferenceSystem >().isValid() ); |
| 792 | + QVERIFY( !static_cast< QgsProjectionSelectionWidget * >( wrapperB.wrappedWidget() )->crs().isValid() ); |
| 793 | + |
| 794 | + // check signal |
| 795 | + static_cast< QgsProjectionSelectionWidget * >( w )->setCrs( QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:28356" ) ) ); |
| 796 | + QCOMPARE( spy2.count(), 3 ); |
| 797 | + static_cast< QgsProjectionSelectionWidget * >( w )->setCrs( QgsCoordinateReferenceSystem() ); |
| 798 | + QCOMPARE( spy2.count(), 4 ); |
| 799 | + |
| 800 | + // should be no label in batch mode |
| 801 | + QVERIFY( !wrapperB.createWrappedLabel() ); |
| 802 | + delete w; |
| 803 | + |
| 804 | + // modeler wrapper |
| 805 | + QgsProcessingCrsWidgetWrapper wrapperM( ¶m, QgsProcessingGui::Modeler ); |
| 806 | + |
| 807 | + w = wrapperM.createWrappedWidget( context ); |
| 808 | + QSignalSpy spy3( &wrapperM, &QgsProcessingCrsWidgetWrapper::widgetValueHasChanged ); |
| 809 | + wrapperM.setWidgetValue( QStringLiteral( "epsg:3111" ), context ); |
| 810 | + QCOMPARE( wrapperM.widgetValue().value< QgsCoordinateReferenceSystem >().authid(), QStringLiteral( "EPSG:3111" ) ); |
| 811 | + QCOMPARE( spy3.count(), 1 ); |
| 812 | + QCOMPARE( wrapperM.mProjectionSelectionWidget->crs().authid(), QStringLiteral( "EPSG:3111" ) ); |
| 813 | + QVERIFY( !wrapperM.mUseProjectCrsCheckBox->isChecked() ); |
| 814 | + wrapperM.setWidgetValue( QgsCoordinateReferenceSystem(), context ); |
| 815 | + QVERIFY( !wrapperM.widgetValue().value< QgsCoordinateReferenceSystem >().isValid() ); |
| 816 | + QCOMPARE( spy3.count(), 2 ); |
| 817 | + QVERIFY( !wrapperM.mProjectionSelectionWidget->crs().isValid() ); |
| 818 | + QVERIFY( !wrapperM.mUseProjectCrsCheckBox->isChecked() ); |
| 819 | + wrapperM.setWidgetValue( QStringLiteral( "ProjectCrs" ), context ); |
| 820 | + QCOMPARE( wrapperM.widgetValue().toString(), QStringLiteral( "ProjectCrs" ) ); |
| 821 | + QCOMPARE( spy3.count(), 3 ); |
| 822 | + QVERIFY( wrapperM.mUseProjectCrsCheckBox->isChecked() ); |
| 823 | + |
| 824 | + // check signal |
| 825 | + wrapperM.mUseProjectCrsCheckBox->setChecked( false ); |
| 826 | + QCOMPARE( spy3.count(), 4 ); |
| 827 | + wrapperM.mProjectionSelectionWidget->setCrs( QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:28355" ) ) ); |
| 828 | + QCOMPARE( spy3.count(), 5 ); |
| 829 | + wrapperM.mProjectionSelectionWidget->setCrs( QgsCoordinateReferenceSystem() ); |
| 830 | + QCOMPARE( spy3.count(), 6 ); |
| 831 | + |
| 832 | + // should be a label in modeler mode |
| 833 | + l = wrapperM.createWrappedLabel(); |
| 834 | + QVERIFY( l ); |
| 835 | + QCOMPARE( l->text(), QStringLiteral( "crs" ) ); |
| 836 | + QCOMPARE( l->toolTip(), param.toolTip() ); |
| 837 | + delete w; |
| 838 | + delete l; |
| 839 | +} |
| 840 | + |
740 | 841 | QGSTEST_MAIN( TestProcessingGui )
|
741 | 842 | #include "testprocessinggui.moc"
|
0 commit comments