Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Factor common code of QgsMapToolAddCircle/Ellipse/Rectangle/RegularRe…
…ctangle Those classes have identical implementations for a number of methods. Add a QgsMapToolAddAbstract class for that, and make them derive for it.
- Loading branch information
1 parent
3711fcf
commit fffcf66
Showing
11 changed files
with
203 additions
and
474 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/*************************************************************************** | ||
qgsmaptooladdabstract.cpp - abstract class for map tools of the 'add' kind | ||
--------------------- | ||
begin : July 2017 | ||
copyright : (C) 2017 | ||
email : lbartoletti at tuxfamily dot org | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsmaptooladdabstract.h" | ||
#include "qgsgeometryrubberband.h" | ||
#include "qgsgeometryutils.h" | ||
#include "qgsmapcanvas.h" | ||
#include "qgspoint.h" | ||
#include "qgisapp.h" | ||
#include "qgssnapindicator.h" | ||
|
||
QgsMapToolAddAbstract::QgsMapToolAddAbstract( QgsMapToolCapture *parentTool, QgsMapCanvas *canvas, CaptureMode mode ) | ||
: QgsMapToolCapture( canvas, QgisApp::instance()->cadDockWidget(), mode ) | ||
, mParentTool( parentTool ) | ||
, mSnapIndicator( std::make_unique< QgsSnapIndicator>( canvas ) ) | ||
{ | ||
QgsMapToolAddAbstract::clean(); | ||
|
||
connect( QgisApp::instance(), &QgisApp::newProject, this, &QgsMapToolAddAbstract::stopCapturing ); | ||
connect( QgisApp::instance(), &QgisApp::projectRead, this, &QgsMapToolAddAbstract::stopCapturing ); | ||
} | ||
|
||
QgsMapToolAddAbstract::~QgsMapToolAddAbstract() | ||
{ | ||
QgsMapToolAddAbstract::clean(); | ||
} | ||
|
||
void QgsMapToolAddAbstract::keyPressEvent( QKeyEvent *e ) | ||
{ | ||
if ( e && e->isAutoRepeat() ) | ||
{ | ||
return; | ||
} | ||
|
||
if ( e && e->key() == Qt::Key_Escape ) | ||
{ | ||
clean(); | ||
if ( mParentTool ) | ||
mParentTool->keyPressEvent( e ); | ||
} | ||
|
||
if ( e && e->key() == Qt::Key_Backspace ) | ||
{ | ||
if ( mPoints.size() == 1 ) | ||
{ | ||
|
||
if ( mTempRubberBand ) | ||
{ | ||
delete mTempRubberBand; | ||
mTempRubberBand = nullptr; | ||
} | ||
|
||
mPoints.clear(); | ||
} | ||
else if ( mPoints.size() > 1 ) | ||
{ | ||
mPoints.removeLast(); | ||
|
||
} | ||
if ( mParentTool ) | ||
mParentTool->keyPressEvent( e ); | ||
} | ||
} | ||
|
||
void QgsMapToolAddAbstract::keyReleaseEvent( QKeyEvent *e ) | ||
{ | ||
if ( e && e->isAutoRepeat() ) | ||
{ | ||
return; | ||
} | ||
} | ||
|
||
void QgsMapToolAddAbstract::activate() | ||
{ | ||
clean(); | ||
QgsMapToolCapture::activate(); | ||
} | ||
|
||
void QgsMapToolAddAbstract::clean() | ||
{ | ||
if ( mTempRubberBand ) | ||
{ | ||
delete mTempRubberBand; | ||
mTempRubberBand = nullptr; | ||
} | ||
|
||
mPoints.clear(); | ||
|
||
if ( mParentTool ) | ||
{ | ||
mParentTool->deleteTempRubberBand(); | ||
} | ||
|
||
QgsVectorLayer *vLayer = static_cast<QgsVectorLayer *>( QgisApp::instance()->activeLayer() ); | ||
if ( vLayer ) | ||
mLayerType = vLayer->geometryType(); | ||
} | ||
|
||
void QgsMapToolAddAbstract::release( QgsMapMouseEvent *e ) | ||
{ | ||
deactivate(); | ||
if ( mParentTool ) | ||
{ | ||
mParentTool->canvasReleaseEvent( e ); | ||
} | ||
activate(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/*************************************************************************** | ||
qgsmaptooladdabstract.h - abstract class for map tools of the 'add' kind | ||
--------------------- | ||
begin : May 2017 | ||
copyright : (C) 2017 | ||
email : lbartoletti at tuxfamily dot org | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSMAPTOOLADDABSTRACT_H | ||
#define QGSMAPTOOLADDABSTRACT_H | ||
|
||
#include "qgsmaptoolcapture.h" | ||
#include "qgsellipse.h" | ||
#include "qgssettingsregistrycore.h" | ||
#include "qgis_app.h" | ||
|
||
class QgsGeometryRubberBand; | ||
class QgsSnapIndicator; | ||
|
||
class APP_EXPORT QgsMapToolAddAbstract: public QgsMapToolCapture | ||
{ | ||
Q_OBJECT | ||
public: | ||
QgsMapToolAddAbstract( QgsMapToolCapture *parentTool, QgsMapCanvas *canvas, CaptureMode mode = CaptureLine ); | ||
~QgsMapToolAddAbstract() override; | ||
|
||
void keyPressEvent( QKeyEvent *e ) override; | ||
void keyReleaseEvent( QKeyEvent *e ) override; | ||
|
||
void deactivate() override = 0; | ||
|
||
void activate() override; | ||
void clean() override; | ||
|
||
protected: | ||
explicit QgsMapToolAddAbstract( QgsMapCanvas *canvas ) = delete; //forbidden | ||
|
||
//! Convenient method to release (activate/deactivate) tools | ||
void release( QgsMapMouseEvent *e ); | ||
|
||
/** | ||
* The parent map tool, e.g. the add feature tool. | ||
* Completed geometry will be added to this tool by calling its toLineString() method. | ||
*/ | ||
QPointer<QgsMapToolCapture> mParentTool; | ||
//! Ellipse points (in map coordinates) | ||
QgsPointSequence mPoints; | ||
//! The rubberband to show the geometry currently working on | ||
QgsGeometryRubberBand *mTempRubberBand = nullptr; | ||
|
||
//! Layer type which will be used for rubberband | ||
QgsWkbTypes::GeometryType mLayerType = QgsWkbTypes::LineGeometry; | ||
|
||
//! Snapping indicators | ||
std::unique_ptr<QgsSnapIndicator> mSnapIndicator; | ||
|
||
}; | ||
|
||
#endif // QGSMAPTOOLADDABSTRACT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.