QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
qgscalloutsregistry.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgscalloutsregistry.cpp
3 -----------------------
4 begin : July 2019
5 copyright : (C) 2019 by 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#include "qgscalloutsregistry.h"
17#include "qgscallout.h"
18#include "qgsxmlutils.h"
19#include "qgsapplication.h"
20
21//
22// QgsCalloutAbstractMetadata
23//
24
29
30//
31// QgsCalloutMetadata
32//
33
34QgsCallout *QgsCalloutMetadata::createCallout( const QVariantMap &properties, const QgsReadWriteContext &context )
35{
36 return mCreateFunc ? mCreateFunc( properties, context ) : nullptr;
37}
38
43
44
45//
46// QgsCalloutRegistry
47//
48
50{
51 // init registry with known callouts
52 addCalloutType( new QgsCalloutMetadata( QStringLiteral( "simple" ), QObject::tr( "Simple lines" ), QgsApplication::getThemeIcon( QStringLiteral( "labelingCalloutSimple.svg" ) ), QgsSimpleLineCallout::create ) );
53 addCalloutType( new QgsCalloutMetadata( QStringLiteral( "manhattan" ), QObject::tr( "Manhattan lines" ), QgsApplication::getThemeIcon( QStringLiteral( "labelingCalloutManhattan.svg" ) ), QgsManhattanLineCallout::create ) );
54 addCalloutType( new QgsCalloutMetadata( QStringLiteral( "curved" ), QObject::tr( "Curved lines" ), QgsApplication::getThemeIcon( QStringLiteral( "labelingCalloutCurved.svg" ) ), QgsCurvedLineCallout::create ) );
55 addCalloutType( new QgsCalloutMetadata( QStringLiteral( "balloon" ), QObject::tr( "Balloons" ), QgsApplication::getThemeIcon( QStringLiteral( "labelingCalloutManhattan.svg" ) ), QgsBalloonCallout::create ) );
56}
57
59{
60 qDeleteAll( mMetadata );
61}
62
64{
65 if ( !metadata || mMetadata.contains( metadata->name() ) )
66 return false;
67
68 mMetadata[metadata->name()] = metadata;
69 return true;
70}
71
72QgsCallout *QgsCalloutRegistry::createCallout( const QString &name, const QDomElement &element, const QgsReadWriteContext &context ) const
73{
74 const QVariantMap props = QgsXmlUtils::readVariant( element.firstChildElement() ).toMap();
75 return createCallout( name, props, context );
76}
77
79{
80 return mMetadata.keys();
81}
82
84{
85 return mMetadata.value( name );
86}
87
92
93QgsCallout *QgsCalloutRegistry::createCallout( const QString &name, const QVariantMap &properties, const QgsReadWriteContext &context ) const
94{
95 if ( !mMetadata.contains( name ) )
96 return nullptr;
97
98 return mMetadata[name]->createCallout( properties, context );
99}
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
static QgsCallout * create(const QVariantMap &properties=QVariantMap(), const QgsReadWriteContext &context=QgsReadWriteContext())
Creates a new QgsBalloonCallout, using the settings serialized in the properties map (corresponding t...
Stores metadata about one callout renderer class.
virtual QgsCalloutWidget * createCalloutWidget(QgsMapLayer *)
Creates a widget for configuring callouts of this type.
QString name() const
Returns the unique name of the callout type.
Convenience metadata class that uses static functions to create callouts and their widgets.
QgsCalloutWidgetFunc mWidgetFunc
QgsCalloutCreateFunc mCreateFunc
QgsCalloutWidget * createCalloutWidget(QgsMapLayer *vl) override
Creates a widget for configuring callouts of this type.
QgsCallout * createCallout(const QVariantMap &properties, const QgsReadWriteContext &context) override
Create a callout of this type given the map of properties.
QgsCalloutAbstractMetadata * calloutMetadata(const QString &type) const
Returns the metadata for specified the specified callout type.
static QgsCallout * defaultCallout()
Create a new instance of a callout with default settings.
bool addCalloutType(QgsCalloutAbstractMetadata *metadata)
Registers a new callout type.
QStringList calloutTypes() const
Returns a list of all available callout types.
QgsCallout * createCallout(const QString &type, const QVariantMap &properties=QVariantMap(), const QgsReadWriteContext &context=QgsReadWriteContext()) const
Creates a new instance of a callout, given the callout type and properties.
Base class for widgets which allow control over the properties of callouts.
Abstract base class for callout renderers.
Definition qgscallout.h:54
static QgsCallout * create(const QVariantMap &properties=QVariantMap(), const QgsReadWriteContext &context=QgsReadWriteContext())
Creates a new QgsCurvedLineCallout, using the settings serialized in the properties map (correspondin...
static QgsCallout * create(const QVariantMap &properties=QVariantMap(), const QgsReadWriteContext &context=QgsReadWriteContext())
Creates a new QgsManhattanLineCallout, using the settings serialized in the properties map (correspon...
Base class for all map layer types.
Definition qgsmaplayer.h:76
The class is used as a container of context for various read/write operations on other objects.
A simple direct line callout style.
Definition qgscallout.h:514
static QgsCallout * create(const QVariantMap &properties=QVariantMap(), const QgsReadWriteContext &context=QgsReadWriteContext())
Creates a new QgsSimpleLineCallout, using the settings serialized in the properties map (correspondin...
static QVariant readVariant(const QDomElement &element)
Read a QVariant from a QDomElement.