22#include <QTextDocument> 
   32  mBlocks.append( block );
 
 
   43  document.
reserve( lines.size() );
 
   44  for ( 
const QString &line : lines )
 
 
   54#define TAB_REPLACEMENT_MARKER " ignore_me_i_am_a_tab " 
   60  document.
reserve( lines.size() );
 
   62  for ( 
const QString &l : std::as_const( lines ) )
 
   69    QTextDocument sourceDoc;
 
   76    sourceDoc.setHtml( line );
 
   78    QTextBlock sourceBlock = sourceDoc.firstBlock();
 
   82      auto it = sourceBlock.begin();
 
   86        const QTextFragment fragment = it.fragment();
 
   87        if ( fragment.isValid() )
 
   90          const QString fragmentText = fragment.text();
 
   91          if ( fragmentText.contains( QStringLiteral( 
"\u2028" ) ) )
 
   94            const QStringList 
splitLines = fragmentText.split( QStringLiteral( 
"\u2028" ), Qt::SplitBehaviorFlags::SkipEmptyParts );
 
   96            for ( 
const QString &splitLine : std::as_const( 
splitLines ) )
 
  103                previousFormat = &document.
at( document.
size() - 1 ).
at( 0 ).characterFormat();
 
  111                if ( previousFormat )
 
  121                for ( 
const QString &part : tabSplit )
 
  123                  if ( !part.isEmpty() )
 
  126                    block.
append( splitFragment );
 
  128                  if ( index != tabSplit.size() - 1 )
 
  138                splitFragment.
setText( splitLine );
 
  140                if ( previousFormat )
 
  148                block.
append( splitFragment );
 
  162            for ( 
const QString &part : tabSplit )
 
  164              if ( !part.isEmpty() )
 
  167                block.
append( tmpFragment );
 
  169              if ( index != tabSplit.size() - 1 )
 
  184      if ( !block.
empty() )
 
  187      sourceBlock = sourceBlock.next();
 
  188      if ( !sourceBlock.isValid() )
 
 
  198  mBlocks.append( block );
 
 
  203  mBlocks.push_back( block );
 
 
  208  mBlocks.reserve( count );
 
 
  213  return mBlocks.at( i );
 
 
  223  return mBlocks.size();
 
 
  228  QStringList textLines;
 
  229  textLines.reserve( mBlocks.size() );
 
  235      line.append( fragment.text() );
 
 
  244  const QVector< QgsTextBlock > prevBlocks = mBlocks;
 
  246  mBlocks.reserve( prevBlocks.size() );
 
  252      QStringList thisParts;
 
  253      if ( !wrapCharacter.isEmpty() && wrapCharacter != QLatin1String( 
"\n" ) )
 
  256        const QStringList lines = fragment.text().split( wrapCharacter );
 
  257        for ( 
const QString &line : lines )
 
  259          thisParts.
append( line.split( 
'\n' ) );
 
  264        thisParts = fragment.text().split( 
'\n' );
 
  268      if ( autoWrapLength != 0 )
 
  270        QStringList autoWrappedLines;
 
  271        autoWrappedLines.reserve( thisParts.count() );
 
  272        for ( 
const QString &line : std::as_const( thisParts ) )
 
  274          autoWrappedLines.append( 
QgsStringUtils::wordWrap( line, autoWrapLength, useMaxLineLengthWhenAutoWrapping ).split( 
'\n' ) );
 
  276        thisParts = autoWrappedLines;
 
  279      if ( thisParts.empty() )
 
  281      else if ( thisParts.size() == 1 )
 
  282        destinationBlock.
append( fragment );
 
  285        if ( !thisParts.at( 0 ).isEmpty() )
 
  288        append( destinationBlock );
 
  289        destinationBlock.
clear();
 
  290        for ( 
int i = 1 ; i < thisParts.size() - 1; ++i )
 
  294        destinationBlock.
append( 
QgsTextFragment( thisParts.at( thisParts.size() - 1 ), fragment.characterFormat() ) );
 
  297    append( destinationBlock );
 
 
  305    block.applyCapitalization( capitalization );
 
 
  310QVector< QgsTextBlock >::const_iterator QgsTextDocument::begin()
 const 
  312  return mBlocks.begin();
 
  315QVector< QgsTextBlock >::const_iterator QgsTextDocument::end()
 const 
  317  return mBlocks.end();
 
Capitalization
String capitalization options.
 
static QString wordWrap(const QString &string, int length, bool useMaxLineLength=true, const QString &customDelimiter=QString())
Automatically wraps a string by inserting new line characters at appropriate locations in the string.
 
Represents a block of text consisting of one or more QgsTextFragment objects.
 
void clear()
Clears the block, removing all its contents.
 
static QgsTextBlock fromPlainText(const QString &text, const QgsTextCharacterFormat &format=QgsTextCharacterFormat())
Constructor for QgsTextBlock consisting of a plain text, and optional character format.
 
void append(const QgsTextFragment &fragment)
Appends a fragment to the block.
 
bool empty() const
Returns true if the block is empty.
 
Stores information relating to individual character formatting.
 
void overrideWith(const QgsTextCharacterFormat &other)
Override all the default/unset properties of the current character format with the settings from anot...
 
Represents a document consisting of one or more QgsTextBlock objects.
 
void splitLines(const QString &wrapCharacter, int autoWrapLength=0, bool useMaxLineLengthWhenAutoWrapping=true)
Splits lines of text in the document to separate lines, using a specified wrap character (wrapCharact...
 
QgsTextBlock & operator[](int index)
Returns the block at the specified index.
 
const QgsTextBlock & at(int index) const
Returns the block at the specified index.
 
void reserve(int count)
Reserves the specified count of blocks for optimised block appending.
 
QStringList toPlainText() const
Returns a list of plain text lines of text representing the document.
 
int size() const
Returns the number of blocks in the document.
 
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 applyCapitalization(Qgis::Capitalization capitalization)
Applies a capitalization style to the document's text.
 
Stores a fragment of text along with formatting overrides to be used when rendering the fragment.
 
void setText(const QString &text)
Sets the text content of the fragment.
 
void setCharacterFormat(const QgsTextCharacterFormat &format)
Sets the character format for the fragment.
 
const QgsTextCharacterFormat & characterFormat() const
Returns the character formatting for the fragment.
 
#define TAB_REPLACEMENT_MARKER