QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
core
labeling
rules
qgslabelingengineruleregistry.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgslabelingengineruleregistry.cpp
3
---------------------
4
Date : August 2024
5
Copyright : (C) 2024 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
#include "
qgslabelingengineruleregistry.h
"
16
17
#include <geos_c.h>
18
19
#include "
qgslabelingenginerule.h
"
20
#include "
qgslabelingenginerule_impl.h
"
21
22
QgsLabelingEngineRuleRegistry::QgsLabelingEngineRuleRegistry
()
23
{
24
addRule
(
new
QgsLabelingEngineRuleMinimumDistanceLabelToFeature
() );
25
addRule
(
new
QgsLabelingEngineRuleMaximumDistanceLabelToFeature
() );
26
addRule
(
new
QgsLabelingEngineRuleMinimumDistanceLabelToLabel
() );
27
addRule
(
new
QgsLabelingEngineRuleAvoidLabelOverlapWithFeature
() );
28
}
29
30
QgsLabelingEngineRuleRegistry::~QgsLabelingEngineRuleRegistry
() =
default
;
31
32
QStringList
QgsLabelingEngineRuleRegistry::ruleIds
()
const
33
{
34
QStringList res;
35
res.reserve(
static_cast<
int
>
( mRules.size() ) );
36
for
(
auto
&it : mRules )
37
{
38
res.append( it.first );
39
}
40
return
res;
41
}
42
43
QString
QgsLabelingEngineRuleRegistry::displayType
(
const
QString &
id
)
const
44
{
45
auto
it = mRules.find(
id
);
46
if
( it == mRules.end() )
47
return
QString();
48
49
return
it->second->displayType();
50
}
51
52
bool
QgsLabelingEngineRuleRegistry::isAvailable
(
const
QString &
id
)
const
53
{
54
auto
it = mRules.find(
id
);
55
if
( it == mRules.end() )
56
return
false
;
57
58
return
it->second->isAvailable();
59
}
60
61
QgsAbstractLabelingEngineRule
*
QgsLabelingEngineRuleRegistry::create
(
const
QString &
id
)
const
62
{
63
auto
it = mRules.find(
id
);
64
if
( it == mRules.end() )
65
return
nullptr
;
66
67
return
it->second->
clone
();
68
}
69
70
bool
QgsLabelingEngineRuleRegistry::addRule
(
QgsAbstractLabelingEngineRule
*rule )
71
{
72
if
( !rule )
73
return
false
;
74
75
if
( mRules.find( rule->
id
() ) != mRules.end() )
76
{
77
delete
rule;
78
return
false
;
79
}
80
81
mRules[rule->
id
()] = std::unique_ptr< QgsAbstractLabelingEngineRule >( rule );
82
return
true
;
83
}
84
85
void
QgsLabelingEngineRuleRegistry::removeRule
(
const
QString &
id
)
86
{
87
mRules.erase(
id
);
88
}
QgsAbstractLabelingEngineRule
Abstract base class for labeling engine rules.
Definition
qgslabelingenginerule.h:131
QgsAbstractLabelingEngineRule::clone
virtual QgsAbstractLabelingEngineRule * clone() const =0
Creates a clone of this rule.
QgsAbstractLabelingEngineRule::id
virtual QString id() const =0
Returns a string uniquely identifying the rule subclass.
QgsLabelingEngineRuleAvoidLabelOverlapWithFeature
A labeling engine rule which prevents labels being placed overlapping features from a different layer...
Definition
qgslabelingenginerule_impl.h:397
QgsLabelingEngineRuleMaximumDistanceLabelToFeature
A labeling engine rule which prevents labels being placed too far from features from a different laye...
Definition
qgslabelingenginerule_impl.h:231
QgsLabelingEngineRuleMinimumDistanceLabelToFeature
A labeling engine rule which prevents labels being placed too close to features from a different laye...
Definition
qgslabelingenginerule_impl.h:197
QgsLabelingEngineRuleMinimumDistanceLabelToLabel
A labeling engine rule which prevents labels being placed too close to labels from a different layer.
Definition
qgslabelingenginerule_impl.h:265
QgsLabelingEngineRuleRegistry::create
QgsAbstractLabelingEngineRule * create(const QString &id) const
Creates a new rule from the type with matching id.
Definition
qgslabelingengineruleregistry.cpp:61
QgsLabelingEngineRuleRegistry::QgsLabelingEngineRuleRegistry
QgsLabelingEngineRuleRegistry()
Constructor for QgsLabelingEngineRuleRegistry, containing a set of default rules.
Definition
qgslabelingengineruleregistry.cpp:22
QgsLabelingEngineRuleRegistry::isAvailable
bool isAvailable(const QString &id) const
Returns true if the rule is with matching id is available for use within the current QGIS environment...
Definition
qgslabelingengineruleregistry.cpp:52
QgsLabelingEngineRuleRegistry::~QgsLabelingEngineRuleRegistry
~QgsLabelingEngineRuleRegistry()
QgsLabelingEngineRuleRegistry::addRule
bool addRule(QgsAbstractLabelingEngineRule *rule)
Adds a new rule type to the registry.
Definition
qgslabelingengineruleregistry.cpp:70
QgsLabelingEngineRuleRegistry::displayType
QString displayType(const QString &id) const
Returns a user-friendly, translated string representing the rule type with matching id.
Definition
qgslabelingengineruleregistry.cpp:43
QgsLabelingEngineRuleRegistry::ruleIds
QStringList ruleIds() const
Returns a list of the rule IDs for rules present in the registry.
Definition
qgslabelingengineruleregistry.cpp:32
QgsLabelingEngineRuleRegistry::removeRule
void removeRule(const QString &id)
Removes the rule with matching id from the registry.
Definition
qgslabelingengineruleregistry.cpp:85
qgslabelingenginerule.h
qgslabelingenginerule_impl.h
qgslabelingengineruleregistry.h
Generated on
for QGIS API Documentation by
1.17.0