QGraphicsItem ambiguity in subclass
Hello,
I have a question regarding design of multi subclasses item on the scene. I know that's not Qt question but C++ but because of the context I posted it in Qt section, if that's wrong section please move this thread.
What I want to do is to have base class with all common code for the item like this:
Code:
{
// common code for all items on the scene
};
Next I want some object that are i.e. QGraphicsPixmapItem, QGrapthicsTextItem etc, i.e..
Code:
{
}
painter->drawRoundedRect(-10, -10, 20, 20, 5, 5);
}
// Only pixmap related code
};
Now I want to control all these objects so I store pointers to objects like:
The problem is ambiguity of QGraphicsItem (in Base) due to the fact that i.e. QGraphicsPixmapItem (and all Qt item classes) are declared as:
My question is how would I go about designing classes that do subclass from i.e. QGraphicsPixmapItem
Re: QGraphicsItem ambiguity in subclass
There are a couple of options:
1) share the common code via delegation instead of derivation, i.e. have a class that is used by all your items
2) use a base class that is not a QGraphicsItem but which can return a pointer to the graphics item
3) use a template as a base class that derives from the template type
Cheers,
_