Skip to content
Permalink
Browse files

Abstract dxf export label provider away

  • Loading branch information
m-kuhn committed May 7, 2020
1 parent 01ec02a commit 50e63a785b0c51cd50c2341c11f897ba4e53fab5
@@ -491,13 +491,16 @@ Returns list of available DXF encodings
%End


void registerDxfLayer( const QString &layerId, QgsFeatureId fid, const QString &layer );
void registerDxfLayer( const QString &layerId, QgsFeatureId fid, const QString &layer );
%Docstring
Register name of layer for feature

:param layerId: id of layer
:param fid: id of feature
:param layer: dxf layer of feature

.. deprecated::
Will be made private in QGIS 4
%End

private:
@@ -287,6 +287,7 @@ SET(QGIS_CORE_SRCS
qgsimagecache.cpp
qgsinterval.cpp
qgsjsonutils.cpp
qgslabelsink.cpp
qgslayerdefinition.cpp
qgslegendrenderer.cpp
qgslegendsettings.cpp
@@ -450,7 +451,6 @@ SET(QGIS_CORE_SRCS
dxf/qgsdxfexport.cpp
dxf/qgsdxfpaintdevice.cpp
dxf/qgsdxfpaintengine.cpp
dxf/qgsdxfpallabeling.cpp

layout/qgsabstractreportsection.cpp
layout/qgslayout.cpp
@@ -27,7 +27,6 @@
// AutoCAD 2014: http://images.autodesk.com/adsk/files/autocad_2014_pdf_dxf_reference_enu.pdf

#include "qgsdxfexport.h"
#include "qgsdxfpallabeling.h"
#include "qgsgeometrygeneratorsymbollayer.h"
#include "qgsgeometrycollection.h"
#include "qgscurvepolygon.h"
@@ -718,11 +717,17 @@ void QgsDxfExport::writeEntities()

if ( job->labelProvider )
{
job->labelProvider->registerDxfFeature( fet, mRenderContext, lName );
job->labelProvider->registerFeature( fet, mRenderContext );
Q_NOWARN_DEPRECATED_PUSH
registerDxfLayer( job->featureSource.id(), fet.id(), lName );
Q_NOWARN_DEPRECATED_POP
}
else if ( job->ruleBasedLabelProvider )
{
job->ruleBasedLabelProvider->registerDxfFeature( fet, mRenderContext, lName );
job->ruleBasedLabelProvider->registerFeature( fet, mRenderContext );
Q_NOWARN_DEPRECATED_PUSH
registerDxfLayer( job->featureSource.id(), fet.id(), lName );
Q_NOWARN_DEPRECATED_POP
}
}
}
@@ -24,6 +24,7 @@
#include "qgsgeometry.h"
#include "qgssymbol.h" // for OutputUnit enum
#include "qgsmapsettings.h"
#include "qgslabelsink.h"

