QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
236  bool forcedBold() const;
237 
249  void setForcedBold( bool forced );
250 
262  bool forcedItalic() const;
263 
275  void setForcedItalic( bool forced );
276 
286  QStringList families() const;
287 
301  void setFamilies( const QStringList &families );
302 
308  double size() const;
309 
316  void setSize( double size );
317 
324  QgsUnitTypes::RenderUnit sizeUnit() const;
325 
333  void setSizeUnit( QgsUnitTypes::RenderUnit unit );
334 
341  QgsMapUnitScale sizeMapUnitScale() const;
342 
349  void setSizeMapUnitScale( const QgsMapUnitScale &scale );
350 
355  QColor color() const;
356 
362  void setColor( const QColor &color );
363 
369  double opacity() const;
370 
377  void setOpacity( double opacity );
378 
391  int stretchFactor() const;
392 
405  void setStretchFactor( int factor );
406 
411  QPainter::CompositionMode blendMode() const;
412 
418  void setBlendMode( QPainter::CompositionMode mode );
419 
426  double lineHeight() const;
427 
435  void setLineHeight( double height );
436 
442  TextOrientation orientation() const;
443 
449  void setOrientation( TextOrientation orientation );
450 
457  Qgis::Capitalization capitalization() const;
458 
465  void setCapitalization( Qgis::Capitalization capitalization );
466 
481  bool allowHtmlFormatting() const;
482 
497  void setAllowHtmlFormatting( bool allow );
498 
504  QColor previewBackgroundColor() const;
505 
511  void setPreviewBackgroundColor( const QColor &color );
512 
517  void readFromLayer( QgsVectorLayer *layer );
518 
523  void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
524 
529  QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
530 
536  QMimeData *toMimeData() const SIP_FACTORY;
537 
545  static QgsTextFormat fromQFont( const QFont &font );
546 
554  QFont toQFont() const;
555 
561  static QgsTextFormat fromMimeData( const QMimeData *data, bool *ok SIP_OUT = nullptr );
562 
567  bool containsAdvancedEffects() const;
568 
574  bool fontFound() const { return mTextFontFound; }
575 
582  QString resolvedFontFamily() const { return mTextFontFamily; }
583 
589  QgsPropertyCollection &dataDefinedProperties();
590 
597  const QgsPropertyCollection &dataDefinedProperties() const SIP_SKIP;
598 
603  QSet<QString> referencedFields( const QgsRenderContext &context ) const;
604 
611  void setDataDefinedProperties( const QgsPropertyCollection &collection );
612 
617  void updateDataDefinedProperties( QgsRenderContext &context );
618 
627  static QPixmap textFormatPreviewPixmap( const QgsTextFormat &format, QSize size, const QString &previewText = QString(), int padding = 0 );
628 
629  private:
630 
631  QgsTextBufferSettings mBufferSettings;
632  QgsTextBackgroundSettings mBackgroundSettings;
633  QgsTextShadowSettings mShadowSettings;
634  QgsTextMaskSettings mMaskSettings;
635 
636  QString mTextFontFamily;
637  bool mTextFontFound = true;
638 
639  QSharedDataPointer<QgsTextSettingsPrivate> d;
640 
641 };
642 
644 
645 #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:34
operator==
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
Definition: qgsfeatureiterator.h:425
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:582
QgsTextFormat::shadow
QgsTextShadowSettings shadow() const
Returns a reference to the text drop shadow settings.
Definition: qgstextformat.h:141
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:59
qgsunittypes.h
SIP_PYARGREMOVE
#define SIP_PYARGREMOVE
Definition: qgis_sip.h:151
QgsTextFormat::background
QgsTextBackgroundSettings background() const
Returns a reference to the text background settings.
Definition: qgstextformat.h:122
operator!=
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
Definition: qgsfeatureiterator.h:430
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsTextFormat::VerticalOrientation
@ VerticalOrientation
Horizontally oriented text.
Definition: qgstextformat.h:48
QgsTextFormat::mask
QgsTextMaskSettings mask() const
Returns a reference to the masking settings.
Definition: qgstextformat.h:162
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. A selective masking only makes ...
Definition: qgstextmasksettings.h:41
qgis_sip.h
Qgis::Capitalization
Capitalization
String capitalization options.
Definition: qgis.h:1592
QgsMapUnitScale
Struct for storing maximum and minimum scales for measurements in map units.
Definition: qgsmapunitscale.h:36
QgsTextBufferSettings
Container for settings relating to a text buffer.
Definition: qgstextbuffersettings.h:42
QgsTextFormat::buffer
QgsTextBufferSettings buffer() const
Returns a reference to the text buffer settings.
Definition: qgstextformat.h:103
QgsPropertyCollection
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
Definition: qgspropertycollection.h:318
QgsTextShadowSettings
Container for settings relating to a text shadow.
Definition: qgstextshadowsettings.h:37
QgsTextFormat::RotationBasedOrientation
@ RotationBasedOrientation
Horizontally or vertically oriented text based on rotation (only available for map labeling)
Definition: qgstextformat.h:49
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
QgsTextFormat::HorizontalOrientation
@ HorizontalOrientation
Vertically oriented text.
Definition: qgstextformat.h:47
QgsTextFormat::TextOrientation
TextOrientation
Text orientation.
Definition: qgstextformat.h:45