Skip to content

Commit

Permalink
[composer] Holding shift while drawing polyline/polygon constrains
Browse files Browse the repository at this point in the history
line angles
  • Loading branch information
nyalldawson committed Jan 23, 2017
1 parent 012515c commit 71abd4c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
23 changes: 17 additions & 6 deletions src/gui/qgscomposerview.cpp
Expand Up @@ -1246,7 +1246,7 @@ void QgsComposerView::mouseMoveEvent( QMouseEvent* e )
case AddPolygon:
{
if ( ! mPolygonItem.isNull() )
movePolygonNode( scenePoint );
movePolygonNode( scenePoint, shiftModifier );

break;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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 )
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgscomposerview.h
Expand Up @@ -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();
Expand Down

0 comments on commit 71abd4c

Please sign in to comment.