Skip to content
Permalink
Browse files

Port labelling to expression contexts

  • Loading branch information
nyalldawson committed Aug 22, 2015
1 parent 5e03016 commit 1a7acb0d98308a48355937c67c7483bc27d1a273
Showing with 189 additions and 129 deletions.
  1. +19 −5 python/core/qgspallabeling.sip
  2. +1 −0 src/app/qgslabelpropertydialog.cpp
  3. +145 −114 src/core/qgspallabeling.cpp
  4. +24 −10 src/core/qgspallabeling.h
@@ -485,9 +485,14 @@ class QgsPalLayerSettings
double rasterCompressFactor; //pixel resolution scale factor

// called from register feature hook
void calculateLabelSize( const QFontMetricsF* fm, QString text, double& labelX, double& labelY, QgsFeature* f = 0 );
void calculateLabelSize( const QFontMetricsF* fm, QString text, double& labelX, double& labelY, QgsFeature* f = 0, const QgsRenderContext* context = 0 );

// implementation of register feature hook
/** Register a feature for labelling.
* @param f 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.
* @param dfxLayer dxfLayer name
*/
void registerFeature( QgsFeature& f, const QgsRenderContext& context, QString dxfLayer );

void readFromLayer( QgsVectorLayer* layer );
@@ -521,13 +526,14 @@ class QgsPalLayerSettings
* @returns value inside QVariant
* @note not available in python bindings
*/
QVariant dataDefinedValue( QgsPalLayerSettings::DataDefinedProperties p, QgsFeature& f, const QgsFields& fields ) const;
//QVariant dataDefinedValue( QgsPalLayerSettings::DataDefinedProperties p, QgsFeature& f, const QgsFields& fields,
// const QgsExpressionContext* context = 0 ) const;

/** Get data defined property value from expression string or attribute field name
* @returns true/false whether result is null or invalid
* @note not available in python bindings
*/
bool dataDefinedEvaluate( QgsPalLayerSettings::DataDefinedProperties p, QVariant& exprVal ) const;
//bool dataDefinedEvaluate( QgsPalLayerSettings::DataDefinedProperties p, QVariant& exprVal, const QgsExpressionContext* context = 0 ) const;

/** Whether data definition is active
*/
@@ -731,8 +737,16 @@ class QgsPalLabeling : QgsLabelingEngineInterface
virtual int prepareLayer( QgsVectorLayer* layer, QStringList &attrNames, QgsRenderContext& ctx );
//! adds a diagram layer to the labeling engine
virtual int addDiagramLayer( QgsVectorLayer* layer, const QgsDiagramLayerSettings *s );
//! hook called when drawing for every feature in a layer

/** 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.
* @param dxfLayer dxfLayer name
*/
virtual void registerFeature( const QString& layerID, QgsFeature& feat, const QgsRenderContext& context = QgsRenderContext(), QString dxfLayer = QString::null );

virtual void registerDiagramFeature( const QString& layerID, QgsFeature& feat, const QgsRenderContext& context = QgsRenderContext() );
//! called when the map is drawn and labels should be placed
virtual void drawLabeling( QgsRenderContext& context );
@@ -218,6 +218,7 @@ void QgsLabelPropertyDialog::setDataDefinedValues( const QgsPalLayerSettings &la
dd->prepareExpression( vlayer );
}

//TODO - pass expression context
QVariant result = layerSettings.dataDefinedValue( propIt.key(), mCurLabelFeat, vlayer->fields() );
if ( !result.isValid() || result.isNull() )
{

0 comments on commit 1a7acb0

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