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 )