Skip to content
Permalink
Browse files

Remove QgsLabelingEngineInterface base class and implementation in Qg…

…sPalLabeling

It was ready to go for some time, just waiting for QgsMapRender that still used it.
  • Loading branch information
wonder-sk committed Dec 15, 2016
1 parent 3982498 commit 8e5fb436b702b9ab3d2112557f57e5a49cdea03a
@@ -245,7 +245,8 @@ Use QgsComposerAttributeTableV2 instead.
so there is no longer a need for the separate cache class. Code which previously called QgsCRSCache::updateCRSCache()
should now call QgsCoordinateReferenceSystem::invalidateCache() and QgsCoordinateTransformCache::instance()->invalidateCrs( authid ).
- QgsHttpTransaction. This class was outdated and code should be ported to native Qt or Python implementations.
- QgsLabel and QgsLabelAttributes. Replaced by labeling based on PAL library, see QgsLabelingEngineV2.
- QgsLabel and QgsLabelAttributes. Replaced by labeling based on PAL library, see QgsLabelingEngine.
- QgsLabelingEngineInterface. Replaced by QgsLabelingEngine.
- QgsLegendInterface was removed. It was replaced by layer tree API (QgsLayerTreeNode class and others).
Methods that deal with custom actions in main window's layer tree context menu were moved to QgisInterface:
- addLegendLayerAction() moved to QgisInterface::addCustomActionForLayerType()
@@ -1113,7 +1114,7 @@ screenUpdateRequested() were removed. These members have had no effect for a num
- theMinScale and theMaxScale parameters in setMinimumScale and setMaximumScale were renamed to scale
- The layerCrsChanged() signal was renamed to crsChanged()
- theError parameter in appendError() and setError() were renamed to 'error'.
- drawLabels() method was removed. It used old deprecated labeling. Replaced by labeling based on PAL library, see QgsLabelingEngineV2.
- drawLabels() method was removed. It used old deprecated labeling. Replaced by labeling based on PAL library, see QgsLabelingEngine.
- readLayerXML() was renamed to readLayerXml()
- writeLayerXML() was renamed to writeLayerXml()

