Skip to content
Permalink
Browse files

More advanced digitizing dock widget cleanups

- 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 Aug 29, 2017
1 parent 2f8afc0 commit 22ad67295b30362079d29d3506c89db2b6c84e0b
@@ -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.


@@ -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}
@@ -42,13 +42,6 @@ class QgsAdvancedDigitizingDockWidget : QgsDockWidget
Parallel
};

enum AdvancedDigitizingMode
{
SinglePoint,
TwoPoints,
ManyPoints
};

class CadConstraint
{
%Docstring
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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


};

/************************************************************************
@@ -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
@@ -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
@@ -14,6 +14,7 @@
***************************************************************************/

#include "qgsmaptooladdfeature.h"
#include "qgsadvanceddigitizingdockwidget.h"
#include "qgsapplication.h"
#include "qgsattributedialog.h"
#include "qgsexception.h"
@@ -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();
}
}

@@ -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()
@@ -178,6 +169,7 @@ void QgsMapToolMoveFeature::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
}
delete mRubberBand;
mRubberBand = nullptr;
cadDockWidget()->clear();
break;

case CopyMove:
@@ -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;
@@ -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;
}

@@ -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.
@@ -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
@@ -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
@@ -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
*
@@ -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)
@@ -20,7 +20,6 @@

QgsMapToolAdvancedDigitizing::QgsMapToolAdvancedDigitizing( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget )
: QgsMapToolEdit( canvas )
, mCaptureMode( CapturePoint )
, mCadDockWidget( cadDockWidget )
{
}
@@ -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() )
@@ -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
@@ -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
*/
@@ -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:

/**
@@ -40,6 +40,7 @@

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

mCaptureModeFromLayer = mode == CaptureNone;
mCapturing = false;

@@ -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;

0 comments on commit 22ad672

Please sign in to comment.
You can’t perform that action at this time.