From 88d443ac8f1a911c0f1f153460e7a0de1221ef68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Carrillo?= Date: Mon, 29 Sep 2025 12:52:05 +0200 Subject: [PATCH] [tests] Add tests for setting extent in 'Export Map to Image/PDF' dialogs, both with normal behavior and with locking the scale activated --- src/app/qgsmapsavedialog.h | 2 + tests/src/app/CMakeLists.txt | 1 + tests/src/app/testqgsmapsavedialog.cpp | 94 ++++++++++++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 tests/src/app/testqgsmapsavedialog.cpp diff --git a/src/app/qgsmapsavedialog.h b/src/app/qgsmapsavedialog.h index 027a3a663ff..fd70e7eacee 100644 --- a/src/app/qgsmapsavedialog.h +++ b/src/app/qgsmapsavedialog.h @@ -109,6 +109,8 @@ class APP_EXPORT QgsMapSaveDialog : public QDialog, private Ui::QgsMapSaveDialog float mDevicePixelRatio; QString mInfoDetails; + + friend class TestQgsMapSaveDialog; }; #endif // QGSMAPSAVEDIALOG_H diff --git a/tests/src/app/CMakeLists.txt b/tests/src/app/CMakeLists.txt index 43eb43b5c54..93249a70a37 100644 --- a/tests/src/app/CMakeLists.txt +++ b/tests/src/app/CMakeLists.txt @@ -23,6 +23,7 @@ set(TESTS testqgsidentify.cpp testqgslayerpropertiesdialogs.cpp testqgsmapcanvasdockwidget.cpp + testqgsmapsavedialog.cpp testqgsmaptooladdpart.cpp testqgsmaptooldeletepart.cpp testqgsmaptooladdring.cpp diff --git a/tests/src/app/testqgsmapsavedialog.cpp b/tests/src/app/testqgsmapsavedialog.cpp new file mode 100644 index 00000000000..e89b872995c --- /dev/null +++ b/tests/src/app/testqgsmapsavedialog.cpp @@ -0,0 +1,94 @@ +/*************************************************************************** + testqgsmapsavedialog.cpp + ------------------------------ + Date : September 2025 + Copyright : (C) 2025 by Germán Carrillo + Email : german at opengis dot ch + *************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "qgstest.h" +#include + +#include "qgisapp.h" +#include "qgsapplication.h" +#include "qgsmapsavedialog.h" +#include "qgsmapcanvas.h" + + +class TestQgsMapSaveDialog : public QgsTest +{ + Q_OBJECT + + public: + TestQgsMapSaveDialog() + : QgsTest( QStringLiteral( "Map save dialogs" ) ) + {} + + private: + QgisApp *mQgisApp = nullptr; + + private slots: + + void initTestCase() + { + QgsApplication::init(); + QgsApplication::initQgis(); + mQgisApp = new QgisApp(); + } + + void cleanupTestCase() + { + QgsApplication::exitQgis(); + } + + void testUpdateExtent() + { + // Set up base canvas + QgsMapCanvas canvas; + canvas.setDestinationCrs( QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:3857" ) ) ); + canvas.setFrameStyle( QFrame::NoFrame ); + canvas.resize( 800, 600 ); + canvas.show(); // to make the canvas resize + canvas.hide(); + canvas.setExtent( QgsRectangle( 623913, 5720967, 1215325, 6068610 ) ); + + // Set up dialog + QgsMapSaveDialog dialog( nullptr, &canvas ); + dialog.updateDpi( 96 ); + dialog.mLockScale->setChecked( false ); // Default, let's make it explicit + + // Check initial status + QCOMPARE( dialog.mScaleWidget->scale(), 2794072 ); + QCOMPARE( dialog.mDpi, 96 ); + + // Check update extent without locking the scale + dialog.mScaleWidget->setScale( 10000 ); // First set a different arbitrary scale + QCOMPARE( dialog.mScaleWidget->scale(), 10000 ); + + QgsRectangle canvasExtent( 1028930.8433, 5910111.234, 1031976.2192, 5912395.266 ); + canvas.setExtent( canvasExtent ); + dialog.mExtentGroupBox->setOutputExtentFromCurrent(); // Same as set extent from "Map Canvas Extent" + QCOMPARE( dialog.mExtentGroupBox->outputExtent(), canvasExtent ); + QCOMPARE( dialog.mScaleWidget->scale(), 14388 ); + + // Check update extent locking the scale + dialog.mScaleWidget->setScale( 10000 ); // First set a different arbitrary scale + QCOMPARE( dialog.mScaleWidget->scale(), 10000 ); + dialog.mLockScale->setChecked( true ); + + canvas.setExtent( canvasExtent ); + dialog.mExtentGroupBox->setOutputExtentFromCurrent(); // Same as set extent from "Map Canvas Extent" + QCOMPARE( dialog.mExtentGroupBox->outputExtent(), canvasExtent ); + QCOMPARE( dialog.mScaleWidget->scale(), 10000 ); // Our arbitrary scale is kept! + } +}; + +QGSTEST_MAIN( TestQgsMapSaveDialog ) +#include "testqgsmapsavedialog.moc"