QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
qgstextblock.h
Go to the documentation of this file.
1/***************************************************************************
2 qgstextblock.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 QGSTEXTBLOCK_H
17#define QGSTEXTBLOCK_H
18
19#include "qgis_sip.h"
20#include "qgis_core.h"
21#include "qgstextfragment.h"
22#include "qgstextblockformat.h"
23#include "qgsstringutils.h"
24#include <QVector>
25
36class CORE_EXPORT QgsTextBlock
37{
38
39 public:
40
44 QgsTextBlock() = default;
45
49 explicit QgsTextBlock( const QgsTextFragment &fragment );
50
59 static QgsTextBlock fromPlainText( const QString &text, const QgsTextCharacterFormat &format = QgsTextCharacterFormat() );
60
66 QString toPlainText() const;
67
73 void reserve( int count );
74
78 void append( const QgsTextFragment &fragment );
79
83 void append( QgsTextFragment &&fragment ) SIP_SKIP;
84#ifndef SIP_RUN
85
91 void insert( int index, const QgsTextFragment &fragment );
92
93#else
101 void insert( int index, const QgsTextFragment &fragment );
102 % MethodCode
103 if ( a0 < 0 || a0 > sipCpp->size() )
104 {
105 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
106 sipIsErr = 1;
107 }
108 else
109 {
110 sipCpp->insert( a0, *a1 );
111 }
112 % End
113#endif
114
120 void insert( int index, QgsTextFragment &&fragment ) SIP_SKIP;
121
125 void clear();
126
130 bool empty() const;
131
135 int size() const;
136
144 const QgsTextBlockFormat &blockFormat() const { return mBlockFormat; }
145
153 void setBlockFormat( const QgsTextBlockFormat &format );
154
160 void applyCapitalization( Qgis::Capitalization capitalization );
161
167 bool hasBackgrounds() const;
168
169#ifdef SIP_RUN
170 int __len__() const;
171 % MethodCode
172 sipRes = sipCpp->size();
173 % End
174#endif
175
176#ifndef SIP_RUN
177
181 const QgsTextFragment &at( int index ) const SIP_FACTORY;
182#else
183
189 const QgsTextFragment &at( int index ) const SIP_FACTORY;
190 % MethodCode
191 if ( a0 < 0 || a0 >= sipCpp->size() )
192 {
193 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
194 sipIsErr = 1;
195 }
196 else
197 {
198 sipRes = new QgsTextFragment( sipCpp->at( a0 ) );
199 }
200 % End
201#endif
202
206 QgsTextFragment &operator[]( int index ) SIP_FACTORY;
207#ifdef SIP_RUN
208 % MethodCode
209 SIP_SSIZE_T idx = sipConvertFromSequenceIndex( a0, sipCpp->size() );
210 if ( idx < 0 )
211 sipIsErr = 1;
212 else
213 sipRes = new QgsTextFragment( sipCpp->operator[]( idx ) );
214 % End
215#endif
216
217#ifndef SIP_RUN
219 QVector< QgsTextFragment >::const_iterator begin() const;
220 QVector< QgsTextFragment >::const_iterator end() const;
222#endif
223
224 private:
225
226 QVector< QgsTextFragment > mFragments;
227 QgsTextBlockFormat mBlockFormat;
228};
229
230#endif // QGSTEXTBLOCK_H
Capitalization
String capitalization options.
Definition qgis.h:3203
Stores information relating to individual block formatting.
Represents a block of text consisting of one or more QgsTextFragment objects.
const QgsTextBlockFormat & blockFormat() const
Returns the block formatting for the fragment.
QgsTextBlock()=default
Constructor for an empty text block.
Stores information relating to individual character formatting.
Stores a fragment of document along with formatting overrides to be used when rendering the fragment.
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_FACTORY
Definition qgis_sip.h:76