QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgsvectorlayerlabeling.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvectorlayerlabeling.cpp
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 #include "qgsvectorlayerlabeling.h"
16 
17 #include "qgspallabeling.h"
18 #include "qgsrulebasedlabeling.h"
19 #include "qgsvectorlayer.h"
20 
21 
23 {
24 }
25 
27 {
28  if ( element.attribute( "type" ) == "rule-based" )
29  {
30  return QgsRuleBasedLabeling::create( element );
31  }
32  else
33  {
34  // default
36  }
37 }
38 
40 {
41  if ( layer->customProperty( "labeling" ).toString() == QLatin1String( "pal" ) && layer->labelsEnabled() )
42  return new QgsVectorLayerLabelProvider( layer, QString(), false );
43 
44  return nullptr;
45 }
46 
48 {
49  return "simple";
50 }
51 
53 {
54  // all configuration is kept in layer custom properties (for compatibility)
55  QDomElement elem = doc.createElement( "labeling" );
56  elem.setAttribute( "type", "simple" );
57  return elem;
58 }
59 
61 {
62  if ( providerId.isEmpty() )
63  return QgsPalLayerSettings::fromLayer( layer );
64  else
65  return QgsPalLayerSettings();
66 }
bool labelsEnabled() const
Returns whether the layer contains labels which are enabled and should be drawn.
virtual QString type() const override
Unique type string of the labeling configuration implementation.
virtual QgsVectorLayerLabelProvider * provider(QgsVectorLayer *layer) const override
Factory for label provider implementation.
QString attribute(const QString &name, const QString &defValue) const
static QgsPalLayerSettings fromLayer(QgsVectorLayer *layer)
The QgsVectorLayerLabelProvider class implements a label provider for vector layers.
void setAttribute(const QString &name, const QString &value)
bool isEmpty() const
virtual QDomElement save(QDomDocument &doc) const override
Return labeling configuration as XML element.
static QgsRuleBasedLabeling * create(const QDomElement &element)
Create the instance from a DOM element with saved configuration.
virtual QgsPalLayerSettings settings(QgsVectorLayer *layer, const QString &providerId=QString()) const override
Get associated label settings.
static QgsAbstractVectorLayerLabeling * create(const QDomElement &element)
Try to create instance of an implementation based on the XML data.
Abstract base class - its implementations define different approaches to the labeling of a vector lay...
Basic implementation of the labeling interface.
QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
QDomElement createElement(const QString &tagName)
Represents a vector layer which manages a vector based data sets.
QString toString() const