Skip to content
Permalink
Browse files
[composer] Holding shift while drawing polyline/polygon constrains
line angles
  • Loading branch information
nyalldawson committed Jan 23, 2017
1 parent 012515c commit 71abd4cf8fdcf5ce2b4dc79b5da2c078d6129ca3
Showing with 18 additions and 7 deletions.
  1. +17 −6 src/gui/qgscomposerview.cpp
  2. +1 −1 src/gui/qgscomposerview.h
@@ -1246,7 +1246,7 @@ void QgsComposerView::mouseMoveEvent( QMouseEvent* e )
case AddPolygon:
{
if ( ! mPolygonItem.isNull() )
movePolygonNode( scenePoint );
movePolygonNode( scenePoint, shiftModifier );

break;
}
@@ -1255,7 +1255,7 @@ void QgsComposerView::mouseMoveEvent( QMouseEvent* e )
{
if ( ! mPolygonItem.isNull() && ! mPolylineItem.isNull() )
{
movePolygonNode( scenePoint );
movePolygonNode( scenePoint, shiftModifier );

// rebuild a new qpainter path
QPainterPath path;
@@ -2257,15 +2257,26 @@ void QgsComposerView::addPolygonNode( QPointF scenePoint )
mPolygonItem.data()->setPolygon( polygon );
}

void QgsComposerView::movePolygonNode( QPointF scenePoint )
void QgsComposerView::movePolygonNode( QPointF scenePoint, bool constrainAngle )
{
QPolygonF polygon = mPolygonItem.data()->polygon();

if ( polygon.size() > 0 )
if ( polygon.isEmpty() )
return;

if ( polygon.size() > 1 && constrainAngle )
{
polygon.replace( polygon.size() - 1, scenePoint );
mPolygonItem.data()->setPolygon( polygon );
QPointF start = polygon.at( polygon.size() - 2 );
QLineF newLine = QLineF( start, scenePoint );

//movement is contrained to 45 degree angles
double angle = QgsComposerUtils::snappedAngle( newLine.angle() );
newLine.setAngle( angle );
scenePoint = newLine.p2();
}

polygon.replace( polygon.size() - 1, scenePoint );
mPolygonItem.data()->setPolygon( polygon );
}

void QgsComposerView::displayNodes( const bool display )
@@ -240,7 +240,7 @@ class GUI_EXPORT QgsComposerView: public QGraphicsView

//! Point based shape stuff
void addPolygonNode( QPointF scenePoint );
void movePolygonNode( QPointF scenePoint );
void movePolygonNode( QPointF scenePoint, bool constrainAngle );
void displayNodes( const bool display = true );
void setSelectedNode( QgsComposerNodesItem *shape, const int index );
void deselectNode();

0 comments on commit 71abd4c

Please sign in to comment.