QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
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.h"
20#include "qgis_core.h"
21#include "qgis_sip.h"
22#include "qgsscreenproperties.h"
23#include "qgsstringutils.h"
26#include "qgstextmasksettings.h"
28
29#include <QSharedDataPointer>
30
31class QMimeData;
32class QgsTextSettingsPrivate;
33
40class CORE_EXPORT QgsTextFormat
41{
42 public:
43
49
50 QgsTextFormat( const QgsTextFormat &other );
52
53 QgsTextFormat &operator=( const QgsTextFormat &other );
55
57
58 bool operator==( const QgsTextFormat &other ) const;
59 bool operator!=( const QgsTextFormat &other ) const;
60
73 bool isValid() const;
74
81 void setValid();
82
88
93 SIP_SKIP QgsTextBufferSettings buffer() const { return mBufferSettings; }
94
100 void setBuffer( const QgsTextBufferSettings &bufferSettings );
101
106 QgsTextBackgroundSettings &background();
107
112 SIP_SKIP QgsTextBackgroundSettings background() const { return mBackgroundSettings; }
113
119 void setBackground( const QgsTextBackgroundSettings &backgroundSettings );
120
125 QgsTextShadowSettings &shadow();
126
131 SIP_SKIP QgsTextShadowSettings shadow() const { return mShadowSettings; }
132
138 void setShadow( const QgsTextShadowSettings &shadowSettings );
139
144 QgsTextMaskSettings &mask();
145
152 SIP_SKIP QgsTextMaskSettings mask() const { return mMaskSettings; }
153
161 void setMask( const QgsTextMaskSettings &maskSettings );
162
172 QFont font() const;
173
187 QFont scaledFont( const QgsRenderContext &context, double scaleFactor = 1.0, bool *isZeroSize SIP_PYARGREMOVE = nullptr ) const;
188
198 void setFont( const QFont &font );
199
205 QString namedStyle() const;
206
213 void setNamedStyle( const QString &style );
214
226 bool forcedBold() const;
227
239 void setForcedBold( bool forced );
240
252 bool forcedItalic() const;
253
265 void setForcedItalic( bool forced );
266
276 QStringList families() const;
277
291 void setFamilies( const QStringList &families );
292
298 double size() const;
299
306 void setSize( double size );
307
314 Qgis::RenderUnit sizeUnit() const;
315
323 void setSizeUnit( Qgis::RenderUnit unit );
324
331 QgsMapUnitScale sizeMapUnitScale() const;
332
339 void setSizeMapUnitScale( const QgsMapUnitScale &scale );
340
345 QColor color() const;
346
352 void setColor( const QColor &color );
353
359 double opacity() const;
360
369 void multiplyOpacity( double opacityFactor );
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
430 double lineHeight() const;
431
442 void setLineHeight( double height );
443
452 Qgis::RenderUnit lineHeightUnit() const;
453
462 void setLineHeightUnit( Qgis::RenderUnit unit );
463
475 double tabStopDistance() const;
476
490 void setTabStopDistance( double distance );
491
497 class CORE_EXPORT Tab
498 {
499 public:
500
504 explicit Tab( double position );
505
511 void setPosition( double position ) { mPosition = position; }
512
518 double position() const { return mPosition; }
519
520 bool operator==( const QgsTextFormat::Tab &other ) const
521 {
522 return qgsDoubleNear( mPosition, other.mPosition );
523 }
524
525#ifdef SIP_RUN
526 SIP_PYOBJECT __repr__();
527 % MethodCode
528 const QString str = QStringLiteral( "<QgsTextFormat.Tab: %1>" ).arg( sipCpp->position() );
529 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
530 % End
531#endif
532
533 private:
534
535 double mPosition = 0;
536
537 };
538
553 QList< QgsTextFormat::Tab > tabPositions() const;
554
568 void setTabPositions( const QList< QgsTextFormat::Tab > &positions );
569
579 Qgis::RenderUnit tabStopDistanceUnit() const;
580
590 void setTabStopDistanceUnit( Qgis::RenderUnit unit );
591
601 QgsMapUnitScale tabStopDistanceMapUnitScale() const;
602
612 void setTabStopDistanceMapUnitScale( const QgsMapUnitScale &scale );
613
619 Qgis::TextOrientation orientation() const;
620
626 void setOrientation( Qgis::TextOrientation orientation );
627
634 Qgis::Capitalization capitalization() const;
635
642 void setCapitalization( Qgis::Capitalization capitalization );
643
658 bool allowHtmlFormatting() const;
659
674 void setAllowHtmlFormatting( bool allow );
675
681 QColor previewBackgroundColor() const;
682
688 void setPreviewBackgroundColor( const QColor &color );
689
694 void readFromLayer( QgsVectorLayer *layer );
695
700 void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
701
706 QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
707
713 QMimeData *toMimeData() const SIP_FACTORY;
714
722 static QgsTextFormat fromQFont( const QFont &font );
723
731 QFont toQFont() const;
732
738 static QgsTextFormat fromMimeData( const QMimeData *data, bool *ok SIP_OUT = nullptr );
739
744 bool containsAdvancedEffects() const;
745
753 bool hasNonDefaultCompositionMode() const;
754
760 bool fontFound() const { return mTextFontFound; }
761
768 QString resolvedFontFamily() const { return mTextFontFamily; }
769
775 QgsPropertyCollection &dataDefinedProperties();
776
783 const QgsPropertyCollection &dataDefinedProperties() const SIP_SKIP;
784
789 QSet<QString> referencedFields( const QgsRenderContext &context ) const;
790
797 void setDataDefinedProperties( const QgsPropertyCollection &collection );
798
803 void updateDataDefinedProperties( QgsRenderContext &context );
804
814 static QPixmap textFormatPreviewPixmap( const QgsTextFormat &format, QSize size, const QString &previewText = QString(), int padding = 0, const QgsScreenProperties &screen = QgsScreenProperties() );
815
825 QString asCSS( double pointToPixelMultiplier = 1.0 ) const;
826
827 private:
828
829 QgsTextBufferSettings mBufferSettings;
830 QgsTextBackgroundSettings mBackgroundSettings;
831 QgsTextShadowSettings mShadowSettings;
832 QgsTextMaskSettings mMaskSettings;
833
834 QString mTextFontFamily;
835 bool mTextFontFound = true;
836
837 QSharedDataPointer<QgsTextSettingsPrivate> d;
838
839};
840
842
843#endif // QGSTEXTFORMAT_H
Capitalization
String capitalization options.
Definition qgis.h:3389
TextOrientation
Text orientations.
Definition qgis.h:2886
RenderUnit
Rendering size units.
Definition qgis.h:5183
Struct for storing maximum and minimum scales for measurements in map units.
A grouped map of multiple QgsProperty objects, each referenced by an integer key value.
A container for the context for various read/write operations on objects.
Contains information about the context of a rendering operation.
Stores properties relating to a screen.
Container for settings relating to a text background object.
Container for settings relating to a text buffer.
Defines a tab position for a text format.
double position() const
Returns the tab position.
Tab(double position)
Constructor for a Tab at the specified position.
void setPosition(double position)
Sets the tab position.
bool operator==(const QgsTextFormat::Tab &other) const
Container for all settings relating to text rendering.
QgsTextFormat()
Default constructor for QgsTextFormat.
QgsTextBufferSettings buffer() const
Returns a reference to the text buffer settings.
bool fontFound() const
Returns true if the specified font was found on the system, or false if the font was not found and a ...
QString resolvedFontFamily() const
Returns the family for the resolved font, ie if the specified font was not found on the system this w...
bool isValid() const
Returns true if the format is valid.
QgsTextMaskSettings mask() const
Returns a reference to the masking settings.
void setValid()
Sets the format to a valid state, without changing any of the default format settings.
QgsTextBackgroundSettings background() const
Returns a reference to the text background settings.
QgsTextShadowSettings shadow() const
Returns a reference to the text drop shadow settings.
QgsTextFormat & operator=(const QgsTextFormat &other)
QgsTextBufferSettings & buffer()
Returns a reference to the text buffer settings.
Container for settings relating to a selective masking around a text.
Container for settings relating to a text shadow.
Represents a vector layer which manages a vector based dataset.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
Definition qgis.h:6607
#define SIP_SKIP
Definition qgis_sip.h:134
#define SIP_PYARGREMOVE
Definition qgis_sip.h:159
#define SIP_OUT
Definition qgis_sip.h:58
#define SIP_FACTORY
Definition qgis_sip.h:84
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)