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, prevPointPix.y() - 20, 40, 40 ),
static_cast<int>( 16 * -a0 * 180 / M_PI ),
static_cast<int>( 16 * ( a0 - a ) * 180 / M_PI ) );
169 painter->drawLine( prevPointPix, prevPointPix + 60 * QPointF( std::cos( a0 ), std::sin( a0 ) ) );
174 painter->setPen( mLockedPen );
175 const double canvasPadding = QLineF( prevPointPix, curPointPix ).length();
176 painter->drawLine( prevPointPix + ( canvasPadding - canvasDiagonalDimension ) * QPointF( std::cos( a ), std::sin( a ) ), prevPointPix + ( canvasPadding + canvasDiagonalDimension ) * QPointF( std::cos( a ), std::sin( a ) ) );
183 painter->setPen( mLockedPen );
185 QPainterPath ellipsePath;
186 ellipsePath.addEllipse( prevPointPix, r, r );
187 const double a = std::atan2( -( curPoint.
y() - prevPoint.
y() ), curPoint.
x() - prevPoint.
x() ) + canvasRotationRad;
188 const QTransform t = QTransform().translate( prevPointPix.x(), prevPointPix.y() ).rotateRadians( a ).translate( -prevPointPix.x(), -prevPointPix.y() );
189 const QPolygonF ellipsePoly = ellipsePath.toFillPolygon( t );
190 painter->drawPolygon( ellipsePoly );
198 painter->setPen( mLockedPen );
216 painter->drawLine(
toCanvasCoordinates(
QgsPointXY( x, mapPoly[0].y() ) ) - canvasDiagonalDimension * QPointF( std::sin( -canvasRotationRad ), std::cos( -canvasRotationRad ) ),
toCanvasCoordinates(
QgsPointXY( x, mapPoly[0].y() ) ) + canvasDiagonalDimension * QPointF( std::sin( -canvasRotationRad ), std::cos( -canvasRotationRad ) ) );
225 painter->setPen( mLockedPen );
243 painter->drawLine(
toCanvasCoordinates(
QgsPointXY( mapPoly[0].x(), y ) ) - canvasDiagonalDimension * QPointF( std::cos( -canvasRotationRad ), -std::sin( -canvasRotationRad ) ),
toCanvasCoordinates(
QgsPointXY( mapPoly[0].x(), y ) ) + canvasDiagonalDimension * QPointF( std::cos( -canvasRotationRad ), -std::sin( -canvasRotationRad ) ) );
250 if ( curPointExist && previousPointExist )
252 painter->setPen( mConstruction2Pen );
253 painter->drawLine( prevPointPix, curPointPix );
256 if ( previousPointExist && penulPointExist )
258 painter->setPen( mConstruction1Pen );
259 painter->drawLine( penulPointPix, prevPointPix );
265 painter->setPen( mCursorPen );
266 painter->drawLine( curPointPix + QPointF( -5, -5 ), curPointPix + QPointF( +5, +5 ) );
267 painter->drawLine( curPointPix + QPointF( -5, +5 ), curPointPix + QPointF( +5, -5 ) );
273 painter->setPen( mLockedPen );
301 vertex = geom->
vertexAt( previousVertexId );
305 vertex = geom->
vertexAt( nextVertexId );
312 const double angle = std::atan2( snappedPoint.y() - point.y(), snappedPoint.x() - point.x() );
314 const double canvasPadding = QLineF( snappedPoint, curPointPix ).length();
315 painter->drawLine( snappedPoint + ( canvasPadding - canvasDiagonalDimension ) * QPointF( std::cos( angle ), std::sin( angle ) ), snappedPoint + ( canvasPadding + canvasDiagonalDimension ) * QPointF( std::cos( angle ), std::sin( angle ) ) );
321 painter->setPen( mLockedPen );
323 double coordinateExtension = mAdvancedDigitizingDockWidget->
softLockX();
324 if ( coordinateExtension != std::numeric_limits<double>::quiet_NaN() )
326 const QgsPointXY point( coordinateExtension, mapPoly[0].y() );
327 const QPointF rotation( std::sin( -canvasRotationRad ), std::cos( -canvasRotationRad ) );
331 coordinateExtension = mAdvancedDigitizingDockWidget->
softLockY();
332 if ( coordinateExtension != std::numeric_limits<double>::quiet_NaN() )
334 const QgsPointXY point( mapPoly[0].x(), coordinateExtension );
335 const QPointF rotation( std::cos( -canvasRotationRad ), -std::sin( -canvasRotationRad ) );
340 painter->setPen( mCursorPen );
342 const QList<QgsPointLocator::Match> lockedSnapVertices = mAdvancedDigitizingDockWidget->
lockedSnapVertices();
348 painter->drawLine( canvasPoint + QPointF( 5, 5 ), canvasPoint - QPointF( 5, 5 ) );
349 painter->drawLine( canvasPoint + QPointF( -5, 5 ), canvasPoint - QPointF( -5, 5 ) );
352 if ( !lockedSnapVertices.isEmpty() )
354 const QgsPointXY point = lockedSnapVertices.last().point();
357 painter->drawLine( canvasPoint + QPointF( 0, 5 ), canvasPoint - QPointF( 0, 5 ) );
358 painter->drawLine( canvasPoint + QPointF( 5, 0 ), canvasPoint - QPointF( 5, 0 ) );