QGIS API Documentation 3.99.0-Master (d270888f95f)
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 "qgis.h"
20#include "qgsmeshlayer.h"
22#include "qgspallabeling.h"
24
25#include <QString>
26
27using namespace Qt::StringLiterals;
28
30{
31 const QString type = element.attribute( u"type"_s );
32 if ( type == "simple"_L1 )
33 {
34 return QgsMeshLayerSimpleLabeling::create( element, context );
35 }
36 else
37 {
38 return nullptr;
39 }
40}
41
46
53
54
56
57
59 : mSettings( new QgsPalLayerSettings( settings ) )
60 , mLabelFaces( labelFaces )
61{
62}
63
65{
66 return u"simple"_s;
67}
68
70{
71 return new QgsMeshLayerSimpleLabeling( *mSettings, mLabelFaces );
72}
73
75{
76 return new QgsMeshLayerLabelProvider( layer, QString(), mSettings.get(), QString(), mLabelFaces );
77}
78
79QDomElement QgsMeshLayerSimpleLabeling::save( QDomDocument &doc, const QgsReadWriteContext &context ) const
80{
81 QDomElement elem = doc.createElement( u"labeling"_s );
82 elem.setAttribute( u"type"_s, u"simple"_s );
83 elem.setAttribute( u"labelFaces"_s, mLabelFaces ? u"1"_s : u"0"_s );
84 elem.appendChild( mSettings->writeXml( doc, context ) );
85 return elem;
86}
87
89{
90 Q_UNUSED( providerId )
91 return *mSettings;
92}
93
95{
96 if ( mSettings )
97 {
98 QgsStyleLabelSettingsEntity entity( *mSettings );
99 if ( !visitor->visit( &entity ) )
100 return false;
101 }
102 return true;
103}
104
109
111{
112 return mSettings->dataDefinedProperties().isActive( QgsPalLayerSettings::Property::FontBlendMode )
113 || mSettings->dataDefinedProperties().isActive( QgsPalLayerSettings::Property::ShapeBlendMode )
114 || mSettings->dataDefinedProperties().isActive( QgsPalLayerSettings::Property::BufferBlendMode )
115 || mSettings->dataDefinedProperties().isActive( QgsPalLayerSettings::Property::ShadowBlendMode )
116 || mSettings->format().hasNonDefaultCompositionMode();
117}
118
119QgsMeshLayerSimpleLabeling *QgsMeshLayerSimpleLabeling::create( const QDomElement &element, const QgsReadWriteContext &context ) // cppcheck-suppress duplInheritedMember
120{
121 const QDomElement settingsElem = element.firstChildElement( u"settings"_s );
122 if ( !settingsElem.isNull() )
123 {
125 settings.readXml( settingsElem, context );
126 const bool labelFaces = element.attribute( u"labelFaces"_s, u"0"_s ).toInt();
127 return new QgsMeshLayerSimpleLabeling( settings, labelFaces );
128 }
129
131}
132
134{
135 QgsTextFormat format { mSettings->format() };
136 format.multiplyOpacity( opacityFactor );
137 mSettings->setFormat( format );
138}
139
141{
142 Q_UNUSED( providerId )
143
144 if ( mSettings.get() == settings )
145 return;
146
147 mSettings.reset( settings );
148}
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.
Implements a label provider for mesh layers.
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.
bool hasNonDefaultCompositionMode() const override
Returns true the labeling requires a non-default composition mode.
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.
bool containsAdvancedEffects() const
Returns true if any component of the label settings requires advanced effects such as blend modes,...
A container for the context for various read/write operations on 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:1491
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.
void multiplyOpacity(double opacityFactor)
Multiply opacity by opacityFactor.