15 #include <QDesktopWidget> 34 , mScreenDensity( calculateScreenDensity() )
58 return QgsPoint( coor.longitude(), coor.latitude(), coor.altitude() );
73 if ( mapSettings ==
nullptr )
return 0.0;
82 QPoint pointCenter( s.width() / 2, s.height() / 2 );
90 QFileInfo check_file( path );
92 return ( check_file.exists() && check_file.isFile() );
97 QFileInfo fileInfo( path );
98 QString filename( fileInfo.fileName() );
114 QString path = QStringLiteral(
"qrc:/%1.svg" ).arg( name );
115 QgsDebugMsg( QStringLiteral(
"Using icon %1 from %2" ).arg( name, path ) );
121 QString path(
"qgsquick%1.qml" );
122 QStringList supportedWidgets = { QStringLiteral(
"textedit" ),
123 QStringLiteral(
"valuemap" ),
124 QStringLiteral(
"checkbox" ),
125 QStringLiteral(
"externalresource" ),
126 QStringLiteral(
"datetime" )
128 if ( supportedWidgets.contains( widgetName ) )
130 return QUrl( path.arg( widgetName ) );
134 return QUrl( path.arg( QStringLiteral(
"textedit" ) ) );
142 QgsCoordinateFormatter::FormatFlags flags )
157 return QStringLiteral(
"%1 %2" )
158 .arg( QString::number( destDistance,
'f', decimals ) )
169 return formatToMetricDistance( srcDistance, srcUnits, destDistance, destUnits );
173 return formatToImperialDistance( srcDistance, srcUnits, destDistance, destUnits );
177 return formatToUSCSDistance( srcDistance, srcUnits, destDistance, destUnits );
185 void QgsQuickUtils::formatToMetricDistance(
double srcDistance,
187 double &destDistance,
201 destDistance = dist / mmToKm;
209 destDistance = dist / mmToM;
217 destDistance = dist / mmToCm;
226 void QgsQuickUtils::formatToImperialDistance(
double srcDistance,
228 double &destDistance,
240 if ( dist > feetToMile )
242 destDistance = dist / feetToMile;
248 if ( dist > feetToYard )
250 destDistance = dist / feetToYard;
260 void QgsQuickUtils::formatToUSCSDistance(
double srcDistance,
262 double &destDistance,
274 if ( dist > feetToMile )
276 destDistance = dist / feetToMile;
282 if ( dist > feetToYard )
284 destDistance = dist / feetToYard;
296 QRect rec = QApplication::desktop()->screenGeometry();
297 int dpiX = QApplication::desktop()->physicalDpiX();
298 int dpiY = QApplication::desktop()->physicalDpiY();
299 int height = rec.height();
300 int width = rec.width();
301 double sizeX =
static_cast<double>( width ) / dpiX * 25.4;
302 double sizeY =
static_cast<double>( height ) / dpiY * 25.4;
305 msg += tr(
"screen resolution: %1x%2 px\n" ).arg( width ).arg( height );
306 msg += tr(
"screen DPI: %1x%2\n" ).arg( dpiX ).arg( dpiY );
307 msg += tr(
"screen size: %1x%2 mm\n" ).arg( QString::number( sizeX,
'f', 0 ), QString::number( sizeY,
'f', 0 ) );
308 msg += tr(
"screen density: %1" ).arg( mScreenDensity );
314 return mScreenDensity;
317 qreal QgsQuickUtils::calculateScreenDensity()
320 int dpiX = QApplication::desktop()->physicalDpiX();
321 int dpiY = QApplication::desktop()->physicalDpiY();
322 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.
qreal screenDensity() const
"dp" is useful for building building components that work well with different screen densities...
Q_INVOKABLE QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
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...
Q_INVOKABLE QgsPoint screenToCoordinate(const QPointF &point) const
Convert a screen coordinate to a map coordinate.
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.
static Q_INVOKABLE QString toAbbreviatedString(QgsUnitTypes::DistanceUnit unit)
Returns a translated abbreviation representing a distance unit.
QString dumpScreenInfo() const
Returns a string with information about screen size and resolution - useful for debugging.
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.
double measureLine(const QVector< QgsPointXY > &points) const
Measures the length of a line with multiple segments.
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).
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.
static Q_INVOKABLE bool fileExists(const QString &path)
Returns whether file on path exists.
static Q_INVOKABLE void logMessage(const QString &message, const QString &tag=QString("QgsQuick"), Qgis::MessageLevel level=Qgis::Warning)
Log message in QgsMessageLog.