QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
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:
168 const QString &type,
169 const QString &visibleName,
170 const QIcon &creationIcon,
171 const QgsAnnotationItemWidgetFunc &pfWidget = nullptr,
172 const QString &groupId = QString(),
174 const QgsAnnotationItemCreateFunc &pfCreateFunc = nullptr,
175 const QgsCreateAnnotationItemMapToolFunc &pfCreateMapToolFunc = nullptr
176 )
179 , mWidgetFunc( pfWidget )
180 , mCreateFunc( pfCreateFunc )
181 , mCreateMapToolFunc( pfCreateMapToolFunc )
182 {}
183
189
194 void setWidgetFunction( const QgsAnnotationItemWidgetFunc &function ) { mWidgetFunc = function; }
195
201
207
213
219
225
231
232 QIcon creationIcon() const override;
233 QgsAnnotationItemBaseWidget *createItemWidget( QgsAnnotationItem *item ) override;
234
235 QgsAnnotationItem *createItem() override;
236 void newItemAddedToLayer( QgsAnnotationItem *item, QgsAnnotationLayer *layer ) override;
237 QgsCreateAnnotationItemMapToolInterface *createMapTool( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget ) override;
238
239 protected:
240 QIcon mIcon;
245};
246
247#endif
248
262{
263 public:
267 QgsAnnotationItemGuiGroup( const QString &id = QString(), const QString &name = QString(), const QIcon &icon = QIcon() )
268 : id( id )
269 , name( name )
270 , icon( icon )
271 {}
272
276 QString id;
277
281 QString name;
282
286 QIcon icon;
287};
288
289
303class GUI_EXPORT QgsAnnotationItemGuiRegistry : public QObject
304{
305 Q_OBJECT
306
307 public:
314 QgsAnnotationItemGuiRegistry( QObject *parent = nullptr );
315
317
320
325 QgsAnnotationItemAbstractGuiMetadata *itemMetadata( int metadataId ) const;
326
335 int metadataIdForItemType( const QString &type ) const;
336
341
351 bool addItemGroup( const QgsAnnotationItemGuiGroup &group );
352
357 const QgsAnnotationItemGuiGroup &itemGroup( const QString &id ) const;
358
359 /*
360 * IMPORTANT: While it seems like /Factory/ would be the correct annotations here, that's not
361 * the case.
362 * As per Phil Thomson's advice on https://www.riverbankcomputing.com/pipermail/pyqt/2017-July/039450.html:
363 *
364 * "
365 * /Factory/ is used when the instance returned is guaranteed to be new to Python.
366 * In this case it isn't because it has already been seen when being returned by QgsProcessingAlgorithm::createInstance()
367 * (However for a different sub-class implemented in C++ then it would be the first time it was seen
368 * by Python so the /Factory/ on create() would be correct.)
369 *
370 * You might try using /TransferBack/ on create() instead - that might be the best compromise.
371 * "
372 */
373
377 QgsAnnotationItem *createItem( int metadataId ) const SIP_TRANSFERBACK;
378
385 void newItemAddedToLayer( int metadataId, QgsAnnotationItem *item, QgsAnnotationLayer *layer );
386
387 /*
388 * IMPORTANT: While it seems like /Factory/ would be the correct annotations here, that's not
389 * the case.
390 * As per Phil Thomson's advice on https://www.riverbankcomputing.com/pipermail/pyqt/2017-July/039450.html:
391 *
392 * "
393 * /Factory/ is used when the instance returned is guaranteed to be new to Python.
394 * In this case it isn't because it has already been seen when being returned by QgsProcessingAlgorithm::createInstance()
395 * (However for a different sub-class implemented in C++ then it would be the first time it was seen
396 * by Python so the /Factory/ on create() would be correct.)
397 *
398 * You might try using /TransferBack/ on create() instead - that might be the best compromise.
399 * "
400 */
401
406
410 QList<int> itemMetadataIds() const;
411
415 void addDefaultItems();
416
417 signals:
418
423 void typeAdded( int metadataId );
424
425 private:
426#ifdef SIP_RUN
428#endif
429
430 QMap<int, QgsAnnotationItemAbstractGuiMetadata *> mMetadata;
431
432 QMap<QString, QgsAnnotationItemGuiGroup> mItemGroups;
433};
434
435#endif //QGSANNOTATIONITEMGUIREGISTRY_H
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:62
QFlags< AnnotationItemGuiFlag > AnnotationItemGuiFlags
Annotation item GUI flags.
Definition qgis.h:2586
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:133
#define SIP_TRANSFER
Definition qgis_sip.h:35
#define SIP_TRANSFERBACK
Definition qgis_sip.h:47
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.