Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
199 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/*************************************************************************** | ||
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 <QGuiApplication> | ||
#include <QScreen> | ||
#include <QString> | ||
#include <QWindow> | ||
|
||
#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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/*************************************************************************** | ||
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 <QObject> | ||
#include <QString> | ||
#include <QUrl> | ||
#include <QtPositioning/QGeoCoordinate> | ||
#include <QModelIndex> | ||
|
||
#include <limits> | ||
|
||
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/*************************************************************************** | ||
testqgsquickutils.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 <QObject> | ||
#include <QApplication> | ||
#include <QDesktopWidget> | ||
|
||
#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" | ||
|
||
class TestQgsQuickUtils: 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 TestQgsQuickUtils::screen_density() | ||
{ | ||
qreal dp = utils.screenDensity(); | ||
QVERIFY( ( dp > 0 ) && ( dp < 1000 ) ); | ||
} | ||
|
||
QGSTEST_MAIN( TestQgsQuickUtils ) | ||
#include "testqgsquickutils.moc" |