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() )
42 const double canvasWidth = QLineF( mapPoly[0], mapPoly[1] ).length();
43 const double canvasHeight = QLineF( mapPoly[0], mapPoly[3] ).length();
45 const int nPoints = mAdvancedDigitizingDockWidget->
pointsCount();
49 bool previousPointExist, penulPointExist;
53 const bool snappedToVertex = mAdvancedDigitizingDockWidget->
snappedToVertex();
54 const QList<QgsPointXY> snappedSegment = mAdvancedDigitizingDockWidget->
snappedSegment();
55 const bool hasSnappedSegment = snappedSegment.count() == 2;
57 const bool curPointExist = mapPoly.containsPoint( curPoint.
toQPointF(), Qt::OddEvenFill );
64 const double canvasDiagonalDimension = ( canvasWidth + canvasHeight ) / mupp ;
66 QPointF curPointPix, prevPointPix, penulPointPix, snapSegmentPix1, snapSegmentPix2;
72 if ( previousPointExist )
76 if ( penulPointExist )
80 if ( hasSnappedSegment )
86 painter->setRenderHint( QPainter::Antialiasing );
87 painter->setCompositionMode( QPainter::CompositionMode_Difference );
90 if ( curPointExist && snappedToVertex )
92 painter->setPen( mSnapPen );
93 painter->drawEllipse( curPointPix, 10, 10 );
97 if ( hasSnappedSegment && !snappedToVertex )
99 painter->setPen( mSnapPen );
100 painter->drawLine( snapSegmentPix1, snapSegmentPix2 );
104 painter->setPen( mSnapLinePen );
105 painter->drawLine( snapSegmentPix1, curPointPix );
112 painter->setPen( mConstruction2Pen );
113 painter->drawLine( snapSegmentPix1, snapSegmentPix2 );
122 a0 = std::atan2( -( prevPoint.
y() - penulPoint.
y() ), prevPoint.
x() - penulPoint.
x() );
134 a = std::atan2( -( curPoint.
y() - prevPoint.
y() ), curPoint.
x() - prevPoint.
x() );
137 a0 += canvasRotationRad;
138 a += canvasRotationRad;
140 painter->setPen( mConstruction2Pen );
141 painter->drawArc( QRectF( prevPointPix.x() - 20,
142 prevPointPix.y() - 20,
144 static_cast<int>( 16 * -a0 * 180 / M_PI ),
145 static_cast<int>( 16 * ( a0 - a ) * 180 / M_PI ) );
146 painter->drawLine( prevPointPix,
147 prevPointPix + 60 * QPointF( std::cos( a0 ), std::sin( a0 ) ) );
152 painter->setPen( mLockedPen );
153 const double canvasPadding = QLineF( prevPointPix, curPointPix ).length();
154 painter->drawLine( prevPointPix + ( canvasPadding - canvasDiagonalDimension ) * QPointF( std::cos( a ), std::sin( a ) ),
155 prevPointPix + ( canvasPadding + canvasDiagonalDimension ) * QPointF( std::cos( a ), std::sin( a ) ) );
162 painter->setPen( mLockedPen );
164 painter->drawEllipse( prevPointPix, r, r );
172 painter->setPen( mLockedPen );
190 painter->drawLine(
toCanvasCoordinates(
QgsPointXY( x, mapPoly[0].y() ) ) - canvasDiagonalDimension * QPointF( std::sin( -canvasRotationRad ), std::cos( -canvasRotationRad ) ),
191 toCanvasCoordinates(
QgsPointXY( x, mapPoly[0].y() ) ) + canvasDiagonalDimension * QPointF( std::sin( -canvasRotationRad ), std::cos( -canvasRotationRad ) ) );
200 painter->setPen( mLockedPen );
218 painter->drawLine(
toCanvasCoordinates(
QgsPointXY( mapPoly[0].x(), y ) ) - canvasDiagonalDimension * QPointF( std::cos( -canvasRotationRad ), -std::sin( -canvasRotationRad ) ),
219 toCanvasCoordinates(
QgsPointXY( mapPoly[0].x(), y ) ) + canvasDiagonalDimension * QPointF( std::cos( -canvasRotationRad ), -std::sin( -canvasRotationRad ) ) );
227 if ( curPointExist && previousPointExist )
229 painter->setPen( mConstruction2Pen );
230 painter->drawLine( prevPointPix, curPointPix );
233 if ( previousPointExist && penulPointExist )
235 painter->setPen( mConstruction1Pen );
236 painter->drawLine( penulPointPix, prevPointPix );
242 painter->setPen( mCursorPen );
243 painter->drawLine( curPointPix + QPointF( -5, -5 ),
244 curPointPix + QPointF( +5, +5 ) );
245 painter->drawLine( curPointPix + QPointF( -5, +5 ),
246 curPointPix + QPointF( +5, -5 ) );
254 const double canvasWidth = QLineF( mapPoly[0], mapPoly[1] ).length();
255 const double canvasHeight = QLineF( mapPoly[0], mapPoly[3] ).length();
258 mapPoly[0].x() + canvasWidth,
259 mapPoly[0].y() - canvasHeight
262 if (
rect() != mapRect )
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)
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.
A rectangle specified with double values.