16 #include <QApplication> 17 #include <QDesktopWidget> 38 , mScreenDensity( calculateScreenDensity() )
62 return QgsPoint( coor.longitude(), coor.latitude(), coor.altitude() );
77 if ( mapSettings ==
nullptr )
return 0.0;
86 QPoint pointCenter( s.width() / 2, s.height() / 2 );
94 QFileInfo check_file( path );
96 return ( check_file.exists() && check_file.isFile() );
101 QString resultPath = path;
102 QString prefixPathWithSlash;
103 if ( !prefixPath.endsWith(
"/" ) )
104 prefixPathWithSlash = QStringLiteral(
"%1/" ).arg( prefixPath );
106 prefixPathWithSlash = prefixPath;
108 if ( resultPath.startsWith( prefixPathWithSlash ) )
109 return resultPath.replace( prefixPathWithSlash, QString() );
110 QString filePrefixPath = QStringLiteral(
"file://%1" ).arg( prefixPathWithSlash );
111 if ( resultPath.startsWith( filePrefixPath ) )
112 return resultPath.replace( filePrefixPath, QString() );
129 QString path = QStringLiteral(
"qrc:/%1.svg" ).arg( name );
130 QgsDebugMsg( QStringLiteral(
"Using icon %1 from %2" ).arg( name, path ) );
136 QString path(
"qgsquick%1.qml" );
137 QStringList supportedWidgets = { QStringLiteral(
"textedit" ),
138 QStringLiteral(
"valuemap" ),
139 QStringLiteral(
"valuerelation" ),
140 QStringLiteral(
"checkbox" ),
141 QStringLiteral(
"externalresource" ),
142 QStringLiteral(
"datetime" )
144 if ( supportedWidgets.contains( widgetName ) )
146 return QUrl( path.arg( widgetName ) );
150 return QUrl( path.arg( QStringLiteral(
"textedit" ) ) );
158 QgsCoordinateFormatter::FormatFlags flags )
173 return QStringLiteral(
"%1 %2" )
174 .arg( QString::number( destDistance,
'f', decimals ) )
180 QFile file( filePath );
181 return file.remove( filePath );
191 return formatToMetricDistance( srcDistance, srcUnits, destDistance, destUnits );
195 return formatToImperialDistance( srcDistance, srcUnits, destDistance, destUnits );
199 return formatToUSCSDistance( srcDistance, srcUnits, destDistance, destUnits );
207 void QgsQuickUtils::formatToMetricDistance(
double srcDistance,
209 double &destDistance,
223 destDistance = dist / mmToKm;
231 destDistance = dist / mmToM;
239 destDistance = dist / mmToCm;
248 void QgsQuickUtils::formatToImperialDistance(
double srcDistance,
250 double &destDistance,
262 if ( dist > feetToMile )
264 destDistance = dist / feetToMile;
270 if ( dist > feetToYard )
272 destDistance = dist / feetToYard;
282 void QgsQuickUtils::formatToUSCSDistance(
double srcDistance,
284 double &destDistance,
296 if ( dist > feetToMile )
298 destDistance = dist / feetToMile;
304 if ( dist > feetToYard )
306 destDistance = dist / feetToYard;
318 QRect rec = QApplication::desktop()->screenGeometry();
319 int dpiX = QApplication::desktop()->physicalDpiX();
320 int dpiY = QApplication::desktop()->physicalDpiY();
321 int height = rec.height();
322 int width = rec.width();
323 double sizeX =
static_cast<double>( width ) / dpiX * 25.4;
324 double sizeY =
static_cast<double>( height ) / dpiY * 25.4;
327 msg += tr(
"screen resolution: %1x%2 px\n" ).arg( width ).arg( height );
328 msg += tr(
"screen DPI: %1x%2\n" ).arg( dpiX ).arg( dpiY );
329 msg += tr(
"screen size: %1x%2 mm\n" ).arg( QString::number( sizeX,
'f', 0 ), QString::number( sizeY,
'f', 0 ) );
330 msg += tr(
"screen density: %1" ).arg( mScreenDensity );
336 QVariantMap valueMap;
341 valueMap.insert( item.key.toString(), item.value );
348 return mScreenDensity;
351 qreal QgsQuickUtils::calculateScreenDensity()
354 int dpiX = QApplication::desktop()->physicalDpiX();
355 int dpiY = QApplication::desktop()->physicalDpiY();
356 int dpi = dpiX < dpiY ? dpiX : dpiY;
static Q_INVOKABLE const QUrl getEditorComponentSource(const QString &widgetName)
Returns url to field editor component for a feature form.
static Q_INVOKABLE QgsPoint coordinateToPoint(const QGeoCoordinate &coor)
Converts QGeoCoordinate to QgsPoint.
SystemOfMeasurement
Systems of unit measurement.
static Q_INVOKABLE QgsCoordinateReferenceSystem coordinateReferenceSystemFromEpsgId(long epsg)
Creates crs from epsg code in QML.
A class to represent a 2D 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.
bool setEllipsoid(const QString &ellipsoid)
Sets the ellipsoid by its acronym.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
MessageLevel
Level for messages This will be used both for message log and message bar in application.
The QgsQuickMapSettings class encapsulates QgsMapSettings class to offer settings of configuration of...
static Q_INVOKABLE double screenUnitsToMeters(QgsQuickMapSettings *mapSettings, int baseLengthPixels)
Calculates the distance in meter representing baseLengthPixels pixels on the screen based on the curr...
static Q_INVOKABLE QString getRelativePath(const QString &path, const QString &prefixPath)
Returns relative path of the file to given prefixPath.
qreal screenDensity() const
"dp" is useful for building building components that work well with different screen densities...
static Q_INVOKABLE QgsPointXY transformPoint(const QgsCoordinateReferenceSystem &srcCrs, const QgsCoordinateReferenceSystem &destCrs, const QgsCoordinateTransformContext &context, const QgsPointXY &srcPoint)
Transforms point between different crs from QML.
static Q_INVOKABLE QgsCoordinateReferenceSystem fromEpsgId(long epsg)
Creates a CRS from a given EPSG ID.
Q_INVOKABLE QgsPoint screenToCoordinate(const QPointF &point) const
Convert a screen coordinate to a map coordinate.
static Q_INVOKABLE QString toAbbreviatedString(QgsUnitTypes::DistanceUnit unit)
Returns a translated abbreviation representing a distance unit.
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).
Unknown system of measurement.
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.
International System of Units (SI)
Contains information about the context in which a coordinate transform is executed.
static Q_INVOKABLE const QUrl getThemeIcon(const QString &name)
Returns QUrl to image from library's /images folder.
QgsQuickUtils(QObject *parent=nullptr)
Create new utilities.
Point geometry type, with support for z-dimension and m-values.
United States customary system.
DistanceUnit
Units of distance.
QgsCoordinateReferenceSystem destinationCrs
CRS of destination coordinate reference system.
QSize outputSize
The size of the resulting map image.
A general purpose distance and area calculator, capable of performing ellipsoid based calculations...
This class represents a coordinate reference system (CRS).
static Q_INVOKABLE bool removeFile(const QString &filePath)
Deletes file from a given path.
QString dumpScreenInfo() const
Returns a string with information about screen size and resolution - useful for debugging.
void setSourceCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets source spatial reference system crs.
static Q_INVOKABLE QString formatDistance(double distance, QgsUnitTypes::DistanceUnit units, int decimals, QgsUnitTypes::SystemOfMeasurement destSystem=QgsUnitTypes::MetricSystem)
Converts distance to human readable distance.
static Q_INVOKABLE QgsQuickFeatureLayerPair featureFactory(const QgsFeature &feature, QgsVectorLayer *layer=nullptr)
QgsQuickFeatureLayerPair factory for tuple of QgsFeature and QgsVectorLayer used in QgsQUick library...
Pair of QgsFeature and QgsVectorLayer.
static Q_INVOKABLE QgsPointXY pointXY(double x, double y)
Creates QgsPointXY in QML.
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.
static Q_INVOKABLE double fromUnitToUnitFactor(QgsUnitTypes::DistanceUnit fromUnit, QgsUnitTypes::DistanceUnit toUnit)
Returns the conversion factor between the specified distance units.
Represents a vector layer which manages a vector based data sets.
Q_INVOKABLE QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
static Q_INVOKABLE bool fileExists(const QString &path)
Returns whether file on path exists.
double measureLine(const QVector< QgsPointXY > &points) const
Measures the length of a line with multiple segments.
static Q_INVOKABLE QVariantMap createValueRelationCache(const QVariantMap &config, const QgsFeature &formFeature=QgsFeature())
Creates a cache for a value relation field.
static Q_INVOKABLE void logMessage(const QString &message, const QString &tag=QString("QgsQuick"), Qgis::MessageLevel level=Qgis::Warning)
Log message in QgsMessageLog.