#include <QColor>
#include <QList>
@@ -54,8 +55,13 @@ namespace pal // SIP_SKIP
* \ingroup core
* \class QgsDxfExport
*/
#ifdef SIP_RUN
class CORE_EXPORT QgsDxfExport
{
#else
class CORE_EXPORT QgsDxfExport : public QgsLabelSink
{
#endif
public:

/**
@@ -167,7 +173,7 @@ class CORE_EXPORT QgsDxfExport
*/
QgsDxfExport();

~QgsDxfExport();
~QgsDxfExport() override;

/**
* Set map settings and assign layer name attributes
@@ -505,22 +511,21 @@ class CORE_EXPORT QgsDxfExport
static QStringList encodings();

/**
* Output the label
* \param layerId id of the layer
* \param context render context
* \param label position of label
* \param settings label settings
* Add a label to the dxf output.
*
* \note not available in Python bindings
*/
void drawLabel( const QString &layerId, QgsRenderContext &context, pal::LabelPosition *label, const QgsPalLayerSettings &settings ) SIP_SKIP;
void drawLabel( const QString &layerId, QgsRenderContext &context, pal::LabelPosition *label, const QgsPalLayerSettings &settings ) SIP_SKIP override;

/**
* Register name of layer for feature
* \param layerId id of layer
* \param fid id of feature
* \param layer dxf layer of feature
*
* \deprecated Will be made private in QGIS 4
*/
void registerDxfLayer( const QString &layerId, QgsFeatureId fid, const QString &layer );
Q_DECL_DEPRECATED void registerDxfLayer( const QString &layerId, QgsFeatureId fid, const QString &layer );

private:

@@ -22,7 +22,7 @@
#include "qgsvectorlayerfeatureiterator.h"
#include "qgsrenderer.h"
#include "qgsvectorlayerlabeling.h"
#include "qgsdxfpallabeling.h"
#include "qgslabelsink.h"

/**
* Holds information about each layer in a DXF job.
@@ -62,7 +62,7 @@ struct DxfLayerJob
QgsLabelingEngine *labelingEngine = renderContext.labelingEngine();
if ( const QgsRuleBasedLabeling *rbl = dynamic_cast<const QgsRuleBasedLabeling *>( labeling.get() ) )
{
ruleBasedLabelProvider = new QgsDxfRuleBasedLabelProvider( *rbl, vl, dxfExport );
ruleBasedLabelProvider = new QgsRuleBasedLabelSinkProvider( *rbl, vl, dxfExport );
labelingEngine->addProvider( ruleBasedLabelProvider );

if ( !ruleBasedLabelProvider->prepare( renderContext, attributes ) )
@@ -74,7 +74,7 @@ struct DxfLayerJob
else
{
QgsPalLayerSettings settings = labeling->settings();
labelProvider = new QgsDxfLabelProvider( vl, QString(), dxfExport, &settings );
labelProvider = new QgsLabelSinkProvider( vl, QString(), dxfExport, &settings );
labelingEngine->addProvider( labelProvider );

if ( !labelProvider->prepare( renderContext, attributes ) )
@@ -98,8 +98,8 @@ struct DxfLayerJob
QgsDxfExport *dxfExport = nullptr;
QgsCoordinateReferenceSystem crs;
QString layerName;
QgsDxfLabelProvider *labelProvider = nullptr;
QgsDxfRuleBasedLabelProvider *ruleBasedLabelProvider = nullptr;
QgsLabelSinkProvider *labelProvider = nullptr;
QgsRuleBasedLabelSinkProvider *ruleBasedLabelProvider = nullptr;
QString splitLayerAttribute;
QString layerTitle;
QSet<QString> attributes;

This file was deleted.

@@ -0,0 +1,57 @@
/***************************************************************************
qgslabelsink.cpp
---------------------
begin : January 2014
copyright : (C) 2014 by Marco Hugentobler
email : marco at sourcepole dot ch
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgslabelsink.h"
#include "qgspallabeling.h"
#include "qgsmapsettings.h"
#include "qgslogger.h"

QgsLabelSinkProvider::QgsLabelSinkProvider( QgsVectorLayer *layer, const QString &providerId, QgsLabelSink *dxf, const QgsPalLayerSettings *settings )
: QgsVectorLayerLabelProvider( layer, providerId, false, settings )
, mLabelSink( dxf )
{
}

void QgsLabelSinkProvider::drawLabel( QgsRenderContext &context, pal::LabelPosition *label ) const
{
Q_ASSERT( mLabelSink );
mLabelSink->drawLabel( layerId(), context, label, mSettings );
}

QgsRuleBasedLabelSinkProvider::QgsRuleBasedLabelSinkProvider( const QgsRuleBasedLabeling &rules, QgsVectorLayer *layer, QgsLabelSink *dxf )
: QgsRuleBasedLabelProvider( rules, layer, false )
, mLabelSink( dxf )
{
mRules->rootRule()->createSubProviders( layer, mSubProviders, this );
}

void QgsRuleBasedLabelSinkProvider::reinit( QgsVectorLayer *layer )
{
mRules->rootRule()->createSubProviders( layer, mSubProviders, this );
}

QgsVectorLayerLabelProvider *QgsRuleBasedLabelSinkProvider::createProvider( QgsVectorLayer *layer, const QString &providerId, bool withFeatureLoop, const QgsPalLayerSettings *settings )
{
Q_UNUSED( withFeatureLoop )
return new QgsLabelSinkProvider( layer, providerId, mLabelSink, settings );
}

void QgsRuleBasedLabelSinkProvider::drawLabel( QgsRenderContext &context, pal::LabelPosition *label ) const
{
Q_ASSERT( mLabelSink );
mLabelSink->drawLabel( layerId(), context, label, mSettings );
}

0 comments on commit 50e63a7

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