QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
Public Member Functions | Static Public Member Functions | Properties | List of all members
QgsQuickUtils Class Reference

Encapsulating the common utilities for QgsQuick library. More...

#include <qgsquickutils.h>

Inheritance diagram for QgsQuickUtils:
Inheritance graph
[legend]

Public Member Functions

 QgsQuickUtils (QObject *parent=nullptr)
 Create new utilities. More...
 
 ~QgsQuickUtils ()=default
 Destructor. More...
 
QString dumpScreenInfo () const
 Returns a string with information about screen size and resolution - useful for debugging. More...
 
qreal screenDensity () const
 "dp" is useful for building building components that work well with different screen densities. More...
 

Static Public Member Functions

static Q_INVOKABLE QgsCoordinateReferenceSystem coordinateReferenceSystemFromEpsgId (long epsg)
 Creates crs from epsg code in QML. More...
 
static Q_INVOKABLE QgsPoint coordinateToPoint (const QGeoCoordinate &coor)
 Converts QGeoCoordinate to QgsPoint. More...
 
static Q_INVOKABLE QVariantMap createValueRelationCache (const QVariantMap &config, const QgsFeature &formFeature=QgsFeature())
 Creates a cache for a value relation field. More...
 
static Q_INVOKABLE QString dateTimeFieldFormat (const QString &fieldFormat)
 Returns field format's name for given string representing field format defined in QgsDateTimeFieldFormatter. More...
 
static Q_INVOKABLE QString evaluateExpression (const QgsQuickFeatureLayerPair &pair, QgsProject *activeProject, const QString &expression)
 Evaluates expression. More...
 
static Q_INVOKABLE QgsQuickFeatureLayerPair featureFactory (const QgsFeature &feature, QgsVectorLayer *layer=nullptr)
 QgsQuickFeatureLayerPair factory for tuple of QgsFeature and QgsVectorLayer used in QgsQUick library. More...
 
static Q_INVOKABLE QString fieldType (const QgsField &field)
 Returns the QVariant typeName of a field. More...
 
static Q_INVOKABLE bool fileExists (const QString &path)
 Returns whether file on path exists. More...
 
static Q_INVOKABLE QString formatDistance (double distance, QgsUnitTypes::DistanceUnit units, int decimals, QgsUnitTypes::SystemOfMeasurement destSystem=QgsUnitTypes::MetricSystem)
 Converts distance to human readable distance. More...
 
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. More...
 
static Q_INVOKABLE const QUrl getEditorComponentSource (const QString &widgetName)
 Returns url to field editor component for a feature form. More...
 
static Q_INVOKABLE QString getRelativePath (const QString &path, const QString &prefixPath)
 Returns relative path of the file to given prefixPath. More...
 
static Q_INVOKABLE const QUrl getThemeIcon (const QString &name)
 Returns QUrl to image from library's /images folder. More...
 
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. More...
 
static Q_INVOKABLE void logMessage (const QString &message, const QString &tag=QString("QgsQuick"), Qgis::MessageLevel level=Qgis::Warning)
 Log message in QgsMessageLog. More...
 
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. More...
 
static Q_INVOKABLE QgsPointXY pointXY (double x, double y)
 Creates QgsPointXY in QML. More...
 
static Q_INVOKABLE bool removeFile (const QString &filePath)
 Deletes file from a given path. More...
 
