Skip to content
Permalink
Browse files
Add tool for creation of marker annotation items
  • Loading branch information
nyalldawson committed Sep 8, 2021
1 parent ef25d91 commit 84247cb51e49522b898885c476d4ee5c23010d82
@@ -200,13 +200,17 @@ void QgsAnnotationItemGuiRegistry::addDefaultItems()

addAnnotationItemGuiMetadata( new QgsAnnotationItemGuiMetadata( QStringLiteral( "marker" ),
QObject::tr( "Marker" ),
QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddImage.svg" ) ),
QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddMarker.svg" ) ),
[ = ]( QgsAnnotationItem * item )->QgsAnnotationItemBaseWidget *
{
QgsAnnotationMarkerItemWidget *widget = new QgsAnnotationMarkerItemWidget( nullptr );
widget->setItem( item );
return widget;
}, QString(), Qgis::AnnotationItemGuiFlag::FlagNoCreationTools ) );
}, QString(), Qgis::AnnotationItemGuiFlags(), nullptr,
[ = ]( QgsMapCanvas * canvas, QgsAdvancedDigitizingDockWidget * cadDockWidget )->QgsCreateAnnotationItemMapToolInterface *
{
return new QgsCreateMarkerItemMapTool( canvas, cadDockWidget );
} ) );

addAnnotationItemGuiMetadata( new QgsAnnotationItemGuiMetadata( QStringLiteral( "pointtext" ),
QObject::tr( "Text at Point" ),
@@ -16,9 +16,11 @@
#include "qgscreateannotationitemmaptool_impl.h"
#include "qgsmapmouseevent.h"
#include "qgsannotationpointtextitem.h"
#include "qgsannotationmarkeritem.h"
#include "qgsannotationlayer.h"
#include "qgsstyle.h"
#include "qgsmapcanvas.h"
#include "qgsmarkersymbol.h"

///@cond PRIVATE

@@ -61,4 +63,44 @@ QgsMapTool *QgsCreatePointTextItemMapTool::mapTool()
return this;
}



//
// QgsCreateMarkerMapTool
//

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

}

QgsCreateMarkerItemMapTool::~QgsCreateMarkerItemMapTool() = default;

void QgsCreateMarkerItemMapTool::cadCanvasPressEvent( 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() );
}

QgsCreateAnnotationItemMapToolHandler *QgsCreateMarkerItemMapTool::handler()
{
return mHandler;
}

QgsMapTool *QgsCreateMarkerItemMapTool::mapTool()
{
return this;
}

///@endcond PRIVATE
@@ -20,6 +20,7 @@
#include "qgscreateannotationitemmaptool.h"

class QgsAnnotationPointTextItem;
class QgsAnnotationMarkerItem;

#define SIP_NO_FILE

@@ -38,7 +39,24 @@ class QgsCreatePointTextItemMapTool: public QgsMapToolAdvancedDigitizing, public
QgsCreateAnnotationItemMapToolHandler *handler() override;
QgsMapTool *mapTool() override;

QgsAnnotationItem *takeCreatedItem() override;
private:

QgsCreateAnnotationItemMapToolHandler *mHandler = nullptr;

};

class QgsCreateMarkerItemMapTool: public QgsMapToolAdvancedDigitizing, public QgsCreateAnnotationItemMapToolInterface
{
Q_OBJECT

public:

QgsCreateMarkerItemMapTool( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget );
~QgsCreateMarkerItemMapTool() override;

void cadCanvasPressEvent( QgsMapMouseEvent *event ) override;
QgsCreateAnnotationItemMapToolHandler *handler() override;
QgsMapTool *mapTool() override;

private:

0 comments on commit 84247cb

Please sign in to comment.