26#include "moc_qgsquickmapsettings.cpp"
28using namespace Qt::StringLiterals;
50 mProject->disconnect(
this );
61 mMapSettings.setTransformContext( mProject->transformContext() );
62 mMapSettings.setPathResolver( mProject->pathResolver() );
79 return mMapSettings.transformContext();
84 return mMapSettings.extent();
89 if ( mMapSettings.extent() ==
extent )
92 mMapSettings.setExtent(
extent );
116 return mMapSettings.mapUnitsPerPixel();
141 return mMapSettings.visibleExtent();
147 QgsPointXY pp = mMapSettings.mapToPixel().transform( pt );
161 mMapSettings.setTransformContext( ctx );
178 if ( mMapSettings.outputSize() ==
outputSize )
187 return mMapSettings.outputDpi();
202 return mMapSettings.destinationCrs();
216 return mMapSettings.layers();
221 mMapSettings.setLayers(
layers );
225void QgsQuickMapSettings::onCrsChanged()
230void QgsQuickMapSettings::onReadProject(
const QDomDocument &doc )
234 int red = mProject->readNumEntry( u
"Gui"_s, u
"/CanvasColorRedPart"_s, 255 );
235 int green = mProject->readNumEntry( u
"Gui"_s, u
"/CanvasColorGreenPart"_s, 255 );
236 int blue = mProject->readNumEntry( u
"Gui"_s, u
"/CanvasColorBluePart"_s, 255 );
237 mMapSettings.setBackgroundColor( QColor( red, green, blue ) );
239 const bool isTemporal = mProject->readNumEntry( u
"TemporalControllerWidget"_s, u
"/NavigationMode"_s, 0 ) != 0;
243 mMapSettings.setTemporalRange(
QgsDateTimeRange( QDateTime::fromString( startString, Qt::ISODateWithMs ), QDateTime::fromString( endString, Qt::ISODateWithMs ) ) );
246 QDomNodeList nodes = doc.elementsByTagName(
"mapcanvas" );
247 bool foundTheMapCanvas =
false;
248 for (
int i = 0; i < nodes.size(); i++ )
250 QDomNode node = nodes.item( 0 );
251 QDomElement element = node.toElement();
253 if ( element.hasAttribute( u
"name"_s ) && element.attribute( u
"name"_s ) ==
"theMapCanvas"_L1 )
255 foundTheMapCanvas =
true;
256 mMapSettings.readXml( node );
259 QgsMessageLog::logMessage( tr(
"Map Canvas rotation is not supported. Resetting from %1 to 0." ).arg( mMapSettings.rotation() ) );
262 if ( !foundTheMapCanvas )
264 mMapSettings.setDestinationCrs( mProject->crs() );
265 mMapSettings.setExtent( mProject->viewSettings()->fullExtent() );
268 mMapSettings.setRotation( 0 );
270 mMapSettings.setTransformContext( mProject->transformContext() );
271 mMapSettings.setPathResolver( mProject->pathResolver() );
272 mMapSettings.setElevationShadingRenderer( mProject->elevationShadingRenderer() );
285 return mMapSettings.rotation();
296 return mMapSettings.backgroundColor();
301 if ( mMapSettings.backgroundColor() == color )
304 mMapSettings.setBackgroundColor( color );
310 return mDevicePixelRatio;
321 return mMapSettings.isTemporal();
326 mMapSettings.setIsTemporal( temporal );
332 return mMapSettings.temporalRange().begin();
344 return mMapSettings.temporalRange().end();
357 return zRange.
lower();
363 if ( zRange.
lower() == lower )
375 return zRange.
upper();
381 if ( zRange.
upper() == upper )
Represents a coordinate reference system (CRS).
Contains information about the context in which a coordinate transform is executed.
QgsRange which stores a range of double values.
Base class for all map layer types.
virtual QgsRectangle extent() const
Returns the extent of the layer.
Contains configuration for rendering maps.
QgsPointXY layerToMapCoordinates(const QgsMapLayer *layer, QgsPointXY point) const
transform point coordinates from layer's CRS to output CRS
QSize outputSize() const
Returns the size of the resulting map image, in pixels.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true, const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE())
Adds a message to the log instance (and creates it if necessary).
void setY(double y)
Sets the y value of the point.
void setX(double x)
Sets the x value of the point.
QPointF toQPointF() const
Converts a point to a QPointF.
Point geometry type, with support for z-dimension and m-values.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
static QgsProject * instance()
Returns the QgsProject singleton instance.
void crsChanged()
Emitted when the crs() of the project has changed.
QString readEntry(const QString &scope, const QString &key, const QString &def=QString(), bool *ok=nullptr) const
Reads a string from the specified scope and key.
QgsCoordinateReferenceSystem crs
void readProject(const QDomDocument &document)
Emitted when a project is being read.
double outputDpi
Output DPI used for conversion between real world units (e.g.
void setIsTemporal(bool temporal)
Returns true if a temporal filtering is enabled.
QgsQuickMapSettings(QObject *parent=nullptr)
Create new map settings.
void setOutputSize(QSize outputSize)
Sets the size of the resulting map image, in pixels.
void setRotation(double rotation)
The rotation of the resulting map image, in degrees clockwise.
void setTransformContext(const QgsCoordinateTransformContext &context)
Sets the coordinate transform context, which stores various information regarding which datum transfo...
void extentChanged()
Geographical coordinates of the rectangle that should be rendered.
double rotation
The rotation of the resulting map image, in degrees clockwise.
QgsRectangle extent
Geographical coordinates of the rectangle that should be rendered.
void outputSizeChanged()
The size of the resulting map image.
double zRangeLower
The Z range's lower value (since QGIS 3.38).
QDateTime temporalBegin
The temporal range's begin (i.e.
void projectChanged()
A project property should be used as a primary source of project all other components in the applicat...
Q_INVOKABLE QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
bool isTemporal
Returns true if a temporal filtering is enabled.
QgsRectangle visibleExtent
Returns the actual extent derived from requested extent that takes output image size into account.
void outputDpiChanged()
Output DPI used for conversion between real world units (e.g.
void layersChanged()
Set list of layers for map rendering.
void destinationCrsChanged()
CRS of destination coordinate reference system.
void visibleExtentChanged()
Returns the actual extent derived from requested extent that takes output image size into account.
void temporalStateChanged()
Emitted when the temporal state has changed.
void setExtent(const QgsRectangle &extent)
Sets the coordinates of the rectangle which should be rendered.
Q_INVOKABLE QgsPoint screenToCoordinate(const QPointF &point) const
Convert a screen coordinate to a map coordinate.
Q_INVOKABLE void setCenter(const QgsPoint ¢er)
Move current map extent to have center point defined by center.
void devicePixelRatioChanged()
Returns the ratio between physical pixels and device-independent pixels.
double zRangeUpper
The Z range's upper value (since QGIS 3.38).
void setZRangeUpper(const double &upper)
The Z range's lower value (since QGIS 3.38).
QColor backgroundColor
The background color used to render the map.
double mapUnitsPerPixel
Returns the distance in geographical coordinates that equals to one pixel in the map.
void setDevicePixelRatio(const qreal &devicePixelRatio)
Sets the ratio between physical pixels and device-independent pixels.
double mapUnitsPerPoint
Returns the distance in geographical coordinates that equals to one point unit in the map.
QgsMapSettings mapSettings() const
Clone map settings.
void setProject(QgsProject *project)
A project property should be used as a primary source of project all other components in the applicat...
void mapUnitsPerPixelChanged()
Returns the distance in geographical coordinates that equals to one pixel in the map.
void setZRangeLower(const double &lower)
The Z range's lower value (since QGIS 3.38).
void setOutputDpi(double outputDpi)
Sets the dpi (dots per inch) used for conversion between real world units (e.g.
qreal devicePixelRatio() const
Returns the ratio between physical pixels and device-independent pixels.
void setLayers(const QList< QgsMapLayer * > &layers)
Sets the list of layers to render in the map.
Q_INVOKABLE void setCenterToLayer(QgsMapLayer *layer, bool shouldZoom=true)
Move current map extent to have center point defined by layer. Optionally only pan to the layer if sh...
QgsCoordinateReferenceSystem destinationCrs
CRS of destination coordinate reference system.
QDateTime temporalEnd
The temporal range's end (i.e.
QList< QgsMapLayer * > layers
Set list of layers for map rendering.
void setDestinationCrs(const QgsCoordinateReferenceSystem &destinationCrs)
Sets the destination crs (coordinate reference system) for the map render.
QSize outputSize
The size of the resulting map image.
void backgroundColorChanged()
The background color used to render the map.
void setTemporalEnd(const QDateTime &end)
The temporal range's end (i.e.
void zRangeChanged()
Emitted when the Z range has changed.
void rotationChanged()
The rotation of the resulting map image, in degrees clockwise.
Q_INVOKABLE QPointF coordinateToScreen(const QgsPoint &point) const
Convert a map coordinate to screen pixel coordinates.
QgsPoint center
Geographical coordinate representing the center point of the current extent.
void setTemporalBegin(const QDateTime &begin)
The temporal range's begin (i.e.
QgsProject * project
A project property should be used as a primary source of project all other components in the applicat...
void setBackgroundColor(const QColor &color)
The background color used to render the map.
bool includeUpper() const
Returns true if the upper bound is inclusive, or false if the upper bound is exclusive.
T lower() const
Returns the lower bound of the range.
bool includeLower() const
Returns true if the lower bound is inclusive, or false if the lower bound is exclusive.
T upper() const
Returns the upper bound of the range.
A rectangle specified with double values.
void setYMinimum(double y)
Set the minimum y value.
void setXMinimum(double x)
Set the minimum x value.
void setYMaximum(double y)
Set the maximum y value.
void setXMaximum(double x)
Set the maximum x value.
T begin() const
Returns the beginning of the range.
T end() const
Returns the upper bound of the range.
Represent a 2-dimensional vector.
double y() const
Returns the vector's y-component.
double x() const
Returns the vector's x-component.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
QgsTemporalRange< QDateTime > QgsDateTimeRange
QgsRange which stores a range of date times.