Skip to content

Commit da670f9

Browse files
committed
Unit tests for CRS parameter wrapper
1 parent 88b324d commit da670f9

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed

src/gui/processing/qgsprocessingwidgetwrapperimpl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,10 @@ QWidget *QgsProcessingCrsWidgetWrapper::createWidget()
210210
mUseProjectCrsCheckBox->setToolTip( tr( "Always use the current project CRS when running the model" ) );
211211
vl->addWidget( mUseProjectCrsCheckBox );
212212
connect( mUseProjectCrsCheckBox, &QCheckBox::toggled, mProjectionSelectionWidget, &QgsProjectionSelectionWidget::setDisabled );
213+
connect( mUseProjectCrsCheckBox, &QCheckBox::toggled, this, [ = ]
214+
{
215+
emit widgetValueHasChanged( this );
216+
} );
213217

214218
vl->addWidget( mProjectionSelectionWidget );
215219

tests/src/gui/testprocessinggui.cpp

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "processing/models/qgsprocessingmodelalgorithm.h"
3838
#include "qgsxmlutils.h"
3939
#include "qgspropertyoverridebutton.h"
40+
#include "qgsprojectionselectionwidget.h"
4041

4142
class TestParamType : public QgsProcessingParameterDefinition
4243
{
@@ -141,6 +142,7 @@ class TestProcessingGui : public QObject
141142
void testModelerWrapper();
142143
void testBooleanWrapper();
143144
void testStringWrapper();
145+
void testCrsWrapper();
144146
};
145147

146148
void TestProcessingGui::initTestCase()
@@ -737,5 +739,104 @@ void TestProcessingGui::testStringWrapper()
737739
delete l;
738740
}
739741

742+
void TestProcessingGui::testCrsWrapper()
743+
{
744+
QgsProcessingParameterCrs param( QStringLiteral( "crs" ), QStringLiteral( "crs" ) );
745+
746+
// standard wrapper
747+
QgsProcessingCrsWidgetWrapper wrapper( &param );
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( &param, 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( &param, 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+
740841
QGSTEST_MAIN( TestProcessingGui )
741842
#include "testprocessinggui.moc"

0 commit comments

Comments
 (0)