21 #include <QTextDocument>
30 mBlocks.append( block );
41 document.
reserve( lines.size() );
42 for (
const QString &line : lines )
51 document.
reserve( lines.size() );
52 for (
const QString &line : lines )
57 QTextDocument sourceDoc;
58 sourceDoc.setHtml( line );
60 QTextBlock sourceBlock = sourceDoc.firstBlock();
63 auto it = sourceBlock.begin();
67 const QTextFragment fragment = it.fragment();
68 if ( fragment.isValid() )
77 sourceBlock = sourceBlock.next();
78 if ( !sourceBlock.isValid() )
87 mBlocks.append( block );
92 mBlocks.push_back( block );
97 mBlocks.reserve( count );
102 return mBlocks.at( i );
112 return mBlocks.size();
117 QStringList textLines;
118 textLines.reserve( mBlocks.size() );
124 line.append( fragment.text() );
133 const QVector< QgsTextBlock > prevBlocks = mBlocks;
135 mBlocks.reserve( prevBlocks.size() );
141 QStringList thisParts;
142 if ( !wrapCharacter.isEmpty() && wrapCharacter != QLatin1String(
"\n" ) )
145 const QStringList lines = fragment.text().split( wrapCharacter );
146 for (
const QString &line : lines )
148 thisParts.
append( line.split(
'\n' ) );
153 thisParts = fragment.text().split(
'\n' );
157 if ( autoWrapLength != 0 )
159 QStringList autoWrappedLines;
160 autoWrappedLines.reserve( thisParts.count() );
161 for (
const QString &line : std::as_const( thisParts ) )
163 autoWrappedLines.append(
QgsStringUtils::wordWrap( line, autoWrapLength, useMaxLineLengthWhenAutoWrapping ).split(
'\n' ) );
165 thisParts = autoWrappedLines;
168 if ( thisParts.empty() )
170 else if ( thisParts.size() == 1 )
171 destinationBlock.
append( fragment );
174 if ( !thisParts.at( 0 ).isEmpty() )
177 append( destinationBlock );
178 destinationBlock.
clear();
179 for (
int i = 1 ; i < thisParts.size() - 1; ++i )
183 destinationBlock.
append(
QgsTextFragment( thisParts.at( thisParts.size() - 1 ), fragment.characterFormat() ) );
186 append( destinationBlock );
194 block.applyCapitalization( capitalization );
199 QVector< QgsTextBlock >::const_iterator QgsTextDocument::begin()
const
201 return mBlocks.begin();
204 QVector< QgsTextBlock >::const_iterator QgsTextDocument::end()
const
206 return mBlocks.end();