QGIS API Documentation 3.99.0-Master (09f76ad7019)
Loading...
Searching...
No Matches
qgslabellinesettings.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgslabellinesettings.cpp
3 ----------------------------
4 Date : August 2020
5 Copyright : (C) 2020 by Nyall Dawson
6 Email : nyall dot dawson 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
17
19#include "qgslabelingengine.h"
20#include "qgspallabeling.h"
22
23#include <QString>
24
25#include "moc_qgslabellinesettings.cpp"
26
27using namespace Qt::StringLiterals;
28
30{
32 {
34 const QString dataDefinedLineArrangement = properties.valueAsString( QgsPalLayerSettings::Property::LinePlacementOptions, context );
35 if ( !dataDefinedLineArrangement.isEmpty() )
36 {
37 mPlacementFlags = QgsLabelingUtils::decodeLinePlacementFlags( dataDefinedLineArrangement );
38 }
39 }
40
42 {
43 context.setOriginalValueVariable( mOverrunDistance );
44 mOverrunDistance = properties.valueAsDouble( QgsPalLayerSettings::Property::OverrunDistance, context, mOverrunDistance );
45 }
46
48 {
49 context.setOriginalValueVariable( mLineAnchorPercent );
50 mLineAnchorPercent = properties.valueAsDouble( QgsPalLayerSettings::Property::LineAnchorPercent, context, mLineAnchorPercent );
51 }
52
54 {
55 bool ok = false;
56 const QString value = properties.valueAsString( QgsPalLayerSettings::Property::LineAnchorClipping, context, QString(), &ok ).trimmed();
57 if ( ok )
58 {
59 if ( value.compare( "visible"_L1, Qt::CaseInsensitive ) == 0 )
61 else if ( value.compare( "entire"_L1, Qt::CaseInsensitive ) == 0 )
62 mAnchorClipping = AnchorClipping::UseEntireLine;
63 }
64 }
65
67 {
68 bool ok = false;
69 const QString value = properties.valueAsString( QgsPalLayerSettings::Property::LineAnchorType, context, QString(), &ok ).trimmed();
70 if ( ok )
71 {
72 if ( value.compare( "hint"_L1, Qt::CaseInsensitive ) == 0 )
73 mAnchorType = AnchorType::HintOnly;
74 else if ( value.compare( "strict"_L1, Qt::CaseInsensitive ) == 0 )
75 mAnchorType = AnchorType::Strict;
76 }
77 }
78
80 {
81 bool ok = false;
82 const QString value = properties.valueAsString( QgsPalLayerSettings::Property::LineAnchorTextPoint, context, QString(), &ok ).trimmed();
83 if ( ok )
84 {
85 if ( value.compare( "follow"_L1, Qt::CaseInsensitive ) == 0 )
86 mAnchorTextPoint = AnchorTextPoint::FollowPlacement;
87 else if ( value.compare( "start"_L1, Qt::CaseInsensitive ) == 0 )
88 mAnchorTextPoint = AnchorTextPoint::StartOfText;
89 else if ( value.compare( "center"_L1, Qt::CaseInsensitive ) == 0 )
90 mAnchorTextPoint = AnchorTextPoint::CenterOfText;
91 else if ( value.compare( "end"_L1, Qt::CaseInsensitive ) == 0 )
92 mAnchorTextPoint = AnchorTextPoint::EndOfText;
93 }
94 }
95
97 {
98 bool ok = false;
99 const QString value = properties.valueAsString( QgsPalLayerSettings::Property::CurvedLabelMode, context, QString(), &ok ).trimmed();
100 if ( ok )
101 {
102 if ( value.compare( "Default"_L1, Qt::CaseInsensitive ) == 0 )
103 mCurvedLabelMode = Qgis::CurvedLabelMode::Default;
104 else if ( value.compare( "CharactersAtVertices"_L1, Qt::CaseInsensitive ) == 0 )
106 else if ( value.compare( "StretchCharacterSpacingToFit"_L1, Qt::CaseInsensitive ) == 0 )
108 else if ( value.compare( "StretchWordSpacingToFit"_L1, Qt::CaseInsensitive ) == 0 )
110 }
111 }
112}
113
@ StretchCharacterSpacingToFitLine
Increases (or decreases) the character spacing used for each label in order to fit the entire text ov...
Definition qgis.h:1247
@ Default
Default curved placement, characters are placed in an optimal position along the line....
Definition qgis.h:1245
@ StretchWordSpacingToFitLine
Increases (or decreases) the word spacing used for each label in order to fit the entire text over th...
Definition qgis.h:1248
@ PlaceCharactersAtVertices
Each individual character from the label text is placed such that their left-baseline position is loc...
Definition qgis.h:1246
double valueAsDouble(int key, const QgsExpressionContext &context, double defaultValue=0.0, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a double.
QString valueAsString(int key, const QgsExpressionContext &context, const QString &defaultString=QString(), bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a string.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for the context.
@ Strict
Line anchor is a strict placement, and other placements are not permitted.
@ HintOnly
Line anchor is a hint for preferred placement only, but other placements close to the hint are permit...
@ UseEntireLine
Entire original feature line geometry is used when calculating the line anchor for labels.
@ UseVisiblePartsOfLine
Only visible parts of lines are considered when calculating the line anchor for labels.
@ StartOfText
Anchor using start of text.
@ CenterOfText
Anchor using center of text.
@ FollowPlacement
Automatically set the anchor point based on the lineAnchorPercent() value. Values <25% will use the s...
void updateDataDefinedProperties(const QgsPropertyCollection &properties, QgsExpressionContext &context)
Updates the line settings to respect any data defined properties set within the specified properties ...
static Qgis::LabelLinePlacementFlags decodeLinePlacementFlags(const QString &string)
Decodes a string to set of line placement flags.
static QString encodeLinePlacementFlags(Qgis::LabelLinePlacementFlags flags)
Encodes line placement flags to a string.
@ LinePlacementOptions
Line placement flags.
@ LineAnchorType
Line anchor type.
@ LineAnchorClipping
Clipping mode for line anchor calculation.
@ LineAnchorPercent
Portion along line at which labels should be anchored.
@ LineAnchorTextPoint
Line anchor text point.
@ OverrunDistance
Distance which labels can extend past either end of linear features.
@ CurvedLabelMode
Mode which determine how curved labels are generated and placed.
A grouped map of multiple QgsProperty objects, each referenced by an integer key value.
bool isActive(int key) const final
Returns true if the collection contains an active property with the specified key.