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   double canvasWidth = QLineF( mapPoly[0], mapPoly[1] ).length();
    43   double canvasHeight = QLineF( mapPoly[0], mapPoly[3] ).length();
    46                                          mapPoly[0].x() + canvasWidth,
    47                                          mapPoly[0].y() - canvasHeight
    50   if ( 
rect() != mapRect )
    53   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 ) );
 
A rectangle specified with double values. 
 
QgsRectangle rect() const
returns canvas item rectangle in map units 
 
A class to represent a 2D point. 
 
double rotation() const
Gets the current map canvas rotation in clockwise degrees. 
 
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 
 
Map canvas is a class for displaying all GIS data types on a canvas. 
 
QPointF toQPointF() const
Converts a point to a QPointF. 
 
void setRect(const QgsRectangle &r, bool resetRotation=true)
sets canvas item rectangle in map units 
 
double mapUnitsPerPixel() const
Returns current map units per pixel. 
 
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering. 
 
QgsAdvancedDigitizingCanvasItem(QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget)
 
QgsMapCanvas * mMapCanvas
pointer to map canvas 
 
const QgsMapToPixel * getCoordinateTransform()
Gets the current coordinate transform. 
 
QPolygonF visiblePolygon() const
Returns the visible area as a polygon (may be rotated) 
 
QPointF toCanvasCoordinates(const QgsPointXY &point) const
transformation from map coordinates to screen coordinates