Skip to content
Permalink
Browse files

Use composition rather then inheritance for QgsTextBlock/QgsTextDocument

Allows us to expose these to python and hopefully fixes compilation issue on Travis
  • Loading branch information
nyalldawson committed May 12, 2020
1 parent cb1e844 commit 9a63810d82b5294faf90c689f8bd6e6ebd73812f
@@ -10,6 +10,53 @@



class QgsTextBlock
{
%Docstring

Represents a block of text consisting of one or more QgsTextFragment objects.

.. warning::

This API is not considered stable and may change in future QGIS versions.

.. versionadded:: 3.14
%End

%TypeHeaderCode
#include "qgstextblock.h"
%End
public:

QgsTextBlock();
%Docstring
Constructor for an empty text block.
%End

explicit QgsTextBlock( const QgsTextFragment &fragment );
%Docstring
Constructor for a QgsTextBlock consisting of a single text ``fragment``.
%End

void append( const QgsTextFragment &fragment );
%Docstring
Appends a ``fragment`` to the block.
%End


void clear();
%Docstring
Clears the block, removing all its contents.
%End

bool empty() const;
%Docstring
Returns ``True`` if the block is empty.
%End


};

/************************************************************************
* This file has been generated automatically from *
* *
@@ -10,7 +10,81 @@



class QgsTextDocument
{
%Docstring

Represents a document consisting of one or more QgsTextBlock objects.

.. warning::

This API is not considered stable and may change in future QGIS versions.

.. versionadded:: 3.14
%End

%TypeHeaderCode
#include "qgstextdocument.h"
%End
public:

QgsTextDocument();
~QgsTextDocument();

explicit QgsTextDocument( const QgsTextBlock &block );
%Docstring
Constructor for a QgsTextDocument consisting of a single text ``block``.
%End

explicit QgsTextDocument( const QgsTextFragment &fragment );
%Docstring
Constructor for a QgsTextDocument consisting of a single text ``fragment``.
%End

static QgsTextDocument fromPlainText( const QStringList &lines );
%Docstring
Constructor for QgsTextDocument consisting of a set of plain text ``lines``.
%End

static QgsTextDocument fromHtml( const QStringList &lines );
%Docstring
Constructor for QgsTextDocument consisting of a set of HTML formatted ``lines``.
%End

void append( const QgsTextBlock &block );
%Docstring
Appends a ``block`` to the document.
%End


void reserve( int count );
%Docstring
Reserves the specified ``count`` of blocks for optimised block appending.
%End

const QgsTextBlock &at( int index ) const;
%Docstring
Returns the block at the specified ``index``.
%End

QStringList toPlainText() const;
%Docstring
Returns a list of plain text lines of text representing the document.
%End

void splitLines( const QString &wrapCharacter, int autoWrapLength = 0, bool useMaxLineLengthWhenAutoWrapping = true );
%Docstring
Splits lines of text in the document to separate lines, using a specified wrap character (``wrapCharacter``) or newline characters.

The ``autoWrapLength`` argument can be used to specify an ideal length of line to automatically
wrap text to (automatic wrapping is disabled if ``autoWrapLength`` is 0). This automatic wrapping is performed
after processing wrapping using ``wrapCharacter``. When auto wrapping is enabled, the ``useMaxLineLengthWhenAutoWrapping``
argument controls whether the lines should be wrapped to an ideal maximum of ``autoWrapLength`` characters, or
if ``False`` then the lines are wrapped to an ideal minimum length of ``autoWrapLength`` characters.
%End


};

/************************************************************************
* This file has been generated automatically from *
@@ -481,6 +481,7 @@ INCLUDE_DIRECTORIES(
../core/mesh
../core/scalebar
../core/symbology
../core/textrenderer
../gui
../gui/symbology
../gui/attributetable
@@ -48,6 +48,7 @@
#include "qgslabelingengine.h"
#include "qgsvectorlayerlabeling.h"
#include "qgstextrendererutils.h"
#include "qgstextfragment.h"

#include "qgslogger.h"
#include "qgsvectorlayer.h"
@@ -19,7 +19,9 @@
#include "qgspallabeling.h"
#include "qgsmaptopixel.h"
#include "pal/feature.h"
#include <QTextDocument>
#include "qgstextcharacterformat.h"
#include "qgstextfragment.h"
#include "qgstextblock.h"

QgsTextLabelFeature::QgsTextLabelFeature( QgsFeatureId id, geos::unique_ptr geometry, QSizeF size )
: QgsLabelFeature( id, std::move( geometry ), size )
@@ -28,6 +28,8 @@
#include "qgslogger.h"
#include "qgsexpressioncontextutils.h"
#include "qgsmaskidprovider.h"
#include "qgstextcharacterformat.h"
#include "qgstextfragment.h"

#include "feature.h"
#include "labelposition.h"
@@ -629,7 +631,7 @@ void QgsVectorLayerLabelProvider::drawLabelPrivate( pal::LabelPosition *label, Q
const QgsTextCharacterFormat c = lf->characterFormat( label->getPartId() );
const QStringList multiLineList = QgsPalLabeling::splitToLines( txt, tmpLyr.wrapChar, tmpLyr.autoWrapLength, tmpLyr.useMaxLineLengthForAutoWrap );
for ( const QString line : multiLineList )
document << QgsTextBlock( QgsTextFragment( line, c ) );
document.append( QgsTextBlock( QgsTextFragment( line, c ) ) );
}
else
{
@@ -14,9 +14,39 @@
***************************************************************************/

