I have a number of classes representing smart map elements: MapTextElement , MapIconElement , etc. Classes extend the various classes of Qt graphics elements, but also provide common functions, such as the abstract factory method, which returns a property panel specialized for each class. I declared these common methods in a pure virtual class, MapElementInterface . My classes are then multiplied - they inherit the corresponding Qt base class, as well as the interface:
class MapTextElement : public QGraphicsTextItem, public MapElementInterface class MapIconElement : public QGraphicsItem, public MapElementInterface
So my class hierarchy looks something like this:
+-------------+ +-------------------+ |QGraphicsItem| |MapElementInterface| +-------------+ +-------------------+ ^ ^ ^ | | | +------+------+ | | | | | | +-----------------+ +--------------+ | |QGraphicsTextItem| |MapIconElement| | +-----------------+ +--------------+ | ^ | | | +-------------------+ +-----+ | | +--------------+ |MapTextElement| +--------------+
I get a pointer to a QGraphicsItem from a Qt-provided method. In this case, I know that the pointer is not only a QGraphicsItem , but also a MapElementInterface . I want to treat the pointer as a MapElementInterface .
QList<QGraphicsItem*> selected = scene_->selectedItems(); if (selected.count() == 1) {
What is the right choice? Or am I completely wrong about this?
source share