QGIS API Documentation  2.14.0-Essen
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, 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 }
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
The QgsVectorLayerLabelProvider class implements a label provider for vector layers.
void setAttribute(const QString &name, const QString &value)
virtual QDomElement save(QDomDocument &doc) const override
Return labeling configuration as XML element.
QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
static QgsRuleBasedLabeling * create(const QDomElement &element)
Create the instance from a DOM element with saved configuration.
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.
QDomElement createElement(const QString &tagName)
bool labelsEnabled() const
Returns whether the layer contains labels which are enabled and should be drawn.
Represents a vector layer which manages a vector based data sets.
QString toString() const