26 , mLockedPen( QPen( QColor( 0, 127, 0, 255 ), 1, Qt::DashLine ) )
27 , mConstruction1Pen( QPen( QColor( 127, 127, 127, 150 ), 1, Qt::DashLine ) )
28 , mConstruction2Pen( QPen( QColor( 127, 127, 127, 255 ), 1, Qt::DashLine ) )
29 , mSnapPen( QPen( QColor( 127, 0, 0, 150 ), 1 ) )
30 , mSnapLinePen( QPen( QColor( 127, 0, 0, 150 ), 1, Qt::DashLine ) )
31 , mCursorPen( QPen( QColor( 127, 127, 127, 255 ), 1 ) )
32 , mAdvancedDigitizingDockWidget( cadDockWidget )
38 if ( !mAdvancedDigitizingDockWidget->
cadEnabled() )
43 const double canvasWidth = QLineF( mapPoly[0], mapPoly[1] ).length();
44 const double canvasHeight = QLineF( mapPoly[0], mapPoly[3] ).length();
46 const int nPoints = mAdvancedDigitizingDockWidget->
pointsCount();
50 bool previousPointExist, penulPointExist;
54 const bool snappedToVertex = mAdvancedDigitizingDockWidget->
snappedToVertex();
55 const QList<QgsPointXY> snappedSegment = mAdvancedDigitizingDockWidget->
snappedSegment();
56 const bool hasSnappedSegment = snappedSegment.count() == 2;
58 const bool curPointExist = mapPoly.containsPoint( curPoint.
toQPointF(), Qt::OddEvenFill );
65 const double canvasDiagonalDimension = ( canvasWidth + canvasHeight ) / mupp ;
67 QPointF curPointPix, prevPointPix, penulPointPix, snapSegmentPix1, snapSegmentPix2;
73 if ( previousPointExist )
77 if ( penulPointExist )
81 if ( hasSnappedSegment )
87 painter->setRenderHint( QPainter::Antialiasing );
88 painter->setCompositionMode( QPainter::CompositionMode_Difference );
91 if ( curPointExist && snappedToVertex )
93 painter->setPen( mSnapPen );
94 painter->drawEllipse( curPointPix, 10, 10 );
98 if ( hasSnappedSegment && !snappedToVertex )
100 painter->setPen( mSnapPen );
101 painter->drawLine( snapSegmentPix1, snapSegmentPix2 );
105 painter->setPen( mSnapLinePen );
106 painter->drawLine( snapSegmentPix1, curPointPix );
113 painter->setPen( mConstruction2Pen );
114 painter->drawLine( snapSegmentPix1, snapSegmentPix2 );
123 a0 = std::atan2( -( prevPoint.
y() - penulPoint.
y() ), prevPoint.
x() - penulPoint.
x() );
135 a = std::atan2( -( curPoint.
y() - prevPoint.
y() ), curPoint.
x() - prevPoint.
x() );
138 a0 += canvasRotationRad;
139 a += canvasRotationRad;
141 painter->setPen( mConstruction2Pen );
142 painter->drawArc( QRectF( prevPointPix.x() - 20,
143 prevPointPix.y() - 20,
145 static_cast<int>( 16 * -a0 * 180 / M_PI ),
146 static_cast<int>( 16 * ( a0 - a ) * 180 / M_PI ) );
147 painter->drawLine( prevPointPix,
148 prevPointPix + 60 * QPointF( std::cos( a0 ), std::sin( a0 ) ) );
153 painter->setPen( mLockedPen );
154 const double canvasPadding = QLineF( prevPointPix, curPointPix ).length();
155 painter->drawLine( prevPointPix + ( canvasPadding - canvasDiagonalDimension ) * QPointF( std::cos( a ), std::sin( a ) ),
156 prevPointPix + ( canvasPadding + canvasDiagonalDimension ) * QPointF( std::cos( a ), std::sin( a ) ) );
163 painter->setPen( mLockedPen );
165 painter->drawEllipse( prevPointPix, r, r );
173 painter->setPen( mLockedPen );
191 painter->drawLine(
toCanvasCoordinates(
QgsPointXY( x, mapPoly[0].y() ) ) - canvasDiagonalDimension * QPointF( std::sin( -canvasRotationRad ), std::cos( -canvasRotationRad ) ),
192 toCanvasCoordinates(
QgsPointXY( x, mapPoly[0].y() ) ) + canvasDiagonalDimension * QPointF( std::sin( -canvasRotationRad ), std::cos( -canvasRotationRad ) ) );
201 painter->setPen( mLockedPen );
219 painter->drawLine(
toCanvasCoordinates(
QgsPointXY( mapPoly[0].x(), y ) ) - canvasDiagonalDimension * QPointF( std::cos( -canvasRotationRad ), -std::sin( -canvasRotationRad ) ),
220 toCanvasCoordinates(
QgsPointXY( mapPoly[0].x(), y ) ) + canvasDiagonalDimension * QPointF( std::cos( -canvasRotationRad ), -std::sin( -canvasRotationRad ) ) );
228 if ( curPointExist && previousPointExist )
230 painter->setPen( mConstruction2Pen );
231 painter->drawLine( prevPointPix, curPointPix );
234 if ( previousPointExist && penulPointExist )
236 painter->setPen( mConstruction1Pen );
237 painter->drawLine( penulPointPix, prevPointPix );
243 painter->setPen( mCursorPen );
244 painter->drawLine( curPointPix + QPointF( -5, -5 ),
245 curPointPix + QPointF( +5, +5 ) );
246 painter->drawLine( curPointPix + QPointF( -5, +5 ),
247 curPointPix + QPointF( +5, -5 ) );
255 painter->setPen( mLockedPen );
276 const double angle = std::atan2( snappedPoint.y() - point.y(), snappedPoint.x() - point.x() );
278 const double canvasPadding = QLineF( snappedPoint, curPointPix ).length();
279 painter->drawLine( snappedPoint + ( canvasPadding - canvasDiagonalDimension ) * QPointF( std::cos(
angle ), std::sin(
angle ) ),
280 snappedPoint + ( canvasPadding + canvasDiagonalDimension ) * QPointF( std::cos(
angle ), std::sin(
angle ) ) );
287 painter->setPen( mLockedPen );
289 double coordinateExtension = mAdvancedDigitizingDockWidget->
softLockX();
290 if ( coordinateExtension != std::numeric_limits<double>::quiet_NaN() )
292 const QgsPointXY point( coordinateExtension, mapPoly[0].y() );
293 const QPointF rotation( std::sin( -canvasRotationRad ), std::cos( -canvasRotationRad ) );
298 coordinateExtension = mAdvancedDigitizingDockWidget->
softLockY();
299 if ( coordinateExtension != std::numeric_limits<double>::quiet_NaN() )
301 const QgsPointXY point( mapPoly[0].x(), coordinateExtension );
302 const QPointF rotation( std::cos( -canvasRotationRad ), -std::sin( -canvasRotationRad ) );
308 painter->setPen( mCursorPen );
310 const QList< QgsPointLocator::Match > lockedSnapVertices = mAdvancedDigitizingDockWidget->
lockedSnapVertices();
316 painter->drawLine( canvasPoint + QPointF( 5, 5 ),
317 canvasPoint - QPointF( 5, 5 ) );
318 painter->drawLine( canvasPoint + QPointF( -5, 5 ),
319 canvasPoint - QPointF( -5, 5 ) );
322 if ( !lockedSnapVertices.isEmpty() )
324 const QgsPointXY point = lockedSnapVertices.last().point();
327 painter->drawLine( canvasPoint + QPointF( 0, 5 ),
328 canvasPoint - QPointF( 0, 5 ) );
329 painter->drawLine( canvasPoint + QPointF( 5, 0 ),
330 canvasPoint - QPointF( 5, 0 ) );
338 const double canvasWidth = QLineF( mapPoly[0], mapPoly[1] ).length();
339 const double canvasHeight = QLineF( mapPoly[0], mapPoly[3] ).length();
342 mapPoly[0].x() + canvasWidth,
343 mapPoly[0].y() - canvasHeight
346 if (
rect() != mapRect )
@ NoConstraint
No additional constraint.
@ NoVertex
Don't lock to vertex.
@ BeforeVertex
Lock to previous vertex.
void paint(QPainter *painter) override
function to be implemented by derived classes
void updatePosition() override
called on changed extent or resize event to update position of the item
QgsAdvancedDigitizingCanvasItem(QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget)
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
A geometry is the spatial representation of a feature.
QgsPoint vertexAt(int atVertex) const
Returns coordinates of a vertex.
An abstract class for items that can be placed on the map canvas.
QgsRectangle rect() const
returns canvas item rectangle in map units
QPointF toCanvasCoordinates(const QgsPointXY &point) const
transformation from map coordinates to screen coordinates
QgsMapCanvas * mMapCanvas
pointer to map canvas
void setRect(const QgsRectangle &r, bool resetRotation=true)
sets canvas item rectangle in map units
Map canvas is a class for displaying all GIS data types on a canvas.
double rotation() const
Gets the current map canvas rotation in clockwise degrees.
const QgsMapToPixel * getCoordinateTransform()
Gets the current coordinate transform.
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
QPolygonF visiblePolygon() const
Returns the visible area as a polygon (may be rotated)
double mapUnitsPerPixel() const
Returns the current map units per pixel.
A class to represent a 2D point.
QPointF toQPointF() const
Converts a point to a QPointF.
Point geometry type, with support for z-dimension and m-values.
bool isEmpty() const override SIP_HOLDGIL
Returns true if the geometry is empty.
A rectangle specified with double values.
QgsFeature getFeature(QgsFeatureId fid) const
Queries the layer for the feature with the given id.
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
QgsFeatureId featureId() const
The id of the feature to which the snapped geometry belongs.
QgsVectorLayer * layer() const
The vector layer where the snap occurred.
QgsPointXY point() const
for vertex / edge match coords depending on what class returns it (geom.cache: layer coords,...
int vertexIndex() const
for vertex / edge match (first vertex of the edge)