#include "qgstextblock.h"

#include "qgstextfragment.h"

QgsTextBlock::QgsTextBlock( const QgsTextFragment &fragment )
{
append( fragment );
mFragments.append( fragment );
}

void QgsTextBlock::append( const QgsTextFragment &fragment )
{
mFragments.append( fragment );
}

void QgsTextBlock::append( QgsTextFragment &&fragment )
{
mFragments.push_back( fragment );
}

void QgsTextBlock::clear()
{
mFragments.clear();
}

bool QgsTextBlock::empty() const
{
return mFragments.empty();
}

QVector< QgsTextFragment >::const_iterator QgsTextBlock::begin() const
{
return mFragments.begin();
}

QVector< QgsTextFragment >::const_iterator QgsTextBlock::end() const
{
return mFragments.end();
}
@@ -18,32 +18,66 @@

#include "qgis_sip.h"
#include "qgis_core.h"
#include "qgstextfragment.h"

#include <QVector>

#ifndef SIP_RUN
class QgsTextFragment;

/**
* \class QgsTextBlock
*
* Represents a block of text consisting of one or more QgsTextFragment objects.
*
* \warning This API is not considered stable and may change in future QGIS versions.
*
* \since QGIS 3.14
*/
class CORE_EXPORT QgsTextBlock : public QVector< QgsTextFragment >
class CORE_EXPORT QgsTextBlock
{

public:

/**
* Constructor for an empty text block.
*/
QgsTextBlock() = default;

/**
* Constructor for a QgsTextBlock consisting of a single text \a fragment.
*/
explicit QgsTextBlock( const QgsTextFragment &fragment );

};
/**
* Appends a \a fragment to the block.
*/
void append( const QgsTextFragment &fragment );

/**
* Appends a \a fragment to the block.
*/
void append( QgsTextFragment &&fragment ) SIP_SKIP;

/**
* Clears the block, removing all its contents.
*/
void clear();

/**
* Returns TRUE if the block is empty.
*/
bool empty() const;

#ifndef SIP_RUN
///@cond PRIVATE
QVector< QgsTextFragment >::const_iterator begin() const;
QVector< QgsTextFragment >::const_iterator end() const;
///@endcond
#endif

private:

QVector< QgsTextFragment > mFragments;

};

#endif // QGSTEXTBLOCK_H

0 comments on commit 9a63810

Please sign in to comment.
You can’t perform that action at this time.