diff --git a/src/widgets/graphicsview/qgraphicsitem.h b/src/widgets/graphicsview/qgraphicsitem.h index f82c600b3a3..8819813363a 100644 --- a/src/widgets/graphicsview/qgraphicsitem.h +++ b/src/widgets/graphicsview/qgraphicsitem.h @@ -969,15 +969,33 @@ private: template inline T qgraphicsitem_cast(QGraphicsItem *item) { typedef typename std::remove_cv::type>::type Item; - return int(Item::Type) == int(QGraphicsItem::Type) - || (item && int(Item::Type) == item->type()) ? static_cast(item) : nullptr; + constexpr int ItemType = int(Item::Type); + if constexpr (int(Item::Type) == int(QGraphicsItem::Type)) + return static_cast(item); + else + return (item && ItemType == item->type()) ? static_cast(item) : nullptr; } template inline T qgraphicsitem_cast(const QGraphicsItem *item) { typedef typename std::remove_cv::type>::type Item; - return int(Item::Type) == int(QGraphicsItem::Type) - || (item && int(Item::Type) == item->type()) ? static_cast(item) : nullptr; + constexpr int ItemType = int(Item::Type); + if constexpr (ItemType == int(QGraphicsItem::Type)) + return static_cast(item); + else + return (item && ItemType == item->type()) ? static_cast(item) : nullptr; +} + +template <> +inline QGraphicsItem *qgraphicsitem_cast(QGraphicsItem *item) +{ + return item; +} + +template <> +inline const QGraphicsItem *qgraphicsitem_cast(const QGraphicsItem *item) +{ + return item; } #ifndef QT_NO_DEBUG_STREAM