Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up reading/writing of labeling configuration in vector layers
Historically the configuration used to be stored in layer's custom properties, but that does not scale beyond simple rendering and so rule-based labeling introduced storage of configuration natively in XML elements. That left us with two different ways of reading/writing labeling configurations. This work makes all configuration to use native XML elements. To keep compatibility of 2.x projects, reading of configuration from custom properties is preserved. This commit also adds Python APIs for direct manipulation of labeling configuration through vector layer's setLabeling() and labeling() calls.
- Loading branch information
Showing
33 changed files
with
471 additions
and
300 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
|
||
|
||
class QgsRuleBasedLabeling : QgsAbstractVectorLayerLabeling | ||
{ | ||
%TypeHeaderCode | ||
#include "qgsrulebasedlabeling.h" | ||
%End | ||
public: | ||
typedef QList<QgsRuleBasedLabeling::Rule *> RuleList; | ||
|
||
class Rule | ||
{ | ||
%TypeHeaderCode | ||
#include "qgsrulebasedlabeling.h" | ||
%End | ||
public: | ||
Rule( QgsPalLayerSettings *settings /Transfer/, int scaleMinDenom = 0, int scaleMaxDenom = 0, const QString &filterExp = QString(), const QString &description = QString(), bool elseRule = false ); | ||
~Rule(); | ||
|
||
enum RegisterResult | ||
{ | ||
Filtered, | ||
Inactive, | ||
Registered | ||
}; | ||
|
||
QgsPalLayerSettings *settings() const; | ||
bool dependsOnScale() const; | ||
int scaleMinDenom() const; | ||
int scaleMaxDenom() const; | ||
QString filterExpression() const; | ||
QString description() const; | ||
bool active() const; | ||
bool isElse() const; | ||
QString ruleKey() const; | ||
void setSettings( QgsPalLayerSettings *settings /Transfer/ ); | ||
void setScaleMinDenom( int scaleMinDenom ); | ||
void setScaleMaxDenom( int scaleMaxDenom ); | ||
void setFilterExpression( const QString &filterExp ); | ||
void setDescription( const QString &description ); | ||
void setActive( bool state ); | ||
void setIsElse( bool iselse ); | ||
void setRuleKey( const QString &key ); | ||
const QgsRuleBasedLabeling::RuleList &children() const; | ||
QgsRuleBasedLabeling::RuleList descendants() const; | ||
QgsRuleBasedLabeling::Rule *parent(); | ||
void appendChild( QgsRuleBasedLabeling::Rule *rule /Transfer/ ); | ||
void insertChild( int i, QgsRuleBasedLabeling::Rule *rule /Transfer/ ); | ||
void removeChildAt( int i ); | ||
const QgsRuleBasedLabeling::Rule *findRuleByKey( const QString &key ) const; | ||
QgsRuleBasedLabeling::Rule *clone() const /Factory/; | ||
static QgsRuleBasedLabeling::Rule *create( const QDomElement &ruleElem, const QgsReadWriteContext &context ) /Factory/; | ||
QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context ) const; | ||
bool requiresAdvancedEffects() const; | ||
|
||
private: | ||
Rule( const QgsRuleBasedLabeling::Rule &rh ); | ||
}; | ||
|
||
explicit QgsRuleBasedLabeling( QgsRuleBasedLabeling::Rule *root /Transfer/ ); | ||
~QgsRuleBasedLabeling(); | ||
|
||
QgsRuleBasedLabeling::Rule *rootRule(); | ||
|
||
static QgsRuleBasedLabeling *create( const QDomElement &element, const QgsReadWriteContext &context ) /Factory/; | ||
|
||
virtual QString type() const; | ||
virtual QgsRuleBasedLabeling *clone() const /Factory/; | ||
virtual QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context ) const; | ||
virtual QStringList subProviders() const; | ||
virtual QgsPalLayerSettings settings( const QString &providerId = QString() ) const; | ||
virtual bool requiresAdvancedEffects() const; | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/core/qgsvectorlayerlabeling.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ | ||
|
||
|
||
|
||
|
||
|
||
|
||
class QgsAbstractVectorLayerLabeling | ||
{ | ||
%Docstring | ||
Abstract base class - its implementations define different approaches to the labeling of a vector layer. | ||
|
||
.. versionadded:: 3.0 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgsvectorlayerlabeling.h" | ||
%End | ||
public: | ||
|
||
QgsAbstractVectorLayerLabeling(); | ||
virtual ~QgsAbstractVectorLayerLabeling(); | ||
|
||
virtual QString type() const = 0; | ||
%Docstring | ||
Unique type string of the labeling configuration implementation | ||
:rtype: str | ||
%End | ||
|
||
virtual QgsAbstractVectorLayerLabeling *clone() const = 0 /Factory/; | ||
%Docstring | ||
Return a new copy of the object | ||
:rtype: QgsAbstractVectorLayerLabeling | ||
%End | ||
|
||
|
||
virtual QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context ) const = 0; | ||
%Docstring | ||
Return labeling configuration as XML element | ||
:rtype: QDomElement | ||
%End | ||
|
||
virtual QStringList subProviders() const; | ||
%Docstring | ||
Get list of sub-providers within the layer's labeling. | ||
:rtype: list of str | ||
%End | ||
|
||
virtual QgsPalLayerSettings settings( const QString &providerId = QString() ) const = 0; | ||
%Docstring | ||
they are identified by their ID (e.g. in case of rule-based labeling, provider ID == rule key) | ||
:rtype: QgsPalLayerSettings | ||
%End | ||
|
||
virtual bool requiresAdvancedEffects() const = 0; | ||
%Docstring | ||
Returns true if drawing labels requires advanced effects like composition | ||
modes, which could prevent it being used as an isolated cached image | ||
or exported to a vector format. | ||
.. versionadded:: 3.0 | ||
:rtype: bool | ||
%End | ||
|
||
|
||
static QgsAbstractVectorLayerLabeling *create( const QDomElement &element, const QgsReadWriteContext &context ) /Factory/; | ||
%Docstring | ||
Try to create instance of an implementation based on the XML data | ||
:rtype: QgsAbstractVectorLayerLabeling | ||
%End | ||
|
||
private: | ||
QgsAbstractVectorLayerLabeling( const QgsAbstractVectorLayerLabeling &rhs ); | ||
}; | ||
|
||
class QgsVectorLayerSimpleLabeling : QgsAbstractVectorLayerLabeling | ||
{ | ||
%Docstring | ||
Basic implementation of the labeling interface. | ||
|
||
The configuration is kept in layer's custom properties for backward compatibility. | ||
|
||
.. versionadded:: 3.0 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgsvectorlayerlabeling.h" | ||
%End | ||
public: | ||
explicit QgsVectorLayerSimpleLabeling( const QgsPalLayerSettings &settings ); | ||
%Docstring | ||
Constructs simple labeling configuration with given initial settings | ||
%End | ||
|
||
virtual QString type() const; | ||
virtual QgsAbstractVectorLayerLabeling *clone() const /Factory/; | ||
virtual QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context ) const; | ||
virtual QgsPalLayerSettings settings( const QString &providerId = QString() ) const; | ||
virtual bool requiresAdvancedEffects() const; | ||
|
||
|
||
static QgsVectorLayerSimpleLabeling *create( const QDomElement &element, const QgsReadWriteContext &context ); | ||
%Docstring | ||
Create the instance from a DOM element with saved configuration | ||
:rtype: QgsVectorLayerSimpleLabeling | ||
%End | ||
|
||
}; | ||
|
||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/core/qgsvectorlayerlabeling.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.