16 #include <QApplication> 17 #include <QDesktopWidget> 37 , mScreenDensity( calculateScreenDensity() )
61 return QgsPoint( coor.longitude(), coor.latitude(), coor.altitude() );
76 if ( mapSettings ==
nullptr )
return 0.0;
85 QPoint pointCenter( s.width() / 2, s.height() / 2 );
93 QFileInfo check_file( path );
95 return ( check_file.exists() && check_file.isFile() );
100 QFileInfo fileInfo( path );
101 QString filename( fileInfo.fileName() );
117 QString path = QStringLiteral(
"qrc:/%1.svg" ).arg( name );
118 QgsDebugMsg( QStringLiteral(
"Using icon %1 from %2" ).arg( name, path ) );
124 QString path(
"qgsquick%1.qml" );
125 QStringList supportedWidgets = { QStringLiteral(
"textedit" ),
126 QStringLiteral(
"valuemap" ),
127 QStringLiteral(
"checkbox" ),
128 QStringLiteral(
"externalresource" ),
129 QStringLiteral(
"datetime" )
131 if ( supportedWidgets.contains( widgetName ) )
133 return QUrl( path.arg( widgetName ) );
137 return QUrl( path.arg( QStringLiteral(
"textedit" ) ) );
145 QgsCoordinateFormatter::FormatFlags flags )
160 return QStringLiteral(
"%1 %2" )
161 .arg( QString::number( destDistance,
'f', decimals ) )
172 return formatToMetricDistance( srcDistance, srcUnits, destDistance, destUnits );
176 return formatToImperialDistance( srcDistance, srcUnits, destDistance, destUnits );
180 return formatToUSCSDistance( srcDistance, srcUnits, destDistance, destUnits );
188 void QgsQuickUtils::formatToMetricDistance(
double srcDistance,
190 double &destDistance,
204 destDistance = dist / mmToKm;
212 destDistance = dist / mmToM;
220 destDistance = dist / mmToCm;
229 void QgsQuickUtils::formatToImperialDistance(
double srcDistance,
231 double &destDistance,
243 if ( dist > feetToMile )
245 destDistance = dist / feetToMile;
251 if ( dist > feetToYard )
253 destDistance = dist / feetToYard;
263 void QgsQuickUtils::formatToUSCSDistance(
double srcDistance,
265 double &destDistance,
277 if ( dist > feetToMile )
279 destDistance = dist / feetToMile;
285 if ( dist > feetToYard )
287 destDistance = dist / feetToYard;
299 QRect rec = QApplication::desktop()->screenGeometry();
300 int dpiX = QApplication::desktop()->physicalDpiX();
301 int dpiY = QApplication::desktop()->physicalDpiY();
302 int height = rec.height();
303 int width = rec.width();
304 double sizeX =
static_cast<double>( width ) / dpiX * 25.4;
305 double sizeY =
static_cast<double>( height ) / dpiY * 25.4;
308 msg += tr(
"screen resolution: %1x%2 px\n" ).arg( width ).arg( height );
309 msg += tr(
"screen DPI: %1x%2\n" ).arg( dpiX ).arg( dpiY );
310 msg += tr(
"screen size: %1x%2 mm\n" ).arg( QString::number( sizeX,
'f', 0 ), QString::number( sizeY,
'f', 0 ) );
311 msg += tr(
"screen density: %1" ).arg( mScreenDensity );
317 return mScreenDensity;
320 qreal QgsQuickUtils::calculateScreenDensity()
323 int dpiX = QApplication::desktop()->physicalDpiX();
324 int dpiY = QApplication::desktop()->physicalDpiY();
325 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...
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.
static Q_INVOKABLE QString getFileName(const QString &path)
Extracts filename from path.
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).
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 void logMessage(const QString &message, const QString &tag=QString("QgsQuick"), Qgis::MessageLevel level=Qgis::Warning)
Log message in QgsMessageLog.