QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgsquickutils.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsquickutils.cpp
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 #include <QApplication>
17 #include <QDesktopWidget>
18 #include <QString>
19 
20 #include "qgis.h"
22 #include "qgscoordinatetransform.h"
23 #include "qgsdistancearea.h"
24 #include "qgslogger.h"
25 #include "qgsvectorlayer.h"
26 #include "qgsfeature.h"
27 #include "qgsapplication.h"
30 
32 #include "qgsquickmapsettings.h"
33 #include "qgsquickutils.h"
34 #include "qgsunittypes.h"
35 
36 
37 QgsQuickUtils::QgsQuickUtils( QObject *parent )
38  : QObject( parent )
39  , mScreenDensity( calculateScreenDensity() )
40 {
41 }
42 
47 {
49 }
50 
51 QgsPointXY QgsQuickUtils::pointXY( double x, double y )
52 {
53  return QgsPointXY( x, y );
54 }
55 
56 QgsPoint QgsQuickUtils::point( double x, double y, double z, double m )
57 {
58  return QgsPoint( x, y, z, m );
59 }
60 
61 QgsPoint QgsQuickUtils::coordinateToPoint( const QGeoCoordinate &coor )
62 {
63  return QgsPoint( coor.longitude(), coor.latitude(), coor.altitude() );
64 }
65 
67  const QgsCoordinateReferenceSystem &destCrs,
68  const QgsCoordinateTransformContext &context,
69  const QgsPointXY &srcPoint )
70 {
71  QgsCoordinateTransform mTransform( srcCrs, destCrs, context );
72  QgsPointXY pt = mTransform.transform( srcPoint );
73  return pt;
74 }
75 
76 double QgsQuickUtils::screenUnitsToMeters( QgsQuickMapSettings *mapSettings, int baseLengthPixels )
77 {
78  if ( mapSettings == nullptr ) return 0.0;
79 
80  QgsDistanceArea mDistanceArea;
81  mDistanceArea.setEllipsoid( QStringLiteral( "WGS84" ) );
82  mDistanceArea.setSourceCrs( mapSettings->destinationCrs(), mapSettings->transformContext() );
83 
84  // calculate the geographic distance from the central point of extent
85  // to the specified number of points on the right side
86  QSize s = mapSettings->outputSize();
87  QPoint pointCenter( s.width() / 2, s.height() / 2 );
88  QgsPointXY p1 = mapSettings->screenToCoordinate( pointCenter );
89  QgsPointXY p2 = mapSettings->screenToCoordinate( pointCenter + QPoint( baseLengthPixels, 0 ) );
90  return mDistanceArea.measureLine( p1, p2 );
91 }
92 
93 bool QgsQuickUtils::fileExists( const QString &path )
94 {
95  QFileInfo check_file( path );
96  // check if file exists and if yes: Is it really a file and no directory?
97  return ( check_file.exists() && check_file.isFile() );
98 }
99 
100 QString QgsQuickUtils::getRelativePath( const QString &path, const QString &prefixPath )
101 {
102  QString modPath = path;
103  QString filePrefix( "file://" );
104 
105  if ( path.startsWith( filePrefix ) )
106  {
107  modPath = modPath.replace( filePrefix, QString() );
108  }
109 
110  if ( prefixPath.isEmpty() ) return modPath;
111 
112  // Do not use a canonical path for non-existing path
113  if ( !QFileInfo( path ).exists() )
114  {
115  if ( !prefixPath.isEmpty() && modPath.startsWith( prefixPath ) )
116  {
117  return modPath.replace( prefixPath, QString() );
118  }
119  }
120  else
121  {
122  QDir absoluteDir( modPath );
123  QDir prefixDir( prefixPath );
124  QString canonicalPath = absoluteDir.canonicalPath();
125  QString prefixCanonicalPath = prefixDir.canonicalPath() + "/";
126 
127  if ( prefixCanonicalPath.length() > 1 && canonicalPath.startsWith( prefixCanonicalPath ) )
128  {
129  return canonicalPath.replace( prefixCanonicalPath, QString() );
130  }
131  }
132 
133  return QString();
134 }
135 
136 void QgsQuickUtils::logMessage( const QString &message, const QString &tag, Qgis::MessageLevel level )
137 {
138  QgsMessageLog::logMessage( message, tag, level );
139 }
140 
142 {
143  return QgsQuickFeatureLayerPair( feature, layer );
144 }
145 
146 const QUrl QgsQuickUtils::getThemeIcon( const QString &name )
147 {
148  QString path = QStringLiteral( "qrc:/%1.svg" ).arg( name );
149  QgsDebugMsg( QStringLiteral( "Using icon %1 from %2" ).arg( name, path ) );
150  return QUrl( path );
151 }
152 
153 const QUrl QgsQuickUtils::getEditorComponentSource( const QString &widgetName )
154 {
155  QString path( "qgsquick%1.qml" );
156  QStringList supportedWidgets = { QStringLiteral( "textedit" ),
157  QStringLiteral( "valuemap" ),
158  QStringLiteral( "valuerelation" ),
159  QStringLiteral( "checkbox" ),
160  QStringLiteral( "externalresource" ),
161  QStringLiteral( "datetime" ),
162  QStringLiteral( "range" )
163  };
164  if ( supportedWidgets.contains( widgetName ) )
165  {
166  return QUrl( path.arg( widgetName ) );
167  }
168  else
169  {
170  return QUrl( path.arg( QLatin1String( "textedit" ) ) );
171  }
172 }
173 
175  const QgsPoint &point,
177  int decimals,
178  QgsCoordinateFormatter::FormatFlags flags )
179 {
180  return QgsCoordinateFormatter::format( point, format, decimals, flags );
181 }
182 
183 QString QgsQuickUtils::formatDistance( double distance,
185  int decimals,
187 {
188  double destDistance;
189  QgsUnitTypes::DistanceUnit destUnits;
190 
191  humanReadableDistance( distance, units, destSystem, destDistance, destUnits );
192 
193  return QStringLiteral( "%1 %2" )
194  .arg( QString::number( destDistance, 'f', decimals ) )
195  .arg( QgsUnitTypes::toAbbreviatedString( destUnits ) );
196 }
197 
198 bool QgsQuickUtils::removeFile( const QString &filePath )
199 {
200  QFile file( filePath );
201  return file.remove( filePath );
202 }
203 
204 
207  double &destDistance, QgsUnitTypes::DistanceUnit &destUnits )
208 {
209  if ( ( destSystem == QgsUnitTypes::MetricSystem ) || ( destSystem == QgsUnitTypes::UnknownSystem ) )
210  {
211  return formatToMetricDistance( srcDistance, srcUnits, destDistance, destUnits );
212  }
213  else if ( destSystem == QgsUnitTypes::ImperialSystem )
214  {
215  return formatToImperialDistance( srcDistance, srcUnits, destDistance, destUnits );
216  }
217  else if ( destSystem == QgsUnitTypes::USCSSystem )
218  {
219  return formatToUSCSDistance( srcDistance, srcUnits, destDistance, destUnits );
220  }
221  else
222  {
223  Q_ASSERT( false ); //should never happen
224  }
225 }
226 
227 void QgsQuickUtils::formatToMetricDistance( double srcDistance,
229  double &destDistance,
230  QgsUnitTypes::DistanceUnit &destUnits )
231 {
232  double dist = srcDistance * QgsUnitTypes::fromUnitToUnitFactor( srcUnits, QgsUnitTypes::DistanceMillimeters );
233  if ( dist < 0 )
234  {
235  destDistance = 0;
237  return;
238  }
239 
241  if ( dist > mmToKm )
242  {
243  destDistance = dist / mmToKm;
245  return;
246  }
247 
249  if ( dist > mmToM )
250  {
251  destDistance = dist / mmToM;
252  destUnits = QgsUnitTypes::DistanceMeters;
253  return;
254  }
255 
257  if ( dist > mmToCm )
258  {
259  destDistance = dist / mmToCm;
261  return;
262  }
263 
264  destDistance = dist;
266 }
267 
268 void QgsQuickUtils::formatToImperialDistance( double srcDistance,
270  double &destDistance,
271  QgsUnitTypes::DistanceUnit &destUnits )
272 {
273  double dist = srcDistance * QgsUnitTypes::fromUnitToUnitFactor( srcUnits, QgsUnitTypes::DistanceFeet );
274  if ( dist < 0 )
275  {
276  destDistance = 0;
277  destUnits = QgsUnitTypes::DistanceFeet;
278  return;
279  }
280 
282  if ( dist > feetToMile )
283  {
284  destDistance = dist / feetToMile;
285  destUnits = QgsUnitTypes::DistanceMiles;
286  return;
287  }
288 
290  if ( dist > feetToYard )
291  {
292  destDistance = dist / feetToYard;
293  destUnits = QgsUnitTypes::DistanceYards;
294  return;
295  }
296 
297  destDistance = dist;
298  destUnits = QgsUnitTypes::DistanceFeet;
299  return;
300 }
301 
302 void QgsQuickUtils::formatToUSCSDistance( double srcDistance,
304  double &destDistance,
305  QgsUnitTypes::DistanceUnit &destUnits )
306 {
307  double dist = srcDistance * QgsUnitTypes::fromUnitToUnitFactor( srcUnits, QgsUnitTypes::DistanceFeet );
308  if ( dist < 0 )
309  {
310  destDistance = 0;
311  destUnits = QgsUnitTypes::DistanceFeet;
312  return;
313  }
314 
316  if ( dist > feetToMile )
317  {
318  destDistance = dist / feetToMile;
320  return;
321  }
322 
324  if ( dist > feetToYard )
325  {
326  destDistance = dist / feetToYard;
327  destUnits = QgsUnitTypes::DistanceYards;
328  return;
329  }
330 
331  destDistance = dist;
332  destUnits = QgsUnitTypes::DistanceFeet;
333  return;
334 }
335 
337 {
338  QRect rec = QApplication::desktop()->screenGeometry();
339  int dpiX = QApplication::desktop()->physicalDpiX();
340  int dpiY = QApplication::desktop()->physicalDpiY();
341  int height = rec.height();
342  int width = rec.width();
343  double sizeX = static_cast<double>( width ) / dpiX * 25.4;
344  double sizeY = static_cast<double>( height ) / dpiY * 25.4;
345 
346  QString msg;
347  msg += tr( "screen resolution: %1x%2 px\n" ).arg( width ).arg( height );
348  msg += tr( "screen DPI: %1x%2\n" ).arg( dpiX ).arg( dpiY );
349  msg += tr( "screen size: %1x%2 mm\n" ).arg( QString::number( sizeX, 'f', 0 ), QString::number( sizeY, 'f', 0 ) );
350  msg += tr( "screen density: %1" ).arg( mScreenDensity );
351  return msg;
352 }
353 
354 QVariantMap QgsQuickUtils::createValueRelationCache( const QVariantMap &config, const QgsFeature &formFeature )
355 {
356  QVariantMap valueMap;
358 
359  for ( const QgsValueRelationFieldFormatter::ValueRelationItem &item : qgis::as_const( cache ) )
360  {
361  valueMap.insert( item.key.toString(), item.value );
362  }
363  return valueMap;
364 }
365 
366 QString QgsQuickUtils::evaluateExpression( const QgsQuickFeatureLayerPair &pair, QgsProject *activeProject, const QString &expression )
367 {
368  QList<QgsExpressionContextScope *> scopes;
370  scopes << QgsExpressionContextUtils::projectScope( activeProject );
371  scopes << QgsExpressionContextUtils::layerScope( pair.layer() );
372 
373  QgsExpressionContext context( scopes );
374  context.setFeature( pair.feature() );
375  QgsExpression expr( expression );
376  return expr.evaluate( &context ).toString();
377 }
378 
380 {
381  QgsFeatureIds qgsFids;
382  for ( const int &fid : fids )
383  qgsFids << fid;
384  layer->selectByIds( qgsFids, behavior );
385 }
386 
388 {
389  return QVariant( field.type() ).typeName();
390 }
391 
392 QString QgsQuickUtils::dateTimeFieldFormat( const QString &fieldFormat )
393 {
394  if ( QgsDateTimeFieldFormatter::DATE_FORMAT == fieldFormat )
395  {
396  return QString( "Date" );
397  }
398  else if ( QgsDateTimeFieldFormatter::TIME_FORMAT == fieldFormat )
399  {
400  return QString( "Time" );
401  }
402  else if ( QgsDateTimeFieldFormatter::DATETIME_FORMAT == fieldFormat )
403  {
404  return QString( "Date Time" );
405  }
406  else
407  {
408  return QString( "Date Time" );
409  }
410 }
411 
413 {
414  return mScreenDensity;
415 }
416 
417 qreal QgsQuickUtils::calculateScreenDensity()
418 {
419  // calculate screen density for calculation of real pixel sizes from density-independent pixels
420  int dpiX = QApplication::desktop()->physicalDpiX();
421  int dpiY = QApplication::desktop()->physicalDpiY();
422  int dpi = dpiX < dpiY ? dpiX : dpiY; // In case of asymmetrical DPI. Improbable
423  return dpi / 160.; // 160 DPI is baseline for density-independent pixels in Android
424 }
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:370
qgsvaluerelationfieldformatter.h
qgsquickfeaturelayerpair.h
QgsCoordinateTransformContext
Contains information about the context in which a coordinate transform is executed.
Definition: qgscoordinatetransformcontext.h:58
QgsUnitTypes::ImperialSystem
@ ImperialSystem
British Imperial.
Definition: qgsunittypes.h:48
QgsQuickUtils::evaluateExpression
static Q_INVOKABLE QString evaluateExpression(const QgsQuickFeatureLayerPair &pair, QgsProject *activeProject, const QString &expression)
Evaluates expression.
Definition: qgsquickutils.cpp:366
QgsExpressionContextUtils::globalScope
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context.
Definition: qgsexpressioncontextutils.cpp:34
QgsPoint
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:38
QgsExpressionContextUtils::layerScope
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
Definition: qgsexpressioncontextutils.cpp:265
QgsQuickUtils::pointXY
static Q_INVOKABLE QgsPointXY pointXY(double x, double y)
Creates QgsPointXY in QML.
Definition: qgsquickutils.cpp:51
QgsUnitTypes::toAbbreviatedString
static Q_INVOKABLE QString toAbbreviatedString(QgsUnitTypes::DistanceUnit unit)
Returns a translated abbreviation representing a distance unit.
Definition: qgsunittypes.cpp:269
qgsfeature.h
qgis.h
qgsunittypes.h
QgsVectorLayer::selectByIds
Q_INVOKABLE void selectByIds(const QgsFeatureIds &ids, QgsVectorLayer::SelectBehavior behavior=QgsVectorLayer::SetSelection)
Selects matching features using a list of feature IDs.
Definition: qgsvectorlayer.cpp:523
field
const QgsField & field
Definition: qgsfield.h:456
QgsQuickUtils::createValueRelationCache
static Q_INVOKABLE QVariantMap createValueRelationCache(const QVariantMap &config, const QgsFeature &formFeature=QgsFeature())
Creates a cache for a value relation field.
Definition: qgsquickutils.cpp:354
QgsDebugMsg
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
QgsQuickUtils::dateTimeFieldFormat
static Q_INVOKABLE QString dateTimeFieldFormat(const QString &fieldFormat)
Returns field format's name for given string representing field format defined in QgsDateTimeFieldFor...
Definition: qgsquickutils.cpp:392
QgsUnitTypes::DistanceUnit
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:68
QgsCoordinateTransform::transform
QgsPointXY transform(const QgsPointXY &point, TransformDirection direction=ForwardTransform) const SIP_THROW(QgsCsException)
Transform the point from the source CRS to the destination CRS.
Definition: qgscoordinatetransform.cpp:239
QgsUnitTypes::DistanceKilometers
@ DistanceKilometers
Kilometers.
Definition: qgsunittypes.h:70
QgsUnitTypes::SystemOfMeasurement
SystemOfMeasurement
Systems of unit measurement.
Definition: qgsunittypes.h:45
QgsQuickUtils::removeFile
static Q_INVOKABLE bool removeFile(const QString &filePath)
Deletes file from a given path.
Definition: qgsquickutils.cpp:198
QgsQuickUtils::dumpScreenInfo
QString dumpScreenInfo() const
Returns a string with information about screen size and resolution - useful for debugging.
Definition: qgsquickutils.cpp:336
QgsQuickMapSettings::screenToCoordinate
Q_INVOKABLE QgsPoint screenToCoordinate(const QPointF &point) const
Convert a screen coordinate to a map coordinate.
Definition: qgsquickmapsettings.cpp:119
QgsProject
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:95
QgsQuickUtils::formatDistance
static Q_INVOKABLE QString formatDistance(double distance, QgsUnitTypes::DistanceUnit units, int decimals, QgsUnitTypes::SystemOfMeasurement destSystem=QgsUnitTypes::MetricSystem)
Converts distance to human readable distance.
Definition: qgsquickutils.cpp:183
qgsapplication.h
QgsQuickMapSettings
The QgsQuickMapSettings class encapsulates QgsMapSettings class to offer settings of configuration of...
Definition: qgsquickmapsettings.h:47
QgsUnitTypes::fromUnitToUnitFactor
static Q_INVOKABLE double fromUnitToUnitFactor(QgsUnitTypes::DistanceUnit fromUnit, QgsUnitTypes::DistanceUnit toUnit)
Returns the conversion factor between the specified distance units.
Definition: qgsunittypes.cpp:352
QgsDistanceArea::setEllipsoid
bool setEllipsoid(const QString &ellipsoid)
Sets the ellipsoid by its acronym.
Definition: qgsdistancearea.cpp:66
QgsQuickUtils::formatPoint
static Q_INVOKABLE QString formatPoint(const QgsPoint &point, QgsCoordinateFormatter::Format format=QgsCoordinateFormatter::FormatPair, int decimals=3, QgsCoordinateFormatter::FormatFlags flags=QgsCoordinateFormatter::FlagDegreesUseStringSuffix)
Formats a point according to the specified parameters.
Definition: qgsquickutils.cpp:174
QgsQuickMapSettings::destinationCrs
QgsCoordinateReferenceSystem destinationCrs
CRS of destination coordinate reference system.
Definition: qgsquickmapsettings.h:105
QgsExpressionContextUtils::projectScope
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
Definition: qgsexpressioncontextutils.cpp:222
QgsDateTimeFieldFormatter::DATE_FORMAT
static const QString DATE_FORMAT
Definition: qgsdatetimefieldformatter.h:33
QgsQuickMapSettings::outputSize
QSize outputSize
The size of the resulting map image.
Definition: qgsquickmapsettings.h:91
QgsQuickUtils::logMessage
static Q_INVOKABLE void logMessage(const QString &message, const QString &tag=QString("QgsQuick"), Qgis::MessageLevel level=Qgis::Warning)
Log message in QgsMessageLog.
Definition: qgsquickutils.cpp:136
QgsDistanceArea::measureLine
double measureLine(const QVector< QgsPointXY > &points) const
Measures the length of a line with multiple segments.
Definition: qgsdistancearea.cpp:273
QgsQuickFeatureLayerPair::layer
Q_GADGET QgsVectorLayer * layer
Vector layer to which the feature belongs.
Definition: qgsquickfeaturelayerpair.h:49
QgsUnitTypes::DistanceFeet
@ DistanceFeet
Imperial feet.
Definition: qgsunittypes.h:71
QgsUnitTypes::DistanceMeters
@ DistanceMeters
Meters.
Definition: qgsunittypes.h:69
QgsQuickUtils::featureFactory
static Q_INVOKABLE QgsQuickFeatureLayerPair featureFactory(const QgsFeature &feature, QgsVectorLayer *layer=nullptr)
QgsQuickFeatureLayerPair factory for tuple of QgsFeature and QgsVectorLayer used in QgsQUick library.
Definition: qgsquickutils.cpp:141
qgscoordinatetransform.h
QgsQuickFeatureLayerPair::feature
QgsFeature feature
Feature that belongs to layer.
Definition: qgsquickfeaturelayerpair.h:56
QgsDistanceArea::setSourceCrs
void setSourceCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets source spatial reference system crs.
Definition: qgsdistancearea.cpp:60
QgsVectorLayer::SelectBehavior
SelectBehavior
Selection behavior.
Definition: qgsvectorlayer.h:412
QgsCoordinateFormatter::format
static QString format(const QgsPointXY &point, Format format, int precision=12, FormatFlags flags=FlagDegreesUseStringSuffix)
Formats a point according to the specified parameters.
Definition: qgscoordinateformatter.cpp:61
QgsFeatureIds
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeatureid.h:37
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
QgsExpression::evaluate
QVariant evaluate()
Evaluate the feature and return the result.
Definition: qgsexpression.cpp:346
qgsdatetimefieldformatter.h
QgsQuickUtils::fileExists
static Q_INVOKABLE bool fileExists(const QString &path)
Returns whether file on path exists.
Definition: qgsquickutils.cpp:93
QgsQuickUtils::fieldType
static Q_INVOKABLE QString fieldType(const QgsField &field)
Returns the QVariant typeName of a field.
Definition: qgsquickutils.cpp:387
qgsvectorlayer.h
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:44
QgsQuickMapSettings::transformContext
Q_INVOKABLE QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
Definition: qgsquickmapsettings.cpp:70
QgsQuickUtils::screenDensity
qreal screenDensity() const
"dp" is useful for building building components that work well with different screen densities.
Definition: qgsquickutils.cpp:412
QgsQuickUtils::getEditorComponentSource
static Q_INVOKABLE const QUrl getEditorComponentSource(const QString &widgetName)
Returns url to field editor component for a feature form.
Definition: qgsquickutils.cpp:153
QgsUnitTypes::USCSSystem
@ USCSSystem
United States customary system.
Definition: qgsunittypes.h:49
QgsQuickUtils::coordinateToPoint
static Q_INVOKABLE QgsPoint coordinateToPoint(const QGeoCoordinate &coor)
Converts QGeoCoordinate to QgsPoint.
Definition: qgsquickutils.cpp:61
Qgis::MessageLevel
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition: qgis.h:89
QgsValueRelationFieldFormatter::ValueRelationCache
QVector< QgsValueRelationFieldFormatter::ValueRelationItem > ValueRelationCache
Definition: qgsvaluerelationfieldformatter.h:56
QgsUnitTypes::DistanceMillimeters
@ DistanceMillimeters
Millimeters.
Definition: qgsunittypes.h:77
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:387
QgsUnitTypes::DistanceCentimeters
@ DistanceCentimeters
Centimeters.
Definition: qgsunittypes.h:76
QgsValueRelationFieldFormatter::createCache
QVariant createCache(QgsVectorLayer *layer, int fieldIndex, const QVariantMap &config) const override
Create a cache for a given field.
Definition: qgsvaluerelationfieldformatter.cpp:116
QgsCoordinateFormatter::Format
Format
Available formats for displaying coordinates.
Definition: qgscoordinateformatter.h:48
QgsQuickFeatureLayerPair
Pair of QgsFeature and QgsVectorLayer.
Definition: qgsquickfeaturelayerpair.h:41
QgsMessageLog::logMessage
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
Definition: qgsmessagelog.cpp:27
QgsQuickUtils::screenUnitsToMeters
static Q_INVOKABLE double screenUnitsToMeters(QgsQuickMapSettings *mapSettings, int baseLengthPixels)
Calculates the distance in meter representing baseLengthPixels pixels on the screen based on the curr...
Definition: qgsquickutils.cpp:76
QgsUnitTypes::DistanceYards
@ DistanceYards
Imperial yards.
Definition: qgsunittypes.h:73
QgsUnitTypes::UnknownSystem
@ UnknownSystem
Unknown system of measurement.
Definition: qgsunittypes.h:46
QgsDateTimeFieldFormatter::TIME_FORMAT
static const QString TIME_FORMAT
Definition: qgsdatetimefieldformatter.h:34
QgsQuickUtils::coordinateReferenceSystemFromEpsgId
static Q_INVOKABLE QgsCoordinateReferenceSystem coordinateReferenceSystemFromEpsgId(long epsg)
Creates crs from epsg code in QML.
Definition: qgsquickutils.cpp:46
QgsUnitTypes::DistanceMiles
@ DistanceMiles
Terrestrial miles.
Definition: qgsunittypes.h:74
QgsDistanceArea
A general purpose distance and area calculator, capable of performing ellipsoid based calculations.
Definition: qgsdistancearea.h:50
QgsQuickUtils::getRelativePath
static Q_INVOKABLE QString getRelativePath(const QString &path, const QString &prefixPath)
Returns relative path of the file to given prefixPath.
Definition: qgsquickutils.cpp:100
qgsquickutils.h
QgsCoordinateReferenceSystem::fromEpsgId
static Q_INVOKABLE QgsCoordinateReferenceSystem fromEpsgId(long epsg)
Creates a CRS from a given EPSG ID.
Definition: qgscoordinatereferencesystem.cpp:207
qgsdistancearea.h
QgsFeature
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:56
QgsUnitTypes::DistanceNauticalMiles
@ DistanceNauticalMiles
Nautical miles.
Definition: qgsunittypes.h:72
qgslogger.h
QgsQuickUtils::getThemeIcon
static Q_INVOKABLE const QUrl getThemeIcon(const QString &name)
Returns QUrl to image from library's /images folder.
Definition: qgsquickutils.cpp:146
QgsQuickUtils::transformPoint
static Q_INVOKABLE QgsPointXY transformPoint(const QgsCoordinateReferenceSystem &srcCrs, const QgsCoordinateReferenceSystem &destCrs, const QgsCoordinateTransformContext &context, const QgsPointXY &srcPoint)
Transforms point between different crs from QML.
Definition: qgsquickutils.cpp:66
QgsQuickUtils::QgsQuickUtils
QgsQuickUtils(QObject *parent=nullptr)
Create new utilities.
Definition: qgsquickutils.cpp:37
QgsExpression
Class for parsing and evaluation of expressions (formerly called "search strings").
Definition: qgsexpression.h:105
QgsCoordinateTransform
Class for doing transforms between two map coordinate systems.
Definition: qgscoordinatetransform.h:53
QgsQuickUtils::point
static Q_INVOKABLE QgsPoint point(double x, double y, double z=std::numeric_limits< double >::quiet_NaN(), double m=std::numeric_limits< double >::quiet_NaN())
Creates QgsPoint in QML.
Definition: qgsquickutils.cpp:56
QgsValueRelationFieldFormatter::ValueRelationItem
Definition: qgsvaluerelationfieldformatter.h:40
QgsDateTimeFieldFormatter::DATETIME_FORMAT
static const QString DATETIME_FORMAT
Definition: qgsdatetimefieldformatter.h:35
qgscoordinatereferencesystem.h
qgsquickmapsettings.h
QgsQuickUtils::selectFeaturesInLayer
static Q_INVOKABLE void selectFeaturesInLayer(QgsVectorLayer *layer, const QList< int > &fids, QgsVectorLayer::SelectBehavior behavior=QgsVectorLayer::SetSelection)
Selects features in a layer This method is required since QML cannot perform the conversion of a feat...
Definition: qgsquickutils.cpp:379
QgsField::type
QVariant::Type type
Definition: qgsfield.h:57
QgsExpressionContext::setFeature
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
Definition: qgsexpressioncontext.cpp:521
QgsQuickUtils::humanReadableDistance
static void humanReadableDistance(double srcDistance, QgsUnitTypes::DistanceUnit srcUnits, QgsUnitTypes::SystemOfMeasurement destSystem, double &destDistance, QgsUnitTypes::DistanceUnit &destUnits)
Converts distance to human readable distance in destination system of measurement.
Definition: qgsquickutils.cpp:205
QgsField
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:50