QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
265  Q_INVOKABLE static void selectFeaturesInLayer( QgsVectorLayer *layer, const QList<int> &fids, QgsVectorLayer::SelectBehavior behavior = QgsVectorLayer::SetSelection );
266 
267 
273  Q_INVOKABLE static QString fieldType( const QgsField &field );
274 
275 
280  Q_INVOKABLE static QString dateTimeFieldFormat( const QString &fieldFormat );
281 
285  Q_INVOKABLE static QModelIndex invalidIndex();
286 
287  private:
288  static void formatToMetricDistance( double srcDistance,
290  double &destDistance,
291  QgsUnitTypes::DistanceUnit &destUnits );
292 
293  static void formatToImperialDistance( double srcDistance,
295  double &destDistance,
296  QgsUnitTypes::DistanceUnit &destUnits );
297 
298  static void formatToUSCSDistance( double srcDistance,
300  double &destDistance,
301  QgsUnitTypes::DistanceUnit &destUnits );
302 
303 
304  static qreal calculateScreenDensity();
305 
306  qreal mScreenDensity;
307 };
308 
309 #endif // QGSQUICKUTILS_H
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition: qgis.h:89
@ Warning
Definition: qgis.h:91
Format
Available formats for displaying coordinates.
@ FormatPair
Formats coordinates as an "x,y" pair.
@ FlagDegreesUseStringSuffix
Include a direction suffix (eg 'N', 'E', 'S' or 'W'), otherwise a "-" prefix is used for west and sou...
This class represents a coordinate reference system (CRS).
Contains information about the context in which a coordinate transform is executed.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:56
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:51
A class to represent a 2D point.
Definition: qgspointxy.h:44
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:38
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:99
Pair of QgsFeature and QgsVectorLayer.
The QgsQuickMapSettings class encapsulates QgsMapSettings class to offer settings of configuration of...
Encapsulating the common utilities for QgsQuick library.
Definition: qgsquickutils.h:53
~QgsQuickUtils()=default
Destructor.
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:68
SystemOfMeasurement
Systems of unit measurement.
Definition: qgsunittypes.h:45
@ MetricSystem
International System of Units (SI)
Definition: qgsunittypes.h:47
Represents a vector layer which manages a vector based data sets.
SelectBehavior
Selection behavior.
@ SetSelection
Set selection, removing any existing selection.
const QgsField & field
Definition: qgsfield.h:472