QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
qgsmeshlayerlabeling.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsmeshlayerlabeling.cpp
3 ---------------------
4 begin : November 2023
5 copyright : (C) 2023 by Alexander Bruy
6 email : alexander dot bruy at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
18
19#include "qgspallabeling.h"
20#include "qgsmeshlayer.h"
21#include "qgis.h"
24
26{
27 const QString type = element.attribute( QStringLiteral( "type" ) );
28 if ( type == QLatin1String( "simple" ) )
29 {
30 return QgsMeshLayerSimpleLabeling::create( element, context );
31 }
32 else
33 {
34 return nullptr;
35 }
36}
37
42
49
50
52
53
55 : mSettings( new QgsPalLayerSettings( settings ) )
56 , mLabelFaces( labelFaces )
57{
58}
59
61{
62 return QStringLiteral( "simple" );
63}
64
66{
67 return new QgsMeshLayerSimpleLabeling( *mSettings, mLabelFaces );
68}
69
71{
72 return new QgsMeshLayerLabelProvider( layer, QString(), mSettings.get(), QString(), mLabelFaces );
73}
74
75QDomElement QgsMeshLayerSimpleLabeling::save( QDomDocument &doc, const QgsReadWriteContext &context ) const
76{
77 QDomElement elem = doc.createElement( QStringLiteral( "labeling" ) );
78 elem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "simple" ) );
79 elem.setAttribute( QStringLiteral( "labelFaces" ), mLabelFaces ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
80 elem.appendChild( mSettings->writeXml( doc, context ) );
81 return elem;
82}
83
85{
86 Q_UNUSED( providerId )
87 return *mSettings;
88}
89
91{
92 if ( mSettings )
93 {
94 QgsStyleLabelSettingsEntity entity( *mSettings );
95 if ( !visitor->visit( &entity ) )
96 return false;
97 }
98 return true;
99}
100
102{
103 return mSettings->containsAdvancedEffects();
104}
105
106QgsMeshLayerSimpleLabeling *QgsMeshLayerSimpleLabeling::create( const QDomElement &element, const QgsReadWriteContext &context ) // cppcheck-suppress duplInheritedMember
107{
108 const QDomElement settingsElem = element.firstChildElement( QStringLiteral( "settings" ) );
109 if ( !settingsElem.isNull() )
110 {
112 settings.readXml( settingsElem, context );
113 const bool labelFaces = element.attribute( QStringLiteral( "labelFaces" ), QStringLiteral( "0" ) ).toInt();
114 return new QgsMeshLayerSimpleLabeling( settings, labelFaces );
115 }
116
118}
119
121{
122 QgsTextFormat format { mSettings->format() };
123 format.multiplyOpacity( opacityFactor );
124 mSettings->setFormat( format );
125}
126
127void QgsMeshLayerSimpleLabeling::setSettings( QgsPalLayerSettings *settings, const QString &providerId )
128{
129 Q_UNUSED( providerId )
130
131 if ( mSettings.get() == settings )
132 return;
133
134 mSettings.reset( settings );
135}
Abstract base class - its implementations define different approaches to the labeling of a mesh layer...
static QgsPalLayerSettings defaultSettingsForLayer(const QgsMeshLayer *layer)
Returns the default layer settings to use for the specified mesh layer.
static QgsAbstractMeshLayerLabeling * create(const QDomElement &element, const QgsReadWriteContext &context)
Try to create instance of an implementation based on the XML data.
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified symbology visitor, causing it to visit all symbols associated with the labeling...
virtual QString type() const =0
Unique type string of the labeling configuration implementation.
virtual QgsPalLayerSettings settings(const QString &providerId=QString()) const =0
Gets associated label settings.
QgsProject * project() const
Returns the parent project if this map layer is added to a project.
The QgsMeshLayerLabelProvider class implements a label provider for mesh layers.
Basic implementation of the labeling interface for mesh layer.
QgsMeshLayerLabelProvider * provider(QgsMeshLayer *layer) const override
QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context) const override
Returns labeling configuration as XML element.
void setSettings(QgsPalLayerSettings *settings, const QString &providerId=QString()) override
Set pal settings (takes ownership).
QgsMeshLayerSimpleLabeling * clone() const override
Returns a new copy of the object.
void multiplyOpacity(double opacityFactor) override
Multiply opacity by opacityFactor.
static QgsMeshLayerSimpleLabeling * create(const QDomElement &element, const QgsReadWriteContext &context)
Create the instance from a DOM element with saved configuration.
bool requiresAdvancedEffects() const override
Returns true if drawing labels requires advanced effects like composition modes, which could prevent ...
QgsPalLayerSettings settings(const QString &providerId=QString()) const override
Gets associated label settings.
QgsMeshLayerSimpleLabeling(const QgsPalLayerSettings &settings, bool labelFaces=false)
Constructs simple labeling configuration with given initial settings.
QString type() const override
Unique type string of the labeling configuration implementation.
bool accept(QgsStyleEntityVisitorInterface *visitor) const override
Accepts the specified symbology visitor, causing it to visit all symbols associated with the labeling...
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Contains settings for how a map layer will be labeled.
void setFormat(const QgsTextFormat &format)
Sets the label text formatting settings, e.g., font settings, buffer settings, etc.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
The class is used as a container of context for various read/write operations on other objects.
An interface for classes which can visit style entity (e.g.
virtual bool visit(const QgsStyleEntityVisitorInterface::StyleLeaf &entity)
Called when the visitor will visit a style entity.
A label settings entity for QgsStyle databases.
Definition qgsstyle.h:1489
static QgsTextFormat defaultTextFormatForProject(QgsProject *project, QgsStyle::TextFormatContext context=QgsStyle::TextFormatContext::Labeling)
Returns the default text format to use for new text based objects for the specified project,...
Container for all settings relating to text rendering.