Skip to content

Commit

Permalink
More advanced digitizing dock widget cleanups
Browse files Browse the repository at this point in the history
- CaptureMode enum has been moved back to QgsMapToolCapture where it belongs
- map tools that need clearing of CAD points do so explicitly when needed
  • Loading branch information
wonder-sk committed Sep 10, 2017
1 parent 2f8afc0 commit 22ad672
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 101 deletions.
3 changes: 2 additions & 1 deletion doc/api_break.dox
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ QgsAction {#qgis_api_break_3_0_QgsAction}
QgsAdvancedDigitizingDockWidget {#qgis_api_break_3_0_QgsAdvancedDigitizingDockWidget}
-------------------------------

- canvasReleaseEvent takes now QgsAdvancedDigitizingDockWidget::CaptureMode as second argument.
- canvasReleaseEvent() does not take second argument anymore. Map tools are expected to clear CAD points themselves whenever needed.
- snappingMode() was removed. Advanced digitizing now always uses project's snapping configuration.


Expand Down Expand Up @@ -1628,6 +1628,7 @@ QgsMapToolAdvancedDigitizing {#qgis_api_break_3_0_QgsMapToolAdvancedDigi
----------------------------

- setMode() was replaced by setAdvancedDigitizingAllowed() and setAutoSnapEnabled()
- mode() and CaptureMode enum have been moved to QgsMapToolCapture subclass


QgsMapToolCapture {#qgis_api_break_3_0_QgsMapToolCapture}
Expand Down
18 changes: 8 additions & 10 deletions python/gui/qgsadvanceddigitizingdockwidget.sip
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@ class QgsAdvancedDigitizingDockWidget : QgsDockWidget
Parallel
};

enum AdvancedDigitizingMode
{
SinglePoint,
TwoPoints,
ManyPoints
};

class CadConstraint
{
%Docstring
Expand Down Expand Up @@ -188,12 +181,11 @@ class QgsAdvancedDigitizingDockWidget : QgsDockWidget
:rtype: bool
%End

bool canvasReleaseEvent( QgsMapMouseEvent *e, AdvancedDigitizingMode mode );
bool canvasReleaseEvent( QgsMapMouseEvent *e );
%Docstring
Will react on a canvas release event

\param e A mouse event (may be modified)
\param mode determines if the dock has to record one, two or many points.
:return: If the event is hidden (construction mode hides events from the maptool)
:rtype: bool
%End
Expand All @@ -216,7 +208,7 @@ class QgsAdvancedDigitizingDockWidget : QgsDockWidget
:rtype: bool
%End

virtual bool applyConstraints( QgsMapMouseEvent *e );
bool applyConstraints( QgsMapMouseEvent *e );
%Docstring
:return: false if no solution was found (invalid constraints)
:rtype: bool
Expand Down Expand Up @@ -273,6 +265,12 @@ Constraint on a common angle
:rtype: bool
%End

void clearPoints();
%Docstring
Removes all points from the CAD point list
.. versionadded:: 3.0
%End

void setPoints( const QList<QgsPointXY> &points );
%Docstring
Configures list of current CAD points
Expand Down
17 changes: 0 additions & 17 deletions python/gui/qgsmaptooladvanceddigitizing.sip
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@ class QgsMapToolAdvancedDigitizing : QgsMapToolEdit
#include "qgsmaptooladvanceddigitizing.h"
%End
public:
enum CaptureMode
{
CaptureNone,
CapturePoint,
CaptureSegment,
CaptureLine,
CapturePolygon
};

explicit QgsMapToolAdvancedDigitizing( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget );
%Docstring
Expand All @@ -56,14 +48,6 @@ Catch the mouse release event, filters it, transforms it to map coordinates and
Catch the mouse move event, filters it, transforms it to map coordinates and send it to virtual method
%End

CaptureMode mode() const;
%Docstring
The capture mode

:return: Capture mode
:rtype: CaptureMode
%End

virtual void activate();
%Docstring
Registers this maptool with the cad dock widget
Expand Down Expand Up @@ -156,7 +140,6 @@ Catch the mouse move event, filters it, transforms it to map coordinates and sen
\param e Mouse events prepared by the cad system
%End


};

/************************************************************************
Expand Down
17 changes: 17 additions & 0 deletions python/gui/qgsmaptoolcapture.sip
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ class QgsMapToolCapture : QgsMapToolAdvancedDigitizing
#include "qgsmaptoolcapture.h"
%End
public:

enum CaptureMode
{
CaptureNone,
CapturePoint,
CaptureLine,
CapturePolygon
};

QgsMapToolCapture( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget, CaptureMode mode );
%Docstring
constructor
Expand All @@ -28,6 +37,14 @@ constructor
virtual void activate();
virtual void deactivate();

CaptureMode mode() const;
%Docstring
The capture mode

:return: Capture mode
:rtype: CaptureMode
%End

int addCurve( QgsCurve *c );
%Docstring
Adds a whole curve (e.g. circularstring) to the captured geometry. Curve must be in map CRS
Expand Down
4 changes: 4 additions & 0 deletions src/app/qgsmaptooladdfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
***************************************************************************/

#include "qgsmaptooladdfeature.h"
#include "qgsadvanceddigitizingdockwidget.h"
#include "qgsapplication.h"
#include "qgsattributedialog.h"
#include "qgsexception.h"
Expand Down Expand Up @@ -183,6 +184,9 @@ void QgsMapToolAddFeature::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
addFeature( vlayer, &f, false );

vlayer->triggerRepaint();

// we are done with digitizing for now so instruct advanced digitizing dock to reset its CAD points
cadDockWidget()->clearPoints();
}
}

Expand Down
10 changes: 1 addition & 9 deletions src/app/qgsmaptoolmovefeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,6 @@ QgsMapToolMoveFeature::QgsMapToolMoveFeature( QgsMapCanvas *canvas, MoveMode mod
, mMode( mode )
{
mToolName = tr( "Move feature" );
switch ( mode )
{
case Move:
mCaptureMode = QgsMapToolAdvancedDigitizing::CaptureSegment;
break;
case CopyMove:
mCaptureMode = QgsMapToolAdvancedDigitizing::CaptureLine; // we copy/move several times
break;
}
}

QgsMapToolMoveFeature::~QgsMapToolMoveFeature()
Expand Down Expand Up @@ -178,6 +169,7 @@ void QgsMapToolMoveFeature::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
}
delete mRubberBand;
mRubberBand = nullptr;
cadDockWidget()->clear();
break;

case CopyMove:
Expand Down
10 changes: 1 addition & 9 deletions src/gui/qgsadvanceddigitizingdockwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ bool QgsAdvancedDigitizingDockWidget::canvasPressEvent( QgsMapMouseEvent *e )
return mCadEnabled && mConstructionMode;
}

