QGIS API Documentation 3.99.0-Master (26c88405ac0)
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_core.h"
20#include "qgis_sip.h"
21#include "qgsstringutils.h"
22#include "qgstextblockformat.h"
23#include "qgstextfragment.h"
24
25#include <QVector>
26
37class CORE_EXPORT QgsTextBlock
38{
39
40 public:
41
45 QgsTextBlock() = default;
46
50 explicit QgsTextBlock( const QgsTextFragment &fragment );
51
60 static QgsTextBlock fromPlainText( const QString &text, const QgsTextCharacterFormat &format = QgsTextCharacterFormat() );
61
67 QString toPlainText() const;
68
74 void reserve( int count );
75
79 void append( const QgsTextFragment &fragment );
80
84 void append( QgsTextFragment &&fragment ) SIP_SKIP;
85#ifndef SIP_RUN
86
92 void insert( int index, const QgsTextFragment &fragment );
93
94#else
102 void insert( int index, const QgsTextFragment &fragment );
103 % MethodCode
104 if ( a0 < 0 || a0 > sipCpp->size() )
105 {
106 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
107 sipIsErr = 1;
108 }
109 else
110 {
111 sipCpp->insert( a0, *a1 );
112 }
113 % End
114#endif
115
121 void insert( int index, QgsTextFragment &&fragment ) SIP_SKIP;
122
126 void clear();
127
131 bool empty() const;
132
136 int size() const;
137
145 const QgsTextBlockFormat &blockFormat() const { return mBlockFormat; }
146
154 void setBlockFormat( const QgsTextBlockFormat &format );
155
161 void applyCapitalization( Qgis::Capitalization capitalization );
162
168 bool hasBackgrounds() const;
169
170#ifdef SIP_RUN
171 int __len__() const;
172 % MethodCode
173 sipRes = sipCpp->size();
174 % End
175#endif
176
177#ifndef SIP_RUN
178
182 const QgsTextFragment &at( int index ) const SIP_FACTORY;
183#else
184
190 const QgsTextFragment &at( int index ) const SIP_FACTORY;
191 % MethodCode
192 if ( a0 < 0 || a0 >= sipCpp->size() )
193 {
194 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
195 sipIsErr = 1;
196 }
197 else
198 {
199 sipRes = new QgsTextFragment( sipCpp->at( a0 ) );
200 }
201 % End
202#endif
203
207 QgsTextFragment &operator[]( int index ) SIP_FACTORY;
208#ifdef SIP_RUN
209 % MethodCode
210 SIP_SSIZE_T idx = sipConvertFromSequenceIndex( a0, sipCpp->size() );
211 if ( idx < 0 )
212 sipIsErr = 1;
213 else
214 sipRes = new QgsTextFragment( sipCpp->operator[]( idx ) );
215 % End
216#endif
217
218#ifndef SIP_RUN
220 QVector< QgsTextFragment >::const_iterator begin() const;
221 QVector< QgsTextFragment >::const_iterator end() const;
223#endif
224
225 private:
226
227 QVector< QgsTextFragment > mFragments;
228 QgsTextBlockFormat mBlockFormat;
229};
230
231#endif // QGSTEXTBLOCK_H
Capitalization
String capitalization options.
Definition qgis.h:3389
Stores information relating to individual block formatting.
void insert(int index, const QgsTextFragment &fragment)
Inserts a fragment into the block, at the specified index.
QString toPlainText() const
Converts the block to plain text.
const QgsTextBlockFormat & blockFormat() const
Returns the block formatting for the fragment.
static QgsTextBlock fromPlainText(const QString &text, const QgsTextCharacterFormat &format=QgsTextCharacterFormat())
Constructor for QgsTextBlock consisting of a plain text, and optional character format.
QgsTextBlock()=default
Constructor for an empty text block.
void reserve(int count)
Reserves the specified count of fragments for optimised fragment appending.
void append(const QgsTextFragment &fragment)
Appends a fragment to the 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:134
#define SIP_FACTORY
Definition qgis_sip.h:84