QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 
282  private:
283  static void formatToMetricDistance( double srcDistance,
285  double &destDistance,
286  QgsUnitTypes::DistanceUnit &destUnits );
287 
288  static void formatToImperialDistance( double srcDistance,
290  double &destDistance,
291  QgsUnitTypes::DistanceUnit &destUnits );
292 
293  static void formatToUSCSDistance( double srcDistance,
295  double &destDistance,
296  QgsUnitTypes::DistanceUnit &destUnits );
297 
298 
299  static qreal calculateScreenDensity();
300 
301  qreal mScreenDensity;
302 };
303 
304 #endif // QGSQUICKUTILS_H
qgsexpressioncontextutils.h
QgsQuickUtils::~QgsQuickUtils
~QgsQuickUtils()=default
Destructor.
qgsquickfeaturelayerpair.h
QgsCoordinateTransformContext
Contains information about the context in which a coordinate transform is executed.
Definition: qgscoordinatetransformcontext.h:58
QgsPoint
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:38
Qgis::Warning
@ Warning
Definition: qgis.h:91
qgis.h
qgsunittypes.h
qgspoint.h
field
const QgsField & field
Definition: qgsfield.h:456
QgsUnitTypes::DistanceUnit
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:68
QgsUnitTypes::SystemOfMeasurement
SystemOfMeasurement
Systems of unit measurement.
Definition: qgsunittypes.h:45
QgsProject
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:95
QgsQuickMapSettings
The QgsQuickMapSettings class encapsulates QgsMapSettings class to offer settings of configuration of...
Definition: qgsquickmapsettings.h:47
QgsVectorLayer::SelectBehavior
SelectBehavior
Selection behavior.
Definition: qgsvectorlayer.h:412
QgsUnitTypes::MetricSystem
@ MetricSystem
International System of Units (SI)
Definition: qgsunittypes.h:47
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:206
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:44
QgsVectorLayer::SetSelection
@ SetSelection
Set selection, removing any existing selection.
Definition: qgsvectorlayer.h:413
QgsCoordinateFormatter::FormatPair
@ FormatPair
Formats coordinates as an "x,y" pair.
Definition: qgscoordinateformatter.h:49
QgsCoordinateFormatter::FlagDegreesUseStringSuffix
@ FlagDegreesUseStringSuffix
Include a direction suffix (eg 'N', 'E', 'S' or 'W'), otherwise a "-" prefix is used for west and sou...
Definition: qgscoordinateformatter.h:60
Qgis::MessageLevel
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition: qgis.h:89
QgsQuickUtils
Encapsulating the common utilities for QgsQuick library.
Definition: qgsquickutils.h:53
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:387
QgsCoordinateFormatter::Format
Format
Available formats for displaying coordinates.
Definition: qgscoordinateformatter.h:48
QgsQuickFeatureLayerPair
Pair of QgsFeature and QgsVectorLayer.
Definition: qgsquickfeaturelayerpair.h:41
QgsFeature
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:56
qgscoordinateformatter.h
qgsquickmapsettings.h
qgspointxy.h
qgsmessagelog.h
QgsField
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:50