QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgstextformat.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgstextformat.h
3  ---------------
4  begin : May 2020
5  copyright : (C) 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 
16 #ifndef QGSTEXTFORMAT_H
17 #define QGSTEXTFORMAT_H
18 
19 #include "qgis_sip.h"
20 #include "qgis_core.h"
21 #include "qgsunittypes.h"
22 #include "qgstextbuffersettings.h"
24 #include "qgstextshadowsettings.h"
25 #include "qgstextmasksettings.h"
26 
27 #include <QSharedDataPointer>
28 
29 class QgsTextSettingsPrivate;
30 
38 class CORE_EXPORT QgsTextFormat
39 {
40  public:
41 
44  {
48  };
49 
50  QgsTextFormat();
51 
56  QgsTextFormat( const QgsTextFormat &other );
57 
58  QgsTextFormat &operator=( const QgsTextFormat &other );
59 
60  ~QgsTextFormat();
61 
66  QgsTextBufferSettings &buffer() { return mBufferSettings; }
67 
72  SIP_SKIP QgsTextBufferSettings buffer() const { return mBufferSettings; }
73 
79  void setBuffer( const QgsTextBufferSettings &bufferSettings ) { mBufferSettings = bufferSettings; }
80 
85  QgsTextBackgroundSettings &background() { return mBackgroundSettings; }
86 
91  SIP_SKIP QgsTextBackgroundSettings background() const { return mBackgroundSettings; }
92 
98  void setBackground( const QgsTextBackgroundSettings &backgroundSettings ) { mBackgroundSettings = backgroundSettings; }
99 
104  QgsTextShadowSettings &shadow() { return mShadowSettings; }
105 
110  SIP_SKIP QgsTextShadowSettings shadow() const { return mShadowSettings; }
111 
117  void setShadow( const QgsTextShadowSettings &shadowSettings ) { mShadowSettings = shadowSettings; }
118 
123  QgsTextMaskSettings &mask() { return mMaskSettings; }
124 
131  SIP_SKIP QgsTextMaskSettings mask() const { return mMaskSettings; }
132 
140  void setMask( const QgsTextMaskSettings &maskSettings ) { mMaskSettings = maskSettings; }
141 
151  QFont font() const;
152 
161  QFont scaledFont( const QgsRenderContext &context ) const;
162 
172  void setFont( const QFont &font );
173 
179  QString namedStyle() const;
180 
187  void setNamedStyle( const QString &style );
188 
194  double size() const;
195 
202  void setSize( double size );
203 
210  QgsUnitTypes::RenderUnit sizeUnit() const;
211 
219  void setSizeUnit( QgsUnitTypes::RenderUnit unit );
220 
227  QgsMapUnitScale sizeMapUnitScale() const;
228 
235  void setSizeMapUnitScale( const QgsMapUnitScale &scale );
236 
241  QColor color() const;
242 
248  void setColor( const QColor &color );
249 
255  double opacity() const;
256 
263  void setOpacity( double opacity );
264 
269  QPainter::CompositionMode blendMode() const;
270 
276  void setBlendMode( QPainter::CompositionMode mode );
277 
284  double lineHeight() const;
285 
293  void setLineHeight( double height );
294 
300  TextOrientation orientation() const;
301 
307  void setOrientation( TextOrientation orientation );
308 
323  bool allowHtmlFormatting() const;
324 
339  void setAllowHtmlFormatting( bool allow );
340 
346  QColor previewBackgroundColor() const;
347 
353  void setPreviewBackgroundColor( const QColor &color );
354 
359  void readFromLayer( QgsVectorLayer *layer );
360 
365  void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
366 
371  QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
372 
378  QMimeData *toMimeData() const SIP_FACTORY;
379 
387  static QgsTextFormat fromQFont( const QFont &font );
388 
396  QFont toQFont() const;
397 
403  static QgsTextFormat fromMimeData( const QMimeData *data, bool *ok SIP_OUT = nullptr );
404 
409  bool containsAdvancedEffects() const;
410 
416  bool fontFound() const { return mTextFontFound; }
417 
424  QString resolvedFontFamily() const { return mTextFontFamily; }
425 
431  QgsPropertyCollection &dataDefinedProperties();
432 
439  const QgsPropertyCollection &dataDefinedProperties() const SIP_SKIP;
440 
445  QSet<QString> referencedFields( const QgsRenderContext &context ) const;
446 
453  void setDataDefinedProperties( const QgsPropertyCollection &collection );
454 
459  void updateDataDefinedProperties( QgsRenderContext &context );
460 
469  static QPixmap textFormatPreviewPixmap( const QgsTextFormat &format, QSize size, const QString &previewText = QString(), int padding = 0 );
470 
471  private:
472 
473  QgsTextBufferSettings mBufferSettings;
474  QgsTextBackgroundSettings mBackgroundSettings;
475  QgsTextShadowSettings mShadowSettings;
476  QgsTextMaskSettings mMaskSettings;
477 
478  QString mTextFontFamily;
479  bool mTextFontFound = true;
480 
481  QSharedDataPointer<QgsTextSettingsPrivate> d;
482 
483 };
484 
485 #endif // QGSTEXTFORMAT_H
qgstextmasksettings.h
QgsTextFormat::buffer
QgsTextBufferSettings & buffer()
Returns a reference to the text buffer settings.
Definition: qgstextformat.h:66
QgsUnitTypes::RenderUnit
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:166
QgsReadWriteContext
Definition: qgsreadwritecontext.h:34
QgsTextFormat::resolvedFontFamily
QString resolvedFontFamily() const
Returns the family for the resolved font, ie if the specified font was not found on the system this w...
Definition: qgstextformat.h:424
QgsTextFormat::shadow
QgsTextShadowSettings shadow() const
Returns a reference to the text drop shadow settings.
Definition: qgstextformat.h:110
SIP_OUT
#define SIP_OUT
Definition: qgis_sip.h:58
QgsTextBackgroundSettings
Definition: qgstextbackgroundsettings.h:45
qgstextshadowsettings.h
qgstextbackgroundsettings.h
QgsRenderContext
Definition: qgsrendercontext.h:57
QgsTextFormat::shadow
QgsTextShadowSettings & shadow()
Returns a reference to the text drop shadow settings.
Definition: qgstextformat.h:104
qgsunittypes.h
QgsTextFormat::mask
QgsTextMaskSettings & mask()
Returns a reference to the masking settings.
Definition: qgstextformat.h:123
QgsTextFormat::background
QgsTextBackgroundSettings background() const
Returns a reference to the text background settings.
Definition: qgstextformat.h:91
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsTextFormat::VerticalOrientation
@ VerticalOrientation
Horizontally oriented text.
Definition: qgstextformat.h:46
QgsTextFormat::mask
QgsTextMaskSettings mask() const
Returns a reference to the masking settings.
Definition: qgstextformat.h:131
QgsTextFormat::setBackground
void setBackground(const QgsTextBackgroundSettings &backgroundSettings)
Sets the text's background settings.q.
Definition: qgstextformat.h:98
QgsTextFormat
Definition: qgstextformat.h:38
qgstextbuffersettings.h
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsTextMaskSettings
Definition: qgstextmasksettings.h:41
qgis_sip.h
QgsMapUnitScale
Struct for storing maximum and minimum scales for measurements in map units.
Definition: qgsmapunitscale.h:37
QgsTextBufferSettings
Definition: qgstextbuffersettings.h:42
QgsTextFormat::buffer
QgsTextBufferSettings buffer() const
Returns a reference to the text buffer settings.
Definition: qgstextformat.h:72
QgsPropertyCollection
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
Definition: qgspropertycollection.h:318
QgsTextShadowSettings
Definition: qgstextshadowsettings.h:37
QgsTextFormat::setBuffer
void setBuffer(const QgsTextBufferSettings &bufferSettings)
Sets the text's buffer settings.
Definition: qgstextformat.h:79
QgsTextFormat::RotationBasedOrientation
@ RotationBasedOrientation
Horizontally or vertically oriented text based on rotation (only available for map labeling)
Definition: qgstextformat.h:47
QgsTextFormat::setShadow
void setShadow(const QgsTextShadowSettings &shadowSettings)
Sets the text's drop shadow settings.
Definition: qgstextformat.h:117
QgsVectorLayer
Definition: qgsvectorlayer.h:385
QgsTextFormat::setMask
void setMask(const QgsTextMaskSettings &maskSettings)
Sets the text's masking settings.
Definition: qgstextformat.h:140
QgsTextFormat::background
QgsTextBackgroundSettings & background()
Returns a reference to the text background settings.
Definition: qgstextformat.h:85
QgsTextFormat::HorizontalOrientation
@ HorizontalOrientation
Vertically oriented text.
Definition: qgstextformat.h:45
QgsTextFormat::TextOrientation
TextOrientation
Text orientation.
Definition: qgstextformat.h:43