QGIS API Documentation  3.20.0-Odense (decaadbb31)
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 
196  QFont scaledFont( const QgsRenderContext &context, double scaleFactor = 1.0 ) const;
197 
207  void setFont( const QFont &font );
208 
214  QString namedStyle() const;
215 
222  void setNamedStyle( const QString &style );
223 
233  QStringList families() const;
234 
248  void setFamilies( const QStringList &families );
249 
255  double size() const;
256 
263  void setSize( double size );
264 
271  QgsUnitTypes::RenderUnit sizeUnit() const;
272 
280  void setSizeUnit( QgsUnitTypes::RenderUnit unit );
281 
288  QgsMapUnitScale sizeMapUnitScale() const;
289 
296  void setSizeMapUnitScale( const QgsMapUnitScale &scale );
297 
302  QColor color() const;
303 
309  void setColor( const QColor &color );
310 
316  double opacity() const;
317 
324  void setOpacity( double opacity );
325 
330  QPainter::CompositionMode blendMode() const;
331 
337  void setBlendMode( QPainter::CompositionMode mode );
338 
345  double lineHeight() const;
346 
354  void setLineHeight( double height );
355 
361  TextOrientation orientation() const;
362 
368  void setOrientation( TextOrientation orientation );
369 
376  QgsStringUtils::Capitalization capitalization() const;
377 
384  void setCapitalization( QgsStringUtils::Capitalization capitalization );
385 
400  bool allowHtmlFormatting() const;
401 
416  void setAllowHtmlFormatting( bool allow );
417 
423  QColor previewBackgroundColor() const;
424 
430  void setPreviewBackgroundColor( const QColor &color );
431 
436  void readFromLayer( QgsVectorLayer *layer );
437 
442  void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
443 
448  QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
449 
455  QMimeData *toMimeData() const SIP_FACTORY;
456 
464  static QgsTextFormat fromQFont( const QFont &font );
465 
473  QFont toQFont() const;
474 
480  static QgsTextFormat fromMimeData( const QMimeData *data, bool *ok SIP_OUT = nullptr );
481 
486  bool containsAdvancedEffects() const;
487 
493  bool fontFound() const { return mTextFontFound; }
494 
501  QString resolvedFontFamily() const { return mTextFontFamily; }
502 
508  QgsPropertyCollection &dataDefinedProperties();
509 
516  const QgsPropertyCollection &dataDefinedProperties() const SIP_SKIP;
517 
522  QSet<QString> referencedFields( const QgsRenderContext &context ) const;
523 
530  void setDataDefinedProperties( const QgsPropertyCollection &collection );
531 
536  void updateDataDefinedProperties( QgsRenderContext &context );
537 
546  static QPixmap textFormatPreviewPixmap( const QgsTextFormat &format, QSize size, const QString &previewText = QString(), int padding = 0 );
547 
548  private:
549 
550  QgsTextBufferSettings mBufferSettings;
551  QgsTextBackgroundSettings mBackgroundSettings;
552  QgsTextShadowSettings mShadowSettings;
553  QgsTextMaskSettings mMaskSettings;
554 
555  QString mTextFontFamily;
556  bool mTextFontFound = true;
557 
558  QSharedDataPointer<QgsTextSettingsPrivate> d;
559 
560 };
561 
563 
564 #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_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)