Skip to content

Commit

Permalink
Fix remaining rubber band
Browse files Browse the repository at this point in the history
  • Loading branch information
lbartoletti committed Oct 16, 2017
1 parent e208bc0 commit c4a75f0
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 32 deletions.
2 changes: 1 addition & 1 deletion python/gui/qgsmapcanvas.sip
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ Pan to the selected features of current (vector) layer keeping same extent.
.. seealso:: flashFeatureIds()
%End

void setMapTool( QgsMapTool *mapTool );
void setMapTool( QgsMapTool *mapTool, bool clean = false );
%Docstring
Sets the map tool currently being used on the canvas
%End
Expand Down
5 changes: 5 additions & 0 deletions python/gui/qgsmaptool.sip
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ called when set as currently active map tool
virtual void deactivate();
%Docstring
called when map tool is being deactivated
%End

virtual void clean();
%Docstring
convenient method to clean members
%End

QgsMapCanvas *canvas();
Expand Down
5 changes: 5 additions & 0 deletions python/gui/qgsmaptoolcapture.sip
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ Adds a whole curve (e.g. circularstring) to the captured geometry. Curve must be
Clean a temporary rubberband
%End

virtual void clean();
%Docstring
convenient method to clean members
%End

protected:

int nextPoint( const QgsPoint &mapPoint, QgsPoint &layerPoint );
Expand Down
34 changes: 17 additions & 17 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1789,21 +1789,21 @@ void QgisApp::createActions()
connect( mActionAddFeature, &QAction::triggered, this, &QgisApp::addFeature );
connect( mActionCircularStringCurvePoint, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mCircularStringRadius ); } );
connect( mActionCircularStringRadius, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mCircularStringRadius ); } );
connect( mActionCircle2Points, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mCircle2Points ); } );
connect( mActionCircle3Points, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mCircle3Points ); } );
connect( mActionCircle3Tangents, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mCircle3Tangents ); } );
connect( mActionCircle2TangentsPoint, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mCircle2TangentsPoint ); } );
connect( mActionCircleCenterPoint, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mCircleCenterPoint ); } );
connect( mActionEllipseCenter2Points, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mEllipseCenter2Points ); } );
connect( mActionEllipseCenterPoint, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mEllipseCenterPoint ); } );
connect( mActionEllipseExtent, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mEllipseExtent ); } );
connect( mActionEllipseFoci, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mEllipseFoci ); } );
connect( mActionRectangleCenterPoint, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mRectangleCenterPoint ); } );
connect( mActionRectangleExtent, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mRectangleExtent ); } );
connect( mActionRectangle3Points, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mRectangle3Points ); } );
connect( mActionRegularPolygon2Points, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mRegularPolygon2Points ); } );
connect( mActionRegularPolygonCenterPoint, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mRegularPolygonCenterPoint ); } );
connect( mActionRegularPolygonCenterCorner, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mRegularPolygonCenterCorner ); } );
connect( mActionCircle2Points, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mCircle2Points, true ); } );
connect( mActionCircle3Points, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mCircle3Points, true ); } );
connect( mActionCircle3Tangents, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mCircle3Tangents, true ); } );
connect( mActionCircle2TangentsPoint, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mCircle2TangentsPoint, true ); } );
connect( mActionCircleCenterPoint, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mCircleCenterPoint, true ); } );
connect( mActionEllipseCenter2Points, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mEllipseCenter2Points, true ); } );
connect( mActionEllipseCenterPoint, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mEllipseCenterPoint, true ); } );
connect( mActionEllipseExtent, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mEllipseExtent, true ); } );
connect( mActionEllipseFoci, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mEllipseFoci, true ); } );
connect( mActionRectangleCenterPoint, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mRectangleCenterPoint, true ); } );
connect( mActionRectangleExtent, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mRectangleExtent, true ); } );
connect( mActionRectangle3Points, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mRectangle3Points, true ); } );
connect( mActionRegularPolygon2Points, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mRegularPolygon2Points, true ); } );
connect( mActionRegularPolygonCenterPoint, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mRegularPolygonCenterPoint, true ); } );
connect( mActionRegularPolygonCenterCorner, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mRegularPolygonCenterCorner, true ); } );
connect( mActionMoveFeature, &QAction::triggered, this, &QgisApp::moveFeature );
connect( mActionMoveFeature, &QAction::triggered, this, &QgisApp::moveFeature );
connect( mActionMoveFeatureCopy, &QAction::triggered, this, &QgisApp::moveFeatureCopy );
Expand Down Expand Up @@ -7801,9 +7801,9 @@ void QgisApp::addFeature()
mMapCanvas->setMapTool( mMapTools.mAddFeature );
}

void QgisApp::setMapTool( QgsMapTool *tool )
void QgisApp::setMapTool( QgsMapTool *tool, bool clean )
{
mMapCanvas->setMapTool( tool );
mMapCanvas->setMapTool( tool, clean );
}

void QgisApp::selectFeatures()
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgisapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -1261,7 +1261,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
//! shows the snapping Options
void snappingOptions();
//! activates the tool
void setMapTool( QgsMapTool *tool );
void setMapTool( QgsMapTool *tool, bool clean = false );


