15 #include <QDesktopWidget> 29 , mScreenDensity( calculateScreenDensity() )
35 if ( mapSettings ==
nullptr )
return 0.0;
44 QPoint pointCenter( s.width() / 2, s.height() / 2 );
57 QRect rec = QApplication::desktop()->screenGeometry();
58 int dpiX = QApplication::desktop()->physicalDpiX();
59 int dpiY = QApplication::desktop()->physicalDpiY();
60 int height = rec.height();
61 int width = rec.width();
62 double sizeX =
static_cast<double>( width ) / dpiX * 25.4;
63 double sizeY =
static_cast<double>( height ) / dpiY * 25.4;
66 msg += tr(
"screen resolution: %1x%2 px\n" ).arg( width ).arg( height );
67 msg += tr(
"screen DPI: %1x%2\n" ).arg( dpiX ).arg( dpiY );
68 msg += tr(
"screen size: %1x%2 mm\n" ).arg( QString::number( sizeX,
'f', 0 ), QString::number( sizeY,
'f', 0 ) );
69 msg += tr(
"screen density: %1" ).arg( mScreenDensity );
75 return mScreenDensity;
78 qreal QgsQuickUtils::calculateScreenDensity()
81 int dpiX = QApplication::desktop()->physicalDpiX();
82 int dpiY = QApplication::desktop()->physicalDpiY();
83 int dpi = dpiX < dpiY ? dpiX : dpiY;
A class to represent a 2D point.
bool setEllipsoid(const QString &ellipsoid)
Sets the ellipsoid by its acronym.
MessageLevel
Level for messages This will be used both for message log and message bar in application.
The QgsQuickMapSettings class encapsulates QgsMapSettings class to offer settings of configuration of...
qreal screenDensity() const
"dp" is useful for building building components that work well with different screen densities...
Q_INVOKABLE QgsPoint screenToCoordinate(const QPointF &point) const
Convert a screen coordinate to a map coordinate.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
Q_INVOKABLE double screenUnitsToMeters(QgsQuickMapSettings *mapSettings, int baseLengthPixels) const
Calculate the distance in meter representing baseLengthPixels pixels on the screen based on the curre...
QgsQuickUtils(QObject *parent=nullptr)
Create new utilities.
QgsCoordinateReferenceSystem destinationCrs
CRS of destination coordinate reference system.
QSize outputSize
The size of the resulting map image.
A general purpose distance and area calculator, capable of performing ellipsoid based calculations...
QString dumpScreenInfo() const
Returns a string with information about screen size and resolution.
void setSourceCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets source spatial reference system crs.
Q_INVOKABLE QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
double measureLine(const QVector< QgsPointXY > &points) const
Measures the length of a line with multiple segments.
Q_INVOKABLE void logMessage(const QString &message, const QString &tag=QString("QgsQuick"), Qgis::MessageLevel level=Qgis::Warning)
Log message in QgsMessageLog.