@@ -1145,7 +1146,7 @@ QgsMapRendererJob {#qgis_api_break_3_0_QgsMapRendererJob}

- reprojectToLayerExtent() now takes a QgsCoordinateTransform reference, not a pointer. An invalid QgsCoordinateTransform should
be used instead of a null pointer if no transformation is required.
- prepareJobs() and drawLabeling() (neither available in PyQGIS) do not take QgsPalLabeling parameter anymore. All drawing of labels is done by QgsLabelingEngineV2.
- prepareJobs() and drawLabeling() (neither available in PyQGIS) do not take QgsPalLabeling parameter anymore. All drawing of labels is done by QgsLabelingEngine.
- drawOldLabeling(), drawNewLabeling() were removed. The method drawLabeling() should be used instead.


@@ -1253,6 +1254,7 @@ QgsPalettedRasterRenderer {#qgis_api_break_3_0_QgsPalettedRasterRenderer}
QgsPalLabeling {#qgis_api_break_3_0_QgsPalLabeling}
--------------

- all methods implemented from QgsLabelingEngineInterface have been removed: init(), willUseLayer(), clearActiveLayers(), clearActiveLayer(), prepareLayer(), prepareDiagramLayer(), registerFeature(), registerDiagramFeature(), drawLabeling(), exit(), clone(). Labeling is now driven by QgsLabelingEngine.
- init(QgsMapRenderer*) has been removed. Use init(const QgsMapSettings&) instead.
- prepareGeometry and geometryRequiresPreparation now take geometry references, not pointers.
- layer() was removed. If direct access to QgsPalLayerSettings is necessary, use QgsPalLayerSettings::fromLayer()
@@ -1596,7 +1598,7 @@ displayExpression instead. For the map tip use mapTipTemplate() instead.
- addTopologicalPoints() now takes a geometry reference, not a pointer.
- commitErrors() now returns an object, rather than a reference. This has no effect on PyQGIS code.
- subsetString() was made const. This has no effect on PyQGIS code, but c++ code implementing derived layer classes will need to update the signature of this method to match.
- label(), enableLabels(), hasLabelsEnabled(), drawLabels() have been removed. Replaced by labeling based on PAL library, see QgsLabelingEngineV2.
- label(), enableLabels(), hasLabelsEnabled(), drawLabels() have been removed. Replaced by labeling based on PAL library, see QgsLabelingEngine.
- Signal layerDeleted() has been removed. Replaced by Qt signal destroyed().
- Deprecated editor widget methods and enums and structs: struct RangeData, enum FeatureFormSuppress, enum EditType, addAttributeEditorWidget(), editorWidgetV2(), editorWidgetConfig(), attributeEditorElements(), editType(), setEditType(), editorLayout(), setEditorLayout, setEditorWidgetV2Config(), setCheckedState(), editForm(), setEditForm(), featureFormSuppress(), setFeatureFormSuppress(), editFormInit(), setEditFormInit(), valueMap(), range(), dateFormat(), fieldEditable(), labelOnTop(), setFieldEditable() and setLabelOnTop(). Use editFormConfig()
- select() replaced by selectByRect()
@@ -102,44 +102,6 @@ class QgsLabelPosition
QString providerID;
};

/** Labeling engine interface. */
class QgsLabelingEngineInterface
{
%TypeHeaderCode
#include <qgspallabeling.h>
%End

public:

virtual ~QgsLabelingEngineInterface();

//! called when we're going to start with rendering
virtual void init( const QgsMapSettings& mapSettings ) = 0;
//! called to find out whether the layer is used for labeling
virtual bool willUseLayer( QgsVectorLayer* layer ) = 0;
//! clears all PAL layer settings for registered layers
virtual void clearActiveLayers() = 0;
//! clears data defined objects from PAL layer settings for a registered layer
virtual void clearActiveLayer( const QString& layerID ) = 0;
//! called when starting rendering of a layer
virtual int prepareLayer( QgsVectorLayer* layer, QSet<QString>& attrNames, QgsRenderContext& ctx ) = 0;
//! adds a diagram layer to the labeling engine
//! @note added in QGIS 2.12
virtual int prepareDiagramLayer( QgsVectorLayer *layer, QSet<QString>& attrNames, QgsRenderContext& ctx );
//! called for every feature
virtual void registerFeature( const QString &layerID, QgsFeature& feat, QgsRenderContext& context ) = 0;
//! called for every diagram feature
virtual void registerDiagramFeature( const QString& layerID, QgsFeature& feat, QgsRenderContext& context );
//! called when the map is drawn and labels should be placed
virtual void drawLabeling( QgsRenderContext& context ) = 0;
//! called when we're done with rendering
virtual void exit() = 0;

//! called when passing engine among map renderers
virtual QgsLabelingEngineInterface* clone() = 0 /Factory/;
};



class QgsPalLayerSettings
{
@@ -674,7 +636,7 @@ class QgsLabelingResults
};


class QgsPalLabeling : QgsLabelingEngineInterface
class QgsPalLabeling
{
%TypeHeaderCode
#include <qgspallabeling.h>
@@ -721,49 +683,11 @@ class QgsPalLabeling : QgsLabelingEngineInterface
*/
void setDrawLabelRectOnly( bool drawRect );

// implemented methods from labeling engine interface

//! called when we're going to start with rendering
virtual void init( const QgsMapSettings& mapSettings );
//! called to find out whether the layer is used for labeling
virtual bool willUseLayer( QgsVectorLayer* layer );

//! called to find out whether the layer is used for labeling
//! @note added in 2.4
static bool staticWillUseLayer( QgsVectorLayer* layer );
static bool staticWillUseLayer( const QString& layerID );

//! clears all PAL layer settings for registered layers
virtual void clearActiveLayers();
//! clears data defined objects from PAL layer settings for a registered layer
virtual void clearActiveLayer( const QString& layerID );
//! hook called when drawing layer before issuing select()
virtual int prepareLayer( QgsVectorLayer* layer, QSet<QString>& attrNames, QgsRenderContext& ctx );
//! adds a diagram layer to the labeling engine
//! @note added in QGIS 2.12
virtual int prepareDiagramLayer( QgsVectorLayer* layer, QSet<QString>& attrNames, QgsRenderContext& ctx );

/** Register a feature for labelling.
* @param layerID string identifying layer associated with label
* @param feat feature to label
* @param context render context. The QgsExpressionContext contained within the render context
* must have already had the feature and fields sets prior to calling this method.
*/
virtual void registerFeature( const QString& layerID, QgsFeature& feat, QgsRenderContext& context );

virtual void registerDiagramFeature( const QString& layerID, QgsFeature& feat, QgsRenderContext& context );
//! called when the map is drawn and labels should be placed
virtual void drawLabeling( QgsRenderContext& context );
//! called when we're done with rendering
virtual void exit();

//! Return pointer to recently computed results (in drawLabeling()) and pass the ownership of results to the caller
//! @note added in 2.4
QgsLabelingResults* takeResults() /TransferBack/;

//! called when passing engine among map renderers
virtual QgsPalLabeling* clone() /Factory/;

//! @note not available in python bindings
// void drawLabelCandidateRect( pal::LabelPosition* lp, QPainter* painter, const QgsMapToPixel* xform );

@@ -85,11 +85,9 @@ class QgsRenderContext

double rendererScale() const;

QgsLabelingEngineInterface* labelingEngine();

//! Get access to new labeling engine (may be nullptr)
//! @note not available in Python bindings
// QgsLabelingEngine* labelingEngineV2() const { return mLabelingEngine2; }
// QgsLabelingEngine* labelingEngine() const;

QColor selectionColor() const;

@@ -119,10 +117,9 @@ class QgsRenderContext

void setForceVectorOutput( bool force );

void setLabelingEngine( QgsLabelingEngineInterface* iface );
//! Assign new labeling engine
//! @note not available in Python bindings
// void setLabelingEngineV2( QgsLabelingEngine* engine2 ) { mLabelingEngine2 = engine2; }
// void setLabelingEngine( QgsLabelingEngine* engine2 );
void setSelectionColor( const QColor& color );

/** Sets whether vector selections should be shown in the rendered map
@@ -246,7 +246,7 @@ LayerRenderJobs QgsMapRendererJob::prepareJobs( QPainter* painter, QgsLabelingEn

job.context = QgsRenderContext::fromMapSettings( mSettings );
job.context.setPainter( painter );
job.context.setLabelingEngineV2( labelingEngine2 );
job.context.setLabelingEngine( labelingEngine2 );
job.context.setCoordinateTransform( ct );
job.context.setExtent( r1 );

@@ -3207,11 +3207,6 @@ QgsPalLabeling::~QgsPalLabeling()
mEngine = nullptr;
}

bool QgsPalLabeling::willUseLayer( QgsVectorLayer* layer )
{
return staticWillUseLayer( layer );
}

bool QgsPalLabeling::staticWillUseLayer( const QString& layerID )
{
QgsVectorLayer* layer = qobject_cast<QgsVectorLayer*>( QgsProject::instance()->mapLayer( layerID ) );
@@ -3234,66 +3229,6 @@ bool QgsPalLabeling::staticWillUseLayer( QgsVectorLayer* layer )
}


void QgsPalLabeling::clearActiveLayers()
{
}

void QgsPalLabeling::clearActiveLayer( const QString &layerID )
{
Q_UNUSED( layerID );
}


int QgsPalLabeling::prepareLayer( QgsVectorLayer* layer, QSet<QString>& attrNames, QgsRenderContext& ctx )
{
if ( !willUseLayer( layer ) )
{
return 0;
}

if ( !layer->labeling() )
return 0;

QgsVectorLayerLabelProvider* lp = layer->labeling()->provider( layer );
if ( !lp )
return 0;

//QgsVectorLayerLabelProvider* lp = new QgsVectorLayerLabelProvider( layer, false );
// need to be added before calling prepare() - uses map settings from engine
mEngine->addProvider( lp );
mLabelProviders[layer->id()] = lp; // fast lookup table by layer ID

if ( !lp->prepare( ctx, attrNames ) )
{
mEngine->removeProvider( lp );
return 0;
}

return 1; // init successful
}

int QgsPalLabeling::prepareDiagramLayer( QgsVectorLayer* layer, QSet<QString>& attrNames, QgsRenderContext& ctx )
{
QgsVectorLayerDiagramProvider* dp = new QgsVectorLayerDiagramProvider( layer, false );
// need to be added before calling prepare() - uses map settings from engine
mEngine->addProvider( dp );
mDiagramProviders[layer->id()] = dp; // fast lookup table by layer ID

if ( !dp->prepare( ctx, attrNames ) )
{
mEngine->removeProvider( dp );
return 0;
}

return 1;
}

void QgsPalLabeling::registerFeature( const QString& layerID, QgsFeature& f, QgsRenderContext &context )
{
if ( QgsVectorLayerLabelProvider* provider = mLabelProviders.value( layerID, nullptr ) )
provider->registerFeature( f, context );
}

bool QgsPalLabeling::geometryRequiresPreparation( const QgsGeometry& geometry, QgsRenderContext &context, const QgsCoordinateTransform& ct, QgsGeometry* clipGeometry )
{
if ( geometry.isEmpty() )
@@ -3470,23 +3405,6 @@ bool QgsPalLabeling::checkMinimumSizeMM( const QgsRenderContext& context, const
return true; //should never be reached. Return true in this case to label such geometries anyway.
}

void QgsPalLabeling::registerDiagramFeature( const QString& layerID, QgsFeature& feat, QgsRenderContext &context )
{
if ( QgsVectorLayerDiagramProvider* provider = mDiagramProviders.value( layerID, nullptr ) )
provider->registerFeature( feat, context );
}


void QgsPalLabeling::init( const QgsMapSettings& mapSettings )
{
mEngine->setMapSettings( mapSettings );
}

void QgsPalLabeling::exit()
{
delete mEngine;
mEngine = new QgsLabelingEngine();
}

void QgsPalLabeling::dataDefinedTextStyle( QgsPalLayerSettings& tmpLyr,
const QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant >& ddValues )
@@ -3901,21 +3819,10 @@ void QgsPalLabeling::dataDefinedDropShadow( QgsPalLayerSettings& tmpLyr,
}



void QgsPalLabeling::drawLabeling( QgsRenderContext& context )
{
mEngine->run( context );
}

void QgsPalLabeling::deleteTemporaryData()
{
}

QgsLabelingResults *QgsPalLabeling::takeResults()
{
return mEngine->takeResults();
}

void QgsPalLabeling::numCandidatePositions( int& candPoint, int& candLine, int& candPolygon )
{
mEngine->numCandidatePositions( candPoint, candLine, candPolygon );
@@ -4067,18 +3974,6 @@ void QgsPalLabeling::clearEngineSettings()
QgsProject::instance()->removeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/DrawOutlineLabels" ) );
}

QgsPalLabeling* QgsPalLabeling::clone()
{
QgsPalLabeling* lbl = new QgsPalLabeling();
lbl->setShowingAllLabels( isShowingAllLabels() );
lbl->setShowingCandidates( isShowingCandidates() );
lbl->setDrawLabelRectOnly( drawLabelRectOnly() );
lbl->setShowingPartialsLabels( isShowingPartialsLabels() );
lbl->setDrawingOutlineLabels( isDrawingOutlineLabels() );
return lbl;
}


QgsLabelingResults::QgsLabelingResults()
{
mLabelSearchTree = new QgsLabelSearchTree();

0 comments on commit 8e5fb43

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