bool QgsAdvancedDigitizingDockWidget::canvasReleaseEvent( QgsMapMouseEvent *e, AdvancedDigitizingMode mode )
bool QgsAdvancedDigitizingDockWidget::canvasReleaseEvent( QgsMapMouseEvent *e )
{
if ( !mCadEnabled )
return false;
Expand Down Expand Up @@ -940,14 +940,6 @@ bool QgsAdvancedDigitizingDockWidget::canvasReleaseEvent( QgsMapMouseEvent *e, A

releaseLocks( false );

if ( e->button() == Qt::LeftButton )
{
// stop digitizing if not intermediate point and enough points are recorded with respect to the mode
if ( !mConstructionMode && ( mode == SinglePoint || ( mode == TwoPoints && mCadPointList.count() > 2 ) ) )
{
clearPoints();
}
}
return mConstructionMode;
}

Expand Down
22 changes: 7 additions & 15 deletions src/gui/qgsadvanceddigitizingdockwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,6 @@ class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private
Parallel //!< Parallel
};

/**
* Determines if the dock has to record one, two or many points.
*/
enum AdvancedDigitizingMode
{
SinglePoint, //!< Capture a single point (e.g. for point digitizing)
TwoPoints, //!< Capture two points (e.g. for translation)
ManyPoints //!< Capture two or more points (e.g. line or polygon digitizing)
};

/** \ingroup gui
* \brief The CadConstraint is an abstract class for all basic constraints (angle/distance/x/y).
* It contains all values (locked, value, relative) and pointers to corresponding widgets.
Expand Down Expand Up @@ -226,10 +216,9 @@ class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private
* Will react on a canvas release event
*
* \param e A mouse event (may be modified)
* \param mode determines if the dock has to record one, two or many points.
* \returns If the event is hidden (construction mode hides events from the maptool)
*/
bool canvasReleaseEvent( QgsMapMouseEvent *e, AdvancedDigitizingMode mode );
bool canvasReleaseEvent( QgsMapMouseEvent *e );

/**
* Will react on a canvas move event
Expand All @@ -249,7 +238,7 @@ class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private

//! apply the CAD constraints. The will modify the position of the map event in map coordinates by applying the CAD constraints.
//! \returns false if no solution was found (invalid constraints)
virtual bool applyConstraints( QgsMapMouseEvent *e );
bool applyConstraints( QgsMapMouseEvent *e );

/**
* Clear any cached previous clicks and helper lines
Expand Down Expand Up @@ -277,6 +266,11 @@ class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private
//! Constraint on a common angle
bool commonAngleConstraint() const { return mCommonAngleConstraint; }

/** Removes all points from the CAD point list
* \since QGIS 3.0
*/
void clearPoints();

