Hi Martin

Thanks for your efforts to unify the legends. Few comments from my side:

- API break: is there a list of breaks inside the 2.x series? I recently came accross one in the provider API, and it would be good to provide some guidance for people porting code to newer versions. Regarding 'not used according to plugin analysis tool': most plugins are probably not in the plugin repo.

- For the legend graphics options layertitlespace and layerfontcolor, it says 'TODO'.

- qgswmsserver.cpp:671 : it seems a bit strange to iterate over all nodes to set the property. Can this be done inside some legend class (maybe legend renderer)?

Regards,
Marco

On 22.08.2014 13:02, Martin Dobias wrote:
Hi all

In recent weeks I have been busy with the second part of legend
refactoring. The main goals were:
- clean up the mess with legend - there are three different ways of
legend presentation/rendering: 1. in legend widget (now layer tree
view), 2. composer legend, 3. WMS legend
- make legend rendering independent from composer - so it can be used
elsewhere - in WMS or in GUI
- allow different strategies how legend for a layer is created - until
now the legend generation was hardcoded - this should allow things
like data-defined legend, labeling / diagrams in legend
- allow new types of legend items - for greater flexibility of item
appearance - e.g. show a gradient color ramp for raster layer

The code is in my repository:
https://github.com/wonder-sk/QGIS/compare/legend-refactoring-part2

To introduce the important new classes:
- QgsLegendRenderer - takes care of rendering of the legend - similar
to how QgsMapRenderer handles rendering of map
- QgsLegendSettings - contains user configuration of the legend
(fonts, colors, sizes, spacing) - similar to QgsMapSettings for map
- QgsMapLayerLegend - base class for legend implementations. For a
layer an implementation should return a list of legend nodes
- QgsLayerTreeModelLegendNode - base class for legend node
implementation. Provides data(), flags() methods used in the layer
tree model and provides draw() method for rendering of legend in
composer/WMS

The QgsMapLayerLegend and QgsLayerTreeModelLegendNode classes are used
by QgsLayerTreeModel to generate and display legend in a tree.
QgsLegendRenderer makes use of QgsLayerTreeModel and allows the legend
nodes do their legend rendering.

An example of custom legend node:
- screenshot: http://i.imgur.com/GtvTlQ7.png
- code: https://gist.github.com/wonder-sk/c5d925833bcd54b9e401

An example of custom dock widget using legend renderer:
- screenshot: http://i.imgur.com/EAvE96u.png
- code: https://gist.github.com/wonder-sk/211b7130b58e50d78e6d
(in the screenshot above you can also see legend node icon embedded in
layer node)

There are not many changes visible to the user - the changes are
mainly visible for developers. From the few user-visible changes:
- in layer tree view - if a layer has just one legend item, it will be
shown on the left side of the layer name instead of occupying another
line. This is what already happens in composer.
- in composer legend item settings - 1) there is tree view with just
one column, label style is set in popup menu, 2) when auto-update is
on, the tree view is synchronized with project's layer tree and it is
read-only. When auto-update is off, it is possible to manipulate the
source legend tree

Regarding backward compatibility, there are two things worth mentioning:
- QgsComposerLegend::model() will return QgsLegendModel which is not
in use anymore. There is QgsComposerLegend::modelV2() as a
replacement. The way how the models work is significantly different
and I don't see a way of fixing that without a complex and fragile
synchronization logic. Anyway, according to Nathan's plugin analyser
tool there are no plugins using composer's legend model
- reading of older projects with composer legend ignores the
customization (e.g. renamed items, reordered items, removed items). If
time allows, I will try to address this before the release

So... please have a look if you are interested and enjoy the endless
possibilities of new legends :-)
If there are no objections I will merge it during the next week.

Regards
Martin
_______________________________________________
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


--
Dr. Marco Hugentobler
Sourcepole -  Linux & Open Source Solutions
Weberstrasse 5, CH-8004 Zürich, Switzerland
marco.hugentob...@sourcepole.ch http://www.sourcepole.ch
Technical Advisor QGIS Project Steering Committee

_______________________________________________
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer

Reply via email to