Skip to content
Permalink
Browse files
Make QgsCreateMarkerItemMapTool a QgsMapToolCapture
So that we get snapping indicators/etc for free
  • Loading branch information
nyalldawson committed Sep 8, 2021
1 parent 6a7f882 commit 4183c977950489ff9f7818e93ee66a66dc9e1e0d
@@ -25,6 +25,7 @@
#include "qgsmarkersymbol.h"
#include "qgslinesymbol.h"
#include "qgsfillsymbol.h"
#include "qgsadvanceddigitizingdockwidget.h"

///@cond PRIVATE

@@ -74,27 +75,30 @@ QgsMapTool *QgsCreatePointTextItemMapTool::mapTool()
//

QgsCreateMarkerItemMapTool::QgsCreateMarkerItemMapTool( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget )
: QgsMapToolAdvancedDigitizing( canvas, cadDockWidget )
: QgsMapToolCapture( canvas, cadDockWidget, CapturePoint )
, mHandler( new QgsCreateAnnotationItemMapToolHandler( canvas, cadDockWidget ) )
{

}

QgsCreateMarkerItemMapTool::~QgsCreateMarkerItemMapTool() = default;

void QgsCreateMarkerItemMapTool::cadCanvasPressEvent( QgsMapMouseEvent *event )
void QgsCreateMarkerItemMapTool::cadCanvasReleaseEvent( QgsMapMouseEvent *event )
{
if ( event->button() != Qt::LeftButton )
return;

const QgsPointXY layerPoint = toLayerCoordinates( mHandler->targetLayer(), event->mapPoint() );

std::unique_ptr< QgsAnnotationMarkerItem > createdItem = std::make_unique< QgsAnnotationMarkerItem >( QgsPoint( layerPoint ) );
createdItem->setSymbol( qgis::down_cast< QgsMarkerSymbol * >( QgsSymbol::defaultSymbol( QgsWkbTypes::PointGeometry ) ) );
// set reference scale to match canvas scale, but don't enable it by default for marker items
createdItem->setSymbologyReferenceScale( canvas()->scale() );

mHandler->pushCreatedItem( createdItem.release() );

stopCapturing();

cadDockWidget()->clearPoints();
}

QgsCreateAnnotationItemMapToolHandler *QgsCreateMarkerItemMapTool::handler()
@@ -107,6 +111,11 @@ QgsMapTool *QgsCreateMarkerItemMapTool::mapTool()
return this;
}

QgsMapLayer *QgsCreateMarkerItemMapTool::layer() const
{
return mHandler->targetLayer();
}

//
// QgsMapToolCaptureAnnotationItem
//
@@ -43,7 +43,7 @@ class QgsCreatePointTextItemMapTool: public QgsMapToolAdvancedDigitizing, public

};

class QgsCreateMarkerItemMapTool: public QgsMapToolAdvancedDigitizing, public QgsCreateAnnotationItemMapToolInterface
class QgsCreateMarkerItemMapTool: public QgsMapToolCapture, public QgsCreateAnnotationItemMapToolInterface
{
Q_OBJECT

@@ -52,9 +52,10 @@ class QgsCreateMarkerItemMapTool: public QgsMapToolAdvancedDigitizing, public Qg
QgsCreateMarkerItemMapTool( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget );
~QgsCreateMarkerItemMapTool() override;

void cadCanvasPressEvent( QgsMapMouseEvent *event ) override;
void cadCanvasReleaseEvent( QgsMapMouseEvent *event ) override;
QgsCreateAnnotationItemMapToolHandler *handler() override;
QgsMapTool *mapTool() override;
QgsMapLayer *layer() const override;

private:

0 comments on commit 4183c97

Please sign in to comment.