QGIS API Documentation  3.22.4-Białowieża (ce8e65e95e)
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 QMimeData;
31 class QgsTextSettingsPrivate;
32 
40 class CORE_EXPORT QgsTextFormat
41 {
42  public:
43 
46  {
50  };
51 
56  QgsTextFormat();
57 
62  QgsTextFormat( const QgsTextFormat &other );
63 
64  QgsTextFormat &operator=( const QgsTextFormat &other );
65 
66  ~QgsTextFormat();
67 
68  bool operator==( const QgsTextFormat &other ) const;
69  bool operator!=( const QgsTextFormat &other ) const;
70 
83  bool isValid() const;
84 
91  void setValid();
92 
97  QgsTextBufferSettings &buffer();
98 
103  SIP_SKIP QgsTextBufferSettings buffer() const { return mBufferSettings; }
104 
110  void setBuffer( const QgsTextBufferSettings &bufferSettings );
111 
116  QgsTextBackgroundSettings &background();
117 
122  SIP_SKIP QgsTextBackgroundSettings background() const { return mBackgroundSettings; }
123 
129  void setBackground( const QgsTextBackgroundSettings &backgroundSettings );
130 
135  QgsTextShadowSettings &shadow();
136 
141  SIP_SKIP QgsTextShadowSettings shadow() const { return mShadowSettings; }
142 
148  void setShadow( const QgsTextShadowSettings &shadowSettings );
149 
154  QgsTextMaskSettings &mask();
155 
162  SIP_SKIP QgsTextMaskSettings mask() const { return mMaskSettings; }
163 
171  void setMask( const QgsTextMaskSettings &maskSettings );
172 
182  QFont font() const;
183 
197  QFont scaledFont( const QgsRenderContext &context, double scaleFactor = 1.0, bool *isZeroSize SIP_PYARGREMOVE = nullptr ) const;
198 
208  void setFont( const QFont &font );
209 
215  QString namedStyle() const;
216 
223  void setNamedStyle( const QString &style );
224 
234  QStringList families() const;
235 
249  void setFamilies( const QStringList &families );
250 
256  double size() const;
257 
264  void setSize( double size );
265 
272  QgsUnitTypes::RenderUnit sizeUnit() const;
273 
281  void setSizeUnit( QgsUnitTypes::RenderUnit unit );
282 
289  QgsMapUnitScale sizeMapUnitScale() const;
290 
297  void setSizeMapUnitScale( const QgsMapUnitScale &scale );
298 
303  QColor color() const;
304 
310  void setColor( const QColor &color );
311 
317  double opacity() const;
318 
325  void setOpacity( double opacity );
326 
331  QPainter::CompositionMode blendMode() const;
332 
338  void setBlendMode( QPainter::CompositionMode mode );
339 
346  double lineHeight() const;
347 
355  void setLineHeight( double height );
356 
362  TextOrientation orientation() const;
363 
369  void setOrientation( TextOrientation orientation );
370 
377  QgsStringUtils::Capitalization capitalization() const;
378 
385  void setCapitalization( QgsStringUtils::Capitalization capitalization );
386 
401  bool allowHtmlFormatting() const;
402 
417  void setAllowHtmlFormatting( bool allow );
418 
424  QColor previewBackgroundColor() const;
425 
431  void setPreviewBackgroundColor( const QColor &color );
432 
437  void readFromLayer( QgsVectorLayer *layer );
438 
443  void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
444 
449  QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
450 
456  QMimeData *toMimeData() const SIP_FACTORY;
457 
465  static QgsTextFormat fromQFont( const QFont &font );
466 
474  QFont toQFont() const;
475 
481  static QgsTextFormat fromMimeData( const QMimeData *data, bool *ok SIP_OUT = nullptr );
482 
487  bool containsAdvancedEffects() const;
488 
494  bool fontFound() const { return mTextFontFound; }
495 
502  QString resolvedFontFamily() const { return mTextFontFamily; }
503 
509  QgsPropertyCollection &dataDefinedProperties();
510 
517  const QgsPropertyCollection &dataDefinedProperties() const SIP_SKIP;
518 
523  QSet<QString> referencedFields( const QgsRenderContext &context ) const;
524 
531  void setDataDefinedProperties( const QgsPropertyCollection &collection );
532 
537  void updateDataDefinedProperties( QgsRenderContext &context );
538 
547  static QPixmap textFormatPreviewPixmap( const QgsTextFormat &format, QSize size, const QString &previewText = QString(), int padding = 0 );
548 
549  private:
550 
551  QgsTextBufferSettings mBufferSettings;
552  QgsTextBackgroundSettings mBackgroundSettings;
553  QgsTextShadowSettings mShadowSettings;
554  QgsTextMaskSettings mMaskSettings;
555 
556  QString mTextFontFamily;
557  bool mTextFontFound = true;
558 
559  QSharedDataPointer<QgsTextSettingsPrivate> d;
560 
561 };
562 
564 
565 #endif // QGSTEXTFORMAT_H
Struct for storing maximum and minimum scales for measurements in map units.
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
The class is used as a container of context for various read/write operations on other objects.
Contains information about the context of a rendering operation.
Capitalization
Capitalization options.
Container for settings relating to a text background object.
Container for settings relating to a text buffer.
Container for all settings relating to text rendering.
Definition: qgstextformat.h:41
QgsTextBufferSettings buffer() const
Returns a reference to the text buffer settings.
QString resolvedFontFamily() const
Returns the family for the resolved font, ie if the specified font was not found on the system this w...
QgsTextMaskSettings mask() const
Returns a reference to the masking settings.
TextOrientation
Text orientation.
Definition: qgstextformat.h:46
@ HorizontalOrientation
Vertically oriented text.
Definition: qgstextformat.h:47
@ RotationBasedOrientation
Horizontally or vertically oriented text based on rotation (only available for map labeling)
Definition: qgstextformat.h:49
@ VerticalOrientation
Horizontally oriented text.
Definition: qgstextformat.h:48
QgsTextBackgroundSettings background() const
Returns a reference to the text background settings.
QgsTextShadowSettings shadow() const
Returns a reference to the text drop shadow settings.
Container for settings relating to a selective masking around a text.
Container for settings relating to a text shadow.
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:168
Represents a vector layer which manages a vector based data sets.
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_PYARGREMOVE
Definition: qgis_sip.h:146
#define SIP_OUT
Definition: qgis_sip.h:58
#define SIP_FACTORY
Definition: qgis_sip.h:76
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
Q_DECLARE_METATYPE(QgsMeshTimeSettings)