//! activates the rectangle selection tool
Expand Down
4 changes: 1 addition & 3 deletions src/app/qgsmaptooladdcircle.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class QgsMapToolAddCircle: public QgsMapToolCapture

void deactivate() override;
void activate() override;
void clean() override;

protected:
explicit QgsMapToolAddCircle( QgsMapCanvas *canvas ) = delete; //forbidden
Expand All @@ -55,9 +56,6 @@ class QgsMapToolAddCircle: public QgsMapToolCapture
//! Circle
QgsCircle mCircle;

private:
//! convenient method to clean members
void clean();
};

#endif // QGSMAPTOOLADDCIRCLE_H
4 changes: 1 addition & 3 deletions src/app/qgsmaptooladdellipse.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class QgsMapToolAddEllipse: public QgsMapToolCapture
void deactivate() override;

void activate() override;
void clean() override;

protected:
explicit QgsMapToolAddEllipse( QgsMapCanvas *canvas ) = delete; //forbidden
Expand All @@ -53,9 +54,6 @@ class QgsMapToolAddEllipse: public QgsMapToolCapture
//! convenient method to return the number of segments
unsigned int segments( ) { return QgsSettings().value( QStringLiteral( "/qgis/digitizing/offset_quad_seg" ), 8 ).toInt() * 12; }

private:
//! convenient method to clean members
void clean();
};

#endif // QGSMAPTOOLADDELLIPSE_H
3 changes: 1 addition & 2 deletions src/app/qgsmaptooladdrectangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class QgsMapToolAddRectangle: public QgsMapToolCapture
void deactivate( const bool isOriented = false );

void activate() override;
void clean() override;

protected:
explicit QgsMapToolAddRectangle( QgsMapCanvas *canvas ) = delete; //forbidden
Expand Down Expand Up @@ -84,8 +85,6 @@ class QgsMapToolAddRectangle: public QgsMapToolCapture
double mDistance2 = 0.0;
//! Convenient member for the side where the second distance is drawn or when map is rotated.
int mSide = 1;
//! convenient method to clean members
void clean();
};

#endif // QGSMAPTOOLADDRECTANGLE_H
4 changes: 1 addition & 3 deletions src/app/qgsmaptooladdregularpolygon.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class QgsMapToolAddRegularPolygon: public QgsMapToolCapture
void deactivate() override;

void activate() override;
void clean() override;

protected:
explicit QgsMapToolAddRegularPolygon( QgsMapCanvas *canvas ) = delete; //forbidden
Expand All @@ -60,9 +61,6 @@ class QgsMapToolAddRegularPolygon: public QgsMapToolCapture
//! Regular shape as a regular polygon
QgsRegularPolygon mRegularPolygon;

private:
//! convenient method to clean members
void clean();
};

#endif // QGSMAPTOOLADDREGULARPOLYGON_H
5 changes: 4 additions & 1 deletion src/gui/qgsmapcanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1599,13 +1599,16 @@ void QgsMapCanvas::mouseMoveEvent( QMouseEvent *e )
emit xyCoordinates( coord );
}

void QgsMapCanvas::setMapTool( QgsMapTool *tool )
void QgsMapCanvas::setMapTool( QgsMapTool *tool, bool clean )
{
if ( !tool )
return;

if ( mMapTool )
{
if ( clean )
mMapTool->clean();

disconnect( mMapTool, &QObject::destroyed, this, &QgsMapCanvas::mapToolDestroyed );
mMapTool->deactivate();
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsmapcanvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
int flashes = 3, int duration = 500 );

//! \brief Sets the map tool currently being used on the canvas
void setMapTool( QgsMapTool *mapTool );
void setMapTool( QgsMapTool *mapTool, bool clean = false );

/** \brief Unset the current map tool or last non zoom tool
*
Expand Down
5 changes: 5 additions & 0 deletions src/gui/qgsmaptool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ void QgsMapTool::deactivate()
emit deactivated();
}

void QgsMapTool::clean()
{

}

void QgsMapTool::setAction( QAction *action )
{
if ( mAction )
Expand Down
3 changes: 3 additions & 0 deletions src/gui/qgsmaptool.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ class GUI_EXPORT QgsMapTool : public QObject
//! called when map tool is being deactivated
virtual void deactivate();

//! convenient method to clean members
virtual void clean();

//! returns pointer to the tool's map canvas
QgsMapCanvas *canvas();

Expand Down
6 changes: 6 additions & 0 deletions src/gui/qgsmaptoolcapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,12 @@ void QgsMapToolCapture::deleteTempRubberBand()
}
}

void QgsMapToolCapture::clean()
{
stopCapturing();
clearCurve();
}

void QgsMapToolCapture::closePolygon()
{
mCaptureCurve.close();
Expand Down
3 changes: 3 additions & 0 deletions src/gui/qgsmaptoolcapture.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ class GUI_EXPORT QgsMapToolCapture : public QgsMapToolAdvancedDigitizing
*/
void deleteTempRubberBand();

//! convenient method to clean members
virtual void clean() override;

private slots:
void validationFinished();
void currentLayerChanged( QgsMapLayer *layer );
Expand Down

0 comments on commit c4a75f0

Please sign in to comment.