QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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 <functional>
20
21#include "qgis.h"
22#include "qgis_gui.h"
23#include "qgis_sip.h"
25#include "qgsapplication.h"
26#include "qgspathresolver.h"
27
28#include <QIcon>
29
34class QgsMapCanvas;
36
48{
49 public:
58 : mType( type )
59 , mGroupId( groupId )
60 , mName( visibleName )
61 , mFlags( flags )
62 {}
63
65
69 QString type() const { return mType; }
70
74 Qgis::AnnotationItemGuiFlags flags() const { return mFlags; }
75
79 QString groupId() const { return mGroupId; }
80
84 QString visibleName() const { return mName; }
85
89 virtual QIcon creationIcon() const;
90
91 /*
92 * IMPORTANT: While it seems like /Factory/ would be the correct annotations here, that's not
93 * the case.
94 * As per Phil Thomson's advice on https://www.riverbankcomputing.com/pipermail/pyqt/2017-July/039450.html:
95 *
96 * "
97 * /Factory/ is used when the instance returned is guaranteed to be new to Python.
98 * In this case it isn't because it has already been seen when being returned by QgsProcessingAlgorithm::createInstance()
99 * (However for a different sub-class implemented in C++ then it would be the first time it was seen
100 * by Python so the /Factory/ on create() would be correct.)
101 *
102 * You might try using /TransferBack/ on create() instead - that might be the best compromise.
103 * "
104 */
105
109 virtual QgsAnnotationItemBaseWidget *createItemWidget( QgsAnnotationItem *item ) SIP_TRANSFERBACK;
110
117
121 virtual QgsAnnotationItem *createItem() SIP_TRANSFERBACK;
122
129 virtual void newItemAddedToLayer( QgsAnnotationItem *item, QgsAnnotationLayer *layer );
130
131 private:
132 QString mType;
133 QString mGroupId;
134 QString mName;
135 Qgis::AnnotationItemGuiFlags mFlags;
136};
137
140
143
146
147#ifndef SIP_RUN
148
156{
157 public:
167 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 )
170 , mWidgetFunc( pfWidget )
171 , mCreateFunc( pfCreateFunc )
172 , mCreateMapToolFunc( pfCreateMapToolFunc )
173 {}
174
180
185 void setWidgetFunction( const QgsAnnotationItemWidgetFunc &function ) { mWidgetFunc = function; }
186
192
198
204
210
216
222
223 QIcon creationIcon() const override;
224 QgsAnnotationItemBaseWidget *createItemWidget( QgsAnnotationItem *item ) override;
225
226 QgsAnnotationItem *createItem() override;
227 void newItemAddedToLayer( QgsAnnotationItem *item, QgsAnnotationLayer *layer ) override;
228 QgsCreateAnnotationItemMapToolInterface *createMapTool( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget ) override;
229
230 protected:
231 QIcon mIcon;
236};
237
238#endif
239
253{
254 public:
258 QgsAnnotationItemGuiGroup( const QString &id = QString(), const QString &name = QString(), const QIcon &icon = QIcon() )
259 : id( id )
260 , name( name )
261 , icon( icon )
262 {}
263
267 QString id;
268
272 QString name;
273
277 QIcon icon;
278};
279
280
294class GUI_EXPORT QgsAnnotationItemGuiRegistry : public QObject
295{
296 Q_OBJECT
297
298 public:
305 QgsAnnotationItemGuiRegistry( QObject *parent = nullptr );
306
308
311
316 QgsAnnotationItemAbstractGuiMetadata *itemMetadata( int metadataId ) const;
317
326 int metadataIdForItemType( const QString &type ) const;
327
332
342 bool addItemGroup( const QgsAnnotationItemGuiGroup &group );
343
348 const QgsAnnotationItemGuiGroup &itemGroup( const QString &id ) const;
349
350 /*
351 * IMPORTANT: While it seems like /Factory/ would be the correct annotations here, that's not
352 * the case.
353 * As per Phil Thomson's advice on https://www.riverbankcomputing.com/pipermail/pyqt/2017-July/039450.html:
354 *
355 * "
356 * /Factory/ is used when the instance returned is guaranteed to be new to Python.
357 * In this case it isn't because it has already been seen when being returned by QgsProcessingAlgorithm::createInstance()
358 * (However for a different sub-class implemented in C++ then it would be the first time it was seen
359 * by Python so the /Factory/ on create() would be correct.)
360 *
361 * You might try using /TransferBack/ on create() instead - that might be the best compromise.
362 * "
363 */
364
368 QgsAnnotationItem *createItem( int metadataId ) const SIP_TRANSFERBACK;
369
376 void newItemAddedToLayer( int metadataId, QgsAnnotationItem *item, QgsAnnotationLayer *layer );
377
378 /*
379 * IMPORTANT: While it seems like /Factory/ would be the correct annotations here, that's not
380 * the case.
381 * As per Phil Thomson's advice on https://www.riverbankcomputing.com/pipermail/pyqt/2017-July/039450.html:
382 *
383 * "
384 * /Factory/ is used when the instance returned is guaranteed to be new to Python.
385 * In this case it isn't because it has already been seen when being returned by QgsProcessingAlgorithm::createInstance()
386 * (However for a different sub-class implemented in C++ then it would be the first time it was seen
387 * by Python so the /Factory/ on create() would be correct.)
388 *
389 * You might try using /TransferBack/ on create() instead - that might be the best compromise.
390 * "
391 */
392
397
401 QList<int> itemMetadataIds() const;
402
406 void addDefaultItems();
407
408 signals:
409
414 void typeAdded( int metadataId );
415
416 private:
417#ifdef SIP_RUN
419#endif
420
421 QMap<int, QgsAnnotationItemAbstractGuiMetadata *> mMetadata;
422
423 QMap<QString, QgsAnnotationItemGuiGroup> mItemGroups;
424};
425
426#endif //QGSANNOTATIONITEMGUIREGISTRY_H
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:56
QFlags< AnnotationItemGuiFlag > AnnotationItemGuiFlags
Annotation item GUI flags.
Definition qgis.h:2497
A dockable widget used to handle the CAD tools on top of a selection of map tools.
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.
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.
QgsAnnotationItemAddedToLayerFunc mAddedToLayerFunc
void setItemCreationFunction(const QgsAnnotationItemCreateFunc &function)
Sets the classes' item creation function.
QgsAnnotationItemCreateFunc mCreateFunc
QIcon creationIcon() const override
Returns an icon representing creation of the annotation item type.
void setWidgetFunction(const QgsAnnotationItemWidgetFunc &function)
Sets the classes' configuration widget creation function.
QgsAnnotationItemAddedToLayerFunc itemAddToLayerFunction() const
Returns the classes' item added to layer function.
QgsAnnotationItemWidgetFunc mWidgetFunc
void setItemAddedToLayerFunction(const QgsAnnotationItemAddedToLayerFunc &function)
Sets the classes' item creation function.
QgsCreateAnnotationItemMapToolFunc mCreateMapToolFunc
QgsAnnotationItemBaseWidget * createItemWidget(QgsAnnotationItem *item) const
Creates a new instance of an annotation item configuration widget for the specified item.
QgsAnnotationItemGuiRegistry(const QgsAnnotationItemGuiRegistry &rh)=delete
bool addItemGroup(const QgsAnnotationItemGuiGroup &group)
Registers a new item group with the registry.
QgsAnnotationItemAbstractGuiMetadata * itemMetadata(int metadataId) const
Returns the metadata for the specified item metadataId.
bool addAnnotationItemGuiMetadata(QgsAnnotationItemAbstractGuiMetadata *metadata)
Registers the gui metadata for a new annotation item type.
void addDefaultItems()
Populates the registry with default items.
QList< int > itemMetadataIds() const
Returns a list of available item metadata ids handled by the registry.
int metadataIdForItemType(const QString &type) const
Returns the GUI item metadata ID which corresponds to the specified annotation item type.
const QgsAnnotationItemGuiGroup & itemGroup(const QString &id) const
Returns a reference to the item group with matching id.
void typeAdded(int metadataId)
Emitted whenever a new item type is added to the registry, with the specified metadataId.
QgsAnnotationItem * createItem(int metadataId) const
Creates a new instance of an annotation item given the item metadata metadataId.
QgsAnnotationItemGuiRegistry & operator=(const QgsAnnotationItemGuiRegistry &rh)=delete
void newItemAddedToLayer(int metadataId, QgsAnnotationItem *item, QgsAnnotationLayer *layer)
Called when a newly created item of the associated metadata metadataId has been added to a layer.
QgsAnnotationItemGuiRegistry(QObject *parent=nullptr)
Creates a new empty item GUI registry.
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:134
#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.