QGIS API Documentation
3.14.0-Pi (9f7028fd23)
|
Go to the documentation of this file.
29 if ( !mEnabled || !mAvailableByZoomFactor )
35 painter->setRenderHints( QPainter::Antialiasing );
36 painter->setCompositionMode( QPainter::CompositionMode_Difference );
38 double scaleFactor = painter->fontMetrics().xHeight() * .2;
40 mGridPen.setWidth( scaleFactor );
41 mCurrentPointPen.setWidth( scaleFactor * 3 );
42 const int gridMarkerLength = scaleFactor * 3;
49 const double gridXMin = std::ceil( layerExtent.
xMinimum() / mPrecision ) * mPrecision;
50 const double gridXMax = std::ceil( layerExtent.
xMaximum() / mPrecision ) * mPrecision;
51 const double gridYMin = std::ceil( layerExtent.
yMinimum() / mPrecision ) * mPrecision;
52 const double gridYMax = std::ceil( layerExtent.
yMaximum() / mPrecision ) * mPrecision;
54 for (
double x = gridXMin ; x < gridXMax; x += mPrecision )
56 for (
double y = gridYMin ; y < gridYMax; y += mPrecision )
63 painter->setPen( mCurrentPointPen );
67 painter->setPen( mGridPen );
69 painter->drawLine( canvasPt.x() - gridMarkerLength, canvasPt.y(), canvasPt.x() + gridMarkerLength, canvasPt.y() );
70 painter->drawLine( canvasPt.x(), canvasPt.y() - gridMarkerLength, canvasPt.x(), canvasPt.y() + gridMarkerLength );
78 mAvailableByZoomFactor =
false;
128 void QgsSnapToGridCanvasItem::updateMapCanvasCrs()
137 void QgsSnapToGridCanvasItem::updateZoomFactor()
144 const int threshold = 5;
147 if ( extent !=
rect() )
154 static_cast<int>( canvasCenter.y() - threshold ) );
156 static_cast<int>( canvasCenter.y() + threshold ) );
161 const double dist = layerPt1.
distance( layerPt2 );
163 if ( dist < mPrecision )
164 mAvailableByZoomFactor =
true;
166 mAvailableByZoomFactor =
false;
172 mAvailableByZoomFactor =
false;
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.
const QgsCoordinateReferenceSystem & crs
double xMaximum() const
Returns the x maximum value (right side of rectangle).
QgsPointXY toMapCoordinates(int x, int y) const
Transform device coordinates to map (world) coordinates.
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.
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)
double distance(double x, double y) const
Returns the distance between this point and a specified x, y coordinate.
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 yMaximum() const
Returns the y maximum value (top side of rectangle).
QgsCoordinateReferenceSystem destinationCrs() const
returns CRS of destination coordinate reference system
QgsPointXY center() const
Returns the center point of the rectangle.
QgsRectangle rect() const
returns canvas item rectangle in map units
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
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
double xMinimum() const
Returns the x minimum value (left side of rectangle).
void setCrs(const QgsCoordinateReferenceSystem &crs)
The CRS in which the grid should be calculated.