QGIS API Documentation  3.24.2-Tisler (13c1a02865)
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 
339  int stretchFactor() const;
340 
353  void setStretchFactor( int factor );
354 
359  QPainter::CompositionMode blendMode() const;
360 
366  void setBlendMode( QPainter::CompositionMode mode );
367 
374  double lineHeight() const;
375 
383  void setLineHeight( double height );
384 
390  TextOrientation orientation() const;
391 
397  void setOrientation( TextOrientation orientation );
398 
405  Qgis::Capitalization capitalization() const;
406 
413  void setCapitalization( Qgis::Capitalization capitalization );
414 
429  bool allowHtmlFormatting() const;
430 
445  void setAllowHtmlFormatting( bool allow );
446 
452  QColor previewBackgroundColor() const;
453 
459  void setPreviewBackgroundColor( const QColor &color );
460 
465  void readFromLayer( QgsVectorLayer *layer );
466 
471  void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
472 
477  QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
478 
484  QMimeData *toMimeData() const SIP_FACTORY;
485 
493  static QgsTextFormat fromQFont( const QFont &font );
494 
502  QFont toQFont() const;
503 
509  static QgsTextFormat fromMimeData( const QMimeData *data, bool *ok SIP_OUT = nullptr );
510 
515  bool containsAdvancedEffects() const;
516 
522  bool fontFound() const { return mTextFontFound; }
523 
530  QString resolvedFontFamily() const { return mTextFontFamily; }
531 
537  QgsPropertyCollection &dataDefinedProperties();
538 
545  const QgsPropertyCollection &dataDefinedProperties() const SIP_SKIP;
546 
551  QSet<QString> referencedFields( const QgsRenderContext &context ) const;
552 
559  void setDataDefinedProperties( const QgsPropertyCollection &collection );
560 
565  void updateDataDefinedProperties( QgsRenderContext &context );
566 
575  static QPixmap textFormatPreviewPixmap( const QgsTextFormat &format, QSize size, const QString &previewText = QString(), int padding = 0 );
576 
577  private:
578 
579  QgsTextBufferSettings mBufferSettings;
580  QgsTextBackgroundSettings mBackgroundSettings;
581  QgsTextShadowSettings mShadowSettings;
582  QgsTextMaskSettings mMaskSettings;
583 
584  QString mTextFontFamily;
585  bool mTextFontFound = true;
586 
587  QSharedDataPointer<QgsTextSettingsPrivate> d;
588 
589 };
590 
592 
593 #endif // QGSTEXTFORMAT_H
Capitalization
String capitalization options.
Definition: qgis.h:1236
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.
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)