My c++-plugin for QGIS 2.18 should read out the labeling properties from the layer. So I was searching the API for getting informed of rule-based-labeling but still get more confused. In my example I have four rules. For every rule I want to read out the QgsPalLayerSettings and the properties of the rule (name, scale dependency, filter...)
For getting the QgsPalLayerSettings a ProviderID is needed. In the api I found, the member ruleKey() of a Rule is the Unique rule identifier (for identification of rule within labeling, used as provider ID) But there also is a list of providers in the labeling object of the layer. So I ran through the layer with the following code:
if (vLyr->labeling()->type()=="rule-based")
{
const QgsRuleBasedLabeling* rl = static_cast<const QgsRuleBasedLabeling*>( vLyr->labeling() );
QgsRuleBasedLabeling::Rule* rootRule = rl->rootRule()->clone();
qDebug() << QString("Root Rule [%1] ").arg(rootRule->ruleKey());
QStringList sp;
rootRule->subProviderIds(sp);
int i=0;
foreach(QgsRuleBasedLabeling::Rule* rl, rootRule->children())
{
qDebug() << QString("Rule [%1] %2").arg(rl->ruleKey()).arg(sp.at(i));
}
foreach(QString sProv , vLyr->labeling()->subProviders())
{
qDebug() << QString("Provider [%1] ").arg(sProv);
QgsPalLayerSettings layerSettings = vLyr->labeling()->settings( vLyr, sProv );
}
}
And this is the output:
"Root Rule [{0149ca5f-1ae3-46c8-a245-16e55bb9ce3c}] "
"Rule [{ede1075f-0c72-461f-be71-22987a6ab011}] {ede1075f-0c72-461f-be71-22987a6ab011}"
"Rule [{559d4578-770b-49c4-a7cb-eb0665e90838}] {559d4578-770b-49c4-a7cb-eb0665e90838}"
"Rule [{63523eeb-b29d-4225-a4c8-5d8936c031f0}] {63523eeb-b29d-4225-a4c8-5d8936c031f0}"
"Rule [{3c5edfb3-a717-48da-bc83-a4969ee549cc}] {3c5edfb3-a717-48da-bc83-a4969ee549cc}"
"Provider [{72fefc10-2f5c-424c-8524-6c2cc7db7e26}] "
"Provider [{67b3a0c7-c2eb-47a9-bab9-9c3fd7905bbc}] "
"Provider [{48c4d4da-d94b-435f-8424-fe6e1c545ab8}] "
"Provider [{b59c0c89-98fe-42b6-99d3-4b5a4efc63ae}] "
I supposed that the four keys/providerIDs are the same but now I'm confused and don't know what to read out. I don't understand the difference between subProviders() and rooleKeys. And because this class is not available in python, there are no examples to find.
EDIT:
I found out the layersettings I get from rulekeys are empty, those from subProviders have the right informations. But how to combine them? Tried with QgsRuleBasedLabeling::Rule::subProviderIds but the IDs are the same like ruleKeys.