25 , mLockedPen( QPen( QColor( 0, 127, 0, 255 ), 1, Qt::DashLine ) )
26 , mConstruction1Pen( QPen( QColor( 127, 127, 127, 150 ), 1, Qt::DashLine ) )
27 , mConstruction2Pen( QPen( QColor( 127, 127, 127, 255 ), 1, Qt::DashLine ) )
28 , mSnapPen( QPen( QColor( 127, 0, 0, 150 ), 1 ) )
29 , mSnapLinePen( QPen( QColor( 127, 0, 0, 150 ), 1, Qt::DashLine ) )
30 , mCursorPen( QPen( QColor( 127, 127, 127, 255 ), 1 ) )
31 , mAdvancedDigitizingDockWidget( cadDockWidget )
37 if ( !mAdvancedDigitizingDockWidget->
cadEnabled() )
41 if (
rect() != mapRect )
44 int nPoints = mAdvancedDigitizingDockWidget->
pointsCount();
48 bool previousPointExist, penulPointExist;
52 const bool snappedToVertex = mAdvancedDigitizingDockWidget->
snappedToVertex();
53 const QList<QgsPointXY> snappedSegment = mAdvancedDigitizingDockWidget->
snappedSegment();
54 const bool hasSnappedSegment = snappedSegment.count() == 2;
56 const bool curPointExist = mapRect.
contains( curPoint );
62 QPointF curPointPix, prevPointPix, penulPointPix, snapSegmentPix1, snapSegmentPix2;
68 if ( previousPointExist )
72 if ( penulPointExist )
76 if ( hasSnappedSegment )
82 painter->setRenderHint( QPainter::Antialiasing );
83 painter->setCompositionMode( QPainter::CompositionMode_Difference );
86 if ( curPointExist && snappedToVertex )
88 painter->setPen( mSnapPen );
89 painter->drawEllipse( curPointPix, 10, 10 );
93 if ( hasSnappedSegment && !snappedToVertex )
95 painter->setPen( mSnapPen );
96 painter->drawLine( snapSegmentPix1, snapSegmentPix2 );
100 painter->setPen( mSnapLinePen );
101 painter->drawLine( snapSegmentPix1, curPointPix );
108 painter->setPen( mConstruction2Pen );
109 painter->drawLine( snapSegmentPix1, snapSegmentPix2 );
118 a0 = std::atan2( -( prevPoint.
y() - penulPoint.
y() ), prevPoint.
x() - penulPoint.
x() );
130 a = std::atan2( -( curPoint.
y() - prevPoint.
y() ), curPoint.
x() - prevPoint.
x() );
132 painter->setPen( mConstruction2Pen );
133 painter->drawArc( QRectF( prevPointPix.x() - 20,
134 prevPointPix.y() - 20,
136 static_cast<int>( 16 * -a0 * 180 / M_PI ),
137 static_cast<int>( 16 * ( a0 - a ) * 180 / M_PI ) );
138 painter->drawLine( prevPointPix,
139 prevPointPix + 60 * QPointF( std::cos( a0 ), std::sin( a0 ) ) );
144 painter->setPen( mLockedPen );
146 painter->drawLine( prevPointPix - d * QPointF( std::cos( a ), std::sin( a ) ),
147 prevPointPix + d * QPointF( std::cos( a ), std::sin( a ) ) );
154 painter->setPen( mLockedPen );
156 painter->drawEllipse( prevPointPix, r, r );
164 painter->setPen( mLockedPen );
169 x = mAdvancedDigitizingDockWidget->
constraintX()->
value() / mupp + prevPointPix.x();
182 painter->drawLine( QPointF( x, 0 ),
192 painter->setPen( mLockedPen );
198 y = -mAdvancedDigitizingDockWidget->
constraintY()->
value() / mupp + prevPointPix.y();
211 painter->drawLine( QPointF( 0, y ),
219 if ( curPointExist && previousPointExist )
221 painter->setPen( mConstruction2Pen );
222 painter->drawLine( prevPointPix, curPointPix );
225 if ( previousPointExist && penulPointExist )
227 painter->setPen( mConstruction1Pen );
228 painter->drawLine( penulPointPix, prevPointPix );
234 painter->setPen( mCursorPen );
235 painter->drawLine( curPointPix + QPointF( -5, -5 ),
236 curPointPix + QPointF( +5, +5 ) );
237 painter->drawLine( curPointPix + QPointF( -5, +5 ),
238 curPointPix + QPointF( +5, -5 ) );
A rectangle specified with double values.
A class to represent a 2D point.
bool contains(const QgsRectangle &rect) const
Returns true when rectangle contains other rectangle.
An abstract class for items that can be placed on the map canvas.
void paint(QPainter *painter) override
function to be implemented by derived classes
QgsRectangle rect() const
returns canvas item rectangle in map units
Map canvas is a class for displaying all GIS data types on a canvas.
QRectF boundingRect() const override
void setRect(const QgsRectangle &r, bool resetRotation=true)
sets canvas item rectangle in map units
double mapUnitsPerPixel() const
Returns current map units per pixel.
QgsAdvancedDigitizingCanvasItem(QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget)
QgsMapCanvas * mMapCanvas
pointer to map canvas
const QgsMapToPixel * getCoordinateTransform()
Gets the current coordinate transform.
QgsRectangle extent() const
Returns the current zoom extent of the map canvas.
QPointF toCanvasCoordinates(const QgsPointXY &point) const
transformation from map coordinates to screen coordinates