Skip to content
Permalink
Browse files

[quick] fix deprecated use of QApplication::desktopWidget()->screenGe…

…ometry()

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?
  • Loading branch information
3nids committed Nov 5, 2020
1 parent 679af1b commit 81f114dff4c7aeb3a1c5c454160829a976fafa28
Showing with 14 additions and 11 deletions.
  1. +14 −11 src/quickgui/qgsquickutils.cpp
@@ -13,9 +13,10 @@
* *
***************************************************************************/

#include <QApplication>
#include <QDesktopWidget>
#include <QGuiApplication>
#include <QScreen>
#include <QString>
#include <QWindow>

#include "qgis.h"
#include "qgscoordinatereferencesystem.h"
@@ -335,11 +336,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<double>( width ) / dpiX * 25.4;
double sizeY = static_cast<double>( height ) / dpiY * 25.4;

@@ -413,12 +415,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
}

0 comments on commit 81f114d

Please sign in to comment.
You can’t perform that action at this time.