|
66 | 66 | #include "qgscoordinateoperationwidget.h"
|
67 | 67 | #include "qgsmessagebar.h"
|
68 | 68 | #include "qgsfieldcombobox.h"
|
| 69 | +#include "qgsmapthemecollection.h" |
69 | 70 |
|
70 | 71 | class TestParamType : public QgsProcessingParameterDefinition
|
71 | 72 | {
|
@@ -195,6 +196,7 @@ class TestProcessingGui : public QObject
|
195 | 196 | void testCoordinateOperationWrapper();
|
196 | 197 | void mapLayerComboBox();
|
197 | 198 | void paramConfigWidget();
|
| 199 | + void testMapThemeWrapper(); |
198 | 200 |
|
199 | 201 | private:
|
200 | 202 |
|
@@ -4254,6 +4256,124 @@ void TestProcessingGui::paramConfigWidget()
|
4254 | 4256 | QVERIFY( def->flags() & QgsProcessingParameterDefinition::FlagAdvanced );
|
4255 | 4257 | }
|
4256 | 4258 |
|
| 4259 | +void TestProcessingGui::testMapThemeWrapper() |
| 4260 | +{ |
| 4261 | + // add some themes to the project |
| 4262 | + QgsProject p; |
| 4263 | + p.mapThemeCollection()->insert( QStringLiteral( "aa" ), QgsMapThemeCollection::MapThemeRecord() ); |
| 4264 | + p.mapThemeCollection()->insert( QStringLiteral( "bb" ), QgsMapThemeCollection::MapThemeRecord() ); |
| 4265 | + |
| 4266 | + QCOMPARE( p.mapThemeCollection()->mapThemes(), QStringList() << QStringLiteral( "aa" ) << QStringLiteral( "bb" ) ); |
| 4267 | + |
| 4268 | + auto testWrapper = [&p]( QgsProcessingGui::WidgetType type ) |
| 4269 | + { |
| 4270 | + // non optional, no existing themes |
| 4271 | + QgsProcessingParameterMapTheme param( QStringLiteral( "theme" ), QStringLiteral( "theme" ), false ); |
| 4272 | + |
| 4273 | + QgsProcessingMapThemeWidgetWrapper wrapper( ¶m, type ); |
| 4274 | + |
| 4275 | + QgsProcessingContext context; |
| 4276 | + QWidget *w = wrapper.createWrappedWidget( context ); |
| 4277 | + |
| 4278 | + QSignalSpy spy( &wrapper, &QgsProcessingEnumWidgetWrapper::widgetValueHasChanged ); |
| 4279 | + wrapper.setWidgetValue( QStringLiteral( "bb" ), context ); |
| 4280 | + |
| 4281 | + switch ( type ) |
| 4282 | + { |
| 4283 | + case QgsProcessingGui::Standard: |
| 4284 | + case QgsProcessingGui::Batch: |
| 4285 | + // batch or standard mode, only valid themes can be set! |
| 4286 | + QCOMPARE( spy.count(), 0 ); |
| 4287 | + QVERIFY( !wrapper.widgetValue().isValid() ); |
| 4288 | + QCOMPARE( static_cast< QComboBox * >( wrapper.wrappedWidget() )->currentIndex(), -1 ); |
| 4289 | + wrapper.setWidgetValue( QStringLiteral( "aa" ), context ); |
| 4290 | + QCOMPARE( spy.count(), 0 ); |
| 4291 | + QVERIFY( !wrapper.widgetValue().isValid() ); |
| 4292 | + QCOMPARE( static_cast< QComboBox * >( wrapper.wrappedWidget() )->currentIndex(), -1 ); |
| 4293 | + break; |
| 4294 | + |
| 4295 | + case QgsProcessingGui::Modeler: |
| 4296 | + QCOMPARE( spy.count(), 1 ); |
| 4297 | + QCOMPARE( wrapper.widgetValue().toString(), QStringLiteral( "bb" ) ); |
| 4298 | + QCOMPARE( static_cast< QComboBox * >( wrapper.wrappedWidget() )->currentText(), QStringLiteral( "bb" ) ); |
| 4299 | + wrapper.setWidgetValue( QStringLiteral( "aa" ), context ); |
| 4300 | + QCOMPARE( spy.count(), 2 ); |
| 4301 | + QCOMPARE( wrapper.widgetValue().toString(), QStringLiteral( "aa" ) ); |
| 4302 | + QCOMPARE( static_cast< QComboBox * >( wrapper.wrappedWidget() )->currentText(), QStringLiteral( "aa" ) ); |
| 4303 | + break; |
| 4304 | + } |
| 4305 | + |
| 4306 | + delete w; |
| 4307 | + |
| 4308 | + // with project |
| 4309 | + QgsProcessingParameterWidgetContext widgetContext; |
| 4310 | + widgetContext.setProject( &p ); |
| 4311 | + |
| 4312 | + QgsProcessingMapThemeWidgetWrapper wrapper2( ¶m, type ); |
| 4313 | + wrapper2.setWidgetContext( widgetContext ); |
| 4314 | + w = wrapper2.createWrappedWidget( context ); |
| 4315 | + |
| 4316 | + QSignalSpy spy2( &wrapper2, &QgsProcessingEnumWidgetWrapper::widgetValueHasChanged ); |
| 4317 | + wrapper2.setWidgetValue( QStringLiteral( "bb" ), context ); |
| 4318 | + QCOMPARE( spy2.count(), 1 ); |
| 4319 | + QCOMPARE( wrapper2.widgetValue().toString(), QStringLiteral( "bb" ) ); |
| 4320 | + QCOMPARE( static_cast< QComboBox * >( wrapper2.wrappedWidget() )->currentText(), QStringLiteral( "bb" ) ); |
| 4321 | + wrapper2.setWidgetValue( QStringLiteral( "aa" ), context ); |
| 4322 | + QCOMPARE( spy2.count(), 2 ); |
| 4323 | + QCOMPARE( wrapper2.widgetValue().toString(), QStringLiteral( "aa" ) ); |
| 4324 | + QCOMPARE( static_cast< QComboBox * >( wrapper2.wrappedWidget() )->currentText(), QStringLiteral( "aa" ) ); |
| 4325 | + |
| 4326 | + // check signal |
| 4327 | + static_cast< QComboBox * >( wrapper2.wrappedWidget() )->setCurrentIndex( 2 ); |
| 4328 | + QCOMPARE( spy2.count(), 3 ); |
| 4329 | + |
| 4330 | + delete w; |
| 4331 | + |
| 4332 | + // optional |
| 4333 | + QgsProcessingParameterMapTheme param2( QStringLiteral( "theme" ), QStringLiteral( "theme" ), true ); |
| 4334 | + QgsProcessingMapThemeWidgetWrapper wrapper3( ¶m2, type ); |
| 4335 | + wrapper3.setWidgetContext( widgetContext ); |
| 4336 | + w = wrapper3.createWrappedWidget( context ); |
| 4337 | + |
| 4338 | + QSignalSpy spy3( &wrapper3, &QgsProcessingEnumWidgetWrapper::widgetValueHasChanged ); |
| 4339 | + wrapper3.setWidgetValue( QStringLiteral( "bb" ), context ); |
| 4340 | + QCOMPARE( spy3.count(), 1 ); |
| 4341 | + QCOMPARE( wrapper3.widgetValue().toString(), QStringLiteral( "bb" ) ); |
| 4342 | + QCOMPARE( static_cast< QComboBox * >( wrapper3.wrappedWidget() )->currentText(), QStringLiteral( "bb" ) ); |
| 4343 | + wrapper3.setWidgetValue( QStringLiteral( "aa" ), context ); |
| 4344 | + QCOMPARE( spy3.count(), 2 ); |
| 4345 | + QCOMPARE( wrapper3.widgetValue().toString(), QStringLiteral( "aa" ) ); |
| 4346 | + QCOMPARE( static_cast< QComboBox * >( wrapper3.wrappedWidget() )->currentText(), QStringLiteral( "aa" ) ); |
| 4347 | + wrapper3.setWidgetValue( QVariant(), context ); |
| 4348 | + QCOMPARE( spy3.count(), 3 ); |
| 4349 | + QVERIFY( !wrapper3.widgetValue().isValid() ); |
| 4350 | + delete w; |
| 4351 | + |
| 4352 | + |
| 4353 | + QLabel *l = wrapper.createWrappedLabel(); |
| 4354 | + if ( wrapper.type() != QgsProcessingGui::Batch ) |
| 4355 | + { |
| 4356 | + QVERIFY( l ); |
| 4357 | + QCOMPARE( l->text(), QStringLiteral( "theme" ) ); |
| 4358 | + QCOMPARE( l->toolTip(), param.toolTip() ); |
| 4359 | + delete l; |
| 4360 | + } |
| 4361 | + else |
| 4362 | + { |
| 4363 | + QVERIFY( !l ); |
| 4364 | + } |
| 4365 | + }; |
| 4366 | + |
| 4367 | + // standard wrapper |
| 4368 | + testWrapper( QgsProcessingGui::Standard ); |
| 4369 | + |
| 4370 | + // batch wrapper |
| 4371 | + testWrapper( QgsProcessingGui::Batch ); |
| 4372 | + |
| 4373 | + // modeler wrapper |
| 4374 | + testWrapper( QgsProcessingGui::Modeler ); |
| 4375 | +} |
| 4376 | + |
4257 | 4377 | void TestProcessingGui::cleanupTempDir()
|
4258 | 4378 | {
|
4259 | 4379 | QDir tmpDir = QDir( mTempDir );
|
|
0 commit comments