QGIS API Documentation  3.19.0-Master (c9e5875a2b)
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 
229  double size() const;
230 
237  void setSize( double size );
238 
245  QgsUnitTypes::RenderUnit sizeUnit() const;
246 
254  void setSizeUnit( QgsUnitTypes::RenderUnit unit );
255 
262  QgsMapUnitScale sizeMapUnitScale() const;
263 
270  void setSizeMapUnitScale( const QgsMapUnitScale &scale );
271 
276  QColor color() const;
277 
283  void setColor( const QColor &color );
284 
290  double opacity() const;
291 
298  void setOpacity( double opacity );
299 
304  QPainter::CompositionMode blendMode() const;
305 
311  void setBlendMode( QPainter::CompositionMode mode );
312 
319  double lineHeight() const;
320 
328  void setLineHeight( double height );
329 
335  TextOrientation orientation() const;
336 
342  void setOrientation( TextOrientation orientation );
343 
350  QgsStringUtils::Capitalization capitalization() const;
351 
358  void setCapitalization( QgsStringUtils::Capitalization capitalization );
359 
374  bool allowHtmlFormatting() const;
375 
390  void setAllowHtmlFormatting( bool allow );
391 
397  QColor previewBackgroundColor() const;
398 
404  void setPreviewBackgroundColor( const QColor &color );
405 
410  void readFromLayer( QgsVectorLayer *layer );
411 
416  void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
417 
422  QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
423 
429  QMimeData *toMimeData() const SIP_FACTORY;
430 
438  static QgsTextFormat fromQFont( const QFont &font );
439 
447  QFont toQFont() const;
448 
454  static QgsTextFormat fromMimeData( const QMimeData *data, bool *ok SIP_OUT = nullptr );
455 
460  bool containsAdvancedEffects() const;
461 
467  bool fontFound() const { return mTextFontFound; }
468 
475  QString resolvedFontFamily() const { return mTextFontFamily; }
476 
482  QgsPropertyCollection &dataDefinedProperties();
483 
490  const QgsPropertyCollection &dataDefinedProperties() const SIP_SKIP;
491 
496  QSet<QString> referencedFields( const QgsRenderContext &context ) const;
497 
504  void setDataDefinedProperties( const QgsPropertyCollection &collection );
505 
510  void updateDataDefinedProperties( QgsRenderContext &context );
511 
520  static QPixmap textFormatPreviewPixmap( const QgsTextFormat &format, QSize size, const QString &previewText = QString(), int padding = 0 );
521 
522  private:
523 
524  QgsTextBufferSettings mBufferSettings;
525  QgsTextBackgroundSettings mBackgroundSettings;
526  QgsTextShadowSettings mShadowSettings;
527  QgsTextMaskSettings mMaskSettings;
528 
529  QString mTextFontFamily;
530  bool mTextFontFound = true;
531 
532  QSharedDataPointer<QgsTextSettingsPrivate> d;
533 
534 };
535 
537 
538 #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)