qgis/QGIS — pull request #1556 by leyan (2014-08-24 00:57:28+00:00)
Title: Convert a symbology to rule based symbology

Hi devs,

Very often I start with a categorized or graduated symbology, but I realize later I have to refine it with a custom rule. Or I make a complex symbol with several layer, data defined attributes, etc., then realize I cannot use a single symbol representation for what I want to achieve and I have to work with rules. Sometimes I know from the beginning I will need rules, but it is very tedious to build as these rules are very close to a categorized symbology, so a lot of classes need to be created. In all these cases, I have to start from scratch again when switching to rule-based symbology.

I propose to improve this situation by allowing to automatically convert other renderers to a rule based renderer when we switch renderers in the properties. If the renderer supports it, it should implement convertToRuleBasedRenderer() and the existing rendering will be preserved when switching to a rule based renderer. If it can't, the previous behavior is kept and a new rule based renderer is created (for example inverted polygons or point displacement renderer).

This conversion supports rotation fields and size scale fields by converting them to data-defined symbology. I think these fields should be replaced by data-defined symbology anyway, now that it is so powerful.

The result gives something like that:
![categorized](https://cloud.githubusercontent.com/assets/537624/4022281/0b23f228-2b28-11e4-882a-671e29765071.png)
![rule_based](https://cloud.githubusercontent.com/assets/537624/4022283/121d982c-2b28-11e4-89ab-101ae7256c63.png)
![graduated](https://cloud.githubusercontent.com/assets/537624/4022284/17b6b1c4-2b28-11e4-96c1-79d920d09fdd.png)
![rule_based_2](https://cloud.githubusercontent.com/assets/537624/4022286/2eae18ae-2b28-11e4-9f82-7e1b8a77a04f.png)