/**
* Configures list of current CAD points
*
Expand Down Expand Up @@ -420,8 +414,6 @@ class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private
void updateCurrentPoint( const QgsPointXY &point );
//! remove previous point in the CAD point list
void removePreviousPoint();
//! remove all points from the CAD point list
void clearPoints();

//! filters key press
//! \note called by eventFilter (filter on line edits), canvasKeyPressEvent (filter on map tool) and keyPressEvent (filter on dock)
Expand Down
18 changes: 1 addition & 17 deletions src/gui/qgsmaptooladvanceddigitizing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

QgsMapToolAdvancedDigitizing::QgsMapToolAdvancedDigitizing( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget )
: QgsMapToolEdit( canvas )
, mCaptureMode( CapturePoint )
, mCadDockWidget( cadDockWidget )
{
}
Expand All @@ -42,24 +41,9 @@ void QgsMapToolAdvancedDigitizing::canvasPressEvent( QgsMapMouseEvent *e )

void QgsMapToolAdvancedDigitizing::canvasReleaseEvent( QgsMapMouseEvent *e )
{
QgsAdvancedDigitizingDockWidget::AdvancedDigitizingMode dockMode;
switch ( mCaptureMode )
{
case CaptureLine:
case CapturePolygon:
dockMode = QgsAdvancedDigitizingDockWidget::ManyPoints;
break;
case CaptureSegment:
dockMode = QgsAdvancedDigitizingDockWidget::TwoPoints;
break;
default:
dockMode = QgsAdvancedDigitizingDockWidget::SinglePoint;
break;
}

if ( isAdvancedDigitizingAllowed() && mCadDockWidget->cadEnabled() )
{
if ( mCadDockWidget->canvasReleaseEvent( e, dockMode ) )
if ( mCadDockWidget->canvasReleaseEvent( e ) )
return; // decided to eat the event and not pass it to the map tool (construction mode or picking a segment)
}
else if ( isAutoSnapEnabled() )
Expand Down
19 changes: 0 additions & 19 deletions src/gui/qgsmaptooladvanceddigitizing.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,6 @@ class GUI_EXPORT QgsMapToolAdvancedDigitizing : public QgsMapToolEdit
{
Q_OBJECT
public:
//! Different capture modes
enum CaptureMode
{
CaptureNone, //!< Do not capture
CapturePoint, //!< Capture points
CaptureSegment, //!< Capture a segment (i.e. 2 points)
CaptureLine, //!< Capture lines
CapturePolygon //!< Capture polygons
};

/**
* Creates an advanced digitizing maptool
Expand All @@ -59,13 +50,6 @@ class GUI_EXPORT QgsMapToolAdvancedDigitizing : public QgsMapToolEdit
//! Catch the mouse move event, filters it, transforms it to map coordinates and send it to virtual method
virtual void canvasMoveEvent( QgsMapMouseEvent *e ) override;

/**
* The capture mode
*
* \returns Capture mode
*/
CaptureMode mode() const { return mCaptureMode; }

/**
* Registers this maptool with the cad dock widget
*/
Expand Down Expand Up @@ -153,9 +137,6 @@ class GUI_EXPORT QgsMapToolAdvancedDigitizing : public QgsMapToolEdit
*/
virtual void cadCanvasMoveEvent( QgsMapMouseEvent *e ) { Q_UNUSED( e ) }

//! The capture mode in which this tool operates
CaptureMode mCaptureMode;

private slots:

/**
Expand Down
6 changes: 2 additions & 4 deletions src/gui/qgsmaptoolcapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

QgsMapToolCapture::QgsMapToolCapture( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget, CaptureMode mode )
: QgsMapToolAdvancedDigitizing( canvas, cadDockWidget )
, mCaptureMode( mode )
, mRubberBand( nullptr )
, mTempRubberBand( nullptr )
, mValidator( nullptr )
Expand All @@ -48,8 +49,6 @@ QgsMapToolCapture::QgsMapToolCapture( QgsMapCanvas *canvas, QgsAdvancedDigitizin
, mSkipNextContextMenuEvent( 0 )
#endif
{
mCaptureMode = mode;

mCaptureModeFromLayer = mode == CaptureNone;
mCapturing = false;

Expand Down Expand Up @@ -649,9 +648,8 @@ void QgsMapToolCapture::validateGeometry()
case CaptureNone:
case CapturePoint:
return;
case CaptureSegment:
case CaptureLine:
if ( size() < 2 || ( mCaptureMode == CaptureSegment && size() > 2 ) )
if ( size() < 2 )
return;
geom = QgsGeometry( mCaptureCurve.curveToLine() );
break;
Expand Down
Loading

0 comments on commit 22ad672

Please sign in to comment.