[Qgis-developer] Symbology NG - rendering of selected symbols
ccrook at linz.govt.nz
Mon Apr 5 18:13:31 EDT 2010
I suppose I was thinking that the changes would need to be made in a minimal, non-breaking way, why I was thinking of adding renderSelectedFeature rather than adding a parameter to the renderFeature function, and by implementing this so it works continues to work with minimal changes for renderers which don't implement this function. However maybe it isn't too late to make more dramatic changes - as this isn't the stable version!
The other reason I can see for creating a separate function and implementation is that it ensures that if a new renderer doesn't provide an implementation for selected features, then they will still be visibly selected.
I think you are right in that it would be good for symbol layers to know how to render themselves when selected, and I guess just using setColor as a default implementation would work well, and give a better implementation than the current one.
With the symbol layers potentially caching symbols in the start/stop functions I'm not sure how handling the selection flag at the symbol level would work. I guess the ideal would be for the startRender function to be passed a flag to let the renderer/symbol/symbolLayer know that they may need a selected version.
I'm not sure I follow your thinking about using the QgsSymbolV2RenderContext to pass a selected flag, as it looks to me as if this is only created within the QgsSymbolV2 startRender, stopRender, and renderFeature funtions, where the selected status isn't available.
I guess a boolean field in the QgsRenderContext could be used. In the startRender function it would be used that the the renderer/symbol/symbolLayer needed to have a selected version available, and in the renderFeature function it would mean that the feature to be rendered is selected.
Alternatively the selected flag could be added as a parameter to the startRender and renderFeature functions for the renderer, symbol, and symbol layer.
Certainly adding the flag to the context would be less work than changing function signatures through the symbology stack. I'm not sure which would be the "more correct" implementation?
So I guess I'm leaning towards:
1) Adding a boolean selected flag to QgsRenderContext, which is only used by the V2 renderers, used in startRender to indicate a selected symbology will be required, and renderFeature to indicate that the current feature is selected.
2) Updating QgsSimpleMarkerSymbolLayerV2 to optionally cache and use a selected version of the image (using setColor to set the colour to the selected colour ... Should this change the border colour too?)
3) Update QgsFontMarkerSymbolLayerV2 to use the selected colour if it is selected
4) Update QgsSvgMarkerSymbolLayerV2 to cache and use a selected version of the image. Not sure how to do this? This should include an option for defining a selected version of the symbol (but maybe not yet implemented in GUI), and also some sort of default handling - perhaps creating a picture by rendering a larger background circle in the selected colour under the SVG image.
5) Update QgsSimpleLineSymbolLayerV2 and QgsLineDecorationSymbolLayerV2 to create and optionally use a mSelectedPen, and QgsMarkerLineSymbolLayerV2 to pass the selected flag to its marker symbol
6) Update QgsMarkerLineSymbolLayerV2 to optionally use the selected colour, and QgsSVGFillSymbolLayer to optionally fill the polygon with the selected colour before applying the SVG fill.
2) Adding a renderSelectedFeature virtual function to the QgsFeatureRendererV2 which by default just sets the QgsRenderContext flag and calls the renderFeature function
From: Martin Dobias [mailto:wonder.sk at gmail.com]
Sent: Sunday, 4 April 2010 9:49 p.m.
To: Chris Crook
Cc: qgis-developer at lists.osgeo.org
Subject: Re: [Qgis-developer] Symbology NG - rendering of selected symbols
On Sat, Apr 3, 2010 at 8:40 PM, Chris Crook <ccrook at linz.govt.nz> wrote:
> I'm wondering if we could improve the way that Qgis renders selected symbols.
> Currently it seems that the rendering loop uses a standard renderer (defined in QgsVectorLayer::drawRendererV2Levels) for this independent of the renderer used for the layer. Where the actual renderer generates a very distinctive symbology (in my case an oriented arrow), selected symbols don't look anything like the orginal symbology, and don't carry any of the information of the original symbology.
right, the rendering of selected features is somehow suboptimal. Old symbology simply changes color of the symbol which should be drawn as selected. This is a problem e.g. with svg symbol where the color can't be easily changed. New symbology indeed could do it better...
> I'm wanting to add the flexibility for the renderer to customise this.
> I was thinking that perhaps the way to do this is to add a
> "renderSelectedFeature" virtual function to the QgsFeatureRendererV2
> interface, and implement the default functions in the
> QgsFeatureRenderer (maybe by instantiating the standard renderer and
> passing the renderSelectedFeature onto its renderFeature function, and
> of course handling the start and stop render functions there too)
I think the support for selection should have two levels:
- symbols: it should be possible to tell the symbol (resp. symbol
layer) to be drawn in "selected" mode - maybe by passing a flag in QgsSymbolV2RenderContext. Default implementation would only change color of the symbol to the selected color. Custom implementation should be possible (e.g. to allow svg symbol to draw a circle/rectangle around the symbol)
- renderers: they should be aware whether the symbol should be rendererd in normal or selected mode. Again, default implementation would handle that automatically, special renderers that do additional drawing should be able to customize what should be done.
The passing of selected/not selected flag could done either by adding a new function as you propose, or by adding a new parameter to existing renderFeature function...
This message contains information, which is confidential and may be subject to legal privilege.
If you are not the intended recipient, you must not peruse, use, disseminate, distribute or copy this message.
If you have received this message in error, please notify us immediately (Phone 0800 665 463 or info at linz.govt.nz) and destroy the original message.
LINZ accepts no responsibility for changes to this email, or for any attachments, after its transmission from LINZ.
More information about the Qgis-developer