QGIS API Documentation  3.8.0-Zanzibar (11aff65)
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 
133  Q_INVOKABLE static QString getRelativePath( const QString &path, const QString &prefixPath );
134 
138  Q_INVOKABLE static void logMessage( const QString &message,
139  const QString &tag = QString( "QgsQuick" ),
141 
149  Q_INVOKABLE static QgsQuickFeatureLayerPair featureFactory( const QgsFeature &feature, QgsVectorLayer *layer = nullptr );
150 
156  Q_INVOKABLE static const QUrl getThemeIcon( const QString &name );
157 
165  Q_INVOKABLE static const QUrl getEditorComponentSource( const QString &widgetName );
166 
172  Q_INVOKABLE static QString formatPoint(
173  const QgsPoint &point,
175  int decimals = 3,
176  QgsCoordinateFormatter::FormatFlags flags = QgsCoordinateFormatter::FlagDegreesUseStringSuffix );
177 
195  Q_INVOKABLE static QString formatDistance( double distance,
197  int decimals,
199 
208  Q_INVOKABLE static bool removeFile( const QString &filePath );
209 
223  static void humanReadableDistance( double srcDistance,
226  double &destDistance,
227  QgsUnitTypes::DistanceUnit &destUnits );
228 
230  QString dumpScreenInfo() const;
231 
242  Q_INVOKABLE static QVariantMap createValueRelationCache( const QVariantMap &config, const QgsFeature &formFeature = QgsFeature() );
243 
244  private:
245  static void formatToMetricDistance( double srcDistance,
247  double &destDistance,
248  QgsUnitTypes::DistanceUnit &destUnits );
249 
250  static void formatToImperialDistance( double srcDistance,
252  double &destDistance,
253  QgsUnitTypes::DistanceUnit &destUnits );
254 
255  static void formatToUSCSDistance( double srcDistance,
257  double &destDistance,
258  QgsUnitTypes::DistanceUnit &destUnits );
259 
260 
261  static qreal calculateScreenDensity();
262 
263  qreal mScreenDensity;
264 };
265 
266 #endif // QGSQUICKUTILS_H
SystemOfMeasurement
Systems of unit measurement.
Definition: qgsunittypes.h:44
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:66
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: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:54
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.