QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
Loading...
Searching...
No Matches
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"
26#include <QDomElement>
27
29 : QObject( parent )
30{
31}
32
34{
35 qDeleteAll( mMetadata );
36}
37
39{
40 if ( !mMetadata.isEmpty() )
41 return false;
42
43 mMetadata.insert( QStringLiteral( "marker" ), new QgsAnnotationItemMetadata( QStringLiteral( "marker" ), QObject::tr( "Marker" ), QObject::tr( "Markers" ),
45 mMetadata.insert( QStringLiteral( "linestring" ), new QgsAnnotationItemMetadata( QStringLiteral( "linestring" ), QObject::tr( "Polyline" ), QObject::tr( "Polylines" ),
47 mMetadata.insert( QStringLiteral( "polygon" ), new QgsAnnotationItemMetadata( QStringLiteral( "polygon" ), QObject::tr( "Polygon" ), QObject::tr( "Polygons" ),
49 mMetadata.insert( QStringLiteral( "pointtext" ), new QgsAnnotationItemMetadata( QStringLiteral( "pointtext" ), QObject::tr( "Text at point" ), QObject::tr( "Text at points" ),
51 mMetadata.insert( QStringLiteral( "linetext" ), new QgsAnnotationItemMetadata( QStringLiteral( "linetext" ), QObject::tr( "Text along line" ), QObject::tr( "Text along lines" ),
53 mMetadata.insert( QStringLiteral( "recttext" ), new QgsAnnotationItemMetadata( QStringLiteral( "recttext" ), QObject::tr( "Text in rectangle" ), QObject::tr( "Text in rectangles" ),
55 mMetadata.insert( QStringLiteral( "picture" ), new QgsAnnotationItemMetadata( QStringLiteral( "picture" ), QObject::tr( "Picture" ), QObject::tr( "Pictures" ),
57 return true;
58}
59
61{
62 return mMetadata.value( type );
63}
64
66{
67 if ( !metadata || mMetadata.contains( metadata->type() ) )
68 return false;
69
70 mMetadata[metadata->type()] = metadata;
71 emit typeAdded( metadata->type(), metadata->visibleName() );
72 return true;
73}
74
76{
77 if ( !mMetadata.contains( type ) )
78 return nullptr;
79
80 return mMetadata[type]->createItem();
81}
82
83QMap<QString, QString> QgsAnnotationItemRegistry::itemTypes() const
84{
85 QMap<QString, QString> types;
86 for ( auto it = mMetadata.constBegin(); it != mMetadata.constEnd(); ++it )
87 {
88 types.insert( it.key(), it.value()->visibleName() );
89 }
90 return types;
91}
Stores metadata about one annotation item class.
QString type() const
Returns the unique item type string for the annotation item class.
QString visibleName() const
Returns a translated, user visible name for the annotation item class.
Convenience metadata class that uses static functions to create annotation items and their configurat...
QgsAnnotationItem * createItem(const QString &type) const
Creates a new instance of a annotation item given the item type.
QgsAnnotationItemAbstractMetadata * itemMetadata(const QString &type) const
Returns the metadata for the specified item type.
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.
bool populate()
Populates the registry with standard item types.
QgsAnnotationItemRegistry(QObject *parent=nullptr)
Creates a new empty item registry.
QMap< QString, QString > itemTypes() const
Returns a map of available item types to translated name.
bool addItemType(QgsAnnotationItemAbstractMetadata *metadata)
Registers a new annotation item type.
Abstract base class for annotation items which are drawn with QgsAnnotationLayers.
static QgsAnnotationLineItem * create()
Creates a new linestring annotation item.
static QgsAnnotationLineTextItem * create()
Creates a new linestring annotation item.
static QgsAnnotationMarkerItem * create()
Creates a new marker annotation item.
static QgsAnnotationPictureItem * create()
Creates a new polygon annotation item.
static QgsAnnotationPointTextItem * create()
Creates a new text at point annotation item.
static QgsAnnotationPolygonItem * create()
Creates a new polygon annotation item.
static QgsAnnotationRectangleTextItem * create()
Creates a new rectangle text annotation item.