QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
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 "qgsmapcanvas.h"
21#include "qgsannotationlayer.h"
22
28
30{
31 return setNewItem( item );
32}
33
38
43
45{
46 mItemId = id;
47}
48
50{
51 return mItemId;
52}
53
58
63
67
72
74{
76 if ( !canvas )
77 return nullptr;
78
79 QString layerId;
80 if ( const QgsAnnotationLayer *layer = mLayer.data() )
81 {
82 layerId = layer->id();
83 }
84 if ( layerId.isEmpty() )
85 return nullptr;
86
87 const QgsRenderedItemResults *renderedItemResults = canvas->renderedItemResults( false );
88 if ( !renderedItemResults )
89 {
90 return nullptr;
91 }
92
93 const QList<QgsRenderedItemDetails *> items = renderedItemResults->renderedItems();
94 const QString annotationId = mItemId;
95 auto it = std::find_if( items.begin(), items.end(), [layerId, annotationId]( const QgsRenderedItemDetails * item )
96 {
97 if ( const QgsRenderedAnnotationItemDetails *annotationItem = dynamic_cast< const QgsRenderedAnnotationItemDetails *>( item ) )
98 {
99 if ( annotationItem->itemId() == annotationId && annotationItem->layerId() == layerId )
100 return true;
101 }
102 return false;
103 } );
104 if ( it != items.end() )
105 {
106 return dynamic_cast< const QgsRenderedAnnotationItemDetails *>( *it );
107 }
108 return nullptr;
109}
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.