QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
qgsannotationitemwidget.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsannotationitemwidget.cpp
3 ------------------------
4 Date : September 2021
5 Copyright : (C) 2021 Nyall Dawson
6 Email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
17#include "moc_qgsannotationitemwidget.cpp"
18#include "qgsmapcanvas.h"
22#include "qgsannotationlayer.h"
23
29
31{
32 return setNewItem( item );
33}
34
39
44
46{
47 mItemId = id;
48}
49
51{
52 return mItemId;
53}
54
59
64
68
73
75{
77 if ( !canvas )
78 return nullptr;
79
80 QString layerId;
81 if ( const QgsAnnotationLayer *layer = mLayer.data() )
82 {
83 layerId = layer->id();
84 }
85 if ( layerId.isEmpty() )
86 return nullptr;
87
88 const QgsRenderedItemResults *renderedItemResults = canvas->renderedItemResults( false );
89 if ( !renderedItemResults )
90 {
91 return nullptr;
92 }
93
94 const QList<QgsRenderedItemDetails *> items = renderedItemResults->renderedItems();
95 const QString annotationId = mItemId;
96 auto it = std::find_if( items.begin(), items.end(), [layerId, annotationId]( const QgsRenderedItemDetails * item )
97 {
98 if ( const QgsRenderedAnnotationItemDetails *annotationItem = dynamic_cast< const QgsRenderedAnnotationItemDetails *>( item ) )
99 {
100 if ( annotationItem->itemId() == annotationId && annotationItem->layerId() == layerId )
101 return true;
102 }
103 return false;
104 } );
105 if ( it != items.end() )
106 {
107 return dynamic_cast< const QgsRenderedAnnotationItemDetails *>( *it );
108 }
109 return nullptr;
110}
QgsAnnotationItemBaseWidget(QWidget *parent)
Constructor for QgsAnnotationItemBaseWidget.
QPointer< QgsAnnotationLayer > mLayer
QgsSymbolWidgetContext context() const
Returns the context in which the widget is shown, e.g., the associated map canvas and expression cont...
virtual void focusDefaultWidget()
Focuses the default widget for the page.
QString itemId() const
Returns the associated annotation item id.
QgsSymbolWidgetContext mContext
Context in which widget is shown.
virtual void setContext(const QgsSymbolWidgetContext &context)
Sets the context in which the widget is shown, e.g., the associated map canvas and expression context...
bool setItem(QgsAnnotationItem *item)
Sets the current item to show in the widget.
QgsAnnotationLayer * layer()
Returns the associated annotation map layer.
void setItemId(const QString &id)
Sets the associated annotation item id.
virtual bool setNewItem(QgsAnnotationItem *item)
Attempts to update the widget to show the properties for the specified item.
const QgsRenderedAnnotationItemDetails * renderedItemDetails()
Retrieve rendered annotation details for the associated annotation, if available.
virtual void setLayer(QgsAnnotationLayer *layer)
Sets the associated annotation map layer.
Abstract base class for annotation items which are drawn with QgsAnnotationLayers.
Represents a map layer containing a set of georeferenced annotations, e.g.
Map canvas is a class for displaying all GIS data types on a canvas.
const QgsRenderedItemResults * renderedItemResults(bool allowOutdatedResults=true) const
Gets access to the rendered item results (may be nullptr), which includes the results of rendering an...
QString id
Definition qgsmaplayer.h:79
Base class for any widget that can be shown as a inline panel.
Contains information about a rendered annotation item.
Base class for detailed information about a rendered item.
Stores collated details of rendered items during a map rendering operation.
QList< QgsRenderedItemDetails * > renderedItems() const
Returns a list of all rendered items.
Contains settings which reflect the context in which a symbol (or renderer) widget is shown,...
QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.