38 if ( !mAdvancedDigitizingDockWidget->
cadEnabled() )
41 painter->setRenderHint( QPainter::Antialiasing );
42 painter->setCompositionMode( QPainter::CompositionMode_Difference );
51 painter->setPen( mConstructionGuidesPen );
57 painter->drawPolyline( polygon );
66 tool->paint( painter );
72 const double canvasWidth = QLineF( mapPoly[0], mapPoly[1] ).length();
73 const double canvasHeight = QLineF( mapPoly[0], mapPoly[3] ).length();
75 const int nPoints = mAdvancedDigitizingDockWidget->
pointsCount();
79 bool previousPointExist, penulPointExist;
83 const bool snappedToVertex = mAdvancedDigitizingDockWidget->
snappedToVertex();
84 const QList<QgsPointXY> snappedSegment = mAdvancedDigitizingDockWidget->
snappedSegment();
85 const bool hasSnappedSegment = snappedSegment.count() == 2;
87 const bool curPointExist = mapPoly.containsPoint( curPoint.
toQPointF(), Qt::OddEvenFill );
94 const double canvasDiagonalDimension = ( canvasWidth + canvasHeight ) / mupp ;
96 QPointF curPointPix, prevPointPix, penulPointPix, snapSegmentPix1, snapSegmentPix2;
102 if ( previousPointExist )
106 if ( penulPointExist )
110 if ( hasSnappedSegment )
117 if ( curPointExist && snappedToVertex )
119 painter->setPen( mSnapPen );
120 painter->drawEllipse( curPointPix, 10, 10 );
124 if ( hasSnappedSegment && !snappedToVertex )
126 painter->setPen( mSnapPen );
127 painter->drawLine( snapSegmentPix1, snapSegmentPix2 );
131 painter->setPen( mSnapLinePen );
132 painter->drawLine( snapSegmentPix1, curPointPix );
139 painter->setPen( mConstruction2Pen );
140 painter->drawLine( snapSegmentPix1, snapSegmentPix2 );
149 a0 = std::atan2( -( prevPoint.
y() - penulPoint.
y() ), prevPoint.
x() - penulPoint.
x() );
161 a = std::atan2( -( curPoint.
y() - prevPoint.
y() ), curPoint.
x() - prevPoint.
x() );
164 a0 += canvasRotationRad;
165 a += canvasRotationRad;
167 painter->setPen( mConstruction2Pen );
168 painter->drawArc( QRectF( prevPointPix.x() - 20,
169 prevPointPix.y() - 20,
171 static_cast<int>( 16 * -a0 * 180 / M_PI ),
172 static_cast<int>( 16 * ( a0 - a ) * 180 / M_PI ) );
173 painter->drawLine( prevPointPix,
174 prevPointPix + 60 * QPointF( std::cos( a0 ), std::sin( a0 ) ) );
179 painter->setPen( mLockedPen );
180 const double canvasPadding = QLineF( prevPointPix, curPointPix ).length();
181 painter->drawLine( prevPointPix + ( canvasPadding - canvasDiagonalDimension ) * QPointF( std::cos( a ), std::sin( a ) ),
182 prevPointPix + ( canvasPadding + canvasDiagonalDimension ) * QPointF( std::cos( a ), std::sin( a ) ) );
189 painter->setPen( mLockedPen );
191 QPainterPath ellipsePath;
192 ellipsePath.addEllipse( prevPointPix, r, r );
193 const double a = std::atan2( -( curPoint.
y() - prevPoint.
y() ), curPoint.
x() - prevPoint.
x() ) + canvasRotationRad;
194 const QTransform t = QTransform().translate( prevPointPix.x(), prevPointPix.y() ).rotateRadians( a ).translate( -prevPointPix.x(), -prevPointPix.y() );
195 const QPolygonF ellipsePoly = ellipsePath.toFillPolygon( t );
196 painter->drawPolygon( ellipsePoly );
204 painter->setPen( mLockedPen );
222 painter->drawLine(
toCanvasCoordinates(
QgsPointXY( x, mapPoly[0].y() ) ) - canvasDiagonalDimension * QPointF( std::sin( -canvasRotationRad ), std::cos( -canvasRotationRad ) ),
223 toCanvasCoordinates(
QgsPointXY( x, mapPoly[0].y() ) ) + canvasDiagonalDimension * QPointF( std::sin( -canvasRotationRad ), std::cos( -canvasRotationRad ) ) );
232 painter->setPen( mLockedPen );
250 painter->drawLine(
toCanvasCoordinates(
QgsPointXY( mapPoly[0].x(), y ) ) - canvasDiagonalDimension * QPointF( std::cos( -canvasRotationRad ), -std::sin( -canvasRotationRad ) ),
251 toCanvasCoordinates(
QgsPointXY( mapPoly[0].x(), y ) ) + canvasDiagonalDimension * QPointF( std::cos( -canvasRotationRad ), -std::sin( -canvasRotationRad ) ) );
259 if ( curPointExist && previousPointExist )
261 painter->setPen( mConstruction2Pen );
262 painter->drawLine( prevPointPix, curPointPix );
265 if ( previousPointExist && penulPointExist )
267 painter->setPen( mConstruction1Pen );
268 painter->drawLine( penulPointPix, prevPointPix );
274 painter->setPen( mCursorPen );
275 painter->drawLine( curPointPix + QPointF( -5, -5 ),
276 curPointPix + QPointF( +5, +5 ) );
277 painter->drawLine( curPointPix + QPointF( -5, +5 ),
278 curPointPix + QPointF( +5, -5 ) );
286 painter->setPen( mLockedPen );
314 vertex = geom->
vertexAt( previousVertexId );
318 vertex = geom->
vertexAt( nextVertexId );
325 const double angle = std::atan2( snappedPoint.y() - point.y(), snappedPoint.x() - point.x() );
327 const double canvasPadding = QLineF( snappedPoint, curPointPix ).length();
328 painter->drawLine( snappedPoint + ( canvasPadding - canvasDiagonalDimension ) * QPointF( std::cos( angle ), std::sin( angle ) ),
329 snappedPoint + ( canvasPadding + canvasDiagonalDimension ) * QPointF( std::cos( angle ), std::sin( angle ) ) );
336 painter->setPen( mLockedPen );
338 double coordinateExtension = mAdvancedDigitizingDockWidget->
softLockX();
339 if ( coordinateExtension != std::numeric_limits<double>::quiet_NaN() )
341 const QgsPointXY point( coordinateExtension, mapPoly[0].y() );
342 const QPointF rotation( std::sin( -canvasRotationRad ), std::cos( -canvasRotationRad ) );
347 coordinateExtension = mAdvancedDigitizingDockWidget->
softLockY();
348 if ( coordinateExtension != std::numeric_limits<double>::quiet_NaN() )
350 const QgsPointXY point( mapPoly[0].x(), coordinateExtension );
351 const QPointF rotation( std::cos( -canvasRotationRad ), -std::sin( -canvasRotationRad ) );
357 painter->setPen( mCursorPen );
359 const QList< QgsPointLocator::Match > lockedSnapVertices = mAdvancedDigitizingDockWidget->
lockedSnapVertices();
365 painter->drawLine( canvasPoint + QPointF( 5, 5 ),
366 canvasPoint - QPointF( 5, 5 ) );
367 painter->drawLine( canvasPoint + QPointF( -5, 5 ),
368 canvasPoint - QPointF( -5, 5 ) );
371 if ( !lockedSnapVertices.isEmpty() )
373 const QgsPointXY point = lockedSnapVertices.last().point();
376 painter->drawLine( canvasPoint + QPointF( 0, 5 ),
377 canvasPoint - QPointF( 0, 5 ) );
378 painter->drawLine( canvasPoint + QPointF( 5, 0 ),
379 canvasPoint - QPointF( 5, 0 ) );