QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 #include "qgsstringutils.h"
27 
28 #include <QSharedDataPointer>
29 
30 class QgsTextSettingsPrivate;
31 
39 class CORE_EXPORT QgsTextFormat
40 {
41  public:
42 
45  {
49  };
50 
55  QgsTextFormat();
56 
61  QgsTextFormat( const QgsTextFormat &other );
62 
63  QgsTextFormat &operator=( const QgsTextFormat &other );
64 
65  ~QgsTextFormat();
66 
67  bool operator==( const QgsTextFormat &other ) const;
68  bool operator!=( const QgsTextFormat &other ) const;
69 
82  bool isValid() const;
83 
90  void setValid();
91 
96  QgsTextBufferSettings &buffer();
97 
102  SIP_SKIP QgsTextBufferSettings buffer() const { return mBufferSettings; }
103 
109  void setBuffer( const QgsTextBufferSettings &bufferSettings );
110 
115  QgsTextBackgroundSettings &background();
116 
121  SIP_SKIP QgsTextBackgroundSettings background() const { return mBackgroundSettings; }
122 
128  void setBackground( const QgsTextBackgroundSettings &backgroundSettings );
129 
134  QgsTextShadowSettings &shadow();
135 
140  SIP_SKIP QgsTextShadowSettings shadow() const { return mShadowSettings; }
141 
147  void setShadow( const QgsTextShadowSettings &shadowSettings );
148 
153  QgsTextMaskSettings &mask();
154 
161  SIP_SKIP QgsTextMaskSettings mask() const { return mMaskSettings; }
162 
170  void setMask( const QgsTextMaskSettings &maskSettings );
171 
181  QFont font() const;
182 
195  QFont scaledFont( const QgsRenderContext &context, double scaleFactor = 1.0 ) const;
196 
206  void setFont( const QFont &font );
207 
213  QString namedStyle() const;
214 
221  void setNamedStyle( const QString &style );
222 
228  double size() const;
229 
236  void setSize( double size );
237 
244  QgsUnitTypes::RenderUnit sizeUnit() const;
245 
253  void setSizeUnit( QgsUnitTypes::RenderUnit unit );
254 
261  QgsMapUnitScale sizeMapUnitScale() const;
262 
269  void setSizeMapUnitScale( const QgsMapUnitScale &scale );
270 
275  QColor color() const;
276 
282  void setColor( const QColor &color );
283 
289  double opacity() const;
290 
297  void setOpacity( double opacity );
298 
303  QPainter::CompositionMode blendMode() const;
304 
310  void setBlendMode( QPainter::CompositionMode mode );
311 
318  double lineHeight() const;
319 
327  void setLineHeight( double height );
328 
334  TextOrientation orientation() const;
335 
341  void setOrientation( TextOrientation orientation );
342 
349  QgsStringUtils::Capitalization capitalization() const;
350 
357  void setCapitalization( QgsStringUtils::Capitalization capitalization );
358 
373  bool allowHtmlFormatting() const;
374 
389  void setAllowHtmlFormatting( bool allow );
390 
396  QColor previewBackgroundColor() const;
397 
403  void setPreviewBackgroundColor( const QColor &color );
404 
409  void readFromLayer( QgsVectorLayer *layer );
410 
415  void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
416 
421  QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
422 
428  QMimeData *toMimeData() const SIP_FACTORY;
429 
437  static QgsTextFormat fromQFont( const QFont &font );
438 
446  QFont toQFont() const;
447 
453  static QgsTextFormat fromMimeData( const QMimeData *data, bool *ok SIP_OUT = nullptr );
454 
459  bool containsAdvancedEffects() const;
460 
466  bool fontFound() const { return mTextFontFound; }
467 
474  QString resolvedFontFamily() const { return mTextFontFamily; }
475 
481  QgsPropertyCollection &dataDefinedProperties();
482 
489  const QgsPropertyCollection &dataDefinedProperties() const SIP_SKIP;
490 
495  QSet<QString> referencedFields( const QgsRenderContext &context ) const;
496 
503  void setDataDefinedProperties( const QgsPropertyCollection &collection );
504 
509  void updateDataDefinedProperties( QgsRenderContext &context );
510 
519  static QPixmap textFormatPreviewPixmap( const QgsTextFormat &format, QSize size, const QString &previewText = QString(), int padding = 0 );
520 
521  private:
522 
523  QgsTextBufferSettings mBufferSettings;
524  QgsTextBackgroundSettings mBackgroundSettings;
525  QgsTextShadowSettings mShadowSettings;
526  QgsTextMaskSettings mMaskSettings;
527 
528  QString mTextFontFamily;
529  bool mTextFontFound = true;
530 
531  QSharedDataPointer<QgsTextSettingsPrivate> d;
532 
533 };
534 
536 
537 #endif // QGSTEXTFORMAT_H
qgstextmasksettings.h
QgsUnitTypes::RenderUnit
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:167
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:35
operator==
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
Definition: qgsfeatureiterator.h:400
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:474
QgsTextFormat::shadow
QgsTextShadowSettings shadow() const
Returns a reference to the text drop shadow settings.
Definition: qgstextformat.h:140
SIP_OUT
#define SIP_OUT
Definition: qgis_sip.h:58
qgsstringutils.h
QgsTextBackgroundSettings
Container for settings relating to a text background object.
Definition: qgstextbackgroundsettings.h:46
qgstextshadowsettings.h
qgstextbackgroundsettings.h
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:58
qgsunittypes.h
QgsTextFormat::background
QgsTextBackgroundSettings background() const
Returns a reference to the text background settings.
Definition: qgstextformat.h:121
QgsStringUtils::Capitalization
Capitalization
Capitalization options.
Definition: qgsstringutils.h:189
operator!=
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
Definition: qgsfeatureiterator.h:405
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsTextFormat::VerticalOrientation
@ VerticalOrientation
Horizontally oriented text.
Definition: qgstextformat.h:47
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(QgsMeshTimeSettings)
QgsTextFormat::mask
QgsTextMaskSettings mask() const
Returns a reference to the masking settings.
Definition: qgstextformat.h:161
QgsTextFormat
Container for all settings relating to text rendering.
Definition: qgstextformat.h:40
qgstextbuffersettings.h
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsTextMaskSettings
Container for settings relating to a selective masking around a text.
Definition: qgstextmasksettings.h:42
qgis_sip.h
QgsMapUnitScale
Struct for storing maximum and minimum scales for measurements in map units.
Definition: qgsmapunitscale.h:38
QgsTextBufferSettings
Container for settings relating to a text buffer.
Definition: qgstextbuffersettings.h:43
QgsTextFormat::buffer
QgsTextBufferSettings buffer() const
Returns a reference to the text buffer settings.
Definition: qgstextformat.h:102
QgsPropertyCollection
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
Definition: qgspropertycollection.h:319
QgsTextShadowSettings
Container for settings relating to a text shadow.
Definition: qgstextshadowsettings.h:38
QgsTextFormat::RotationBasedOrientation
@ RotationBasedOrientation
Horizontally or vertically oriented text based on rotation (only available for map labeling)
Definition: qgstextformat.h:48
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:387
QgsTextFormat::HorizontalOrientation
@ HorizontalOrientation
Vertically oriented text.
Definition: qgstextformat.h:46
QgsTextFormat::TextOrientation
TextOrientation
Text orientation.
Definition: qgstextformat.h:45