[Qgis-developer] Create groups in python plugins

Martin Dobias wonder.sk at gmail.com
Mon Nov 23 08:33:25 EST 2009


On Mon, Nov 23, 2009 at 10:09 AM, Andres Manz <manz.andres at gmail.com> wrote:
> Hi list,
>
> While implementing QgsLegendInterface for the Python API, I ran into
> another problem: QgsLegend inherits from QTreeWidget, which inherits
> from QObject. As QgsLegendInterface should have signals and slots, it
> should inherit from QObject, too. When QgsLegend implements
> QgsLegendInterface, I get the diamond problem: Both,
> QgsLegendInterface and QTreeWidget inherit from QObject. How should I
> handle that? Up to now, there are three possibilities:
>
> 1. QgsLegendInterface inherits from QTreeWidget and QgsLegend only
> implements QgsLegendInterface. Not a very nice solution, and the
> members of QTreeWidget would be exposed to the python scripter.
>
> 2. QgsLegendInterface is a "wrapper" class for QgsLegend. It holds a
> pointer to the QgsLegend and inherits from QObject.
>
> 3. Split up QgsLegend, so the part that doesn't inherit from
> QTreeWidget could implement QgsLegendInterface. QgsLegend is a huge
> class, so it would be a lot of work to do that.
>
> Do you have any other solutions? Or could you recommend one of the above?

Hi Andres

I would prefer solution 2. This approach is used also for
QgisInterface and its implementation QgisAppInterface. It has a lot of
flexibility - even for cases where e.g. legend widget is interchanged
with a model/view pattern.

Regards
Martin


More information about the Qgis-developer mailing list