mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-15 00:07:25 -05:00
Use composition rather then inheritance for QgsTextBlock/QgsTextDocument
Allows us to expose these to python and hopefully fixes compilation issue on Travis
This commit is contained in:
parent
cb1e8445d3
commit
9a63810d82
@ -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,24 +18,28 @@
|
||||
|
||||
#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;
|
||||
|
||||
/**
|
||||
@ -43,7 +47,37 @@ class CORE_EXPORT QgsTextBlock : public QVector< QgsTextFragment >
|
||||
*/
|
||||
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
|
||||
|
||||
@ -16,17 +16,23 @@
|
||||
#include "qgstextdocument.h"
|
||||
#include "qgis.h"
|
||||
#include "qgsstringutils.h"
|
||||
#include "qgstextblock.h"
|
||||
#include "qgstextfragment.h"
|
||||
#include <QTextDocument>
|
||||
#include <QTextBlock>
|
||||
|
||||
QgsTextDocument::~QgsTextDocument() = default;
|
||||
|
||||
QgsTextDocument::QgsTextDocument() = default;
|
||||
|
||||
QgsTextDocument::QgsTextDocument( const QgsTextBlock &block )
|
||||
{
|
||||
append( block );
|
||||
mBlocks.append( block );
|
||||
}
|
||||
|
||||
QgsTextDocument::QgsTextDocument( const QgsTextFragment &fragment )
|
||||
{
|
||||
append( QgsTextBlock( fragment ) );
|
||||
mBlocks.append( QgsTextBlock( fragment ) );
|
||||
}
|
||||
|
||||
QgsTextDocument QgsTextDocument::fromPlainText( const QStringList &lines )
|
||||
@ -65,8 +71,8 @@ QgsTextDocument QgsTextDocument::fromHtml( const QStringList &lines )
|
||||
}
|
||||
it++;
|
||||
}
|
||||
if ( !block.isEmpty() )
|
||||
document << block;
|
||||
if ( !block.empty() )
|
||||
document.append( block );
|
||||
|
||||
sourceBlock = sourceBlock.next();
|
||||
if ( !sourceBlock.isValid() )
|
||||
@ -76,11 +82,31 @@ QgsTextDocument QgsTextDocument::fromHtml( const QStringList &lines )
|
||||
return document;
|
||||
}
|
||||
|
||||
void QgsTextDocument::append( const QgsTextBlock &block )
|
||||
{
|
||||
mBlocks.append( block );
|
||||
}
|
||||
|
||||
void QgsTextDocument::append( QgsTextBlock &&block )
|
||||
{
|
||||
mBlocks.push_back( block );
|
||||
}
|
||||
|
||||
void QgsTextDocument::reserve( int count )
|
||||
{
|
||||
mBlocks.reserve( count );
|
||||
}
|
||||
|
||||
const QgsTextBlock &QgsTextDocument::at( int i ) const
|
||||
{
|
||||
return mBlocks.at( i );
|
||||
}
|
||||
|
||||
QStringList QgsTextDocument::toPlainText() const
|
||||
{
|
||||
QStringList textLines;
|
||||
textLines.reserve( size() );
|
||||
for ( const QgsTextBlock &block : *this )
|
||||
textLines.reserve( mBlocks.size() );
|
||||
for ( const QgsTextBlock &block : mBlocks )
|
||||
{
|
||||
QString line;
|
||||
for ( const QgsTextFragment &fragment : block )
|
||||
@ -94,9 +120,9 @@ QStringList QgsTextDocument::toPlainText() const
|
||||
|
||||
void QgsTextDocument::splitLines( const QString &wrapCharacter, int autoWrapLength, bool useMaxLineLengthWhenAutoWrapping )
|
||||
{
|
||||
const QVector< QgsTextBlock > prevBlocks = *this;
|
||||
clear();
|
||||
reserve( prevBlocks.size() );
|
||||
const QVector< QgsTextBlock > prevBlocks = mBlocks;
|
||||
mBlocks.clear();
|
||||
mBlocks.reserve( prevBlocks.size() );
|
||||
for ( const QgsTextBlock &block : prevBlocks )
|
||||
{
|
||||
QgsTextBlock destinationBlock;
|
||||
@ -132,19 +158,29 @@ void QgsTextDocument::splitLines( const QString &wrapCharacter, int autoWrapLeng
|
||||
if ( thisParts.empty() )
|
||||
continue;
|
||||
else if ( thisParts.size() == 1 )
|
||||
destinationBlock << fragment;
|
||||
destinationBlock.append( fragment );
|
||||
else
|
||||
{
|
||||
destinationBlock << QgsTextFragment( thisParts.at( 0 ), fragment.characterFormat() );
|
||||
destinationBlock.append( QgsTextFragment( thisParts.at( 0 ), fragment.characterFormat() ) );
|
||||
append( destinationBlock );
|
||||
destinationBlock.clear();
|
||||
for ( int i = 1 ; i < thisParts.size() - 1; ++i )
|
||||
{
|
||||
append( QgsTextBlock( QgsTextFragment( thisParts.at( i ), fragment.characterFormat() ) ) );
|
||||
}
|
||||
destinationBlock << QgsTextFragment( thisParts.at( thisParts.size() - 1 ), fragment.characterFormat() );
|
||||
destinationBlock.append( QgsTextFragment( thisParts.at( thisParts.size() - 1 ), fragment.characterFormat() ) );
|
||||
}
|
||||
}
|
||||
append( destinationBlock );
|
||||
}
|
||||
}
|
||||
|
||||
QVector< QgsTextBlock >::const_iterator QgsTextDocument::begin() const
|
||||
{
|
||||
return mBlocks.begin();
|
||||
}
|
||||
|
||||
QVector< QgsTextBlock >::const_iterator QgsTextDocument::end() const
|
||||
{
|
||||
return mBlocks.end();
|
||||
}
|
||||
|
||||
@ -18,26 +18,28 @@
|
||||
|
||||
#include "qgis_sip.h"
|
||||
#include "qgis_core.h"
|
||||
#include "qgstextblock.h"
|
||||
|
||||
#include <QVector>
|
||||
|
||||
|
||||
#ifndef SIP_RUN
|
||||
class QgsTextBlock;
|
||||
class QgsTextFragment;
|
||||
|
||||
/**
|
||||
* \class QgsTextDocument
|
||||
*
|
||||
* Represents a document consisting of one or more QgsTextBlock objects.
|
||||
*
|
||||
* \warning This API is not considered stable and may change in future QGIS versions.
|
||||
*
|
||||
* \since QGIS 3.14
|
||||
*/
|
||||
class CORE_EXPORT QgsTextDocument : public QVector< QgsTextBlock >
|
||||
class CORE_EXPORT QgsTextDocument
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
QgsTextDocument() = default;
|
||||
QgsTextDocument();
|
||||
~QgsTextDocument();
|
||||
|
||||
/**
|
||||
* Constructor for a QgsTextDocument consisting of a single text \a block.
|
||||
@ -59,6 +61,26 @@ class CORE_EXPORT QgsTextDocument : public QVector< QgsTextBlock >
|
||||
*/
|
||||
static QgsTextDocument fromHtml( const QStringList &lines );
|
||||
|
||||
/**
|
||||
* Appends a \a block to the document.
|
||||
*/
|
||||
void append( const QgsTextBlock &block );
|
||||
|
||||
/**
|
||||
* Appends a \a block to the document.
|
||||
*/
|
||||
void append( QgsTextBlock &&block ) SIP_SKIP;
|
||||
|
||||
/**
|
||||
* Reserves the specified \a count of blocks for optimised block appending.
|
||||
*/
|
||||
void reserve( int count );
|
||||
|
||||
/**
|
||||
* Returns the block at the specified \a index.
|
||||
*/
|
||||
const QgsTextBlock &at( int index ) const;
|
||||
|
||||
/**
|
||||
* Returns a list of plain text lines of text representing the document.
|
||||
*/
|
||||
@ -75,9 +97,17 @@ class CORE_EXPORT QgsTextDocument : public QVector< QgsTextBlock >
|
||||
*/
|
||||
void splitLines( const QString &wrapCharacter, int autoWrapLength = 0, bool useMaxLineLengthWhenAutoWrapping = true );
|
||||
|
||||
};
|
||||
|
||||
#ifndef SIP_RUN
|
||||
///@cond PRIVATE
|
||||
QVector< QgsTextBlock >::const_iterator begin() const;
|
||||
QVector< QgsTextBlock >::const_iterator end() const;
|
||||
///@endcond
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
||||
QVector< QgsTextBlock > mBlocks;
|
||||
|
||||
};
|
||||
|
||||
#endif // QGSTEXTDOCUMENT_H
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
#include "qgsvectorlayer.h"
|
||||
#include "qgstextformat.h"
|
||||
#include "qgstextdocument.h"
|
||||
#include "qgstextfragment.h"
|
||||
#include "qgspallabeling.h"
|
||||
#include "qgspainteffect.h"
|
||||
#include "qgspainterswapper.h"
|
||||
|
||||
@ -28,6 +28,7 @@
|
||||
#include "qgsapplication.h"
|
||||
#include "qgsexpressioncontextutils.h"
|
||||
#include "qgsvectorlayer.h"
|
||||
#include "qgstextrenderer.h"
|
||||
#include <QMenu>
|
||||
#include <QClipboard>
|
||||
#include <QDrag>
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
|
||||
#include "qgstextpreview.h"
|
||||
#include "qgsapplication.h"
|
||||
#include "qgstextrenderer.h"
|
||||
#include <QDesktopWidget>
|
||||
#include <QPainter>
|
||||
|
||||
|
||||
@ -47,6 +47,7 @@ INCLUDE_DIRECTORIES(
|
||||
${CMAKE_SOURCE_DIR}/src/core/raster
|
||||
${CMAKE_SOURCE_DIR}/src/core/symbology
|
||||
${CMAKE_SOURCE_DIR}/src/core/effects
|
||||
${CMAKE_SOURCE_DIR}/src/core/textrenderer
|
||||
${CMAKE_SOURCE_DIR}/src/gui
|
||||
${CMAKE_SOURCE_DIR}/src/gui/layertree
|
||||
${CMAKE_SOURCE_DIR}/src/plugins
|
||||
|
||||
@ -9,6 +9,7 @@ INCLUDE_DIRECTORIES(
|
||||
${CMAKE_SOURCE_DIR}/src/core/symbology
|
||||
${CMAKE_SOURCE_DIR}/src/core/effects
|
||||
${CMAKE_SOURCE_DIR}/src/core/pal
|
||||
${CMAKE_SOURCE_DIR}/src/core/textrenderer
|
||||
${CMAKE_SOURCE_DIR}/src/gui
|
||||
${CMAKE_SOURCE_DIR}/src/gui/auth
|
||||
${CMAKE_SOURCE_DIR}/external
|
||||
|
||||
@ -40,6 +40,7 @@ INCLUDE_DIRECTORIES(
|
||||
${CMAKE_SOURCE_DIR}/src/core/raster
|
||||
${CMAKE_SOURCE_DIR}/src/core/symbology
|
||||
${CMAKE_SOURCE_DIR}/src/core/effects
|
||||
${CMAKE_SOURCE_DIR}/src/core/textrenderer
|
||||
${CMAKE_SOURCE_DIR}/src/gui
|
||||
${CMAKE_SOURCE_DIR}/src/gui/auth
|
||||
${CMAKE_SOURCE_DIR}/external
|
||||
|
||||
@ -49,6 +49,7 @@ INCLUDE_DIRECTORIES (
|
||||
${CMAKE_SOURCE_DIR}/src/core/symbology # needed by qgsvectorfilewriter.h
|
||||
${CMAKE_SOURCE_DIR}/src/core/effects # needed by qgssymbollayer.h
|
||||
${CMAKE_SOURCE_DIR}/src/core/labeling
|
||||
${CMAKE_SOURCE_DIR}/src/core/textrenderer
|
||||
${CMAKE_SOURCE_DIR}/src/core/geocms/geonode
|
||||
${CMAKE_SOURCE_DIR}/src/core/metadata
|
||||
${CMAKE_SOURCE_DIR}/src/gui
|
||||
|
||||
@ -108,6 +108,7 @@ INCLUDE_DIRECTORIES(
|
||||
${CMAKE_SOURCE_DIR}/src/core/effects
|
||||
${CMAKE_SOURCE_DIR}/src/core/layout
|
||||
${CMAKE_SOURCE_DIR}/src/core/layertree
|
||||
${CMAKE_SOURCE_DIR}/src/core/textrenderer
|
||||
${CMAKE_SOURCE_DIR}/src/analysis/interpolation
|
||||
${CMAKE_SOURCE_DIR}/src/plugins/diagram_overlay
|
||||
${CMAKE_SOURCE_DIR}/src/python
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user