42#include <QImageReader>
45#include "moc_qgscreateannotationitemmaptool_impl.cpp"
47using namespace Qt::StringLiterals;
58 mToolName = tr(
"Annotation tool" );
107 setUseSnappingIndicator(
true );
114 if ( event->button() != Qt::LeftButton )
119 auto createdItem = std::make_unique<QgsAnnotationPointTextItem>( tr(
"Text" ), layerPoint );
120 createdItem->setAlignment( Qt::AlignLeft );
124 createdItem->setFormat( format );
126 createdItem->setUseSymbologyReferenceScale(
true );
127 createdItem->setSymbologyReferenceScale(
canvas()->scale() );
128 mHandler->pushCreatedItem( createdItem.release() );
154 if ( event->button() != Qt::LeftButton )
158 auto createdItem = std::make_unique<QgsAnnotationMarkerItem>( QgsPoint( layerPoint ) );
163 createdItem->setSymbol( markerSymbol.release() );
166 createdItem->setSymbologyReferenceScale(
canvas()->scale() );
168 mHandler->pushCreatedItem( createdItem.release() );
185void QgsCreateLineItemMapTool::lineCaptured(
const QgsCurve *line )
194 auto createdItem = std::make_unique<QgsAnnotationLineItem>( qgis::down_cast<QgsCurve *>( geometry.release() ) );
199 createdItem->setSymbol( lineSymbol.release() );
202 createdItem->setSymbologyReferenceScale(
canvas()->scale() );
204 mHandler->pushCreatedItem( createdItem.release() );
218void QgsCreatePolygonItemMapTool::polygonCaptured(
const QgsCurvePolygon *polygon )
226 auto newPolygon = std::make_unique<QgsCurvePolygon>();
227 newPolygon->setExteriorRing( qgis::down_cast<QgsCurve *>( geometry.release() ) );
228 auto createdItem = std::make_unique<QgsAnnotationPolygonItem>( newPolygon.release() );
233 createdItem->setSymbol( fillSymbol.release() );
236 createdItem->setSymbologyReferenceScale(
canvas()->scale() );
238 mHandler->pushCreatedItem( createdItem.release() );
248 =
new QgsSettingsEntryString( u
"last-source-folder"_s, sTreePicture, QString(), u
"Last used folder for picture annotation source files"_s );
254 setUseSnappingIndicator(
true );
259 if ( event->button() == Qt::RightButton && mRubberBand )
266 if ( event->button() != Qt::LeftButton )
271 mFirstPoint =
event->snapPoint();
272 mRect.setRect( mFirstPoint.x(), mFirstPoint.y(), mFirstPoint.x(), mFirstPoint.y() );
279 color.setAlphaF( color.alphaF() * alphaScale );
280 mRubberBand->setLineStyle( Qt::DotLine );
281 mRubberBand->setStrokeColor( color );
284 mRubberBand->setFillColor( fillColor );
290 QStringList formatsFilter;
291 formatsFilter.append( u
"*.svg"_s );
292 const QByteArrayList supportedFormats = QImageReader::supportedImageFormats();
293 for (
const auto &format : supportedFormats )
295 formatsFilter.append( QString( u
"*.%1"_s ).arg( QString( format ) ) );
297 const QString dialogFilter = u
"%1 (%2);;%3 (*.*)"_s.arg( tr(
"Images" ), formatsFilter.join(
' '_L1 ), tr(
"All files" ) );
299 const QString imagePath = QFileDialog::getOpenFileName(
nullptr, tr(
"Add Picture Annotation" ), initialDir.isEmpty() ? QDir::homePath() : initialDir, dialogFilter );
301 if ( imagePath.isEmpty() )
313 const double initialWidthPixels = std::abs( devicePoint1.
x() - devicePoint2.
x() );
314 const double initialHeightPixels = std::abs( devicePoint1.
y() - devicePoint2.
y() );
316 const QFileInfo pathInfo( imagePath );
320 if ( pathInfo.suffix().compare(
"svg"_L1, Qt::CaseInsensitive ) == 0 )
333 auto createdItem = std::make_unique<QgsAnnotationPictureItem>( format, imagePath, QgsRectangle( point1, point2 ) );
334 if ( size.isValid() )
336 const double pixelsToMm =
mCanvas->mapSettings().outputDpi() / 25.4;
337 if ( size.width() / size.height() > initialWidthPixels / initialHeightPixels )
339 createdItem->setFixedSize( QSizeF( initialWidthPixels / pixelsToMm, size.height() / size.width() * initialWidthPixels / pixelsToMm ) );
343 createdItem->setFixedSize( QSizeF( size.width() / size.height() * initialHeightPixels / pixelsToMm, initialHeightPixels / pixelsToMm ) );
348 mHandler->pushCreatedItem( createdItem.release() );
357 const QgsPointXY mapPoint =
event->snapPoint();
358 mRect.setBottomRight( mapPoint.
toQPointF() );
361 mRubberBand->addPoint( mRect.bottomLeft(),
false );
362 mRubberBand->addPoint( mRect.bottomRight(),
false );
363 mRubberBand->addPoint( mRect.topRight(),
false );
364 mRubberBand->addPoint( mRect.topLeft(),
true );
369 if ( event->key() == Qt::Key_Escape )
399 setUseSnappingIndicator(
true );
404 if ( event->button() == Qt::RightButton && mRubberBand )
411 if ( event->button() != Qt::LeftButton )
416 mFirstPoint =
event->snapPoint();
417 mRect.setRect( mFirstPoint.x(), mFirstPoint.y(), mFirstPoint.x(), mFirstPoint.y() );
424 color.setAlphaF( color.alphaF() * alphaScale );
425 mRubberBand->setLineStyle( Qt::DotLine );
426 mRubberBand->setStrokeColor( color );
429 mRubberBand->setFillColor( fillColor );
440 auto createdItem = std::make_unique<QgsAnnotationRectangleTextItem>( tr(
"Text" ), QgsRectangle( point1, point2 ) );
445 createdItem->setFormat( format );
448 createdItem->setUseSymbologyReferenceScale(
true );
449 createdItem->setSymbologyReferenceScale(
canvas()->scale() );
450 mHandler->pushCreatedItem( createdItem.release() );
459 const QgsPointXY mapPoint =
event->snapPoint();
460 mRect.setBottomRight( mapPoint.
toQPointF() );
463 mRubberBand->addPoint( mRect.bottomLeft(),
false );
464 mRubberBand->addPoint( mRect.bottomRight(),
false );
465 mRubberBand->addPoint( mRect.topRight(),
false );
466 mRubberBand->addPoint( mRect.topLeft(),
true );
471 if ( event->key() == Qt::Key_Escape )
503void QgsCreateLineTextItemMapTool::lineCaptured(
const QgsCurve *line )
512 auto createdItem = std::make_unique<QgsAnnotationLineTextItem>( tr(
"Text" ), qgis::down_cast<QgsCurve *>( geometry.release() ) );
521 createdItem->setFormat( format );
524 createdItem->setUseSymbologyReferenceScale(
true );
525 createdItem->setSymbologyReferenceScale(
canvas()->scale() );
526 mHandler->pushCreatedItem( createdItem.release() );
CaptureTechnique
Capture technique.
@ NurbsCurve
Digitizes NURBS curves with control points (curve is attracted to but does not pass through control p...
@ 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).
@ PolyBezier
Digitizes poly-Bézier curves with anchors and tangent handles (curve passes through anchor points).
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.
QSize originalSize(const QString &path, bool blocking=false) const
Returns the original size (in pixels) of the image at the specified path.
Map canvas is a class for displaying all GIS data types on a canvas.
Base class for all map layer types.
A mouse event which is the result of a user interaction with 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
QPointF toQPointF() const
Converts a point to a QPointF.
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...
T value(const QString &dynamicKeyPart=QString()) const
Returns 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.
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
T qgsgeometry_cast(QgsAbstractGeometry *geom)