QGIS API Documentation
4.3.0-Master (9dce731a7a1)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
core
annotations
qgsannotationregistry.h
Go to the documentation of this file.
1
/***************************************************************************
2
qgsannotationregistry.h
3
-----------------------
4
Date : January 2017
5
Copyright : (C) 2017 Nyall Dawson
6
Email : nyall dot dawson at gmail dot com
7
***************************************************************************
8
* *
9
* This program is free software; you can redistribute it and/or modify *
10
* it under the terms of the GNU General Public License as published by *
11
* the Free Software Foundation; either version 2 of the License, or *
12
* (at your option) any later version. *
13
* *
14
***************************************************************************/
15
16
#ifndef QGSANNOTATIONREGISTRY_H
17
#define QGSANNOTATIONREGISTRY_H
18
19
20
#include <functional>
21
22
#include "qgis_core.h"
23
#include "
qgsannotation.h
"
24
#include "
qgshtmlannotation.h
"
25
#include "
qgssvgannotation.h
"
26
#include "
qgstextannotation.h
"
27
28
#include <QString>
29
30
#define SIP_NO_FILE
31
32
using namespace
Qt::StringLiterals;
33
35
36
// None of this is stable API!
37
39
typedef
std::function<
QgsAnnotation
*() > QgsCreateAnnotationFunc;
40
46
class
CORE_EXPORT QgsAnnotationMetadata
47
{
48
public
:
53
QgsAnnotationMetadata(
const
QString &typeName,
const
QgsCreateAnnotationFunc &createFunc )
54
: mTypeName( typeName )
55
, mCreateFunc( createFunc )
56
{}
57
61
QString type()
const
{
return
mTypeName; }
62
66
QgsAnnotation
*createAnnotation()
const
{
return
mCreateFunc ? mCreateFunc() :
nullptr
; }
67
68
private
:
69
QString mTypeName;
70
QgsCreateAnnotationFunc mCreateFunc =
nullptr
;
71
72
QgsAnnotationMetadata() =
default
;
73
friend
class
QMap< QString, QgsAnnotationMetadata >;
74
};
75
81
class
CORE_EXPORT QgsAnnotationRegistry
82
{
83
public
:
88
QgsAnnotationRegistry()
89
{
90
addAnnotationType( QgsAnnotationMetadata( u
"TextAnnotationItem"
_s,
QgsTextAnnotation::create
) );
91
addAnnotationType( QgsAnnotationMetadata( u
"HtmlAnnotationItem"
_s,
QgsHtmlAnnotation::create
) );
92
addAnnotationType( QgsAnnotationMetadata( u
"SVGAnnotationItem"
_s,
QgsSvgAnnotation::create
) );
93
}
94
100
bool
addAnnotationType(
const
QgsAnnotationMetadata &metadata )
101
{
102
if
( mMetadata.contains( metadata.type() ) )
103
return
false
;
104
105
mMetadata.insert( metadata.type(), metadata );
106
return
true
;
107
}
108
113
QgsAnnotation *create(
const
QString &typeName )
const
114
{
115
if
( !mMetadata.contains( typeName ) )
116
return
nullptr
;
117
118
return
mMetadata.value( typeName ).createAnnotation();
119
}
120
121
private
:
122
QMap< QString, QgsAnnotationMetadata > mMetadata;
123
};
124
126
127
#endif
// QGSANNOTATIONREGISTRY_H
QgsAnnotation
Abstract base class for annotation items which are drawn over a map.
Definition
qgsannotation.h:53
QgsHtmlAnnotation::create
static QgsHtmlAnnotation * create()
Returns a new QgsHtmlAnnotation object.
Definition
qgshtmlannotation.h:77
QgsSvgAnnotation::create
static QgsSvgAnnotation * create()
Returns a new QgsSvgAnnotation object.
Definition
qgssvgannotation.h:61
QgsTextAnnotation::create
static QgsTextAnnotation * create()
Returns a new QgsTextAnnotation object.
Definition
qgstextannotation.h:63
qgsannotation.h
qgshtmlannotation.h
qgssvgannotation.h
qgstextannotation.h
Generated on
for QGIS API Documentation by
1.17.0