From 09fb81d879f4f69f82362ecc516bb9b3c0efc33a Mon Sep 17 00:00:00 2001 From: Denis Rouzaud Date: Thu, 7 Nov 2019 09:39:20 +0100 Subject: [PATCH] [quick] fix deprecated use of QApplication::desktopWidget()->screenGeometry() This takes the first top level window and use it to get the screen. The "perfect" approach would be to use a widget as argument in the method. @PeterPetrik thoughts? --- src/quickgui/qgsquickutils.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/quickgui/qgsquickutils.cpp b/src/quickgui/qgsquickutils.cpp index e30c009e5d13..66d3b3d3fa32 100644 --- a/src/quickgui/qgsquickutils.cpp +++ b/src/quickgui/qgsquickutils.cpp @@ -13,9 +13,10 @@ * * ***************************************************************************/ -#include -#include +#include +#include #include +#include #include "qgis.h" #include "qgscoordinatereferencesystem.h" @@ -346,11 +347,12 @@ void QgsQuickUtils::formatToUSCSDistance( double srcDistance, QString QgsQuickUtils::dumpScreenInfo() const { - QRect rec = QApplication::desktop()->screenGeometry(); - int dpiX = QApplication::desktop()->physicalDpiX(); - int dpiY = QApplication::desktop()->physicalDpiY(); - int height = rec.height(); - int width = rec.width(); + // take the first top level window + QScreen *screen = QGuiApplication::topLevelWindows().at( 0 )->screen(); + double dpiX = screen->physicalDotsPerInchX(); + double dpiY = screen->physicalDotsPerInchY(); + int height = screen->geometry().height(); + int width = screen->geometry().width(); double sizeX = static_cast( width ) / dpiX * 25.4; double sizeY = static_cast( height ) / dpiY * 25.4; @@ -429,12 +431,13 @@ qreal QgsQuickUtils::screenDensity() const { return mScreenDensity; } - qreal QgsQuickUtils::calculateScreenDensity() { // calculate screen density for calculation of real pixel sizes from density-independent pixels - int dpiX = QApplication::desktop()->physicalDpiX(); - int dpiY = QApplication::desktop()->physicalDpiY(); - int dpi = dpiX < dpiY ? dpiX : dpiY; // In case of asymmetrical DPI. Improbable + // take the first top level window + QScreen *screen = QGuiApplication::topLevelWindows().at( 0 )->screen(); + double dpiX = screen->physicalDotsPerInchX(); + double dpiY = screen->physicalDotsPerInchY(); + double dpi = dpiX < dpiY ? dpiX : dpiY; // In case of asymmetrical DPI. Improbable return dpi / 160.; // 160 DPI is baseline for density-independent pixels in Android }