Skip to content
Permalink
Browse files

Move prepare step into qgspallabeling

  • Loading branch information
m-kuhn committed Mar 11, 2019
1 parent 05ff817 commit 6d465f017d0c6a5e2dd4f8ec30b8461845e53d64
Showing with 1 addition and 96 deletions.
  1. +1 −96 src/core/qgsvectorlayerlabelprovider.cpp
@@ -93,106 +93,11 @@ QgsVectorLayerLabelProvider::~QgsVectorLayerLabelProvider()

bool QgsVectorLayerLabelProvider::prepare( const QgsRenderContext &context, QSet<QString> &attributeNames )
{
QgsPalLayerSettings &lyr = mSettings;
const QgsMapSettings &mapSettings = mEngine->mapSettings();

QgsDebugMsgLevel( "PREPARE LAYER " + mLayerId, 4 );

if ( lyr.drawLabels )
{
if ( lyr.fieldName.isEmpty() )
{
return false;
}

if ( lyr.isExpression )
{
QgsExpression exp( lyr.fieldName );
if ( exp.hasEvalError() )
{
QgsDebugMsgLevel( "Prepare error:" + exp.evalErrorString(), 4 );
return false;
}
}
else
{
// If we aren't an expression, we check to see if we can find the column.
if ( mFields.lookupField( lyr.fieldName ) == -1 )
{
return false;
}
}
}

lyr.mCurFields = mFields;

if ( lyr.drawLabels || lyr.obstacle )
{
if ( lyr.drawLabels )
{
// add field indices for label's text, from expression or field
if ( lyr.isExpression )
{
// prepare expression for use in QgsPalLayerSettings::registerFeature()
QgsExpression *exp = lyr.getLabelExpression();
exp->prepare( &context.expressionContext() );
if ( exp->hasEvalError() )
{
QgsDebugMsgLevel( "Prepare error:" + exp->evalErrorString(), 4 );
}
Q_FOREACH ( const QString &name, exp->referencedColumns() )
{
QgsDebugMsgLevel( "REFERENCED COLUMN = " + name, 4 );
attributeNames.insert( name );
}
}
else
{
attributeNames.insert( lyr.fieldName );
}
}

lyr.dataDefinedProperties().prepare( context.expressionContext() );
// add field indices of data defined expression or field
attributeNames.unite( lyr.dataDefinedProperties().referencedFields( context.expressionContext() ) );
}

// NOW INITIALIZE QgsPalLayerSettings

// TODO: ideally these (non-configuration) members should get out of QgsPalLayerSettings to here
// (together with registerFeature() & related methods) and QgsPalLayerSettings just stores config

// save the pal layer to our layer context (with some additional info)
lyr.fieldIndex = mFields.lookupField( lyr.fieldName );

lyr.xform = &mapSettings.mapToPixel();
lyr.ct = QgsCoordinateTransform();
if ( context.coordinateTransform().isValid() )
// this is context for layer rendering
lyr.ct = context.coordinateTransform();
else
{
// otherwise fall back to creating our own CT
lyr.ct = QgsCoordinateTransform( mCrs, mapSettings.destinationCrs(), mapSettings.transformContext() );
}
lyr.ptZero = lyr.xform->toMapCoordinates( 0, 0 );
lyr.ptOne = lyr.xform->toMapCoordinates( 1, 0 );

// rect for clipping
lyr.extentGeom = QgsGeometry::fromRect( mapSettings.visibleExtent() );
if ( !qgsDoubleNear( mapSettings.rotation(), 0.0 ) )
{
//PAL features are prerotated, so extent also needs to be unrotated
lyr.extentGeom.rotate( -mapSettings.rotation(), mapSettings.visibleExtent().center() );
}

lyr.mFeatsSendingToPal = 0;

return true;
return mSettings.prepare( context, attributeNames, mFields, mapSettings, mCrs );
}



QList<QgsLabelFeature *> QgsVectorLayerLabelProvider::labelFeatures( QgsRenderContext &ctx )
{
if ( !mSource )

0 comments on commit 6d465f0

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