Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 9a63810
Show file tree
Hide file tree
Showing 18 changed files with 292 additions and 27 deletions.
47 changes: 47 additions & 0 deletions python/core/auto_generated/textrenderer/qgstextblock.sip.in
Expand Up @@ -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 *
* *
Expand Down
74 changes: 74 additions & 0 deletions python/core/auto_generated/textrenderer/qgstextdocument.sip.in
Expand Up @@ -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 *
Expand Down
1 change: 1 addition & 0 deletions src/app/CMakeLists.txt
Expand Up @@ -481,6 +481,7 @@ INCLUDE_DIRECTORIES(
../core/mesh
../core/scalebar
../core/symbology
../core/textrenderer
../gui
../gui/symbology
../gui/attributetable
Expand Down
1 change: 1 addition & 0 deletions src/core/labeling/qgspallabeling.cpp
Expand Up @@ -48,6 +48,7 @@
#include "qgslabelingengine.h"
#include "qgsvectorlayerlabeling.h"
#include "qgstextrendererutils.h"
#include "qgstextfragment.h"

#include "qgslogger.h"
#include "qgsvectorlayer.h"
Expand Down
4 changes: 3 additions & 1 deletion src/core/labeling/qgstextlabelfeature.cpp
Expand Up @@ -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 )
Expand Down
4 changes: 3 additions & 1 deletion src/core/labeling/qgsvectorlayerlabelprovider.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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
{
Expand Down
34 changes: 32 additions & 2 deletions src/core/textrenderer/qgstextblock.cpp
Expand Up @@ -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();
}
42 changes: 38 additions & 4 deletions src/core/textrenderer/qgstextblock.h
Expand Up @@ -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.