Skip to content
Permalink
Browse files

use qreal overloads of painter methods in advanced digitizing canvas …

…item (#7967)

* use qreal overloads of painter methods in advanced digitizing canvas item

* better use of existing variables
  • Loading branch information
3nids committed Sep 20, 2018
1 parent f208191 commit 7b5afb953f4ee8ada959d2dc2723a936719048e4
Showing with 22 additions and 45 deletions.
  1. +22 −45 src/gui/qgsadvanceddigitizingcanvasitem.cpp
@@ -93,29 +93,20 @@ void QgsAdvancedDigitizingCanvasItem::paint( QPainter *painter )
if ( hasSnappedSegment && !snappedToVertex )
{
painter->setPen( mSnapPen );
painter->drawLine( snapSegmentPix1.x(),
snapSegmentPix1.y(),
snapSegmentPix2.x(),
snapSegmentPix2.y() );
painter->drawLine( snapSegmentPix1, snapSegmentPix2 );

if ( curPointExist )
{
painter->setPen( mSnapLinePen );
painter->drawLine( snapSegmentPix1.x(),
snapSegmentPix1.y(),
curPointPix.x(),
curPointPix.y() );
painter->drawLine( snapSegmentPix1, curPointPix );
}
}

// Draw segment par/per input
if ( mAdvancedDigitizingDockWidget->additionalConstraint() != QgsAdvancedDigitizingDockWidget::NoConstraint && hasSnappedSegment )
{
painter->setPen( mConstruction2Pen );
painter->drawLine( snapSegmentPix1.x(),
snapSegmentPix1.y(),
snapSegmentPix2.x(),
snapSegmentPix2.y() );
painter->drawLine( snapSegmentPix1, snapSegmentPix2 );
}

// Draw angle
@@ -139,24 +130,21 @@ void QgsAdvancedDigitizingCanvasItem::paint( QPainter *painter )
a = std::atan2( -( curPoint.y() - prevPoint.y() ), curPoint.x() - prevPoint.x() );
}
painter->setPen( mConstruction2Pen );
painter->drawArc( prevPointPix.x() - 20,
prevPointPix.y() - 20,
40, 40,
16 * -a0 * 180 / M_PI,
16 * ( a0 - a ) * 180 / M_PI );
painter->drawLine( prevPointPix.x(),
prevPointPix.y(),
prevPointPix.x() + 60 * std::cos( a0 ),
prevPointPix.y() + 60 * std::sin( a0 ) );
painter->drawArc( QRectF( prevPointPix.x() - 20,
prevPointPix.y() - 20,
40, 40 ),
static_cast<int>( 16 * -a0 * 180 / M_PI ),
static_cast<int>( 16 * ( a0 - a ) * 180 / M_PI ) );
painter->drawLine( prevPointPix,
prevPointPix + 60 * QPointF( std::cos( a0 ), std::sin( a0 ) ) );


if ( mAdvancedDigitizingDockWidget->constraintAngle()->isLocked() )
{
painter->setPen( mLockedPen );
double d = std::max( boundingRect().width(), boundingRect().height() );
painter->drawLine( prevPointPix.x() - d * std::cos( a ),
prevPointPix.y() - d * std::sin( a ),
prevPointPix.x() + d * std::cos( a ),
prevPointPix.y() + d * std::sin( a ) );
painter->drawLine( prevPointPix - d * QPointF( std::cos( a ), std::sin( a ) ),
prevPointPix + d * QPointF( std::cos( a ), std::sin( a ) ) );
}
}

@@ -191,10 +179,8 @@ void QgsAdvancedDigitizingCanvasItem::paint( QPainter *painter )
}
if ( draw )
{
painter->drawLine( x,
0,
x,
boundingRect().height() );
painter->drawLine( QPointF( x, 0 ),
QPointF( x, boundingRect().height() ) );
}
}

@@ -235,33 +221,24 @@ void QgsAdvancedDigitizingCanvasItem::paint( QPainter *painter )
if ( curPointExist && previousPointExist )
{
painter->setPen( mConstruction2Pen );
painter->drawLine( prevPointPix.x(),
prevPointPix.y(),
curPointPix.x(),
curPointPix.y() );
painter->drawLine( prevPointPix, curPointPix );
}

if ( previousPointExist && penulPointExist )
{
painter->setPen( mConstruction1Pen );
painter->drawLine( penulPointPix.x(),
penulPointPix.y(),
prevPointPix.x(),
prevPointPix.y() );
painter->drawLine( penulPointPix, prevPointPix );
}
}

if ( curPointExist )
{
painter->setPen( mCursorPen );
painter->drawLine( curPointPix.x() - 5,
curPointPix.y() - 5,
curPointPix.x() + 5,
curPointPix.y() + 5 );
painter->drawLine( curPointPix.x() - 5,
curPointPix.y() + 5,
curPointPix.x() + 5,
curPointPix.y() - 5 );
painter->drawLine( curPointPix + QPointF( -5, -5 ),
curPointPix + QPointF( +5, +5 ) );
painter->drawLine( curPointPix + QPointF( -5, +5 ),
curPointPix + QPointF( +5, -5 ) );

}

}

0 comments on commit 7b5afb9

Please sign in to comment.
You can’t perform that action at this time.