Hello,
I am using QT 4.4.0 for designing a circuit editor. I am using Qt's Graphics View framework for drawing different elements of circuit, text, pixmaps and even plots (embedding QwtPlotWidget in QGraphicsProxyWidget class).
I want to have these different elements derived from a common class, lets call it base, and move the functionality common to them in base. Base needs to reimplement some of the methods defined in QGraphicsItem class (itemChange() to mention one), and hence has to derive from QGraphicsItem class. However, this design leads to diamond inheritance issue (as the classes deriving from base also have to derive from classes like QGraphicsPixmapItem and QGraphicsProxyWidget which derive from QGraphicsPixmapItem). Unfortunately, none of the classes given by Qt which derive from QGraphicsPixmapItem (like QGraphicsPixmapItem) inherit it virtually, and put a lot of restriction on my design. Can anyone please suggest me a solution or workaround?
Thanks in advance,
Pankaj
Given below is the pseudo code depicting my problem:
{
//Lots of common code
{ //Update certain common data upon state change, common to all}
}
{
}
class Plot : public QwtPlotWidget, public Element
{
}
{
TextElement *t = new TextElement;
Plot *p = new Plot;
addItem( t); // Problem: Ambiguous conversion from TextElement* to QGraphicsItem*
addItem(p);//Problem :Ambiguous conversion from Plot* to QGraphicsItem*
//Also, problem while directly or indirectly accessing itemChange() ( ambiguous access)
}
class Element : public QGraphicsPixmapItem
{
//Lots of common code
QVariant itemChange ( GraphicsItemChange change, const QVariant & value )
{ //Update certain common data upon state change, common to all}
}
class TextElement : public Element, public QGraphicsTextItem
{
}
class Plot : public QwtPlotWidget, public Element
{
}
class scene : public QGraphicsScene
{
TextElement *t = new TextElement;
Plot *p = new Plot;
addItem( t); // Problem: Ambiguous conversion from TextElement* to QGraphicsItem*
addItem(p);//Problem :Ambiguous conversion from Plot* to QGraphicsItem*
//Also, problem while directly or indirectly accessing itemChange() ( ambiguous access)
}
To copy to clipboard, switch view to plain text mode
Bookmarks