QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
qgsannotationitemguiregistry.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsannotationitemguiregistry.h
3 --------------------------
4 begin : September 2021
5 copyright : (C) 2021 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
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#ifndef QGSANNOTATIONITEMGUIREGISTRY_H
17#define QGSANNOTATIONITEMGUIREGISTRY_H
18
19#include "qgis_gui.h"
20#include "qgis_sip.h"
21#include "qgsapplication.h"
22#include "qgspathresolver.h"
24#include "qgis.h"
25#include <QIcon>
26#include <functional>
27
32class QgsMapCanvas;
34
46{
47 public:
55 QgsAnnotationItemAbstractGuiMetadata( const QString &type, const QString &visibleName, const QString &groupId = QString(), Qgis::AnnotationItemGuiFlags flags = Qgis::AnnotationItemGuiFlags() )
56 : mType( type )
57 , mGroupId( groupId )
58 , mName( visibleName )
59 , mFlags( flags )
60 {}
61
63
67 QString type() const { return mType; }
68
72 Qgis::AnnotationItemGuiFlags flags() const { return mFlags; }
73
77 QString groupId() const { return mGroupId; }
78
82 QString visibleName() const { return mName; }
83
87 virtual QIcon creationIcon() const;
88
89 /*
90 * IMPORTANT: While it seems like /Factory/ would be the correct annotations here, that's not
91 * the case.
92 * As per Phil Thomson's advice on https://www.riverbankcomputing.com/pipermail/pyqt/2017-July/039450.html:
93 *
94 * "
95 * /Factory/ is used when the instance returned is guaranteed to be new to Python.
96 * In this case it isn't because it has already been seen when being returned by QgsProcessingAlgorithm::createInstance()
97 * (However for a different sub-class implemented in C++ then it would be the first time it was seen
98 * by Python so the /Factory/ on create() would be correct.)
99 *
100 * You might try using /TransferBack/ on create() instead - that might be the best compromise.
101 * "
102 */
103
107 virtual QgsAnnotationItemBaseWidget *createItemWidget( QgsAnnotationItem *item ) SIP_TRANSFERBACK;
108
115
119 virtual QgsAnnotationItem *createItem() SIP_TRANSFERBACK;
120
127 virtual void newItemAddedToLayer( QgsAnnotationItem *item, QgsAnnotationLayer *layer );
128
129 private:
130 QString mType;
131 QString mGroupId;
132 QString mName;
133 Qgis::AnnotationItemGuiFlags mFlags;
134};
135
138
141
144
145#ifndef SIP_RUN
146
154{
155 public:
165 QgsAnnotationItemGuiMetadata( const QString &type, const QString &visibleName, const QIcon &creationIcon, const QgsAnnotationItemWidgetFunc &pfWidget = nullptr, const QString &groupId = QString(), Qgis::AnnotationItemGuiFlags flags = Qgis::AnnotationItemGuiFlags(), const QgsAnnotationItemCreateFunc &pfCreateFunc = nullptr, const QgsCreateAnnotationItemMapToolFunc &pfCreateMapToolFunc = nullptr )
166 : QgsAnnotationItemAbstractGuiMetadata( type, visibleName, groupId, flags )
167 , mIcon( creationIcon )
168 , mWidgetFunc( pfWidget )
169 , mCreateFunc( pfCreateFunc )
170 , mCreateMapToolFunc( pfCreateMapToolFunc )
171 {}
172
177 QgsAnnotationItemWidgetFunc widgetFunction() const { return mWidgetFunc; }
178
183 void setWidgetFunction( const QgsAnnotationItemWidgetFunc &function ) { mWidgetFunc = function; }
184
189 QgsCreateAnnotationItemMapToolFunc createMapToolFunction() const { return mCreateMapToolFunc; }
190
195 void setCreateMapToolFunction( const QgsCreateAnnotationItemMapToolFunc &function ) { mCreateMapToolFunc = function; }
196
201 QgsAnnotationItemCreateFunc itemCreationFunction() const { return mCreateFunc; }
202
207 void setItemCreationFunction( const QgsAnnotationItemCreateFunc &function ) { mCreateFunc = function; }
208
213 QgsAnnotationItemAddedToLayerFunc itemAddToLayerFunction() const { return mAddedToLayerFunc; }
214
219 void setItemAddedToLayerFunction( const QgsAnnotationItemAddedToLayerFunc &function ) { mAddedToLayerFunc = function; }
220
221 QIcon creationIcon() const override;
222 QgsAnnotationItemBaseWidget *createItemWidget( QgsAnnotationItem *item ) override;
223
224 QgsAnnotationItem *createItem() override;
225 void newItemAddedToLayer( QgsAnnotationItem *item, QgsAnnotationLayer *layer ) override;
226 QgsCreateAnnotationItemMapToolInterface *createMapTool( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget ) override;
227
228 protected:
229 QIcon mIcon;
230 QgsAnnotationItemWidgetFunc mWidgetFunc = nullptr;
231 QgsAnnotationItemCreateFunc mCreateFunc = nullptr;
232 QgsCreateAnnotationItemMapToolFunc mCreateMapToolFunc = nullptr;
233 QgsAnnotationItemAddedToLayerFunc mAddedToLayerFunc = nullptr;
234};
235
236#endif
237
251{
252 public:
256 QgsAnnotationItemGuiGroup( const QString &id = QString(), const QString &name = QString(), const QIcon &icon = QIcon() )
257 : id( id )
258 , name( name )
259 , icon( icon )
260 {}
261
265 QString id;
266
270 QString name;
271
275 QIcon icon;
276};
277
278
292class GUI_EXPORT QgsAnnotationItemGuiRegistry : public QObject
293{
294 Q_OBJECT
295
296 public:
303 QgsAnnotationItemGuiRegistry( QObject *parent = nullptr );
304
306
309
314 QgsAnnotationItemAbstractGuiMetadata *itemMetadata( int metadataId ) const;
315
324 int metadataIdForItemType( const QString &type ) const;
325
329 bool addAnnotationItemGuiMetadata( QgsAnnotationItemAbstractGuiMetadata *metadata SIP_TRANSFER );
330
340 bool addItemGroup( const QgsAnnotationItemGuiGroup &group );
341
346 const QgsAnnotationItemGuiGroup &itemGroup( const QString &id );
347
348 /*
349 * IMPORTANT: While it seems like /Factory/ would be the correct annotations here, that's not
350 * the case.
351 * As per Phil Thomson's advice on https://www.riverbankcomputing.com/pipermail/pyqt/2017-July/039450.html:
352 *
353 * "
354 * /Factory/ is used when the instance returned is guaranteed to be new to Python.
355 * In this case it isn't because it has already been seen when being returned by QgsProcessingAlgorithm::createInstance()
356 * (However for a different sub-class implemented in C++ then it would be the first time it was seen
357 * by Python so the /Factory/ on create() would be correct.)
358 *
359 * You might try using /TransferBack/ on create() instead - that might be the best compromise.
360 * "
361 */
362
366 QgsAnnotationItem *createItem( int metadataId ) const SIP_TRANSFERBACK;
367
374 void newItemAddedToLayer( int metadataId, QgsAnnotationItem *item, QgsAnnotationLayer *layer );
375
376 /*
377 * IMPORTANT: While it seems like /Factory/ would be the correct annotations here, that's not
378 * the case.
379 * As per Phil Thomson's advice on https://www.riverbankcomputing.com/pipermail/pyqt/2017-July/039450.html:
380 *
381 * "
382 * /Factory/ is used when the instance returned is guaranteed to be new to Python.
383 * In this case it isn't because it has already been seen when being returned by QgsProcessingAlgorithm::createInstance()
384 * (However for a different sub-class implemented in C++ then it would be the first time it was seen
385 * by Python so the /Factory/ on create() would be correct.)
386 *
387 * You might try using /TransferBack/ on create() instead - that might be the best compromise.
388 * "
389 */
390
394 QgsAnnotationItemBaseWidget *createItemWidget( QgsAnnotationItem *item ) const SIP_TRANSFERBACK;
395
399 QList<int> itemMetadataIds() const;
400
404 void addDefaultItems();
405
406 signals:
407
412 void typeAdded( int metadataId );
413
414 private:
415#ifdef SIP_RUN
417#endif
418
419 QMap<int, QgsAnnotationItemAbstractGuiMetadata *> mMetadata;
420
421 QMap<QString, QgsAnnotationItemGuiGroup> mItemGroups;
422};
423
424#endif //QGSANNOTATIONITEMGUIREGISTRY_H
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
QFlags< AnnotationItemGuiFlag > AnnotationItemGuiFlags
Annotation item GUI flags.
Definition qgis.h:2392
The QgsAdvancedDigitizingDockWidget class is a dockable widget used to handle the CAD tools on top of...
Stores GUI metadata about one annotation item class.
QString groupId() const
Returns the item group ID, if set.
virtual ~QgsAnnotationItemAbstractGuiMetadata()=default
QString type() const
Returns the unique item type code for the annotation item class.
QgsAnnotationItemAbstractGuiMetadata(const QString &type, const QString &visibleName, const QString &groupId=QString(), Qgis::AnnotationItemGuiFlags flags=Qgis::AnnotationItemGuiFlags())
Constructor for QgsAnnotationItemAbstractGuiMetadata with the specified class type.
QString visibleName() const
Returns a translated, user visible name identifying the corresponding annotation item.
Qgis::AnnotationItemGuiFlags flags() const
Returns item flags.
A base class for property widgets for annotation items.
Stores GUI metadata about a group of annotation item classes.
QgsAnnotationItemGuiGroup(const QString &id=QString(), const QString &name=QString(), const QIcon &icon=QIcon())
Constructor for QgsAnnotationItemGuiGroup.
QString name
Translated group name.
QString id
Unique (untranslated) group ID string.
Convenience metadata class that uses static functions to handle annotation item GUI behavior.
void setCreateMapToolFunction(const QgsCreateAnnotationItemMapToolFunc &function)
Sets the classes' create new item map tool creation function.
QgsAnnotationItemGuiMetadata(const QString &type, const QString &visibleName, const QIcon &creationIcon, const QgsAnnotationItemWidgetFunc &pfWidget=nullptr, const QString &groupId=QString(), Qgis::AnnotationItemGuiFlags flags=Qgis::AnnotationItemGuiFlags(), const QgsAnnotationItemCreateFunc &pfCreateFunc=nullptr, const QgsCreateAnnotationItemMapToolFunc &pfCreateMapToolFunc=nullptr)
Constructor for QgsAnnotationItemGuiMetadata with the specified class type and creationIcon,...
QgsAnnotationItemCreateFunc itemCreationFunction() const
Returns the classes' item creation function.
QgsCreateAnnotationItemMapToolFunc createMapToolFunction() const
Returns the classes' create new item map tool creation function.
QgsAnnotationItemWidgetFunc widgetFunction() const
Returns the classes' configuration widget creation function.
void setItemCreationFunction(const QgsAnnotationItemCreateFunc &function)
Sets the classes' item creation function.
void setWidgetFunction(const QgsAnnotationItemWidgetFunc &function)
Sets the classes' configuration widget creation function.
QgsAnnotationItemAddedToLayerFunc itemAddToLayerFunction() const
Returns the classes' item added to layer function.
void setItemAddedToLayerFunction(const QgsAnnotationItemAddedToLayerFunc &function)
Sets the classes' item creation function.
Registry of available annotation item GUI behavior.
QgsAnnotationItemGuiRegistry(const QgsAnnotationItemGuiRegistry &rh)=delete
void typeAdded(int metadataId)
Emitted whenever a new item type is added to the registry, with the specified metadataId.
QgsAnnotationItemGuiRegistry & operator=(const QgsAnnotationItemGuiRegistry &rh)=delete
Abstract base class for annotation items which are drawn with QgsAnnotationLayers.
Represents a map layer containing a set of georeferenced annotations, e.g.
An interface for map tools which create annotation items.
Map canvas is a class for displaying all GIS data types on a canvas.
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_TRANSFERBACK
Definition qgis_sip.h:48
std::function< QgsCreateAnnotationItemMapToolInterface *(QgsMapCanvas *, QgsAdvancedDigitizingDockWidget *)> QgsCreateAnnotationItemMapToolFunc
Create annotation map tool creation function.
std::function< void(QgsAnnotationItem *, QgsAnnotationLayer *layer)> QgsAnnotationItemAddedToLayerFunc
Annotation item added to layer callback.
std::function< QgsAnnotationItemBaseWidget *(QgsAnnotationItem *)> QgsAnnotationItemWidgetFunc
Annotation item configuration widget creation function.
std::function< QgsAnnotationItem *()> QgsAnnotationItemCreateFunc
Annotation item creation function.