QGIS API Documentation 3.99.0-Master (d270888f95f)
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#include <QString>
31
32using namespace Qt::StringLiterals;
33
34class QMimeData;
35class QgsTextSettingsPrivate;
36
43class CORE_EXPORT QgsTextFormat
44{
45 public:
46
52
53 QgsTextFormat( const QgsTextFormat &other );
55
56 QgsTextFormat &operator=( const QgsTextFormat &other );
58
60
61 bool operator==( const QgsTextFormat &other ) const;
62 bool operator!=( const QgsTextFormat &other ) const;
63
76 bool isValid() const;
77
84 void setValid();
85
91
96 SIP_SKIP QgsTextBufferSettings buffer() const { return mBufferSettings; }
97
103 void setBuffer( const QgsTextBufferSettings &bufferSettings );
104
109 QgsTextBackgroundSettings &background();
110
115 SIP_SKIP QgsTextBackgroundSettings background() const { return mBackgroundSettings; }
116
122 void setBackground( const QgsTextBackgroundSettings &backgroundSettings );
123
128 QgsTextShadowSettings &shadow();
129
134 SIP_SKIP QgsTextShadowSettings shadow() const { return mShadowSettings; }
135
141 void setShadow( const QgsTextShadowSettings &shadowSettings );
142
147 QgsTextMaskSettings &mask();
148
155 SIP_SKIP QgsTextMaskSettings mask() const { return mMaskSettings; }
156
164 void setMask( const QgsTextMaskSettings &maskSettings );
165
175 QFont font() const;
176
190 QFont scaledFont( const QgsRenderContext &context, double scaleFactor = 1.0, bool *isZeroSize SIP_PYARGREMOVE = nullptr ) const;
191
201 void setFont( const QFont &font );
202
208 QString namedStyle() const;
209
216 void setNamedStyle( const QString &style );
217
229 bool forcedBold() const;
230
242 void setForcedBold( bool forced );
243
255 bool forcedItalic() const;
256
268 void setForcedItalic( bool forced );
269
279 QStringList families() const;
280
294 void setFamilies( const QStringList &families );
295
301 double size() const;
302
309 void setSize( double size );
310
317 Qgis::RenderUnit sizeUnit() const;
318
326 void setSizeUnit( Qgis::RenderUnit unit );
327
334 QgsMapUnitScale sizeMapUnitScale() const;
335
342 void setSizeMapUnitScale( const QgsMapUnitScale &scale );
343
348 QColor color() const;
349
355 void setColor( const QColor &color );
356
362 double opacity() const;
363
372 void multiplyOpacity( double opacityFactor );
373
380 void setOpacity( double opacity );
381
394 int stretchFactor() const;
395
408 void setStretchFactor( int factor );
409
414 QPainter::CompositionMode blendMode() const;
415
421 void setBlendMode( QPainter::CompositionMode mode );
422
433 double lineHeight() const;
434
445 void setLineHeight( double height );
446
455 Qgis::RenderUnit lineHeightUnit() const;
456
465 void setLineHeightUnit( Qgis::RenderUnit unit );
466
478 double tabStopDistance() const;
479
493 void setTabStopDistance( double distance );
494
500 class CORE_EXPORT Tab
501 {
502 public:
503
507 explicit Tab( double position );
508
514 void setPosition( double position ) { mPosition = position; }
515
521 double position() const { return mPosition; }
522
523 bool operator==( const QgsTextFormat::Tab &other ) const
524 {
525 return qgsDoubleNear( mPosition, other.mPosition );
526 }
527
528#ifdef SIP_RUN
529 SIP_PYOBJECT __repr__();
530 % MethodCode
531 const QString str = u"<QgsTextFormat.Tab: %1>"_s.arg( sipCpp->position() );
532 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
533 % End
534#endif
535
536 private:
537
538 double mPosition = 0;
539
540 };
541
556 QList< QgsTextFormat::Tab > tabPositions() const;
557
571 void setTabPositions( const QList< QgsTextFormat::Tab > &positions );
572
582 Qgis::RenderUnit tabStopDistanceUnit() const;
583
593 void setTabStopDistanceUnit( Qgis::RenderUnit unit );
594
604 QgsMapUnitScale tabStopDistanceMapUnitScale() const;
605
615 void setTabStopDistanceMapUnitScale( const QgsMapUnitScale &scale );
616
622 Qgis::TextOrientation orientation() const;
623
629 void setOrientation( Qgis::TextOrientation orientation );
630
637 Qgis::Capitalization capitalization() const;
638
645 void setCapitalization( Qgis::Capitalization capitalization );
646
661 bool allowHtmlFormatting() const;
662
677 void setAllowHtmlFormatting( bool allow );
678
684 QColor previewBackgroundColor() const;
685
691 void setPreviewBackgroundColor( const QColor &color );
692
697 void readFromLayer( QgsVectorLayer *layer );
698
703 void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
704
709 QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
710
716 QMimeData *toMimeData() const SIP_FACTORY;
717
725 static QgsTextFormat fromQFont( const QFont &font );
726
734 QFont toQFont() const;
735
741 static QgsTextFormat fromMimeData( const QMimeData *data, bool *ok SIP_OUT = nullptr );
742
747 bool containsAdvancedEffects() const;
748
756 bool hasNonDefaultCompositionMode() const;
757
763 bool fontFound() const { return mTextFontFound; }
764
771 QString resolvedFontFamily() const { return mTextFontFamily; }
772
778 QgsPropertyCollection &dataDefinedProperties();
779
786 const QgsPropertyCollection &dataDefinedProperties() const SIP_SKIP;
787
792 QSet<QString> referencedFields( const QgsRenderContext &context ) const;
793
800 void setDataDefinedProperties( const QgsPropertyCollection &collection );
801
806 void updateDataDefinedProperties( QgsRenderContext &context );
807
817 static QPixmap textFormatPreviewPixmap( const QgsTextFormat &format, QSize size, const QString &previewText = QString(), int padding = 0, const QgsScreenProperties &screen = QgsScreenProperties() );
818
828 QString asCSS( double pointToPixelMultiplier = 1.0 ) const;
829
830 private:
831
832 QgsTextBufferSettings mBufferSettings;
833 QgsTextBackgroundSettings mBackgroundSettings;
834 QgsTextShadowSettings mShadowSettings;
835 QgsTextMaskSettings mMaskSettings;
836
837 QString mTextFontFamily;
838 bool mTextFontFound = true;
839
840 QSharedDataPointer<QgsTextSettingsPrivate> d;
841
842};
843
845
846#endif // QGSTEXTFORMAT_H
Capitalization
String capitalization options.
Definition qgis.h:3448
TextOrientation
Text orientations.
Definition qgis.h:2944
RenderUnit
Rendering size units.
Definition qgis.h:5255
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:6900
#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)