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();
46 mapPoly[0].x() + canvasWidth,
47 mapPoly[0].y() - canvasHeight
50 if (
rect() != mapRect )
53 const int nPoints = mAdvancedDigitizingDockWidget->
pointsCount();
57 bool previousPointExist, penulPointExist;
61 const bool snappedToVertex = mAdvancedDigitizingDockWidget->
snappedToVertex();
62 const QList<QgsPointXY> snappedSegment = mAdvancedDigitizingDockWidget->
snappedSegment();
63 const bool hasSnappedSegment = snappedSegment.count() == 2;
65 const bool curPointExist = mapPoly.containsPoint( curPoint.
toQPointF(), Qt::OddEvenFill );
72 const double canvasMaxDimension = std::max( canvasWidth / mupp, canvasHeight / mupp );
74 QPointF curPointPix, prevPointPix, penulPointPix, snapSegmentPix1, snapSegmentPix2;
80 if ( previousPointExist )
84 if ( penulPointExist )
88 if ( hasSnappedSegment )
94 painter->setRenderHint( QPainter::Antialiasing );
95 painter->setCompositionMode( QPainter::CompositionMode_Difference );
98 if ( curPointExist && snappedToVertex )
100 painter->setPen( mSnapPen );
101 painter->drawEllipse( curPointPix, 10, 10 );
105 if ( hasSnappedSegment && !snappedToVertex )
107 painter->setPen( mSnapPen );
108 painter->drawLine( snapSegmentPix1, snapSegmentPix2 );
112 painter->setPen( mSnapLinePen );
113 painter->drawLine( snapSegmentPix1, curPointPix );
120 painter->setPen( mConstruction2Pen );
121 painter->drawLine( snapSegmentPix1, snapSegmentPix2 );
130 a0 = std::atan2( -( prevPoint.
y() - penulPoint.
y() ), prevPoint.
x() - penulPoint.
x() );
142 a = std::atan2( -( curPoint.
y() - prevPoint.
y() ), curPoint.
x() - prevPoint.
x() );
145 a0 += canvasRotationRad;
146 a += canvasRotationRad;
148 painter->setPen( mConstruction2Pen );
149 painter->drawArc( QRectF( prevPointPix.x() - 20,
150 prevPointPix.y() - 20,
152 static_cast<int>( 16 * -a0 * 180 / M_PI ),
153 static_cast<int>( 16 * ( a0 - a ) * 180 / M_PI ) );
154 painter->drawLine( prevPointPix,
155 prevPointPix + 60 * QPointF( std::cos( a0 ), std::sin( a0 ) ) );
160 painter->setPen( mLockedPen );
161 painter->drawLine( prevPointPix - canvasMaxDimension * QPointF( std::cos( a ), std::sin( a ) ),
162 prevPointPix + canvasMaxDimension * QPointF( std::cos( a ), std::sin( a ) ) );
169 painter->setPen( mLockedPen );
171 painter->drawEllipse( prevPointPix, r, r );
179 painter->setPen( mLockedPen );
197 painter->drawLine(
toCanvasCoordinates(
QgsPointXY( x, mapPoly[0].y() ) ) - canvasMaxDimension * QPointF( std::sin( -canvasRotationRad ), std::cos( -canvasRotationRad ) ),
198 toCanvasCoordinates(
QgsPointXY( x, mapPoly[0].y() ) ) + canvasMaxDimension * QPointF( std::sin( -canvasRotationRad ), std::cos( -canvasRotationRad ) ) );
207 painter->setPen( mLockedPen );
225 painter->drawLine(
toCanvasCoordinates(
QgsPointXY( mapPoly[0].x(), y ) ) - canvasMaxDimension * QPointF( std::cos( -canvasRotationRad ), -std::sin( -canvasRotationRad ) ),
226 toCanvasCoordinates(
QgsPointXY( mapPoly[0].x(), y ) ) + canvasMaxDimension * QPointF( std::cos( -canvasRotationRad ), -std::sin( -canvasRotationRad ) ) );
234 if ( curPointExist && previousPointExist )
236 painter->setPen( mConstruction2Pen );
237 painter->drawLine( prevPointPix, curPointPix );
240 if ( previousPointExist && penulPointExist )
242 painter->setPen( mConstruction1Pen );
243 painter->drawLine( penulPointPix, prevPointPix );
249 painter->setPen( mCursorPen );
250 painter->drawLine( curPointPix + QPointF( -5, -5 ),
251 curPointPix + QPointF( +5, +5 ) );
252 painter->drawLine( curPointPix + QPointF( -5, +5 ),
253 curPointPix + QPointF( +5, -5 ) );
void paint(QPainter *painter) override
function to be implemented by derived classes
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.