perden
15th June 2010, 21:19
In short, I'm looking for a way to get around a multiple inheritance problem and would like to know if there's a Qt-esque solution for what I'm trying to achieve. Read on for more info.
I've developed an abstract base class, Foo, as a subclass of QGraphicsProxyWidget for a number of different QWidget-based graphics items, WarmFoo and HotFoo. These items share a lot of the same code in the Foo, most importantly various features of QObject, including Q_PROPERTY definitions, and signals / slots. Everything has worked fine, but I want to expand the capabilities a bit more.
I want to derive a new subclass of QGraphicsWidget, ColdFoo, to take advantage of some of the performance increases you get by avoiding QGraphicsProxyWidget. But I'd also like to derive the same class from Foo to use the methods and attributes I've built up for the widget-based items. The class inheritances that I've come up with so far all have a dreaded diamond (http://www.parashift.com/c++-faq-lite/multiple-inheritance.html#faq-25.8) leading to a ambiguous base class error.
Here is the current inheritance diagram along with some other structures I've considered to solve the problem.
/*
* QGraphicsProxyWidget
* ^
* |
* Foo <------ HotFoo
* ^
* |
* WarmFoo
*
* This is how the inheritance works now.
*/
/*
* QGraphicsWidget <--- QGraphicsProxyWidget
* ^ ^
* | |
* Foo <---------------- FooProxy <------ HotFoo
* ^ ^
* | |
* ColdFoo WarmFoo
*
* In this possiblity, Foo is re-subclassed to
* extend QGraphicsWidget and FooProxy maintains
* a specialization for already made widgets. The
* dreaded diamond extends down from QGraphicsWidget
* to FooProxy.
*/
/*
* /----- QGraphicsWidget <-------- QGraphicsProxyWidget
* | ^ ^
* v | |
* QObject FooWidget <--- ColdFoo /--- FooProxy <--- HotFoo
* ^ | | ^
* | v | |
* \---------- Foo <-----------------/ WarmFoo
*
* In this possiblilty, Foo is completely detached
* from the graphics subsystem, yet still extends
* QObject because of the object subsystem features
* it uses. The dreaded diamond exists down from
* QObject to FooWidget and FooProxy.
*/
Is there a way to handle or get around such a thing using the facilities available in Qt? Maybe use QGraphicsProxyWidget in such a way that it behaves like a QGraphicsWidget?
Or perhaps what I really need to be do is pull the QObject-related info out of the new Foo class and move it to each of Foo's subclasses. I'd like to avoid maintaining the same code in multiple places as a top priority, for obvious reasons.
Thoughts? Ideas? Thanks for the feedback!
If nothing else, I hope you enjoyed my ASCII inheritance diagrams... :p
I've developed an abstract base class, Foo, as a subclass of QGraphicsProxyWidget for a number of different QWidget-based graphics items, WarmFoo and HotFoo. These items share a lot of the same code in the Foo, most importantly various features of QObject, including Q_PROPERTY definitions, and signals / slots. Everything has worked fine, but I want to expand the capabilities a bit more.
I want to derive a new subclass of QGraphicsWidget, ColdFoo, to take advantage of some of the performance increases you get by avoiding QGraphicsProxyWidget. But I'd also like to derive the same class from Foo to use the methods and attributes I've built up for the widget-based items. The class inheritances that I've come up with so far all have a dreaded diamond (http://www.parashift.com/c++-faq-lite/multiple-inheritance.html#faq-25.8) leading to a ambiguous base class error.
Here is the current inheritance diagram along with some other structures I've considered to solve the problem.
/*
* QGraphicsProxyWidget
* ^
* |
* Foo <------ HotFoo
* ^
* |
* WarmFoo
*
* This is how the inheritance works now.
*/
/*
* QGraphicsWidget <--- QGraphicsProxyWidget
* ^ ^
* | |
* Foo <---------------- FooProxy <------ HotFoo
* ^ ^
* | |
* ColdFoo WarmFoo
*
* In this possiblity, Foo is re-subclassed to
* extend QGraphicsWidget and FooProxy maintains
* a specialization for already made widgets. The
* dreaded diamond extends down from QGraphicsWidget
* to FooProxy.
*/
/*
* /----- QGraphicsWidget <-------- QGraphicsProxyWidget
* | ^ ^
* v | |
* QObject FooWidget <--- ColdFoo /--- FooProxy <--- HotFoo
* ^ | | ^
* | v | |
* \---------- Foo <-----------------/ WarmFoo
*
* In this possiblilty, Foo is completely detached
* from the graphics subsystem, yet still extends
* QObject because of the object subsystem features
* it uses. The dreaded diamond exists down from
* QObject to FooWidget and FooProxy.
*/
Is there a way to handle or get around such a thing using the facilities available in Qt? Maybe use QGraphicsProxyWidget in such a way that it behaves like a QGraphicsWidget?
Or perhaps what I really need to be do is pull the QObject-related info out of the new Foo class and move it to each of Foo's subclasses. I'd like to avoid maintaining the same code in multiple places as a top priority, for obvious reasons.
Thoughts? Ideas? Thanks for the feedback!
If nothing else, I hope you enjoyed my ASCII inheritance diagrams... :p