Move prepare step into qgspallabeling

This commit is contained in:
Matthias Kuhn 2019-03-11 11:58:48 +01:00
parent 05ff817a97
commit 6d465f017d
No known key found for this signature in database
GPG Key ID: 7A7F1A1C90C3E6A7

View File

@ -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 )