Food for thought: Why isn't QGraphicsView::setScene a virtual function?
-
Hi.
I am wondering whether anyone is able to see why QGraphicsView::setScene would be better off being a virtual function?
I think when it is a virtual function, whenever you create a derived class from QGraphicsView, you can override the function and re-implement new functionality to include some custom connections and others. It also allows the new class to fully encapsulate what it needs to do rather than assigning the scene to it and make connections call outside the class.
If it is a good suggestion, how do I suggest this enhancement to Qt developers?
Thanks. :)
-
Your idea is essentially not a bad idea. There are however two things to consider that may shed light on why this is not the chosen implementation (note that I'm reasoning about the choice, I haven't made it). The first is that if you allow setScene() to be overridden, your base class may not work as expected to the outside world; the set functionality could be denied by the overload: @void MyOverload::setScene(QGraphicsScene )
{
/ neener neener neener! Up yours, QGraphicsView! */
}@The second is that QGraphicsView is a view class and it tells the scene about all the events it receives. There really is no need to overload QGraphicsView. Almost in all cases it is a better choice to have a widget that contains the graphics view and add any functionality that you don't implement in the scene in the container widget.
-
[quote author="Jason X" date="1303308416"]Hi.
I am wondering whether anyone is able to see why QGraphicsView::setScene would be better off being a virtual function?
I think when it is a virtual function, whenever you create a derived class from QGraphicsView, you can override the function and re-implement new functionality to include some custom connections and others. It also allows the new class to fully encapsulate what it needs to do rather than assigning the scene to it and make connections call outside the class.
If it is a good suggestion, how do I suggest this enhancement to Qt developers?
Thanks. :)[/quote]
Can you make a detailed example of such functionality? (BTW, note that adding new virtuals is forbidden during Qt 4 lifetime. It would mean going for "implementation slots".)
-
It is an open source library and if you really feel it is necessary for what your trying to do you could make a modified version of the class with setscene as a virtual function. Then you could inherent from your modified version and re-implement setscene to your needs. That is one nice thing about an open-source library is you can modify the library itself and add to it.
-
[quote author="Keith Cancel" date="1303343176"]It is an open source library and if you really feel it is necessary for what your trying to do you could make a modified version of the class with setscene as a virtual function. Then you could inherent from your modified version and re-implement setscene to your needs. That is one nice thing about an open-source library is you can modify the library itself and add to it. [/quote]
Nice as it may be, you still have to consider the fact that you are going to have to maintain the patch. It would really be a waste of time to do that if the desired functionality doesn't really need to be in the graphics view in the first place ;-) .
-
I agree with Franzk: what would introducing this bring in terms of benefits that encapsulating a QGraphicsView does not?