QGIS API Documentation 3.99.0-Master (26c88405ac0)
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:
50
59 : mType( type )
60 , mGroupId( groupId )
61 , mName( visibleName )
62 , mFlags( flags )
63 {}
64
66
70 QString type() const { return mType; }
71
75 Qgis::AnnotationItemGuiFlags flags() const { return mFlags; }
76
80 QString groupId() const { return mGroupId; }
81
85 QString visibleName() const { return mName; }
86
90 virtual QIcon creationIcon() const;
91
92 /*
93 * IMPORTANT: While it seems like /Factory/ would be the correct annotations here, that's not
94 * the case.
95 * As per Phil Thomson's advice on https://www.riverbankcomputing.com/pipermail/pyqt/2017-July/039450.html:
96 *
97 * "
98 * /Factory/ is used when the instance returned is guaranteed to be new to Python.
99 * In this case it isn't because it has already been seen when being returned by QgsProcessingAlgorithm::createInstance()
100 * (However for a different sub-class implemented in C++ then it would be the first time it was seen
101 * by Python so the /Factory/ on create() would be correct.)
102 *
103 * You might try using /TransferBack/ on create() instead - that might be the best compromise.
104 * "
105 */
106
110 virtual QgsAnnotationItemBaseWidget *createItemWidget( QgsAnnotationItem *item ) SIP_TRANSFERBACK;
111
118
122 virtual QgsAnnotationItem *createItem() SIP_TRANSFERBACK;
123
130 virtual void newItemAddedToLayer( QgsAnnotationItem *item, QgsAnnotationLayer *layer );
131
132 private:
133 QString mType;
134 QString mGroupId;
135 QString mName;
136 Qgis::AnnotationItemGuiFlags mFlags;
137};
138
141
144
147
148#ifndef SIP_RUN
149
157{
158 public:
159
169 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 )
172 , mWidgetFunc( pfWidget )
173 , mCreateFunc( pfCreateFunc )
174 , mCreateMapToolFunc( pfCreateMapToolFunc )
175 {}
176
182
187 void setWidgetFunction( const QgsAnnotationItemWidgetFunc &function ) { mWidgetFunc = function; }
188
194
200
206
212
218
224
225 QIcon creationIcon() const override;
226 QgsAnnotationItemBaseWidget *createItemWidget( QgsAnnotationItem *item ) override;
227
228 QgsAnnotationItem *createItem() override;
229 void newItemAddedToLayer( QgsAnnotationItem *item, QgsAnnotationLayer *layer ) override;
230 QgsCreateAnnotationItemMapToolInterface *createMapTool( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget ) override;
231
232 protected:
233 QIcon mIcon;
238};
239
240#endif
241
255{
256 public:
257
261 QgsAnnotationItemGuiGroup( const QString &id = QString(), const QString &name = QString(), const QIcon &icon = QIcon() )
262 : id( id )
263 , name( name )
264 , icon( icon )
265 {}
266
270 QString id;
271
275 QString name;
276
280 QIcon icon;
281};
282
283
297class GUI_EXPORT QgsAnnotationItemGuiRegistry : public QObject
298{
299 Q_OBJECT
300
301 public:
302
309 QgsAnnotationItemGuiRegistry( QObject *parent = nullptr );
310
312
315
320 QgsAnnotationItemAbstractGuiMetadata *itemMetadata( int metadataId ) const;
321
330 int metadataIdForItemType( const QString &type ) const;
331
336
346 bool addItemGroup( const QgsAnnotationItemGuiGroup &group );
347
352 const QgsAnnotationItemGuiGroup &itemGroup( const QString &id ) const;
353
354 /*
355 * IMPORTANT: While it seems like /Factory/ would be the correct annotations here, that's not
356 * the case.
357 * As per Phil Thomson's advice on https://www.riverbankcomputing.com/pipermail/pyqt/2017-July/039450.html:
358 *
359 * "
360 * /Factory/ is used when the instance returned is guaranteed to be new to Python.
361 * In this case it isn't because it has already been seen when being returned by QgsProcessingAlgorithm::createInstance()
362 * (However for a different sub-class implemented in C++ then it would be the first time it was seen
363 * by Python so the /Factory/ on create() would be correct.)
364 *
365 * You might try using /TransferBack/ on create() instead - that might be the best compromise.
366 * "
367 */
368
372 QgsAnnotationItem *createItem( int metadataId ) const SIP_TRANSFERBACK;
373
380 void newItemAddedToLayer( int metadataId, QgsAnnotationItem *item, QgsAnnotationLayer *layer );
381
382 /*
383 * IMPORTANT: While it seems like /Factory/ would be the correct annotations here, that's not
384 * the case.
385 * As per Phil Thomson's advice on https://www.riverbankcomputing.com/pipermail/pyqt/2017-July/039450.html:
386 *
387 * "
388 * /Factory/ is used when the instance returned is guaranteed to be new to Python.
389 * In this case it isn't because it has already been seen when being returned by QgsProcessingAlgorithm::createInstance()
390 * (However for a different sub-class implemented in C++ then it would be the first time it was seen
391 * by Python so the /Factory/ on create() would be correct.)
392 *
393 * You might try using /TransferBack/ on create() instead - that might be the best compromise.
394 * "
395 */
396
401
405 QList<int> itemMetadataIds() const;
406
410 void addDefaultItems();
411
412 signals:
413
418 void typeAdded( int metadataId );
419
420 private:
421#ifdef SIP_RUN
423#endif
424
425 QMap<int, QgsAnnotationItemAbstractGuiMetadata *> mMetadata;
426
427 QMap<QString, QgsAnnotationItemGuiGroup> mItemGroups;
428};
429
430#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.