QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
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_sip.h"
20#include "qgis_core.h"
21#include "qgis.h"
25#include "qgstextmasksettings.h"
26#include "qgsstringutils.h"
27#include "qgsscreenproperties.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 );
51
52 QgsTextFormat &operator=( const QgsTextFormat &other );
53
55
56 bool operator==( const QgsTextFormat &other ) const;
57 bool operator!=( const QgsTextFormat &other ) const;
58
71 bool isValid() const;
72
79 void setValid();
80
85 QgsTextBufferSettings &buffer();
86
91 SIP_SKIP QgsTextBufferSettings buffer() const { return mBufferSettings; }
92
98 void setBuffer( const QgsTextBufferSettings &bufferSettings );
99
104 QgsTextBackgroundSettings &background();
105
110 SIP_SKIP QgsTextBackgroundSettings background() const { return mBackgroundSettings; }
111
117 void setBackground( const QgsTextBackgroundSettings &backgroundSettings );
118
123 QgsTextShadowSettings &shadow();
124
129 SIP_SKIP QgsTextShadowSettings shadow() const { return mShadowSettings; }
130
136 void setShadow( const QgsTextShadowSettings &shadowSettings );
137
142 QgsTextMaskSettings &mask();
143
150 SIP_SKIP QgsTextMaskSettings mask() const { return mMaskSettings; }
151
159 void setMask( const QgsTextMaskSettings &maskSettings );
160
170 QFont font() const;
171
185 QFont scaledFont( const QgsRenderContext &context, double scaleFactor = 1.0, bool *isZeroSize SIP_PYARGREMOVE = nullptr ) const;
186
196 void setFont( const QFont &font );
197
203 QString namedStyle() const;
204
211 void setNamedStyle( const QString &style );
212
224 bool forcedBold() const;
225
237 void setForcedBold( bool forced );
238
250 bool forcedItalic() const;
251
263 void setForcedItalic( bool forced );
264
274 QStringList families() const;
275
289 void setFamilies( const QStringList &families );
290
296 double size() const;
297
304 void setSize( double size );
305
312 Qgis::RenderUnit sizeUnit() const;
313
321 void setSizeUnit( Qgis::RenderUnit unit );
322
329 QgsMapUnitScale sizeMapUnitScale() const;
330
337 void setSizeMapUnitScale( const QgsMapUnitScale &scale );
338
343 QColor color() const;
344
350 void setColor( const QColor &color );
351
357 double opacity() const;
358
367 void multiplyOpacity( double opacityFactor );
368
375 void setOpacity( double opacity );
376
389 int stretchFactor() const;
390
403 void setStretchFactor( int factor );
404
409 QPainter::CompositionMode blendMode() const;
410
416 void setBlendMode( QPainter::CompositionMode mode );
417
428 double lineHeight() const;
429
440 void setLineHeight( double height );
441
450 Qgis::RenderUnit lineHeightUnit() const;
451
460 void setLineHeightUnit( Qgis::RenderUnit unit );
461
473 double tabStopDistance() const;
474
488 void setTabStopDistance( double distance );
489
495 class CORE_EXPORT Tab
496 {
497 public:
498
502 explicit Tab( double position );
503
509 void setPosition( double position ) { mPosition = position; }
510
516 double position() const { return mPosition; }
517
518 bool operator==( const QgsTextFormat::Tab &other ) const
519 {
520 return qgsDoubleNear( mPosition, other.mPosition );
521 }
522
523#ifdef SIP_RUN
524 SIP_PYOBJECT __repr__();
525 % MethodCode
526 const QString str = QStringLiteral( "<QgsTextFormat.Tab: %1>" ).arg( sipCpp->position() );
527 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
528 % End
529#endif
530
531 private:
532
533 double mPosition = 0;
534
535 };
536
551 QList< QgsTextFormat::Tab > tabPositions() const;
552
566 void setTabPositions( const QList< QgsTextFormat::Tab > &positions );
567
577 Qgis::RenderUnit tabStopDistanceUnit() const;
578
588 void setTabStopDistanceUnit( Qgis::RenderUnit unit );
589
599 QgsMapUnitScale tabStopDistanceMapUnitScale() const;
600
610 void setTabStopDistanceMapUnitScale( const QgsMapUnitScale &scale );
611
617 Qgis::TextOrientation orientation() const;
618
624 void setOrientation( Qgis::TextOrientation orientation );
625
632 Qgis::Capitalization capitalization() const;
633
640 void setCapitalization( Qgis::Capitalization capitalization );
641
656 bool allowHtmlFormatting() const;
657
672 void setAllowHtmlFormatting( bool allow );
673
679 QColor previewBackgroundColor() const;
680
686 void setPreviewBackgroundColor( const QColor &color );
687
692 void readFromLayer( QgsVectorLayer *layer );
693
698 void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
699
704 QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
705
711 QMimeData *toMimeData() const SIP_FACTORY;
712
720 static QgsTextFormat fromQFont( const QFont &font );
721
729 QFont toQFont() const;
730
736 static QgsTextFormat fromMimeData( const QMimeData *data, bool *ok SIP_OUT = nullptr );
737
742 bool containsAdvancedEffects() const;
743
749 bool fontFound() const { return mTextFontFound; }
750
757 QString resolvedFontFamily() const { return mTextFontFamily; }
758
764 QgsPropertyCollection &dataDefinedProperties();
765
772 const QgsPropertyCollection &dataDefinedProperties() const SIP_SKIP;
773
778 QSet<QString> referencedFields( const QgsRenderContext &context ) const;
779
786 void setDataDefinedProperties( const QgsPropertyCollection &collection );
787
792 void updateDataDefinedProperties( QgsRenderContext &context );
793
803 static QPixmap textFormatPreviewPixmap( const QgsTextFormat &format, QSize size, const QString &previewText = QString(), int padding = 0, const QgsScreenProperties &screen = QgsScreenProperties() );
804
814 QString asCSS( double pointToPixelMultiplier = 1.0 ) const;
815
816 private:
817
818 QgsTextBufferSettings mBufferSettings;
819 QgsTextBackgroundSettings mBackgroundSettings;
820 QgsTextShadowSettings mShadowSettings;
821 QgsTextMaskSettings mMaskSettings;
822
823 QString mTextFontFamily;
824 bool mTextFontFound = true;
825
826 QSharedDataPointer<QgsTextSettingsPrivate> d;
827
828};
829
831
832#endif // QGSTEXTFORMAT_H
Capitalization
String capitalization options.
Definition qgis.h:3132
TextOrientation
Text orientations.
Definition qgis.h:2684
RenderUnit
Rendering size units.
Definition qgis.h:4839
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.
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.
void setPosition(double position)
Sets the tab position.
bool operator==(const QgsTextFormat::Tab &other) const
Container for all settings relating to text rendering.
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.
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.
Represents a vector layer which manages a vector based data sets.
#define str(x)
Definition qgis.cpp:39
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition qgis.h:5917
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_PYARGREMOVE
Definition qgis_sip.h:151
#define SIP_OUT
Definition qgis_sip.h:58
#define SIP_FACTORY
Definition qgis_sip.h:76
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)