QgsQuickUtils class
Encapsulating the common utilies for QgsQuick library.
Contents
Public static functions
- static auto coordinateReferenceSystemFromEpsgId(long epsg) -> Q_INVOKABLE QgsCoordinateReferenceSystem
- Creates crs from epsg code in QML.
- static auto coordinateToPoint(const QGeoCoordinate& coor) -> Q_INVOKABLE QgsPoint
- Converts QGeoCoordinate to QgsPoint.
- static auto featureFactory(const QgsFeature& feature, QgsVectorLayer* layer = nullptr) -> Q_INVOKABLE QgsQuickFeatureLayerPair
- QgsQuickFeatureLayerPair factory for tuple of QgsFeature and QgsVectorLayer used in QgsQUick library.
- static auto fileExists(const QString& path) -> Q_INVOKABLE bool
- Returns whether file on path exists.
-
static auto formatDistance(double distance,
QgsUnitTypes::
DistanceUnit units, int decimals, QgsUnitTypes:: SystemOfMeasurement destSystem = QgsUnitTypes:: MetricSystem) -> Q_INVOKABLE QString - Converts distance to human readable distance.
-
static auto formatPoint(const QgsPoint& point,
QgsCoordinateFormatter::
Format format = QgsCoordinateFormatter:: FormatPair, int decimals = 3, QgsCoordinateFormatter::FormatFlags flags = QgsCoordinateFormatter:: FlagDegreesUseStringSuffix) -> Q_INVOKABLE QString - Formats a point according to the specified parameters.
- static auto getEditorComponentSource(const QString& widgetName) -> Q_INVOKABLE const QUrl
- Returns url to field editor component for a feature form.
- static auto getFileName(const QString& path) -> Q_INVOKABLE QString
- Extracts filename from path.
- static auto getThemeIcon(const QString& name) -> Q_INVOKABLE const QUrl
- Returns QUrl to image from library's /images folder.
-
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.
-
static auto logMessage(const QString& message,
const QString& tag = QString("QgsQuick"),
Qgis::
MessageLevel level = Qgis:: Warning) -> Q_INVOKABLE void - Log message in QgsMessageLog.
- static auto point(double x, double y, double z = std::numeric_limits<double>::quiet_NaN(), double m = std::numeric_limits<double>::quiet_NaN()) -> Q_INVOKABLE QgsPoint
- Creates QgsPoint in QML.
- static auto pointXY(double x, double y) -> Q_INVOKABLE QgsPointXY
- Creates QgsPointXY in QML.
- static auto screenUnitsToMeters(QgsQuickMapSettings* mapSettings, int baseLengthPixels) -> Q_INVOKABLE double
- Calculates the distance in meter representing baseLengthPixels pixels on the screen based on the current map settings.
- static auto transformPoint(const QgsCoordinateReferenceSystem& srcCrs, const QgsCoordinateReferenceSystem& destCrs, const QgsCoordinateTransformContext& context, const QgsPointXY& srcPoint) -> Q_INVOKABLE QgsPointXY
- Transforms point between different crs from QML.
Constructors, destructors, conversion operators
- QgsQuickUtils(QObject* parent = nullptr)
- Create new utilities.
- ~QgsQuickUtils() defaulted
- Destructor.
Public functions
- auto dumpScreenInfo() const -> QString
- Returns a string with information about screen size and resolution - useful for debugging.
- auto screenDensity() const -> qreal
- "dp" is useful for building building components that work well with different screen densities.
Function documentation
static Q_INVOKABLE QgsCoordinateReferenceSystem QgsQuickUtils:: coordinateReferenceSystemFromEpsgId(long epsg)
Creates crs from epsg code in QML.
Makes QgsCoordinateReferenceSystem::
static Q_INVOKABLE QgsPoint QgsQuickUtils:: coordinateToPoint(const QGeoCoordinate& coor)
Converts QGeoCoordinate to QgsPoint.
static Q_INVOKABLE QgsQuickFeatureLayerPair QgsQuickUtils:: featureFactory(const QgsFeature& feature,
QgsVectorLayer* layer = nullptr)
QgsQuickFeatureLayerPair factory for tuple of QgsFeature and QgsVectorLayer used in QgsQUick library.
| Parameters | |
|---|---|
| feature | QgsFeature linked to new QgsQuickFeature instance. |
| layer | QgsVectorLayer which the feature belongs to, optional. |
static Q_INVOKABLE bool QgsQuickUtils:: fileExists(const QString& path)
Returns whether file on path exists.
static Q_INVOKABLE QString QgsQuickUtils:: formatDistance(double distance,
QgsUnitTypes:: DistanceUnit units,
int decimals,
QgsUnitTypes:: SystemOfMeasurement destSystem = QgsUnitTypes:: MetricSystem)
Converts distance to human readable distance.
| Parameters | |
|---|---|
| distance | distance in units |
| units | units of dist |
| decimals | decimal to use |
| destSystem | system of measurement of the result |
| Returns | string represetation of dist in desired destSystem. For distance less than 0, 0 is returned. |
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
static Q_INVOKABLE QString QgsQuickUtils:: 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.
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.
static Q_INVOKABLE const QUrl QgsQuickUtils:: getEditorComponentSource(const QString& widgetName)
Returns url to field editor component for a feature form.
| Parameters | |
|---|---|
| widgetName | name of the attribute field widget |
If the widgetName does not match any supported widget, text edit is returned.
static Q_INVOKABLE QString QgsQuickUtils:: getFileName(const QString& path)
Extracts filename from path.
static Q_INVOKABLE const QUrl QgsQuickUtils:: getThemeIcon(const QString& name)
Returns QUrl to image from library's /images folder.
static void QgsQuickUtils:: 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.
| Parameters | |
|---|---|
| srcDistance | distance in units |
| srcUnits | units of dist |
| destSystem | system of measurement of the result |
| destDistance | output: distance if desired system of measurement |
| destUnits | output: unit of destDistance |
static Q_INVOKABLE QgsPointXY QgsQuickUtils:: pointXY(double x,
double y)
Creates QgsPointXY in QML.
static Q_INVOKABLE QgsPointXY QgsQuickUtils:: transformPoint(const QgsCoordinateReferenceSystem& srcCrs,
const QgsCoordinateReferenceSystem& destCrs,
const QgsCoordinateTransformContext& context,
const QgsPointXY& srcPoint)
Transforms point between different crs from QML.
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.