QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
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 "qgsstringutils.h"
23 #include <QVector>
24 
35 class CORE_EXPORT QgsTextBlock
36 {
37 
38  public:
39 
43  QgsTextBlock() = default;
44 
48  explicit QgsTextBlock( const QgsTextFragment &fragment );
49 
55  QString toPlainText() const;
56 
60  void append( const QgsTextFragment &fragment );
61 
65  void append( QgsTextFragment &&fragment ) SIP_SKIP;
66 
70  void clear();
71 
75  bool empty() const;
76 
80  int size() const;
81 
87  void applyCapitalization( QgsStringUtils::Capitalization capitalization );
88 
89 #ifdef SIP_RUN
90  int __len__() const;
91  % MethodCode
92  sipRes = sipCpp->size();
93  % End
94 #endif
95 
99  const QgsTextFragment &at( int index ) const SIP_FACTORY;
100 #ifdef SIP_RUN
101  % MethodCode
102  if ( a0 < 0 || a0 >= sipCpp->size() )
103  {
104  PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) );
105  sipIsErr = 1;
106  }
107  else
108  {
109  sipRes = new QgsTextFragment( sipCpp->at( a0 ) );
110  }
111  % End
112 #endif
113 
117  QgsTextFragment &operator[]( int index ) SIP_FACTORY;
118 #ifdef SIP_RUN
119  % MethodCode
120  SIP_SSIZE_T idx = sipConvertFromSequenceIndex( a0, sipCpp->size() );
121  if ( idx < 0 )
122  sipIsErr = 1;
123  else
124  sipRes = new QgsTextFragment( sipCpp->operator[]( idx ) );
125  % End
126 #endif
127 
128 #ifndef SIP_RUN
130  QVector< QgsTextFragment >::const_iterator begin() const;
131  QVector< QgsTextFragment >::const_iterator end() const;
133 #endif
134 
135  private:
136 
137  QVector< QgsTextFragment > mFragments;
138 
139 };
140 
141 #endif // QGSTEXTBLOCK_H
Capitalization
Capitalization options.
Represents a block of text consisting of one or more QgsTextFragment objects.
Definition: qgstextblock.h:36
QgsTextBlock()=default
Constructor for an empty text block.
Stores a fragment of text 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