Summary: | Add qgraphicsitem_cast check. | ||
---|---|---|---|
Product: | [Developer tools] clazy | Reporter: | Roman <dismine> |
Component: | general | Assignee: | Sergio Martins <smartins> |
Status: | CONFIRMED --- | ||
Severity: | wishlist | CC: | dismine, smartins |
Priority: | NOR | ||
Version: | unspecified | ||
Target Milestone: | --- | ||
Platform: | Other | ||
OS: | All | ||
Latest Commit: | Version Fixed In: | ||
Sentry Crash Report: |
Description
Roman
2017-10-24 08:32:47 UTC
QGraphicsItem *item = ...; if you do qgraphicsitem_cast<Foo>(item); I can warn if Foo::type() is missing, indeed. But what's this about "middle" ? If Foo derives from Bar, and Bar::type() is also implemented, isn't this OK ? Sorry, I've never used qgraphicsitem_cast See, this cast function is very tricky. Let's imagine such an hierarchy: class Bar : public QGraphicsItem { virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + 1}; }; class Foo : public Bar { virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + 2}; }; Foo *f = new Foo(); Bar *b = f; b->type() == f->type(); Because the type() function is virtual in both cases you will get the same result from Foo::type(). This looks obvious. But what if i want use qgraphicsitem_cast like this: QGraphicsItem *p = new Foo(); Bar *parent = qgraphicsitem_cast<Bar *>(p); It will not work! qgraphicsitem_cast can only cast to Foo in this case. If i want to cast to Bar i must not to reimplement the type() function in Foo. |