QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
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 ***************************************************************************/
18#include <geos_c.h>
19
27
29
31{
32 QStringList res;
33 res.reserve( static_cast< int >( mRules.size() ) );
34 for ( auto &it : mRules )
35 {
36 res.append( it.first );
37 }
38 return res;
39}
40
41QString QgsLabelingEngineRuleRegistry::displayType( const QString &id ) const
42{
43 auto it = mRules.find( id );
44 if ( it == mRules.end() )
45 return QString();
46
47 return it->second->displayType();
48}
49
50bool QgsLabelingEngineRuleRegistry::isAvailable( const QString &id ) const
51{
52 auto it = mRules.find( id );
53 if ( it == mRules.end() )
54 return false;
55
56 return it->second->isAvailable();
57}
58
60{
61 auto it = mRules.find( id );
62 if ( it == mRules.end() )
63 return nullptr;
64
65 return it->second->clone();
66}
67
69{
70 if ( !rule )
71 return false;
72
73 if ( mRules.find( rule->id() ) != mRules.end() )
74 {
75 delete rule;
76 return false;
77 }
78
79 mRules[ rule->id() ] = std::unique_ptr< QgsAbstractLabelingEngineRule >( rule );
80 return true;
81}
82
84{
85 mRules.erase( id );
86}
87
Abstract base class for labeling engine rules.
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.