QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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"
29 #include "qgsmessagelog.h"
30 #include "qgspoint.h"
31 #include "qgspointxy.h"
32 #include "qgsunittypes.h"
33 #include "qgsquickmapsettings.h"
35 #include "qgis_quick.h"
36 #include "qgscoordinateformatter.h"
37 
38 
39 class QgsFeature;
40 class QgsVectorLayer;
42 
52 class QUICK_EXPORT QgsQuickUtils: public QObject
53 {
54  Q_OBJECT
55 
67  Q_PROPERTY( qreal dp READ screenDensity CONSTANT )
68 
69  public:
71  QgsQuickUtils( QObject *parent = nullptr );
73  ~QgsQuickUtils() = default;
74 
76  qreal screenDensity() const;
77 
83  Q_INVOKABLE static QgsCoordinateReferenceSystem coordinateReferenceSystemFromEpsgId( long epsg );
84 
90  Q_INVOKABLE static QgsPointXY pointXY( double x, double y );
91 
97  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() );
98 
104  Q_INVOKABLE static QgsPoint coordinateToPoint( const QGeoCoordinate &coor );
105 
111  Q_INVOKABLE static QgsPointXY transformPoint( const QgsCoordinateReferenceSystem &srcCrs,
112  const QgsCoordinateReferenceSystem &destCrs,
113  const QgsCoordinateTransformContext &context,
114  const QgsPointXY &srcPoint );
115 
119  Q_INVOKABLE static double screenUnitsToMeters( QgsQuickMapSettings *mapSettings, int baseLengthPixels );
120 
125  Q_INVOKABLE static bool fileExists( const QString &path );
126 
134  Q_INVOKABLE static QString getRelativePath( const QString &path, const QString &prefixPath );
135 
139  Q_INVOKABLE static void logMessage( const QString &message,
140  const QString &tag = QString( "QgsQuick" ),
142 
150  Q_INVOKABLE static QgsQuickFeatureLayerPair featureFactory( const QgsFeature &feature, QgsVectorLayer *layer = nullptr );
151 
157  Q_INVOKABLE static const QUrl getThemeIcon( const QString &name );
158 
166  Q_INVOKABLE static const QUrl getEditorComponentSource( const QString &widgetName );
167 
173  Q_INVOKABLE static QString formatPoint(
174  const QgsPoint &point,
176  int decimals = 3,
177  QgsCoordinateFormatter::FormatFlags flags = QgsCoordinateFormatter::FlagDegreesUseStringSuffix );
178 
196  Q_INVOKABLE static QString formatDistance( double distance,
198  int decimals,
200 
209  Q_INVOKABLE static bool removeFile( const QString &filePath );
210 
224  static void humanReadableDistance( double srcDistance,
227  double &destDistance,
228  QgsUnitTypes::DistanceUnit &destUnits );
229 
231  QString dumpScreenInfo() const;
232 
243  Q_INVOKABLE static QVariantMap createValueRelationCache( const QVariantMap &config, const QgsFeature &formFeature = QgsFeature() );
244 
254  Q_INVOKABLE static QString evaluateExpression( const QgsQuickFeatureLayerPair &pair, QgsProject *activeProject, const QString &expression );
255 
256  private:
257  static void formatToMetricDistance( double srcDistance,
259  double &destDistance,
260  QgsUnitTypes::DistanceUnit &destUnits );
261 
262  static void formatToImperialDistance( double srcDistance,
264  double &destDistance,
265  QgsUnitTypes::DistanceUnit &destUnits );
266 
267  static void formatToUSCSDistance( double srcDistance,
269  double &destDistance,
270  QgsUnitTypes::DistanceUnit &destUnits );
271 
272 
273  static qreal calculateScreenDensity();
274 
275  qreal mScreenDensity;
276 };
277 
278 #endif // QGSQUICKUTILS_H
SystemOfMeasurement
Systems of unit measurement.
Definition: qgsunittypes.h:44
Encapsulating the common utilies for QgsQuick library.
Definition: qgsquickutils.h:52
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:67
The QgsQuickMapSettings class encapsulates QgsMapSettings class to offer settings of configuration of...
Format
Available formats for displaying coordinates.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts, annotations, canvases, etc.
Definition: qgsproject.h:89
International System of Units (SI)
Definition: qgsunittypes.h:47
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:66
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.