QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgsannotationitemregistry.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsannotationitemregistry.cpp
3  -------------------------
4  begin : October 2019
5  copyright : (C) 2019 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 
18 #include "qgsannotationitem.h"
20 #include "qgsannotationlineitem.h"
23 #include <QDomElement>
24 
26  : QObject( parent )
27 {
28 }
29 
31 {
32  qDeleteAll( mMetadata );
33 }
34 
36 {
37  if ( !mMetadata.isEmpty() )
38  return false;
39 
40  mMetadata.insert( QStringLiteral( "marker" ), new QgsAnnotationItemMetadata( QStringLiteral( "marker" ), QObject::tr( "Marker" ), QObject::tr( "Markers" ),
42  mMetadata.insert( QStringLiteral( "linestring" ), new QgsAnnotationItemMetadata( QStringLiteral( "linestring" ), QObject::tr( "Polyline" ), QObject::tr( "Polylines" ),
44  mMetadata.insert( QStringLiteral( "polygon" ), new QgsAnnotationItemMetadata( QStringLiteral( "polygon" ), QObject::tr( "Polygon" ), QObject::tr( "Polygons" ),
46  mMetadata.insert( QStringLiteral( "pointtext" ), new QgsAnnotationItemMetadata( QStringLiteral( "pointtext" ), QObject::tr( "Text at point" ), QObject::tr( "Text at points" ),
48  return true;
49 }
50 
52 {
53  return mMetadata.value( type );
54 }
55 
57 {
58  if ( !metadata || mMetadata.contains( metadata->type() ) )
59  return false;
60 
61  mMetadata[metadata->type()] = metadata;
62  emit typeAdded( metadata->type(), metadata->visibleName() );
63  return true;
64 }
65 
67 {
68  if ( !mMetadata.contains( type ) )
69  return nullptr;
70 
71  return mMetadata[type]->createItem();
72 }
73 
74 QMap<QString, QString> QgsAnnotationItemRegistry::itemTypes() const
75 {
76  QMap<QString, QString> types;
77  for ( auto it = mMetadata.constBegin(); it != mMetadata.constEnd(); ++it )
78  {
79  types.insert( it.key(), it.value()->visibleName() );
80  }
81  return types;
82 }
QgsAnnotationItemRegistry::populate
bool populate()
Populates the registry with standard item types.
Definition: qgsannotationitemregistry.cpp:35
QgsAnnotationItemRegistry::QgsAnnotationItemRegistry
QgsAnnotationItemRegistry(QObject *parent=nullptr)
Creates a new empty item registry.
Definition: qgsannotationitemregistry.cpp:25
qgsannotationpolygonitem.h
QgsAnnotationItemRegistry::typeAdded
void typeAdded(const QString &type, const QString &name)
Emitted whenever a new item type is added to the registry, with the specified type and visible name.
qgsannotationlineitem.h
QgsAnnotationItemAbstractMetadata::type
QString type() const
Returns the unique item type string for the annotation item class.
Definition: qgsannotationitemregistry.h:62
qgsannotationmarkeritem.h
QgsAnnotationItemRegistry::itemTypes
QMap< QString, QString > itemTypes() const
Returns a map of available item types to translated name.
Definition: qgsannotationitemregistry.cpp:74
QgsAnnotationItemMetadata
Convenience metadata class that uses static functions to create annotation items and their configurat...
Definition: qgsannotationitemregistry.h:99
QgsAnnotationItemRegistry::~QgsAnnotationItemRegistry
~QgsAnnotationItemRegistry() override
Definition: qgsannotationitemregistry.cpp:30
QgsAnnotationItemRegistry::createItem
QgsAnnotationItem * createItem(const QString &type) const
Creates a new instance of a annotation item given the item type.
Definition: qgsannotationitemregistry.cpp:66
QgsAnnotationItemRegistry::itemMetadata
QgsAnnotationItemAbstractMetadata * itemMetadata(const QString &type) const
Returns the metadata for the specified item type.
Definition: qgsannotationitemregistry.cpp:51
QgsAnnotationPointTextItem::create
static QgsAnnotationPointTextItem * create()
Creates a new text at point annotation item.
Definition: qgsannotationpointtextitem.cpp:73
qgsannotationpointtextitem.h
QgsAnnotationMarkerItem::create
static QgsAnnotationMarkerItem * create()
Creates a new marker annotation item.
Definition: qgsannotationmarkeritem.cpp:69
QgsAnnotationItemAbstractMetadata::visibleName
QString visibleName() const
Returns a translated, user visible name for the annotation item class.
Definition: qgsannotationitemregistry.h:68
QgsAnnotationItemAbstractMetadata
Stores metadata about one annotation item class.
Definition: qgsannotationitemregistry.h:42
qgsannotationitemregistry.h
qgsannotationitem.h
QgsAnnotationItemRegistry::addItemType
bool addItemType(QgsAnnotationItemAbstractMetadata *metadata)
Registers a new annotation item type.
Definition: qgsannotationitemregistry.cpp:56
QgsAnnotationLineItem::create
static QgsAnnotationLineItem * create()
Creates a new linestring annotation item.
Definition: qgsannotationlineitem.cpp:82
QgsAnnotationItem
Abstract base class for annotation items which are drawn with QgsAnnotationLayers.
Definition: qgsannotationitem.h:39
QgsAnnotationPolygonItem::create
static QgsAnnotationPolygonItem * create()
Creates a new polygon annotation item.
Definition: qgsannotationpolygonitem.cpp:96