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 modPath = path;
   102   QString filePrefix( 
"file://" );
   104   if ( path.startsWith( filePrefix ) )
   106     modPath = modPath.replace( filePrefix, QString() );
   109   if ( prefixPath.isEmpty() ) 
return modPath;
   112   if ( !QFileInfo( path ).exists() )
   114     if ( !prefixPath.isEmpty() && modPath.startsWith( prefixPath ) )
   116       return modPath.replace( prefixPath, QString() );
   121     QDir absoluteDir( modPath );
   122     QDir prefixDir( prefixPath );
   123     QString canonicalPath = absoluteDir.canonicalPath();
   124     QString prefixCanonicalPath = prefixDir.canonicalPath() + 
"/";
   126     if ( prefixCanonicalPath.length() > 1 && canonicalPath.startsWith( prefixCanonicalPath ) )
   128       return canonicalPath.replace( prefixCanonicalPath, QString() );
   147   QString path = QStringLiteral( 
"qrc:/%1.svg" ).arg( name );
   148   QgsDebugMsg( QStringLiteral( 
"Using icon %1 from %2" ).arg( name, path ) );
   154   QString path( 
"qgsquick%1.qml" );
   155   QStringList supportedWidgets = { QStringLiteral( 
"textedit" ),
   156                                    QStringLiteral( 
"valuemap" ),
   157                                    QStringLiteral( 
"valuerelation" ),
   158                                    QStringLiteral( 
"checkbox" ),
   159                                    QStringLiteral( 
"externalresource" ),
   160                                    QStringLiteral( 
"datetime" ),
   161                                    QStringLiteral( 
"range" )
   163   if ( supportedWidgets.contains( widgetName ) )
   165     return QUrl( path.arg( widgetName ) );
   169     return QUrl( path.arg( QStringLiteral( 
"textedit" ) ) );
   177   QgsCoordinateFormatter::FormatFlags flags )
   192   return QStringLiteral( 
"%1 %2" )
   193          .arg( QString::number( destDistance, 
'f', decimals ) )
   199   QFile file( filePath );
   200   return file.remove( filePath );
   210     return formatToMetricDistance( srcDistance, srcUnits, destDistance, destUnits );
   214     return formatToImperialDistance( srcDistance, srcUnits, destDistance, destUnits );
   218     return formatToUSCSDistance( srcDistance, srcUnits, destDistance, destUnits );
   226 void QgsQuickUtils::formatToMetricDistance( 
double srcDistance,
   228     double &destDistance,
   242     destDistance = dist / mmToKm;
   250     destDistance = dist / mmToM;
   258     destDistance = dist / mmToCm;
   267 void QgsQuickUtils::formatToImperialDistance( 
double srcDistance,
   269     double &destDistance,
   281   if ( dist > feetToMile )
   283     destDistance = dist / feetToMile;
   289   if ( dist > feetToYard )
   291     destDistance = dist / feetToYard;
   301 void QgsQuickUtils::formatToUSCSDistance( 
double srcDistance,
   303     double &destDistance,
   315   if ( dist > feetToMile )
   317     destDistance = dist / feetToMile;
   323   if ( dist > feetToYard )
   325     destDistance = dist / feetToYard;
   337   QRect rec = QApplication::desktop()->screenGeometry();
   338   int dpiX = QApplication::desktop()->physicalDpiX();
   339   int dpiY = QApplication::desktop()->physicalDpiY();
   340   int height = rec.height();
   341   int width = rec.width();
   342   double sizeX = 
static_cast<double>( width ) / dpiX * 25.4;
   343   double sizeY = 
static_cast<double>( height ) / dpiY * 25.4;
   346   msg += tr( 
"screen resolution: %1x%2 px\n" ).arg( width ).arg( height );
   347   msg += tr( 
"screen DPI: %1x%2\n" ).arg( dpiX ).arg( dpiY );
   348   msg += tr( 
"screen size: %1x%2 mm\n" ).arg( QString::number( sizeX, 
'f', 0 ), QString::number( sizeY, 
'f', 0 ) );
   349   msg += tr( 
"screen density: %1" ).arg( mScreenDensity );
   355   QVariantMap valueMap;
   360     valueMap.insert( item.key.toString(), item.value );
   367   QList<QgsExpressionContextScope *> scopes;
   373   context.setFeature( pair.
feature() );
   375   return expr.
evaluate( &context ).toString();
   381   for ( 
const int &fid : fids )
   388   return mScreenDensity;
   391 qreal QgsQuickUtils::calculateScreenDensity()
   394   int dpiX = QApplication::desktop()->physicalDpiX();
   395   int dpiY = QApplication::desktop()->physicalDpiY();
   396   int dpi = dpiX < dpiY ? dpiX : dpiY; 
 Class for parsing and evaluation of expressions (formerly called "search strings"). 
 
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. 
 
QSet< QgsFeatureId > QgsFeatureIds
 
static Q_INVOKABLE QgsCoordinateReferenceSystem coordinateReferenceSystemFromEpsgId(long epsg)
Creates crs from epsg code in QML. 
 
A class to represent a 2D point. 
 
QVariant evaluate()
Evaluate the feature and return the result. 
 
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. 
 
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project. 
 
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 QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context...
 
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 feat...
 
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
 
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. 
 
Encapsulates a QGIS project, including sets of map layers and their styles, layouts, annotations, canvases, etc. 
 
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...
 
SelectBehavior
Selection behavior. 
 
QgsFeature feature
Feature that belongs to layer. 
 
This class represents a coordinate reference system (CRS). 
 
static Q_INVOKABLE QString evaluateExpression(const QgsQuickFeatureLayerPair &pair, QgsProject *activeProject, const QString &expression)
Evaluates expression. 
 
Q_INVOKABLE void selectByIds(const QgsFeatureIds &ids, QgsVectorLayer::SelectBehavior behavior=QgsVectorLayer::SetSelection)
Selects matching features using a list of feature IDs. 
 
QgsVectorLayer layer
Vector layer to which the feature belongs. 
 
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 QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer. 
 
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.