static Q_INVOKABLE double screenUnitsToMeters (QgsQuickMapSettings *mapSettings, int baseLengthPixels)
 Calculates the distance in meter representing baseLengthPixels pixels on the screen based on the current map settings. More...
 
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 feature ID to a QgsFeatureId (i.e. More...
 
static Q_INVOKABLE QgsPointXY transformPoint (const QgsCoordinateReferenceSystem &srcCrs, const QgsCoordinateReferenceSystem &destCrs, const QgsCoordinateTransformContext &context, const QgsPointXY &srcPoint)
 Transforms point between different crs from QML. More...
 

Properties

qreal dp
 "dp" is useful for building building components that work well with different screen densities. More...
 

Detailed Description

Encapsulating the common utilities for QgsQuick library.

Note
QML Type: Utils (Singleton)
Since
QGIS 3.2

Definition at line 52 of file qgsquickutils.h.

Constructor & Destructor Documentation

◆ QgsQuickUtils()

QgsQuickUtils::QgsQuickUtils ( QObject *  parent = nullptr)

Create new utilities.

Definition at line 37 of file qgsquickutils.cpp.

◆ ~QgsQuickUtils()

QgsQuickUtils::~QgsQuickUtils ( )
default

Destructor.

Member Function Documentation

◆ coordinateReferenceSystemFromEpsgId()

QgsCoordinateReferenceSystem QgsQuickUtils::coordinateReferenceSystemFromEpsgId ( long  epsg)
static

Creates crs from epsg code in QML.

Makes QgsCoordinateReferenceSystem::fromEpsgId accessible for QML components.

Since
QGIS 3.4

Definition at line 46 of file qgsquickutils.cpp.

◆ coordinateToPoint()

QgsPoint QgsQuickUtils::coordinateToPoint ( const QGeoCoordinate &  coor)
static

Converts QGeoCoordinate to QgsPoint.

Since
QGIS 3.4

Definition at line 61 of file qgsquickutils.cpp.

◆ createValueRelationCache()

QVariantMap QgsQuickUtils::createValueRelationCache ( const QVariantMap &  config,
const QgsFeature formFeature = QgsFeature() 
)
static

Creates a cache for a value relation field.

This can be used to keep the value map in the local memory if doing multiple lookups in a loop.

Parameters
configThe widget configuration
formFeatureThe feature currently being edited with current attribute values
Returns
A kvp list of values for the widget
Since
QGIS 3.6

Definition at line 354 of file qgsquickutils.cpp.

◆ dateTimeFieldFormat()

QString QgsQuickUtils::dateTimeFieldFormat ( const QString &  fieldFormat)
static

Returns field format's name for given string representing field format defined in QgsDateTimeFieldFormatter.

Parameters
fieldFormatstring representing formats from QgsDateTimeFieldFormatter.

Definition at line 392 of file qgsquickutils.cpp.

◆ dumpScreenInfo()

QString QgsQuickUtils::dumpScreenInfo ( ) const

Returns a string with information about screen size and resolution - useful for debugging.

Definition at line 336 of file qgsquickutils.cpp.

◆ evaluateExpression()

QString QgsQuickUtils::evaluateExpression ( const QgsQuickFeatureLayerPair pair,
QgsProject activeProject,
const QString &  expression 
)
static

Evaluates expression.

Parameters
pairUsed to define a context scope.
activeProjectUsed to define a context scope.
expression
Returns
Evaluated expression
Since
QGIS 3.10

Definition at line 366 of file qgsquickutils.cpp.

◆ featureFactory()

QgsQuickFeatureLayerPair QgsQuickUtils::featureFactory ( const QgsFeature feature,
QgsVectorLayer layer = nullptr 
)
static

QgsQuickFeatureLayerPair factory for tuple of QgsFeature and QgsVectorLayer used in QgsQUick library.

Parameters
featureQgsFeature linked to new QgsQuickFeature instance.
layerQgsVectorLayer which the feature belongs to, optional.
Since
QGIS 3.4

Definition at line 141 of file qgsquickutils.cpp.

◆ fieldType()

QString QgsQuickUtils::fieldType ( const QgsField field)
static

Returns the QVariant typeName of a field.

This is a stable identifier (compared to the provider field name).

Parameters
fieldQgsField

Definition at line 387 of file qgsquickutils.cpp.

◆ fileExists()

bool QgsQuickUtils::fileExists ( const QString &  path)
static

Returns whether file on path exists.

Since
QGIS 3.4

Definition at line 93 of file qgsquickutils.cpp.

◆ formatDistance()

QString QgsQuickUtils::formatDistance ( double  distance,
QgsUnitTypes::DistanceUnit  units,
int  decimals,
QgsUnitTypes::SystemOfMeasurement  destSystem = QgsUnitTypes::MetricSystem 
)
static

Converts distance to human readable distance.

This is useful for scalebar texts or output of the GPS accuracy

The resulting units are determined automatically, based on requested system of measurement. e.g. 1222.234 m is converted to 1.2 km

Parameters
distancedistance in units
unitsunits of dist
decimalsdecimal to use
destSystemsystem of measurement of the result
Returns
string represetation of dist in desired destSystem. For distance less than 0, 0 is returned.
Since
QGIS 3.4

Definition at line 183 of file qgsquickutils.cpp.

◆ formatPoint()

QString QgsQuickUtils::formatPoint ( const QgsPoint point,
QgsCoordinateFormatter::Format  format = QgsCoordinateFormatter::FormatPair,
int  decimals = 3,
QgsCoordinateFormatter::FormatFlags  flags = QgsCoordinateFormatter::FlagDegreesUseStringSuffix 
)
static

Formats a point according to the specified parameters.

The format argument indicates the desired display format for the coordinate.

The precision argument gives the number of decimal places to include for coordinates.

Optional flags can be specified to control the output format.

Since
QGIS 3.4

Definition at line 174 of file qgsquickutils.cpp.

◆ getEditorComponentSource()

const QUrl QgsQuickUtils::getEditorComponentSource ( const QString &  widgetName)
static

Returns url to field editor component for a feature form.

If the widgetName does not match any supported widget, text edit is returned.

Parameters
widgetNamename of the attribute field widget
Since
QGIS 3.4

Definition at line 153 of file qgsquickutils.cpp.

◆ getRelativePath()

QString QgsQuickUtils::getRelativePath ( const QString &  path,
const QString &  prefixPath 
)
static

Returns relative path of the file to given prefixPath.

If prefixPath does not match a path parameter, returns an empty string. If a path starts with "file://", this prefix is ignored.

Parameters
pathAbsolute path to file
prefixPath
Since
QGIS 3.8

Definition at line 100 of file qgsquickutils.cpp.

◆ getThemeIcon()

const QUrl QgsQuickUtils::getThemeIcon ( const QString &  name)
static

Returns QUrl to image from library's /images folder.

Since
QGIS 3.4

Definition at line 146 of file qgsquickutils.cpp.

◆ humanReadableDistance()

void QgsQuickUtils::humanReadableDistance ( double  srcDistance,
QgsUnitTypes::DistanceUnit  srcUnits,
QgsUnitTypes::SystemOfMeasurement  destSystem,
double &  destDistance,
QgsUnitTypes::DistanceUnit destUnits 
)
static

Converts distance to human readable distance in destination system of measurement.

See also
QgsQuickUtils::formatDistance()
Parameters
srcDistancedistance in units
srcUnitsunits of dist
destSystemsystem of measurement of the result
destDistanceoutput: distance if desired system of measurement
destUnitsoutput: unit of destDistance
Since
QGIS 3.4

Definition at line 205 of file qgsquickutils.cpp.

◆ logMessage()

void QgsQuickUtils::logMessage ( const QString &  message,
const QString &  tag = QString( "QgsQuick" ),
Qgis::MessageLevel  level = Qgis::Warning 
)
static

Log message in QgsMessageLog.

Definition at line 136 of file qgsquickutils.cpp.

◆ point()

QgsPoint QgsQuickUtils::point ( double  x,
double  y,
double  z = std::numeric_limits<double>::quiet_NaN(),
double  m = std::numeric_limits<double>::quiet_NaN() 
)
static

Creates QgsPoint in QML.

Since
QGIS 3.4

Definition at line 56 of file qgsquickutils.cpp.

◆ pointXY()

QgsPointXY QgsQuickUtils::pointXY ( double  x,
double  y 
)
static

Creates QgsPointXY in QML.

Since
QGIS 3.4

Definition at line 51 of file qgsquickutils.cpp.

◆ removeFile()

bool QgsQuickUtils::removeFile ( const QString &  filePath)
static

Deletes file from a given path.

Parameters
filePathAbsolute path to file
Returns
bool true, if removal was successful, otherwise false.
Since
QGIS 3.8

Definition at line 198 of file qgsquickutils.cpp.

◆ screenDensity()

qreal QgsQuickUtils::screenDensity ( ) const

"dp" is useful for building building components that work well with different screen densities.

It stands for density-independent pixels. A width of 10dp is going to be the same physical size on all screens regardless their density. In QML code, all values are specified in screen pixels, so in order to set a width of 10dp, one would use the following code: "width: 10 * QgsQuick.Utils.dp"

1dp is approximately 0.16mm. When screen has 160 DPI (baseline), the value of "dp" is 1. On high DPI screen the value will be greater, e.g. 1.5.

This is a readonly property.

Definition at line 412 of file qgsquickutils.cpp.

◆ screenUnitsToMeters()

double QgsQuickUtils::screenUnitsToMeters ( QgsQuickMapSettings mapSettings,
int  baseLengthPixels 
)
static

Calculates the distance in meter representing baseLengthPixels pixels on the screen based on the current map settings.

Definition at line 76 of file qgsquickutils.cpp.

◆ selectFeaturesInLayer()

void QgsQuickUtils::selectFeaturesInLayer ( QgsVectorLayer layer,
const QList< int > &  fids,
QgsVectorLayer::SelectBehavior  behavior = QgsVectorLayer::SetSelection 
)
static

Selects features in a layer This method is required since QML cannot perform the conversion of a feature ID to a QgsFeatureId (i.e.

a qint64)

Parameters
layerthe vector layer
fidsthe list of feature IDs
behaviorthe selection behavior
Since
QGIS 3.12

Definition at line 379 of file qgsquickutils.cpp.

◆ transformPoint()

QgsPointXY QgsQuickUtils::transformPoint ( const QgsCoordinateReferenceSystem srcCrs,
const QgsCoordinateReferenceSystem destCrs,
const QgsCoordinateTransformContext context,
const QgsPointXY srcPoint 
)
static

Transforms point between different crs from QML.

Since
QGIS 3.4

Definition at line 66 of file qgsquickutils.cpp.

Property Documentation

◆ dp

qreal QgsQuickUtils::dp
read

"dp" is useful for building building components that work well with different screen densities.

It stands for density-independent pixels. A width of 10dp is going to be the same physical size on all screens regardless their density. In QML code, all values are specified in screen pixels, so in order to set a width of 10dp, one would use the following code: "width: 10 * QgsQuick.Utils.dp"

1dp is approximately 0.16mm. When screen has 160 DPI (baseline), the value of "dp" is 1. On high DPI screen the value will be greater, e.g. 1.5.

This is a readonly property.

Definition at line 1 of file qgsquickutils.h.


The documentation for this class was generated from the following files: