Skip to content

Commit

Permalink
[quick] fix deprecated use of QApplication::desktopWidget()->screenGe…
Browse files Browse the repository at this point in the history
…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 authored and nyalldawson committed Feb 5, 2021
1 parent 8e3252c commit aa5b09b
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/quickgui/qgsquickutils.cpp
Expand Up @@ -13,9 +13,10 @@
* *
***************************************************************************/

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

#include "qgis.h"
#include "qgscoordinatereferencesystem.h"
Expand Down Expand Up @@ -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<double>( width ) / dpiX * 25.4;
double sizeY = static_cast<double>( height ) / dpiY * 25.4;

Expand Down Expand Up @@ -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
}

0 comments on commit aa5b09b

Please sign in to comment.