QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
gui
annotations
qgsannotationmaptool.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgsmaptoolannotation.cpp
3
----------------
4
copyright : (C) 2025 by Mathieu Pellerin
5
email : mathieu at opengis dot ch
6
***************************************************************************/
7
8
/***************************************************************************
9
* *
10
* This program is free software; you can redistribute it and/or modify *
11
* it under the terms of the GNU General Public License as published by *
12
* the Free Software Foundation; either version 2 of the License, or *
13
* (at your option) any later version. *
14
* *
15
***************************************************************************/
16
17
#include "
qgsannotationmaptool.h
"
18
19
#include "
qgsannotationitem.h
"
20
#include "
qgsannotationlayer.h
"
21
#include "
qgsmapcanvas.h
"
22
#include "
qgsmaptoolselectannotationmousehandles.h
"
23
#include "
qgsproject.h
"
24
#include "
qgsrenderedannotationitemdetails.h
"
25
#include "
qgsrendereditemdetails.h
"
26
#include "
qgsrendereditemresults.h
"
27
28
#include "moc_qgsannotationmaptool.cpp"
29
30
QgsAnnotationMapTool::QgsAnnotationMapTool
(
QgsMapCanvas
*
canvas
,
QgsAdvancedDigitizingDockWidget
*
cadDockWidget
)
31
:
QgsMapToolAdvancedDigitizing
(
canvas
,
cadDockWidget
)
32
{}
33
34
const
QgsRenderedAnnotationItemDetails
*
QgsAnnotationMapTool::findClosestItemToPoint
(
const
QgsPointXY
&mapPoint,
const
QList<const QgsRenderedAnnotationItemDetails *> &items,
QgsRectangle
&bounds )
35
{
36
const
QgsRenderedAnnotationItemDetails
*closestItem =
nullptr
;
37
double
closestItemDistance = std::numeric_limits<double>::max();
38
double
closestItemArea = std::numeric_limits<double>::max();
39
40
for
(
const
QgsRenderedAnnotationItemDetails
*item : items )
41
{
42
const
QgsAnnotationItem
*annotationItem =
annotationItemFromId
( item->layerId(), item->itemId() );
43
if
( !annotationItem )
44
continue
;
45
46
const
QgsRectangle
itemBounds = item->boundingBox();
47
const
double
itemDistance = itemBounds.
contains
( mapPoint ) ? 0 : itemBounds.
distance
( mapPoint );
48
if
( !closestItem || itemDistance < closestItemDistance || ( itemDistance == closestItemDistance && itemBounds.
area
() < closestItemArea ) )
49
{
50
closestItem = item;
51
closestItemDistance = itemDistance;
52
closestItemArea = itemBounds.
area
();
53
bounds = itemBounds;
54
}
55
}
56
return
closestItem;
57
}
58
59
QgsAnnotationLayer
*
QgsAnnotationMapTool::annotationLayerFromId
(
const
QString &layerId )
60
{
61
QgsAnnotationLayer
*
layer
= qobject_cast<QgsAnnotationLayer *>(
QgsProject::instance
()->mapLayer( layerId ) );
62
if
( !
layer
&& layerId ==
QgsProject::instance
()->mainAnnotationLayer()->
id
() )
63
{
64
layer
=
QgsProject::instance
()->
mainAnnotationLayer
();
65
}
66
return
layer
;
67
}
68
69
QgsAnnotationItem
*
QgsAnnotationMapTool::annotationItemFromId
(
const
QString &layerId,
const
QString &itemId )
70
{
71
QgsAnnotationLayer
*
layer
=
annotationLayerFromId
( layerId );
72
return
layer
?
layer
->item( itemId ) :
nullptr
;
73
}
QgsAdvancedDigitizingDockWidget
A dockable widget used to handle the CAD tools on top of a selection of map tools.
Definition
qgsadvanceddigitizingdockwidget.h:55
QgsAnnotationItem
Abstract base class for annotation items which are drawn with QgsAnnotationLayers.
Definition
qgsannotationitem.h:49
QgsAnnotationLayer
Represents a map layer containing a set of georeferenced annotations, e.g.
Definition
qgsannotationlayer.h:52
QgsAnnotationMapTool::annotationLayerFromId
QgsAnnotationLayer * annotationLayerFromId(const QString &layerId)
Returns the annotation layer matching a given ID.
Definition
qgsannotationmaptool.cpp:59
QgsAnnotationMapTool::QgsAnnotationMapTool
QgsAnnotationMapTool(QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget)
Constructor for QgsAnnotationMapTool.
Definition
qgsannotationmaptool.cpp:30
QgsAnnotationMapTool::findClosestItemToPoint
const QgsRenderedAnnotationItemDetails * findClosestItemToPoint(const QgsPointXY &mapPoint, const QList< const QgsRenderedAnnotationItemDetails * > &items, QgsRectangle &bounds)
Returns the closest item from a list of annotation items to a given map point.
Definition
qgsannotationmaptool.cpp:34
QgsAnnotationMapTool::annotationItemFromId
QgsAnnotationItem * annotationItemFromId(const QString &layerId, const QString &itemId)
Returns the annotation item matching a given pair of layer and item IDs.
Definition
qgsannotationmaptool.cpp:69
QgsMapToolAdvancedDigitizing::layer
virtual QgsMapLayer * layer() const
Returns the layer associated with the map tool.
Definition
qgsmaptooladvanceddigitizing.cpp:155
QgsMapToolAdvancedDigitizing::cadDockWidget
QgsAdvancedDigitizingDockWidget * cadDockWidget() const
Definition
qgsmaptooladvanceddigitizing.h:70
QgsMapToolAdvancedDigitizing::QgsMapToolAdvancedDigitizing
QgsMapToolAdvancedDigitizing(QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget)
Creates an advanced digitizing maptool.
Definition
qgsmaptooladvanceddigitizing.cpp:36
QgsMapTool::canvas
QgsMapCanvas * canvas() const
returns pointer to the tool's map canvas
Definition
qgsmaptool.cpp:236
QgsMapTool::QgsMapCanvas
friend class QgsMapCanvas
Definition
qgsmaptool.h:423
QgsPointXY
Represents a 2D point.
Definition
qgspointxy.h:62
QgsProject::instance
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition
qgsproject.cpp:490
QgsProject::mainAnnotationLayer
QgsAnnotationLayer * mainAnnotationLayer()
Returns the main annotation layer associated with the project.
Definition
qgsproject.cpp:5037
QgsRectangle
A rectangle specified with double values.
Definition
qgsrectangle.h:47
QgsRectangle::contains
bool contains(const QgsRectangle &rect) const
Returns true when rectangle contains other rectangle.
Definition
qgsrectangle.h:495
QgsRectangle::area
double area
Definition
qgsrectangle.h:56
QgsRectangle::distance
double distance(const QgsPointXY &point) const
Returns the distance from point to the nearest point on the boundary of the rectangle.
Definition
qgsrectangle.h:566
QgsRenderedAnnotationItemDetails
Contains information about a rendered annotation item.
Definition
qgsrenderedannotationitemdetails.h:34
qgsannotationitem.h
qgsannotationlayer.h
qgsannotationmaptool.h
qgsmapcanvas.h
qgsmaptoolselectannotationmousehandles.h
qgsproject.h
qgsrenderedannotationitemdetails.h
qgsrendereditemdetails.h
qgsrendereditemresults.h
Generated on
for QGIS API Documentation by
1.17.0