QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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
64{
65 return u"simple"_s;
66}
67
69{
70 return new QgsMeshLayerSimpleLabeling( *mSettings, mLabelFaces );
71}
72
74{
75 return new QgsMeshLayerLabelProvider( layer, QString(), mSettings.get(), QString(), mLabelFaces );
76}
77
78QDomElement QgsMeshLayerSimpleLabeling::save( QDomDocument &doc, const QgsReadWriteContext &context ) const
79{
80 QDomElement elem = doc.createElement( u"labeling"_s );
81 elem.setAttribute( u"type"_s, u"simple"_s );
82 elem.setAttribute( u"labelFaces"_s, mLabelFaces ? u"1"_s : u"0"_s );
83 elem.appendChild( mSettings->writeXml( doc, context ) );
84 return elem;
85}
86
88{
89 Q_UNUSED( providerId )
90 return *mSettings;
91}
92
94{
95 if ( mSettings )
96 {
97 QgsStyleLabelSettingsEntity entity( *mSettings );
98 if ( !visitor->visit( &entity ) )
99 return false;
100 }
101 return true;
102}
103
108
110{
111 return mSettings->dataDefinedProperties().isActive( QgsPalLayerSettings::Property::FontBlendMode )
112 || mSettings->dataDefinedProperties().isActive( QgsPalLayerSettings::Property::ShapeBlendMode )
113 || mSettings->dataDefinedProperties().isActive( QgsPalLayerSettings::Property::BufferBlendMode )
114 || mSettings->dataDefinedProperties().isActive( QgsPalLayerSettings::Property::ShadowBlendMode )
115 || mSettings->format().hasNonDefaultCompositionMode();
116}
117
118QgsMeshLayerSimpleLabeling *QgsMeshLayerSimpleLabeling::create( const QDomElement &element, const QgsReadWriteContext &context ) // cppcheck-suppress duplInheritedMember
119{
120 const QDomElement settingsElem = element.firstChildElement( u"settings"_s );
121 if ( !settingsElem.isNull() )
122 {
124 settings.readXml( settingsElem, context );
125 const bool labelFaces = element.attribute( u"labelFaces"_s, u"0"_s ).toInt();
126 return new QgsMeshLayerSimpleLabeling( settings, labelFaces );
127 }
128
130}
131
133{
134 QgsTextFormat format { mSettings->format() };
135 format.multiplyOpacity( opacityFactor );
136 mSettings->setFormat( format );
137}
138
140{
141 Q_UNUSED( providerId )
142
143 if ( mSettings.get() == settings )
144 return;
145
146 mSettings.reset( settings );
147}
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:1478
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.