QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgstextblock.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgstextblock.cpp
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 #include "qgstextblock.h"
17 #include "qgstextfragment.h"
18 
20 {
21  mFragments.append( fragment );
22 }
23 
25 {
26  QString res;
27  for ( const QgsTextFragment &fragment : mFragments )
28  {
29  res.append( fragment.text() );
30  }
31  return res;
32 }
33 
34 void QgsTextBlock::append( const QgsTextFragment &fragment )
35 {
36  mFragments.append( fragment );
37 }
38 
40 {
41  mFragments.push_back( fragment );
42 }
43 
45 {
46  mFragments.clear();
47 }
48 
49 bool QgsTextBlock::empty() const
50 {
51  return mFragments.empty();
52 }
53 
54 int QgsTextBlock::size() const
55 {
56  return mFragments.size();
57 }
58 
60 {
61  for ( QgsTextFragment &fragment : mFragments )
62  {
63  fragment.applyCapitalization( capitalization );
64  }
65 }
66 
67 const QgsTextFragment &QgsTextBlock::at( int index ) const
68 {
69  return mFragments.at( index );
70 }
71 
73 {
74  return mFragments[ index ];
75 }
76 
78 QVector< QgsTextFragment >::const_iterator QgsTextBlock::begin() const
79 {
80  return mFragments.begin();
81 }
82 
83 QVector< QgsTextFragment >::const_iterator QgsTextBlock::end() const
84 {
85  return mFragments.end();
86 }
QgsTextBlock::operator[]
QgsTextFragment & operator[](int index)
Returns the fragment at the specified index.
Definition: qgstextblock.cpp:72
qgstextfragment.h
QgsTextBlock::clear
void clear()
Clears the block, removing all its contents.
Definition: qgstextblock.cpp:44
QgsTextBlock::at
const QgsTextFragment & at(int index) const
Returns the fragment at the specified index.
Definition: qgstextblock.cpp:67
QgsTextBlock::size
int size() const
Returns the number of fragments in the block.
Definition: qgstextblock.cpp:54
QgsTextBlock::append
void append(const QgsTextFragment &fragment)
Appends a fragment to the block.
Definition: qgstextblock.cpp:34
QgsTextBlock::empty
bool empty() const
Returns true if the block is empty.
Definition: qgstextblock.cpp:49
QgsTextBlock::toPlainText
QString toPlainText() const
Converts the block to plain text.
Definition: qgstextblock.cpp:24
QgsTextBlock::QgsTextBlock
QgsTextBlock()=default
Constructor for an empty text block.
QgsTextFragment
Stores a fragment of text along with formatting overrides to be used when rendering the fragment.
Definition: qgstextfragment.h:35
Qgis::Capitalization
Capitalization
String capitalization options.
Definition: qgis.h:1592
QgsTextBlock::applyCapitalization
void applyCapitalization(Qgis::Capitalization capitalization)
Applies a capitalization style to the block's text.
Definition: qgstextblock.cpp:59
qgstextblock.h