QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
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 ***************************************************************************/
16
17#include <geos_c.h>
18
21
29
31
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
43QString 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
52bool 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
62{
63 auto it = mRules.find( id );
64 if ( it == mRules.end() )
65 return nullptr;
66
67 return it->second->clone();
68}
69
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
86{
87 mRules.erase( id );
88}
89
Abstract base class for labeling engine rules.
virtual QgsAbstractLabelingEngineRule * clone() const =0
Creates a clone of this rule.
virtual QString id() const =0
Returns a string uniquely identifying the rule subclass.
A labeling engine rule which prevents labels being placed overlapping features from a different layer...
A labeling engine rule which prevents labels being placed too far from features from a different laye...
A labeling engine rule which prevents labels being placed too close to features from a different laye...
A labeling engine rule which prevents labels being placed too close to labels from a different layer.
QgsAbstractLabelingEngineRule * create(const QString &id) const
Creates a new rule from the type with matching id.
QgsLabelingEngineRuleRegistry()
Constructor for QgsLabelingEngineRuleRegistry, containing a set of default rules.
bool isAvailable(const QString &id) const
Returns true if the rule is with matching id is available for use within the current QGIS environment...
bool addRule(QgsAbstractLabelingEngineRule *rule)
Adds a new rule type to the registry.
QString displayType(const QString &id) const
Returns a user-friendly, translated string representing the rule type with matching id.
QStringList ruleIds() const
Returns a list of the rule IDs for rules present in the registry.
void removeRule(const QString &id)
Removes the rule with matching id from the registry.