41#include <QImageReader>
52 mToolName = tr(
"Annotation tool" );
60QgsMapTool *QgsMapToolCaptureAnnotationItem::mapTool()
65QgsMapLayer *QgsMapToolCaptureAnnotationItem::layer()
const
67 return mHandler->targetLayer();
74 return SupportsCurves;
99 setUseSnappingIndicator(
true );
102QgsCreatePointTextItemMapTool::~QgsCreatePointTextItemMapTool() =
default;
104void QgsCreatePointTextItemMapTool::cadCanvasPressEvent(
QgsMapMouseEvent *event )
106 if ( event->button() != Qt::LeftButton )
109 const QgsPointXY layerPoint = toLayerCoordinates( mHandler->targetLayer(), event->
mapPoint() );
111 std::unique_ptr< QgsAnnotationPointTextItem > createdItem = std::make_unique< QgsAnnotationPointTextItem >( tr(
"Text" ), layerPoint );
112 createdItem->setAlignment( Qt::AlignLeft );
116 createdItem->setFormat( format );
118 createdItem->setUseSymbologyReferenceScale(
true );
119 createdItem->setSymbologyReferenceScale( canvas()->scale() );
120 mHandler->pushCreatedItem( createdItem.release() );
128QgsMapTool *QgsCreatePointTextItemMapTool::mapTool()
140 : QgsMapToolCaptureAnnotationItem( canvas, cadDockWidget, CapturePoint )
145void QgsCreateMarkerItemMapTool::cadCanvasReleaseEvent(
QgsMapMouseEvent *event )
147 if ( event->button() != Qt::LeftButton )
150 const QgsPointXY layerPoint = toLayerCoordinates( mHandler->targetLayer(), event->
mapPoint() );
151 std::unique_ptr< QgsAnnotationMarkerItem > createdItem = std::make_unique< QgsAnnotationMarkerItem >(
QgsPoint( layerPoint ) );
156 createdItem->setSymbol( markerSymbol.release() );
159 createdItem->setSymbologyReferenceScale( canvas()->scale() );
161 mHandler->pushCreatedItem( createdItem.release() );
165 cadDockWidget()->clearPoints();
173 : QgsMapToolCaptureAnnotationItem( canvas, cadDockWidget, CaptureLine )
178void QgsCreateLineItemMapTool::lineCaptured(
const QgsCurve *line )
185 if ( qgsgeometry_cast< QgsCurve * >( geometry.get() ) )
187 std::unique_ptr< QgsAnnotationLineItem > createdItem = std::make_unique< QgsAnnotationLineItem >( qgsgeometry_cast< QgsCurve * >( geometry.release() ) );
192 createdItem->setSymbol( lineSymbol.release() );
195 createdItem->setSymbologyReferenceScale( canvas()->scale() );
197 mHandler->pushCreatedItem( createdItem.release() );
206 : QgsMapToolCaptureAnnotationItem( canvas, cadDockWidget, CapturePolygon )
211void QgsCreatePolygonItemMapTool::polygonCaptured(
const QgsCurvePolygon *polygon )
217 if ( qgsgeometry_cast< QgsCurve * >( geometry.get() ) )
219 std::unique_ptr< QgsCurvePolygon > newPolygon = std::make_unique< QgsCurvePolygon >();
220 newPolygon->setExteriorRing( qgsgeometry_cast< QgsCurve * >( geometry.release() ) );
221 std::unique_ptr< QgsAnnotationPolygonItem > createdItem = std::make_unique< QgsAnnotationPolygonItem >( newPolygon.release() );
226 createdItem->setSymbol( fillSymbol.release() );
229 createdItem->setSymbologyReferenceScale( canvas()->scale() );
231 mHandler->pushCreatedItem( createdItem.release() );
240const QgsSettingsEntryString *QgsCreatePictureItemMapTool::settingLastSourceFolder =
new QgsSettingsEntryString( QStringLiteral(
"last-source-folder" ), sTreePicture, QString(), QStringLiteral(
"Last used folder for picture annotation source files" ) );
246 setUseSnappingIndicator(
true );
249void QgsCreatePictureItemMapTool::cadCanvasPressEvent(
QgsMapMouseEvent *event )
251 if ( event->button() == Qt::RightButton && mRubberBand )
254 cadDockWidget()->clearPoints();
258 if ( event->button() != Qt::LeftButton )
263 mFirstPoint =
event->snapPoint();
264 mRect.setRect( mFirstPoint.x(), mFirstPoint.y(), mFirstPoint.x(), mFirstPoint.y() );
267 mRubberBand->setWidth( digitizingStrokeWidth() );
268 QColor color = digitizingStrokeColor();
271 color.setAlphaF( color.alphaF() * alphaScale );
272 mRubberBand->setLineStyle( Qt::DotLine );
273 mRubberBand->setStrokeColor( color );
275 const QColor fillColor = digitizingFillColor();
276 mRubberBand->setFillColor( fillColor );
282 QStringList formatsFilter;
283 formatsFilter.append( QStringLiteral(
"*.svg" ) );
284 const QByteArrayList supportedFormats = QImageReader::supportedImageFormats();
285 for (
const auto &format : supportedFormats )
287 formatsFilter.append( QString( QStringLiteral(
"*.%1" ) ).arg( QString( format ) ) );
289 const QString dialogFilter = QStringLiteral(
"%1 (%2);;%3 (*.*)" ).arg( tr(
"Images" ), formatsFilter.join( QLatin1Char(
' ' ) ), tr(
"All files" ) );
290 const QString initialDir = settingLastSourceFolder->value();
291 const QString imagePath = QFileDialog::getOpenFileName(
nullptr, tr(
"Add Picture Annotation" ), initialDir.isEmpty() ? QDir::homePath() : initialDir, dialogFilter );
293 if ( imagePath.isEmpty() )
298 settingLastSourceFolder->setValue( QFileInfo( imagePath ).path() );
300 const QgsPointXY point1 = toLayerCoordinates( mHandler->targetLayer(), mFirstPoint );
301 const QgsPointXY point2 = toLayerCoordinates( mHandler->targetLayer(), event->
snapPoint() );
303 const QgsPointXY devicePoint1 = toCanvasCoordinates( mFirstPoint );
305 const double initialWidthPixels = std::abs( devicePoint1.
x() - devicePoint2.
x() );
306 const double initialHeightPixels = std::abs( devicePoint1.
y() - devicePoint2.
y() );
308 const QFileInfo pathInfo( imagePath );
312 if ( pathInfo.suffix().compare( QLatin1String(
"svg" ), Qt::CaseInsensitive ) == 0 )
323 cadDockWidget()->clearPoints();
325 std::unique_ptr< QgsAnnotationPictureItem > createdItem = std::make_unique< QgsAnnotationPictureItem >( format, imagePath,
QgsRectangle( point1, point2 ) );
326 if ( size.isValid() )
328 const double pixelsToMm = mCanvas->mapSettings().outputDpi() / 25.4;
329 if ( size.width() / size.height() > initialWidthPixels / initialHeightPixels )
331 createdItem->setFixedSize( QSizeF( initialWidthPixels / pixelsToMm, size.height() / size.width() * initialWidthPixels / pixelsToMm ) );
335 createdItem->setFixedSize( QSizeF( size.width() / size.height() * initialHeightPixels / pixelsToMm, initialHeightPixels / pixelsToMm ) );
340 mHandler->pushCreatedItem( createdItem.release() );
344void QgsCreatePictureItemMapTool::cadCanvasMoveEvent(
QgsMapMouseEvent *event )
349 const QgsPointXY mapPoint =
event->snapPoint();
350 mRect.setBottomRight( mapPoint.
toQPointF() );
353 mRubberBand->addPoint( mRect.bottomLeft(),
false );
354 mRubberBand->addPoint( mRect.bottomRight(),
false );
355 mRubberBand->addPoint( mRect.topRight(),
false );
356 mRubberBand->addPoint( mRect.topLeft(),
true );
359void QgsCreatePictureItemMapTool::keyPressEvent( QKeyEvent *event )
361 if ( event->key() == Qt::Key_Escape )
366 cadDockWidget()->clearPoints();
377QgsMapTool *QgsCreatePictureItemMapTool::mapTool()
392 setUseSnappingIndicator(
true );
395void QgsCreateRectangleTextItemMapTool::cadCanvasPressEvent(
QgsMapMouseEvent *event )
397 if ( event->button() == Qt::RightButton && mRubberBand )
400 cadDockWidget()->clearPoints();
404 if ( event->button() != Qt::LeftButton )
409 mFirstPoint =
event->snapPoint();
410 mRect.setRect( mFirstPoint.x(), mFirstPoint.y(), mFirstPoint.x(), mFirstPoint.y() );
413 mRubberBand->setWidth( digitizingStrokeWidth() );
414 QColor color = digitizingStrokeColor();
417 color.setAlphaF( color.alphaF() * alphaScale );
418 mRubberBand->setLineStyle( Qt::DotLine );
419 mRubberBand->setStrokeColor( color );
421 const QColor fillColor = digitizingFillColor();
422 mRubberBand->setFillColor( fillColor );
428 const QgsPointXY point1 = toLayerCoordinates( mHandler->targetLayer(), mFirstPoint );
429 const QgsPointXY point2 = toLayerCoordinates( mHandler->targetLayer(), event->
snapPoint() );
431 cadDockWidget()->clearPoints();
433 std::unique_ptr< QgsAnnotationRectangleTextItem > createdItem = std::make_unique< QgsAnnotationRectangleTextItem >( tr(
"Text" ),
QgsRectangle( point1, point2 ) );
438 createdItem->setFormat( format );
441 createdItem->setUseSymbologyReferenceScale(
true );
442 createdItem->setSymbologyReferenceScale( canvas()->scale() );
443 mHandler->pushCreatedItem( createdItem.release() );
447void QgsCreateRectangleTextItemMapTool::cadCanvasMoveEvent(
QgsMapMouseEvent *event )
452 const QgsPointXY mapPoint =
event->snapPoint();
453 mRect.setBottomRight( mapPoint.
toQPointF() );
456 mRubberBand->addPoint( mRect.bottomLeft(),
false );
457 mRubberBand->addPoint( mRect.bottomRight(),
false );
458 mRubberBand->addPoint( mRect.topRight(),
false );
459 mRubberBand->addPoint( mRect.topLeft(),
true );
462void QgsCreateRectangleTextItemMapTool::keyPressEvent( QKeyEvent *event )
464 if ( event->key() == Qt::Key_Escape )
469 cadDockWidget()->clearPoints();
480QgsMapTool *QgsCreateRectangleTextItemMapTool::mapTool()
491 : QgsMapToolCaptureAnnotationItem( canvas, cadDockWidget, CaptureLine )
496void QgsCreateLineTextItemMapTool::lineCaptured(
const QgsCurve *line )
503 if ( qgsgeometry_cast< QgsCurve * >( geometry.get() ) )
505 std::unique_ptr< QgsAnnotationLineTextItem > createdItem = std::make_unique< QgsAnnotationLineTextItem >( tr(
"Text" ), qgsgeometry_cast< QgsCurve * >( geometry.release() ) );
514 createdItem->setFormat( format );
517 createdItem->setUseSymbologyReferenceScale(
true );
518 createdItem->setSymbologyReferenceScale( canvas()->scale() );
519 mHandler->pushCreatedItem( createdItem.release() );
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...
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.
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.
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.
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