1

In my plugin I do some labelling a vector layer with QgsPalLayerSettings. This works fine for me with QgsMapRenderer::setLabelingEngine.

But now I also want to implement the rulebased labelling. In API I found the class QgsRuleBasedLabeling::Rule which I thought works similar to setting up a QgsRuleBasedRendererV2::RuleList.

But I can't find the point where the QgsRuleBasedLabeling::Rule has to be set. Ther is no member in QgsMapRenderer. Does anybody has a hint?

2 Answers 2

0

It's not possible yet - the relevant methods and classes aren't exposed to the python API. This will be addressed when 3.0 is released.

1
  • 1
    Oh... But my plugin is in c++, so there should be a possibility. Jul 23, 2016 at 14:08
0

After browsing the QGIS source code found in qgsrulebasedlabelingwidget.cpp the solution:

// also clear old-style labeling config
mLayer->removeCustomProperty( "labeling" );

mLayer->setLabeling( new QgsRuleBasedLabeling( mRootRule->clone() ) );

Before i adapted this code I set up my rootRule like this:

rootRule = new QgsRuleBasedLabeling::Rule( nullptr );

and added the rules in that way:

rootRule->appendChild(new QgsRuleBasedLabeling::Rule(set,minScale,maxScale,sWhere, nam));

Before I filled the QgsPalLayerSettings* set= &palLyr;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.