QGIS API Documentation 4.1.0-Master (60fea48833c)
Loading...
Searching...
No Matches
qgstextdocument.h
Go to the documentation of this file.
1/***************************************************************************
2 qgstextdocument.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 QGSTEXTDOCUMENT_H
17#define QGSTEXTDOCUMENT_H
18
19#include "qgis_core.h"
20#include "qgis_sip.h"
21#include "qgsstringutils.h"
22#include "qgstextblock.h"
23
24#include <QSizeF>
25#include <QVector>
26
27class QgsTextFragment;
28class QgsTextFormat;
29
40class CORE_EXPORT QgsTextDocument
41{
42 public:
44 QgsTextDocument( const QgsTextDocument &other );
48
50
54 explicit QgsTextDocument( const QgsTextBlock &block );
55
59 explicit QgsTextDocument( const QgsTextFragment &fragment );
60
67 static QgsTextDocument fromPlainText( const QStringList &lines );
68
75 static QgsTextDocument fromHtml( const QStringList &lines );
76
84 static QgsTextDocument fromTextAndFormat( const QStringList &lines, const QgsTextFormat &format );
85
89 void append( const QgsTextBlock &block );
90
94 void append( QgsTextBlock &&block ) SIP_SKIP;
95
96#ifndef SIP_RUN
97
103 void insert( int index, const QgsTextBlock &block );
104#else
105 // clang-format off
106
114 void insert( int index, const QgsTextBlock &block );
115 % MethodCode
116 if ( a0 < 0 || a0 > sipCpp->size() )
117 {
118 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
119 sipIsErr = 1;
120 }
121 else
122 {
123 sipCpp->insert( a0, *a1 );
124 }
125 % End
126// clang-format on
127#endif
128
134 void insert( int index, QgsTextBlock &&block ) SIP_SKIP;
135
139 void reserve( int count );
140
141#ifndef SIP_RUN
142
146 const QgsTextBlock &at( int index ) const SIP_FACTORY;
147#else
148 // clang-format off
149
155 const QgsTextBlock &at( int index ) const SIP_FACTORY;
156 % MethodCode
157 if ( a0 < 0 || a0 >= sipCpp->size() )
158 {
159 PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
160 sipIsErr = 1;
161 }
162 else
163 {
164 sipRes = new QgsTextBlock( sipCpp->at( a0 ) );
165 }
166 % End
167// clang-format on
168#endif
169
173 QgsTextBlock &operator[]( int index ) SIP_FACTORY;
174#ifdef SIP_RUN
175 // clang-format off
176 % MethodCode
177 SIP_SSIZE_T idx = sipConvertFromSequenceIndex( a0, sipCpp->size() );
178 if ( idx < 0 )
179 sipIsErr = 1;
180 else
181 sipRes = new QgsTextBlock( sipCpp->operator[]( idx ) );
182 % End
183// clang-format on
184#endif
185
189 int size() const;
190
191#ifdef SIP_RUN
192 // clang-format off
193 int __len__() const;
194 % MethodCode
195 sipRes = sipCpp->size();
196 % End
197// clang-format on
198#endif
199
203 QStringList toPlainText() const;
204
214 void splitLines( const QString &wrapCharacter, int autoWrapLength = 0, bool useMaxLineLengthWhenAutoWrapping = true );
215
221 QVector< QgsTextDocument > splitBlocksToDocuments() const;
222
228 void applyCapitalization( Qgis::Capitalization capitalization );
229
235 bool hasBackgrounds() const;
236
237#ifndef SIP_RUN
239 QVector< QgsTextBlock >::const_iterator begin() const;
240 QVector< QgsTextBlock >::const_iterator end() const;
242#endif
243
244 private:
245 QVector< QgsTextBlock > mBlocks;
246};
247
248#endif // QGSTEXTDOCUMENT_H
Capitalization
String capitalization options.
Definition qgis.h:3503
Represents a block of text consisting of one or more QgsTextFragment objects.
QgsTextDocument & operator=(const QgsTextDocument &other)
static QgsTextDocument fromHtml(const QStringList &lines)
Constructor for QgsTextDocument consisting of a set of HTML formatted lines.
static QgsTextDocument fromPlainText(const QStringList &lines)
Constructor for QgsTextDocument consisting of a set of plain text lines.
void append(const QgsTextBlock &block)
Appends a block to the document.
void insert(int index, const QgsTextBlock &block)
Inserts a block into the document, at the specified index.
static QgsTextDocument fromTextAndFormat(const QStringList &lines, const QgsTextFormat &format)
Constructor for QgsTextDocument consisting of a set of lines, respecting settings from a text format.
Container for all settings relating to text rendering.
Stores a fragment of document along with formatting overrides to be used when rendering the fragment.
#define SIP_SKIP
Definition qgis_sip.h:133
#define SIP_FACTORY
Definition qgis_sip.h:83