QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgsvectorlayerlabeling.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvectorlayerlabeling.h
3  ---------------------
4  begin : September 2015
5  copyright : (C) 2015 by Martin Dobias
6  email : wonder dot sk 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 #ifndef QGSVECTORLAYERLABELING_H
16 #define QGSVECTORLAYERLABELING_H
17 
18 #include <memory>
19 
20 #include <QString>
21 #include <QStringList>
22 #include <QDomNode>
23 
24 #include "qgis.h"
25 
26 class QDomDocument;
27 class QDomElement;
28 
31 class QgsVectorLayer;
34 
42 {
43 
44 #ifdef SIP_RUN
46  if ( sipCpp->type() == "simple" )
47  sipType = sipType_QgsVectorLayerSimpleLabeling;
48  else if ( sipCpp->type() == "rule-based" )
49  sipType = sipType_QgsRuleBasedLabeling;
50  else
51  sipType = 0;
52  SIP_END
53 #endif
54 
55  public:
58  virtual ~QgsAbstractVectorLayerLabeling() = default;
59 
61  virtual QString type() const = 0;
62 
65 
70  virtual QgsVectorLayerLabelProvider *provider( QgsVectorLayer *layer ) const SIP_SKIP { Q_UNUSED( layer ) return nullptr; }
71 
73  virtual QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context ) const = 0;
74 
76  virtual QStringList subProviders() const { return QStringList( QString() ); }
77 
82  virtual QgsPalLayerSettings settings( const QString &providerId = QString() ) const = 0;
83 
92  virtual void setSettings( QgsPalLayerSettings *settings SIP_TRANSFER, const QString &providerId = QString() ) = 0;
93 
100  virtual bool requiresAdvancedEffects() const = 0;
101 
102  // static stuff
103 
105  static QgsAbstractVectorLayerLabeling *create( const QDomElement &element, const QgsReadWriteContext &context ) SIP_FACTORY;
106 
110  virtual void toSld( QDomNode &parent, const QgsStringMap &props ) const
111  {
112  Q_UNUSED( parent )
113  Q_UNUSED( props )
114  QDomDocument doc = parent.ownerDocument();
115  parent.appendChild( doc.createComment( QStringLiteral( "SE Export for %1 not implemented yet" ).arg( type() ) ) );
116  }
117 
127  virtual bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
128 
129  protected:
130 
137  virtual void writeTextSymbolizer( QDomNode &parent, QgsPalLayerSettings &settings, const QgsStringMap &props ) const;
138 
139  private:
140  Q_DISABLE_COPY( QgsAbstractVectorLayerLabeling )
141 
142 #ifdef SIP_RUN
144 #endif
145 
146 };
147 
157 {
158  public:
160  explicit QgsVectorLayerSimpleLabeling( const QgsPalLayerSettings &settings );
161 
162  QString type() const override;
166  QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context ) const override;
167  QgsPalLayerSettings settings( const QString &providerId = QString() ) const override;
168  bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
169 
178  void setSettings( QgsPalLayerSettings *settings SIP_TRANSFER, const QString &providerId = QString() ) override;
179 
180  bool requiresAdvancedEffects() const override;
181  void toSld( QDomNode &parent, const QgsStringMap &props ) const override;
182 
184  static QgsVectorLayerSimpleLabeling *create( const QDomElement &element, const QgsReadWriteContext &context );
185 
186  private:
187  std::unique_ptr<QgsPalLayerSettings> mSettings;
188 };
189 
190 #endif // QGSVECTORLAYERLABELING_H
QgsAbstractVectorLayerLabeling::~QgsAbstractVectorLayerLabeling
virtual ~QgsAbstractVectorLayerLabeling()=default
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:35
QgsPalLayerSettings
Definition: qgspallabeling.h:207
QgsAbstractVectorLayerLabeling::QgsAbstractVectorLayerLabeling
QgsAbstractVectorLayerLabeling()=default
Default constructor.
qgis.h
QgsStyleEntityVisitorInterface
An interface for classes which can visit style entity (e.g.
Definition: qgsstyleentityvisitor.h:34
QgsAbstractVectorLayerLabeling::toSld
virtual void toSld(QDomNode &parent, const QgsStringMap &props) const
Writes the SE 1.1 TextSymbolizer element based on the current layer labeling settings.
Definition: qgsvectorlayerlabeling.h:110
QgsAbstractVectorLayerLabeling::type
virtual QString type() const =0
Unique type string of the labeling configuration implementation.
QgsVectorLayerLabelProvider
The QgsVectorLayerLabelProvider class implements a label provider for vector layers.
Definition: qgsvectorlayerlabelprovider.h:41
QgsAbstractVectorLayerLabeling::setSettings
virtual void setSettings(QgsPalLayerSettings *settings, const QString &providerId=QString())=0
Set pal settings for a specific provider (takes ownership).
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
SIP_CONVERT_TO_SUBCLASS_CODE
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:177
QgsAbstractVectorLayerLabeling::create
static QgsAbstractVectorLayerLabeling * create(const QDomElement &element, const QgsReadWriteContext &context)
Try to create instance of an implementation based on the XML data.
Definition: qgsvectorlayerlabeling.cpp:27
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsAbstractVectorLayerLabeling::subProviders
virtual QStringList subProviders() const
Gets list of sub-providers within the layer's labeling.
Definition: qgsvectorlayerlabeling.h:76
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsAbstractVectorLayerLabeling
Abstract base class - its implementations define different approaches to the labeling of a vector lay...
Definition: qgsvectorlayerlabeling.h:42
QgsAbstractVectorLayerLabeling::provider
virtual QgsVectorLayerLabelProvider * provider(QgsVectorLayer *layer) const
Factory for label provider implementation.
Definition: qgsvectorlayerlabeling.h:70
QgsStringMap
QMap< QString, QString > QgsStringMap
Definition: qgis.h:758
QgsVectorLayerSimpleLabeling
Basic implementation of the labeling interface.
Definition: qgsvectorlayerlabeling.h:157
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:387
QgsAbstractVectorLayerLabeling::requiresAdvancedEffects
virtual bool requiresAdvancedEffects() const =0
Returns true if drawing labels requires advanced effects like composition modes, which could prevent ...
QgsAbstractVectorLayerLabeling::accept
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified symbology visitor, causing it to visit all symbols associated with the labeling...
Definition: qgsvectorlayerlabeling.cpp:44
SIP_END
#define SIP_END
Definition: qgis_sip.h:194
QgsAbstractVectorLayerLabeling::settings
virtual QgsPalLayerSettings settings(const QString &providerId=QString()) const =0
Gets associated label settings.
QgsAbstractVectorLayerLabeling::clone
virtual QgsAbstractVectorLayerLabeling * clone() const =0
Returns a new copy of the object.
QgsAbstractVectorLayerLabeling::save
virtual QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context) const =0
Returns labeling configuration as XML element.