QGIS API Documentation 4.3.0-Master (6402a64e93b)
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
18#include "qgsannotationlayer.h"
19#include "qgsmapcanvas.h"
23
24#include <QComboBox>
25
26#include "moc_qgsannotationitemwidget.cpp"
27
31
33{
34 return setNewItem( item );
35}
36
38{
39 comboBox->addItem( tr( "Ignore Map Rotation" ), QVariant::fromValue( Qgis::SymbolRotationMode::IgnoreMapRotation ) );
40 comboBox->addItem( tr( "Rotate With Map" ), QVariant::fromValue( Qgis::SymbolRotationMode::RespectMapRotation ) );
41}
42
47
52
54{
55 mItemId = id;
56}
57
59{
60 return mItemId;
61}
62
67
72
75
80
82{
83 QgsMapCanvas *canvas = mContext.mapCanvas();
84 if ( !canvas )
85 return nullptr;
86
87 QString layerId;
88 if ( const QgsAnnotationLayer *layer = mLayer.data() )
89 {
90 layerId = layer->id();
91 }
92 if ( layerId.isEmpty() )
93 return nullptr;
94
95 const QgsRenderedItemResults *renderedItemResults = canvas->renderedItemResults( false );
96 if ( !renderedItemResults )
97 {
98 return nullptr;
99 }
100
101 const QList<QgsRenderedItemDetails *> items = renderedItemResults->renderedItems();
102 const QString annotationId = mItemId;
103 auto it = std::find_if( items.begin(), items.end(), [layerId, annotationId]( const QgsRenderedItemDetails *item ) {
104 if ( const QgsRenderedAnnotationItemDetails *annotationItem = dynamic_cast<const QgsRenderedAnnotationItemDetails *>( item ) )
105 {
106 if ( annotationItem->itemId() == annotationId && annotationItem->layerId() == layerId )
107 return true;
108 }
109 return false;
110 } );
111 if ( it != items.end() )
112 {
113 return dynamic_cast<const QgsRenderedAnnotationItemDetails *>( *it );
114 }
115 return nullptr;
116}
@ RespectMapRotation
Entity is rotated along with the map.
Definition qgis.h:849
@ IgnoreMapRotation
Entity ignores map rotation.
Definition qgis.h:850
QgsAnnotationItemBaseWidget(QWidget *parent)
Constructor for QgsAnnotationItemBaseWidget.
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.
static void populateRotationModeComboBox(QComboBox *comboBox)
Populates a comboBox with the available options for rendering an item with respect to the rotation of...
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.
QPointer< QgsAnnotationLayer > mLayer
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...
QgsPanelWidget(QWidget *parent=nullptr)
Base class for any widget that can be shown as an 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,...