1 /***************************************************************************
2     qgmaptoolellipsecenterpoint.cpp  -  map tool for adding ellipse
3     from center and a point
4     ---------------------
5     begin                : July 2017
6     copyright            : (C) 2017 by Loïc Bartoletti
7     email                : lbartoletti at tuxfamily dot org
8  ***************************************************************************
9  *                                                                         *
10  *   This program is free software; you can redistribute it and/or modify  *
11  *   it under the terms of the GNU General Public License as published by  *
12  *   the Free Software Foundation; either version 2 of the License, or     *
13  *   (at your option) any later version.                                   *
14  *                                                                         *
15  ***************************************************************************/
16 
17 #include "qgsmaptoolellipsecenterpoint.h"
18 #include "qgsgeometryrubberband.h"
19 #include "qgsmapcanvas.h"
20 #include "qgspoint.h"
21 #include "qgsmapmouseevent.h"
22 #include "qgssnapindicator.h"
23 
24 
QgsMapToolEllipseCenterPoint(QgsMapToolCapture * parentTool,QgsMapCanvas * canvas,CaptureMode mode)25 QgsMapToolEllipseCenterPoint::QgsMapToolEllipseCenterPoint( QgsMapToolCapture *parentTool,
26     QgsMapCanvas *canvas, CaptureMode mode )
27   : QgsMapToolAddEllipse( parentTool, canvas, mode )
28 {
29 }
30 
cadCanvasReleaseEvent(QgsMapMouseEvent * e)31 void QgsMapToolEllipseCenterPoint::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
32 {
33   QgsPoint point = mapPoint( *e );
34 
35   if ( !currentVectorLayer() )
36   {
37     notifyNotVectorLayer();
38     clean();
39     stopCapturing();
40     e->ignore();
41     return;
42   }
43 
44   if ( e->button() == Qt::LeftButton )
45   {
46     if ( mPoints.empty() )
47       mPoints.append( point );
48 
49     if ( !mTempRubberBand )
50     {
51       mTempRubberBand = createGeometryRubberBand( mLayerType, true );
52       mTempRubberBand->show();
53     }
54   }
55   else if ( e->button() == Qt::RightButton )
56   {
57     release( e );
58   }
59 }
60 
cadCanvasMoveEvent(QgsMapMouseEvent * e)61 void QgsMapToolEllipseCenterPoint::cadCanvasMoveEvent( QgsMapMouseEvent *e )
62 {
63   QgsPoint point = mapPoint( *e );
64 
65   mSnapIndicator->setMatch( e->mapPointMatch() );
66 
67   if ( mTempRubberBand )
68   {
69     mEllipse = QgsEllipse().fromCenterPoint( mPoints.at( 0 ), point );
70     mTempRubberBand->setGeometry( mEllipse.toPolygon( segments() ) );
71   }
72 }
73