qgis / qgis4.0_api

Tracker for QGIS 4.0 API related issues and developer discussion
3 stars 1 forks source link

paint is abused by QgsComposerItems #7

Open nyalldawson opened 8 years ago

nyalldawson commented 8 years ago

See eg https://github.com/qgis/QGIS/blob/master/src/core/composer/qgscomposerlegend.cpp#L140, where it is used to set the size for the composer item.

This prevents usage of QGraphicScene's caching modes (See http://doc.qt.io/qt-4.8/qgraphicsitem.html#CacheMode-enum). So currently, EVERY repaint requires that all the composer items are redrawn. This is very expensive, especially for things like redrawing composer map grids which involve reprojection. It's very noticeable on complex compositions when zooming in or dragging items around the scene.

It also prevents desirable features like paint effects for items (drop shadow! outer glow!) as the expense required to redraw these for every repaint is prohibitive.

To fix this every composer class would need to be refactored to remove all non-drawing code from paint, and requests to redraw the item would need to be pushed by whatever underlying changes have necessitated the redraw.

I'd prefer to modify the item's API to something like: https://github.com/nyalldawson/QGIS/blob/a8c08d28c122fd0dcb20b66fcb3ac9b29415766c/src/core/layout/qgslayoutitem.h#L96 where items have to reimplement a pure virtual "draw" method, which is called by QgsComposerItem's paint method (which should not be overridden by derived items).

It's a considerable amount of work, especially for items which rely on a repaint to update their contents or size (eg legend).