From 1d29e7ad763538f176a1ea2f3275139068f66dd0 Mon Sep 17 00:00:00 2001 From: tomasMizera Date: Thu, 16 Dec 2021 12:27:08 +0100 Subject: [PATCH] remove redundant class qgsquickutils --- src/quickgui/CMakeLists.txt | 2 - src/quickgui/plugin/qgsquickplugin.cpp | 11 --- src/quickgui/qgsquickutils.cpp | 49 ----------- src/quickgui/qgsquickutils.h | 84 ------------------- tests/src/quickgui/CMakeLists.txt | 2 +- ...kutils.cpp => testqgsquickmapsettings.cpp} | 25 +++--- 6 files changed, 11 insertions(+), 162 deletions(-) delete mode 100644 src/quickgui/qgsquickutils.cpp delete mode 100644 src/quickgui/qgsquickutils.h rename tests/src/quickgui/{testqgsquickutils.cpp => testqgsquickmapsettings.cpp} (72%) diff --git a/src/quickgui/CMakeLists.txt b/src/quickgui/CMakeLists.txt index 86bac41193c3..426d6ebb87f6 100644 --- a/src/quickgui/CMakeLists.txt +++ b/src/quickgui/CMakeLists.txt @@ -5,7 +5,6 @@ set(QGIS_QUICK_GUI_MOC_HDRS qgsquickmapcanvasmap.h qgsquickmapsettings.h qgsquickmaptransform.h - qgsquickutils.h ) set(QGIS_QUICK_GUI_SRC @@ -13,7 +12,6 @@ set(QGIS_QUICK_GUI_SRC qgsquickmapcanvasmap.cpp qgsquickmapsettings.cpp qgsquickmaptransform.cpp - qgsquickutils.cpp ) include_directories( diff --git a/src/quickgui/plugin/qgsquickplugin.cpp b/src/quickgui/plugin/qgsquickplugin.cpp index 3435af8e638d..ae81d069c397 100644 --- a/src/quickgui/plugin/qgsquickplugin.cpp +++ b/src/quickgui/plugin/qgsquickplugin.cpp @@ -35,14 +35,6 @@ #include "qgsquickmapsettings.h" #include "qgsquickmaptransform.h" #include "qgsquickplugin.h" -#include "qgsquickutils.h" - -static QObject *_utilsProvider( QQmlEngine *engine, QJSEngine *scriptEngine ) -{ - Q_UNUSED( engine ) - Q_UNUSED( scriptEngine ) - return new QgsQuickUtils(); // the object will be owned by QML engine and destroyed by the engine on exit -} void QgsQuickPlugin::registerTypes( const char *uri ) { @@ -66,7 +58,4 @@ void QgsQuickPlugin::registerTypes( const char *uri ) qmlRegisterType< QgsQuickMapSettings >( uri, 0, 1, "MapSettings" ); qmlRegisterType< QgsQuickMapTransform >( uri, 0, 1, "MapTransform" ); qmlRegisterType< QgsVectorLayer >( uri, 0, 1, "VectorLayer" ); - - qmlRegisterSingletonType< QgsQuickUtils >( uri, 0, 1, "Utils", _utilsProvider ); } - diff --git a/src/quickgui/qgsquickutils.cpp b/src/quickgui/qgsquickutils.cpp deleted file mode 100644 index 16e17fd42353..000000000000 --- a/src/quickgui/qgsquickutils.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/*************************************************************************** - qgsquickutils.cpp - -------------------------------------- - Date : Nov 2017 - Copyright : (C) 2017 by Peter Petrik - Email : zilolv at gmail dot com - *************************************************************************** - * * - * 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 -#include -#include -#include - -#include "qgsquickmapsettings.h" -#include "qgsquickutils.h" - -QgsQuickUtils::QgsQuickUtils( QObject *parent ) - : QObject( parent ) - , mScreenDensity( calculateScreenDensity() ) -{ -} - -qreal QgsQuickUtils::screenDensity() const -{ - return mScreenDensity; -} - -qreal QgsQuickUtils::calculateScreenDensity() -{ - // calculate screen density for calculation of real pixel sizes from density-independent pixels - // take the first top level window - double dpi = 96.0; - const QWindowList windows = QGuiApplication::topLevelWindows(); - if ( !windows.isEmpty() ) - { - QScreen *screen = windows.at( 0 )->screen(); - double dpiX = screen->physicalDotsPerInchX(); - double dpiY = screen->physicalDotsPerInchY(); - dpi = dpiX < dpiY ? dpiX : dpiY; // In case of asymmetrical DPI. Improbable - } - return dpi / 160.; // 160 DPI is baseline for density-independent pixels in Android -} diff --git a/src/quickgui/qgsquickutils.h b/src/quickgui/qgsquickutils.h deleted file mode 100644 index 0d387f0aaa6b..000000000000 --- a/src/quickgui/qgsquickutils.h +++ /dev/null @@ -1,84 +0,0 @@ -/*************************************************************************** - qgsquickutils.h - -------------------------------------- - Date : Nov 2017 - Copyright : (C) 2017 by Peter Petrik - Email : zilolv at gmail dot com - *************************************************************************** - * * - * 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. * - * * - ***************************************************************************/ - -#ifndef QGSQUICKUTILS_H -#define QGSQUICKUTILS_H - - -#include -#include -#include -#include -#include - -#include - -#include "qgis.h" -#include "qgsexpressioncontextutils.h" -#include "qgsmessagelog.h" -#include "qgspoint.h" -#include "qgspointxy.h" -#include "qgsunittypes.h" -#include "qgsquickmapsettings.h" -#include "qgis_quick.h" -#include "qgscoordinateformatter.h" - - -class QgsFeature; -class QgsVectorLayer; -class QgsCoordinateReferenceSystem; - -/** - * \ingroup quick - * - * \brief Encapsulating the common utilities for QgsQuick library. - * - * \note QML Type: Utils (Singleton) - * - * \since QGIS 3.2 - */ -class QUICK_EXPORT QgsQuickUtils: public QObject -{ - Q_OBJECT - - /** - * "dp" is useful for building building components that work well with different screen densities. - * It stands for density-independent pixels. A width of 10dp is going to be the same physical size - * on all screens regardless their density. In QML code, all values are specified in screen pixels, - * so in order to set a width of 10dp, one would use the following code: "width: 10 * QgsQuick.Utils.dp" - * - * 1dp is approximately 0.16mm. When screen has 160 DPI (baseline), the value of "dp" is 1. - * On high DPI screen the value will be greater, e.g. 1.5. - * - * This is a readonly property. - */ - Q_PROPERTY( qreal dp READ screenDensity CONSTANT ) - - public: - //! Create new utilities - QgsQuickUtils( QObject *parent = nullptr ); - //! Destructor - ~QgsQuickUtils() = default; - - //! \copydoc QgsQuickUtils::dp - qreal screenDensity() const; - - private: - static qreal calculateScreenDensity(); - - qreal mScreenDensity; -}; - -#endif // QGSQUICKUTILS_H diff --git a/tests/src/quickgui/CMakeLists.txt b/tests/src/quickgui/CMakeLists.txt index 06c356c2094c..2e27caff95d8 100644 --- a/tests/src/quickgui/CMakeLists.txt +++ b/tests/src/quickgui/CMakeLists.txt @@ -32,7 +32,7 @@ include_directories(SYSTEM ############################################################# # Tests: -add_qgis_test(testqgsquickutils.cpp MODULE quick LINKEDLIBRARIES qgis_quick) +add_qgis_test(testqgsquickmapsettings.cpp MODULE quick LINKEDLIBRARIES qgis_quick) ############################################################# # Add also test application diff --git a/tests/src/quickgui/testqgsquickutils.cpp b/tests/src/quickgui/testqgsquickmapsettings.cpp similarity index 72% rename from tests/src/quickgui/testqgsquickutils.cpp rename to tests/src/quickgui/testqgsquickmapsettings.cpp index 3b63be85ee08..939db0a10259 100644 --- a/tests/src/quickgui/testqgsquickutils.cpp +++ b/tests/src/quickgui/testqgsquickmapsettings.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - testqgsquickutils.cpp + testqgsquickmapsettings.cpp -------------------------------------- Date : Nov 2017 Copyright : (C) 2017 by Peter Petrik @@ -17,33 +17,28 @@ #include #include "qgsapplication.h" -#include "qgscoordinatereferencesystem.h" -#include "qgscoordinatetransformcontext.h" -#include "qgspoint.h" -#include "qgspointxy.h" #include "qgstest.h" #include "qgis.h" #include "qgsunittypes.h" -#include "qgsquickutils.h" +#include "qgsquickmapsettings.h" -class TestQgsQuickUtils: public QObject +class TestQgsQuickSettings: public QObject { Q_OBJECT private slots: void init() {} // will be called before each testfunction is executed. void cleanup() {} // will be called after every testfunction. - void screen_density(); - private: - QgsQuickUtils utils; + void test_project_existency(); }; -void TestQgsQuickUtils::screen_density() +void TestQgsQuickMapSettings::test_project_existency() { - qreal dp = utils.screenDensity(); - QVERIFY( ( dp > 0 ) && ( dp < 1000 ) ); + QgsQuickMapSettings *settings = new QgsQuickMapSettings(); + QVERIFY( !settings->project() ); + delete settings; } -QGSTEST_MAIN( TestQgsQuickUtils ) -#include "testqgsquickutils.moc" +QGSTEST_MAIN( TestQgsQuickMapSettings ) +#include "testqgsquickmapsettings.moc"