Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Port labelling to expression contexts
  • Loading branch information
nyalldawson committed Aug 22, 2015
1 parent 5e03016 commit 1a7acb0
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 129 deletions.
24 changes: 19 additions & 5 deletions python/core/qgspallabeling.sip
Expand Up @@ -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 );
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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 );
Expand Down
1 change: 1 addition & 0 deletions src/app/qgslabelpropertydialog.cpp
Expand Up @@ -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() )
{
Expand Down

0 comments on commit 1a7acb0

Please sign in to comment.