diff --git a/src/core/qgsvectorlayerlabelprovider.cpp b/src/core/qgsvectorlayerlabelprovider.cpp index 1c26a6f7d38..3000c74766d 100644 --- a/src/core/qgsvectorlayerlabelprovider.cpp +++ b/src/core/qgsvectorlayerlabelprovider.cpp @@ -93,106 +93,11 @@ QgsVectorLayerLabelProvider::~QgsVectorLayerLabelProvider() bool QgsVectorLayerLabelProvider::prepare( const QgsRenderContext &context, QSet &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 QgsVectorLayerLabelProvider::labelFeatures( QgsRenderContext &ctx ) { if ( !mSource )