I'm looking into a couple of ways to run proxy-esque patterns to achieve what I'm trying to do.
In this first configuration based off of the first possibility in my first post, the inheritance between QGraphicsProxyWidget and FooProxy has been removed.
/*
* QGraphicsWidget <--- QGraphicsProxyWidget
* ^
* |
* Foo <---------------- FooProxy <------ HotFoo
* ^ ^
* | |
* ColdFoo WarmFoo
*/
/*
* QGraphicsWidget <--- QGraphicsProxyWidget
* ^
* |
* Foo <---------------- FooProxy <------ HotFoo
* ^ ^
* | |
* ColdFoo WarmFoo
*/
To copy to clipboard, switch view to plain text mode
FooProxy now contains an attribute of type QGraphicsProxyWidget pointer called _proxy. Methods are written to redirect calls to _proxy where necessary. As a simplified example, consider the following.
class FooProxy : public Foo {
QGraphicsProxyWidget * _proxy;
public:
// this works fine for simple calls...
void setWidget
(QWidget * widget
) {_proxy
->setWidget
(widget
);
}
protected:
// ...but what happens now?
// this method is protected in _proxy and cannot be called in this context
_proxy->contextMenuEvent(event);
// maybe a potential solution is something like this
}
// ...but that technique wont help here
virtual bool focusNextPrevChild(bool next) {
// this method is also protected in _proxy
return _proxy->focusNextPrevChild(next);
}
}
class FooProxy : public Foo {
QGraphicsProxyWidget * _proxy;
public:
// this works fine for simple calls...
void setWidget(QWidget * widget) {_proxy->setWidget(widget);}
protected:
// ...but what happens now?
virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent * event) {
// this method is protected in _proxy and cannot be called in this context
_proxy->contextMenuEvent(event);
// maybe a potential solution is something like this
QCoreApplication::sendEvent(_proxy, event);
}
// ...but that technique wont help here
virtual bool focusNextPrevChild(bool next) {
// this method is also protected in _proxy
return _proxy->focusNextPrevChild(next);
}
}
To copy to clipboard, switch view to plain text mode
I can't continue on this structure until I find a way to get at the protected methods in _proxy, or find another way of calling these methods.
For an alternative configuration based off of the second possibility from my earlier post, I could re-subclass Foo to extend QObject, and remove the graphics subsystem inheritance from FooWidget and FooProxy.
/*
* /----- QGraphicsWidget <-------- QGraphicsProxyWidget
* |
* v
* QObject FooWidget <--- ColdFoo /--- FooProxy <--- HotFoo
* ^ | | ^
* | v | |
* \---------- Foo <-----------------/ WarmFoo
*/
/*
* /----- QGraphicsWidget <-------- QGraphicsProxyWidget
* |
* v
* QObject FooWidget <--- ColdFoo /--- FooProxy <--- HotFoo
* ^ | | ^
* | v | |
* \---------- Foo <-----------------/ WarmFoo
*/
To copy to clipboard, switch view to plain text mode
To guarantee that FooWidget and FooProxy always maintain a graphics system like appearance (in terms of available methods), each relevant method will need to be added as pure virtual in Foo. That's a lot of methods! I'm still working through this before I can show some code example.
Thoughts?
Bookmarks