QGIS API Documentation  3.4.15-Madeira (e83d02e274)
qgsquickutils.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsquickutils.h
3  --------------------------------------
4  Date : Nov 2017
5  Copyright : (C) 2017 by Peter Petrik
6  Email : zilolv at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSQUICKUTILS_H
17 #define QGSQUICKUTILS_H
18 
19 
20 #include <QObject>
21 #include <QString>
22 #include <QUrl>
23 #include <QtPositioning/QGeoCoordinate>
24 
25 #include <limits>
26 
27 #include "qgis.h"
28 #include "qgsmessagelog.h"
29 #include "qgspoint.h"
30 #include "qgspointxy.h"
31 #include "qgsunittypes.h"
32 #include "qgsquickmapsettings.h"
34 #include "qgis_quick.h"
35 #include "qgscoordinateformatter.h"
36 
37 
38 class QgsFeature;
39 class QgsVectorLayer;
41 
51 class QUICK_EXPORT QgsQuickUtils: public QObject
52 {
53  Q_OBJECT
54 
66  Q_PROPERTY( qreal dp READ screenDensity CONSTANT )
67 
68  public:
70  QgsQuickUtils( QObject *parent = nullptr );
72  ~QgsQuickUtils() = default;
73 
75  qreal screenDensity() const;
76 
82  Q_INVOKABLE static QgsCoordinateReferenceSystem coordinateReferenceSystemFromEpsgId( long epsg );
83 
89  Q_INVOKABLE static QgsPointXY pointXY( double x, double y );
90 
96  Q_INVOKABLE static QgsPoint point( double x, double y, double z = std::numeric_limits<double>::quiet_NaN(), double m = std::numeric_limits<double>::quiet_NaN() );
97 
103  Q_INVOKABLE static QgsPoint coordinateToPoint( const QGeoCoordinate &coor );
104 
110  Q_INVOKABLE static QgsPointXY transformPoint( const QgsCoordinateReferenceSystem &srcCrs,
111  const QgsCoordinateReferenceSystem &destCrs,
112  const QgsCoordinateTransformContext &context,
113  const QgsPointXY &srcPoint );
114 
118  Q_INVOKABLE static double screenUnitsToMeters( QgsQuickMapSettings *mapSettings, int baseLengthPixels );
119 
124  Q_INVOKABLE static bool fileExists( const QString &path );
125 
130  Q_INVOKABLE static QString getFileName( const QString &path );
131 
135  Q_INVOKABLE static void logMessage( const QString &message,
136  const QString &tag = QString( "QgsQuick" ),
138 
146  Q_INVOKABLE static QgsQuickFeatureLayerPair featureFactory( const QgsFeature &feature, QgsVectorLayer *layer = nullptr );
147 
153  Q_INVOKABLE static const QUrl getThemeIcon( const QString &name );
154 
162  Q_INVOKABLE static const QUrl getEditorComponentSource( const QString &widgetName );
163 
169  Q_INVOKABLE static QString formatPoint(
170  const QgsPoint &point,
172  int decimals = 3,
173  QgsCoordinateFormatter::FormatFlags flags = QgsCoordinateFormatter::FlagDegreesUseStringSuffix );
174 
192  Q_INVOKABLE static QString formatDistance( double distance,
194  int decimals,
196 
210  static void humanReadableDistance( double srcDistance,
213  double &destDistance,
214  QgsUnitTypes::DistanceUnit &destUnits );
215 
217  QString dumpScreenInfo() const;
218 
219  private:
220  static void formatToMetricDistance( double srcDistance,
222  double &destDistance,
223  QgsUnitTypes::DistanceUnit &destUnits );
224 
225  static void formatToImperialDistance( double srcDistance,
227  double &destDistance,
228  QgsUnitTypes::DistanceUnit &destUnits );
229 
230  static void formatToUSCSDistance( double srcDistance,
232  double &destDistance,
233  QgsUnitTypes::DistanceUnit &destUnits );
234 
235 
236  static qreal calculateScreenDensity();
237 
238  qreal mScreenDensity;
239 };
240 
241 #endif // QGSQUICKUTILS_H
SystemOfMeasurement
Systems of unit measurement.
Definition: qgsunittypes.h:43
Encapsulating the common utilies for QgsQuick library.
Definition: qgsquickutils.h:51
Formats coordinates as an "x,y" pair.
A class to represent a 2D point.
Definition: qgspointxy.h:43
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition: qgis.h:79
The QgsQuickMapSettings class encapsulates QgsMapSettings class to offer settings of configuration of...
Format
Available formats for displaying coordinates.
International System of Units (SI)
Definition: qgsunittypes.h:46
Contains information about the context in which a coordinate transform is executed.
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:37
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:53
This class represents a coordinate reference system (CRS).
Include a direction suffix (eg &#39;N&#39;, &#39;E&#39;, &#39;S&#39; or &#39;W&#39;), otherwise a "-" prefix is used for west and sou...
Pair of QgsFeature and QgsVectorLayer.
Represents a vector layer which manages a vector based data sets.