QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
30 if ( !mEnabled || !mAvailableByZoomFactor )
36 painter->setRenderHints( QPainter::Antialiasing );
37 painter->setCompositionMode( QPainter::CompositionMode_Difference );
39 const double scaleFactor = painter->fontMetrics().xHeight() * .2;
41 mGridPen.setWidth( scaleFactor );
42 mCurrentPointPen.setWidth( scaleFactor * 3 );
43 const int gridMarkerLength = scaleFactor * 3;
50 const QgsPointXY layerPt = mTransform.
transform( mPoint, Qgis::TransformDirection::Reverse );
52 const double gridXMin = std::ceil( layerExtent.
xMinimum() / mPrecision ) * mPrecision;
53 const double gridXMax = std::ceil( layerExtent.
xMaximum() / mPrecision ) * mPrecision;
54 const double gridYMin = std::ceil( layerExtent.
yMinimum() / mPrecision ) * mPrecision;
55 const double gridYMax = std::ceil( layerExtent.
yMaximum() / mPrecision ) * mPrecision;
57 for (
double x = gridXMin ; x < gridXMax; x += mPrecision )
59 for (
double y = gridYMin ; y < gridYMax; y += mPrecision )
66 painter->setPen( mCurrentPointPen );
70 painter->setPen( mGridPen );
72 painter->drawLine( canvasPt.x() - gridMarkerLength, canvasPt.y(), canvasPt.x() + gridMarkerLength, canvasPt.y() );
73 painter->drawLine( canvasPt.x(), canvasPt.y() - gridMarkerLength, canvasPt.x(), canvasPt.y() + gridMarkerLength );
81 mAvailableByZoomFactor =
false;
129 void QgsSnapToGridCanvasItem::updateMapCanvasCrs()
138 void QgsSnapToGridCanvasItem::updateZoomFactor()
145 const int threshold = 5;
148 if ( extent !=
rect() )
155 static_cast<int>( canvasCenter.y() - threshold ) );
157 static_cast<int>( canvasCenter.y() + threshold ) );
159 const QgsPointXY layerPt1 = mTransform.
transform( pt1, Qgis::TransformDirection::Reverse );
160 const QgsPointXY layerPt2 = mTransform.
transform( pt2, Qgis::TransformDirection::Reverse );
162 const double dist = layerPt1.
distance( layerPt2 );
164 if ( dist < mPrecision )
165 mAvailableByZoomFactor =
true;
167 mAvailableByZoomFactor =
false;
173 mAvailableByZoomFactor =
false;
double distance(double x, double y) const SIP_HOLDGIL
Returns the distance between this point and a specified x, y coordinate.
QgsRectangle extent() const
Returns the current zoom extent of the map canvas.
QgsSnapToGridCanvasItem(QgsMapCanvas *mapCanvas)
Will automatically be added to the mapCanvas.
void destinationCrsChanged()
Emitted when map CRS has changed.
QgsMapCanvas * mMapCanvas
pointer to map canvas
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
QgsPointXY center() const SIP_HOLDGIL
Returns the center point of the rectangle.
const QgsCoordinateReferenceSystem & crs
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
Map canvas is a class for displaying all GIS data types on a canvas.
QgsPointXY toMapCoordinates(int x, int y) const
Transforms device coordinates to map (world) coordinates.
A rectangle specified with double values.
void setPrecision(double precision)
The resolution of the grid in map units.
void setRect(const QgsRectangle &r, bool resetRotation=true)
sets canvas item rectangle in map units
QgsCoordinateReferenceSystem crs() const
The CRS in which the grid should be calculated.
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
Custom exception class for Coordinate Reference System related exceptions.
An abstract class for items that can be placed on the map canvas.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
bool enabled() const
Enable this item.
QPointF toCanvasCoordinates(const QgsPointXY &point) const
transformation from map coordinates to screen coordinates
void setEnabled(bool enabled)
Enable this item.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
QgsPointXY point() const
A point that will be highlighted on the map canvas.
void extentsChanged()
Emitted when the extents of the map change.
void paint(QPainter *painter) override
function to be implemented by derived classes
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
Scoped object for saving and restoring a QPainter object's state.
This class represents a coordinate reference system (CRS).
A class to represent a 2D point.
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination coordinate reference system for the map render.
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
QgsRectangle rect() const
returns canvas item rectangle in map units
double precision() const
The resolution of the grid in map units.
void setPoint(const QgsPointXY &point)
A point that will be highlighted on the map canvas.
const QgsMapToPixel & mapToPixel() const
void setCrs(const QgsCoordinateReferenceSystem &crs)
The CRS in which the grid should be calculated.