17#include "moc_qgscreateannotationitemmaptool_impl.cpp"
42#include <QImageReader>
53 mToolName = tr(
"Annotation tool" );
100 setUseSnappingIndicator(
true );
107 if ( event->button() != Qt::LeftButton )
112 std::unique_ptr< QgsAnnotationPointTextItem > createdItem = std::make_unique< QgsAnnotationPointTextItem >( tr(
"Text" ), layerPoint );
113 createdItem->setAlignment( Qt::AlignLeft );
117 createdItem->setFormat( format );
119 createdItem->setUseSymbologyReferenceScale(
true );
120 createdItem->setSymbologyReferenceScale(
canvas()->scale() );
148 if ( event->button() != Qt::LeftButton )
152 std::unique_ptr< QgsAnnotationMarkerItem > createdItem = std::make_unique< QgsAnnotationMarkerItem >(
QgsPoint( layerPoint ) );
157 createdItem->setSymbol( markerSymbol.release() );
160 createdItem->setSymbologyReferenceScale(
canvas()->
scale() );
179void QgsCreateLineItemMapTool::lineCaptured(
const QgsCurve *line )
186 if ( qgsgeometry_cast< QgsCurve * >( geometry.get() ) )
188 std::unique_ptr< QgsAnnotationLineItem > createdItem = std::make_unique< QgsAnnotationLineItem >( qgsgeometry_cast< QgsCurve * >( geometry.release() ) );
193 createdItem->setSymbol( lineSymbol.release() );
196 createdItem->setSymbologyReferenceScale(
canvas()->
scale() );
212void QgsCreatePolygonItemMapTool::polygonCaptured(
const QgsCurvePolygon *polygon )
218 if ( qgsgeometry_cast< QgsCurve * >( geometry.get() ) )
220 std::unique_ptr< QgsCurvePolygon > newPolygon = std::make_unique< QgsCurvePolygon >();
221 newPolygon->setExteriorRing( qgsgeometry_cast< QgsCurve * >( geometry.release() ) );
222 std::unique_ptr< QgsAnnotationPolygonItem > createdItem = std::make_unique< QgsAnnotationPolygonItem >( newPolygon.release() );
227 createdItem->setSymbol( fillSymbol.release() );
230 createdItem->setSymbologyReferenceScale(
canvas()->
scale() );
247 setUseSnappingIndicator(
true );
252 if ( event->button() == Qt::RightButton && mRubberBand )
259 if ( event->button() != Qt::LeftButton )
264 mFirstPoint =
event->snapPoint();
265 mRect.setRect( mFirstPoint.
x(), mFirstPoint.
y(), mFirstPoint.
x(), mFirstPoint.
y() );
272 color.setAlphaF( color.alphaF() * alphaScale );
283 QStringList formatsFilter;
284 formatsFilter.append( QStringLiteral(
"*.svg" ) );
285 const QByteArrayList supportedFormats = QImageReader::supportedImageFormats();
286 for (
const auto &format : supportedFormats )
288 formatsFilter.append( QString( QStringLiteral(
"*.%1" ) ).arg( QString( format ) ) );
290 const QString dialogFilter = QStringLiteral(
"%1 (%2);;%3 (*.*)" ).arg( tr(
"Images" ), formatsFilter.join( QLatin1Char(
' ' ) ), tr(
"All files" ) );
292 const QString imagePath = QFileDialog::getOpenFileName(
nullptr, tr(
"Add Picture Annotation" ), initialDir.isEmpty() ? QDir::homePath() : initialDir, dialogFilter );
294 if ( imagePath.isEmpty() )
306 const double initialWidthPixels = std::abs( devicePoint1.
x() - devicePoint2.
x() );
307 const double initialHeightPixels = std::abs( devicePoint1.
y() - devicePoint2.
y() );
309 const QFileInfo pathInfo( imagePath );
313 if ( pathInfo.suffix().compare( QLatin1String(
"svg" ), Qt::CaseInsensitive ) == 0 )
326 std::unique_ptr< QgsAnnotationPictureItem > createdItem = std::make_unique< QgsAnnotationPictureItem >( format, imagePath,
QgsRectangle( point1, point2 ) );
327 if ( size.isValid() )
329 const double pixelsToMm =
mCanvas->mapSettings().outputDpi() / 25.4;
330 if ( size.width() / size.height() > initialWidthPixels / initialHeightPixels )
332 createdItem->setFixedSize( QSizeF( initialWidthPixels / pixelsToMm, size.height() / size.width() * initialWidthPixels / pixelsToMm ) );
336 createdItem->setFixedSize( QSizeF( size.width() / size.height() * initialHeightPixels / pixelsToMm, initialHeightPixels / pixelsToMm ) );
350 const QgsPointXY mapPoint =
event->snapPoint();
351 mRect.setBottomRight( mapPoint.
toQPointF() );
354 mRubberBand->
addPoint( mRect.bottomLeft(),
false );
355 mRubberBand->
addPoint( mRect.bottomRight(),
false );
356 mRubberBand->
addPoint( mRect.topRight(),
false );
357 mRubberBand->
addPoint( mRect.topLeft(),
true );
362 if ( event->key() == Qt::Key_Escape )
393 setUseSnappingIndicator(
true );
398 if ( event->button() == Qt::RightButton && mRubberBand )
405 if ( event->button() != Qt::LeftButton )
410 mFirstPoint =
event->snapPoint();
411 mRect.setRect( mFirstPoint.
x(), mFirstPoint.
y(), mFirstPoint.
x(), mFirstPoint.
y() );
418 color.setAlphaF( color.alphaF() * alphaScale );
434 std::unique_ptr< QgsAnnotationRectangleTextItem > createdItem = std::make_unique< QgsAnnotationRectangleTextItem >( tr(
"Text" ),
QgsRectangle( point1, point2 ) );
439 createdItem->setFormat( format );
442 createdItem->setUseSymbologyReferenceScale(
true );
443 createdItem->setSymbologyReferenceScale(
canvas()->scale() );
453 const QgsPointXY mapPoint =
event->snapPoint();
454 mRect.setBottomRight( mapPoint.
toQPointF() );
457 mRubberBand->
addPoint( mRect.bottomLeft(),
false );
458 mRubberBand->
addPoint( mRect.bottomRight(),
false );
459 mRubberBand->
addPoint( mRect.topRight(),
false );
460 mRubberBand->
addPoint( mRect.topLeft(),
true );
465 if ( event->key() == Qt::Key_Escape )
497void QgsCreateLineTextItemMapTool::lineCaptured(
const QgsCurve *line )
504 if ( qgsgeometry_cast< QgsCurve * >( geometry.get() ) )
506 std::unique_ptr< QgsAnnotationLineTextItem > createdItem = std::make_unique< QgsAnnotationLineTextItem >( tr(
"Text" ), qgsgeometry_cast< QgsCurve * >( geometry.release() ) );
515 createdItem->setFormat( format );
518 createdItem->setUseSymbologyReferenceScale(
true );
519 createdItem->setSymbologyReferenceScale(
canvas()->scale() );
void reset(T *p=nullptr)
Will reset the managed pointer to p.
CaptureTechnique
Capture technique.
@ StraightSegments
Default capture mode - capture occurs with straight line segments.
@ CircularString
Capture in circular strings.
@ Streaming
Streaming points digitizing mode (points are automatically added as the mouse cursor moves).
PictureFormat
Picture formats.
@ Unknown
Invalid or unknown image type.
@ Millimeters
Millimeters.
virtual const QgsAbstractGeometry * simplifiedTypeRef() const
Returns a reference to the simplest lossless representation of this geometry, e.g.
virtual bool isEmpty() const
Returns true if the geometry is empty.
virtual QgsAbstractGeometry * clone() const =0
Clones the geometry by performing a deep copy.
static QgsRecentStyleHandler * recentStyleHandler()
Returns the handler for recently used style items.
static QgsImageCache * imageCache()
Returns the application's image cache, used for caching resampled versions of raster images.
static QgsSvgCache * svgCache()
Returns the application's SVG cache, used for caching SVG images and handling parameter replacement w...
QgsCreateLineTextItemMapTool(QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget)
Constructor.
~QgsCreatePointTextItemMapTool() override
QgsMapTool * mapTool() override
Returns a reference to the associated map tool.
void cadCanvasPressEvent(QgsMapMouseEvent *event) override
Override this method when subclassing this class.
QgsCreatePointTextItemMapTool(QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget)
Constructor.
QgsCreateAnnotationItemMapToolHandler * handler() const override
Returns the handler object for the map tool.
QgsCreateRectangleTextItemMapTool(QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget)
Constructor.
QgsMapTool * mapTool() override
Returns a reference to the associated map tool.
void cadCanvasMoveEvent(QgsMapMouseEvent *event) override
Override this method when subclassing this class.
void cadCanvasPressEvent(QgsMapMouseEvent *event) override
Override this method when subclassing this class.
void keyPressEvent(QKeyEvent *event) override
Key event for overriding. Default implementation does nothing.
QgsCreateAnnotationItemMapToolHandler * handler() const override
Returns the handler object for the map tool.
Curve polygon geometry type.
const QgsCurve * exteriorRing() const
Returns the curve polygon's exterior ring.
bool isEmpty() const override
Returns true if the geometry is empty.
Abstract base class for curved geometry type.
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
QSize originalSize(const QString &path, bool blocking=false) const
Returns the original size (in pixels) of the image at the specified path.
A line symbol type, for rendering LineString and MultiLineString geometries.
Map canvas is a class for displaying all GIS data types on a canvas.
double scale() const
Returns the last reported scale of the canvas.
Base class for all map layer types.
A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas.
QgsPointXY mapPoint() const
mapPoint returns the point in coordinates
QgsPointXY snapPoint()
snapPoint will snap the points using the map canvas snapping utils configuration
A marker symbol type, for rendering Point and MultiPoint geometries.
A class to represent a 2D point.
QPointF toQPointF() const
Converts a point to a QPointF.
Point geometry type, with support for z-dimension and m-values.
static QgsProject * instance()
Returns the QgsProject singleton instance.
QgsSymbol * recentSymbol(const QString &identifier) const
Returns a copy of the recently used symbol with the specified identifier, or nullptr if no symbol wit...
A rectangle specified with double values.
A class for drawing transient features (e.g.
void setWidth(double width)
Sets the width of the line.
void reset(Qgis::GeometryType geometryType=Qgis::GeometryType::Line)
Clears all the geometries in this rubberband.
void setStrokeColor(const QColor &color)
Sets the stroke color for the rubberband.
void setLineStyle(Qt::PenStyle penStyle)
Sets the style of the line.
void setFillColor(const QColor &color)
Sets the fill color for the rubberband.
void addPoint(const QgsPointXY &p, bool doUpdate=true, int geometryIndex=0, int ringIndex=0)
Adds a vertex to the rubberband and update canvas.
T value(const QString &dynamicKeyPart=QString()) const
Returns settings value.
bool setValue(const T &value, const QString &dynamicKeyPart=QString()) const
Set settings value.
static const QgsSettingsEntryDouble * settingsDigitizingLineColorAlphaScale
Settings entry digitizing line color alpha scale.
static QgsTextFormat defaultTextFormatForProject(QgsProject *project, QgsStyle::TextFormatContext context=QgsStyle::TextFormatContext::Labeling)
Returns the default text format to use for new text based objects for the specified project,...
@ Labeling
Text format used in labeling.
QSizeF svgViewboxSize(const QString &path, double size, const QColor &fill, const QColor &stroke, double strokeWidth, double widthScaleFactor, double fixedAspectRatio=0, bool blocking=false, const QMap< QString, QString > ¶meters=QMap< QString, QString >())
Calculates the viewbox size of a (possibly cached) SVG file.
static QgsSymbol * defaultSymbol(Qgis::GeometryType geomType)
Returns a new default symbol for the specified geometry type.
Container for all settings relating to text rendering.
void setAllowHtmlFormatting(bool allow)
Sets whether text should be treated as a HTML document and HTML tags should be used for formatting th...
#define BUILTIN_UNREACHABLE