From a7027b8a432b1af76dbfd82f39d174eb6dda42c5 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Wed, 18 May 2022 00:16:10 +0200 Subject: [PATCH] QAbstractItemModel: Fix Qt::TextAlignmentRole when metatype is uint When combining text alignment flags, it no longer works since the metatype for example QVariant(Qt::AlignRight | Qt::AlignVCenter) is uint, not int. Fixes: QTBUG-103576 Change-Id: If0291b99606787081c4bc26fd00431f8a17a61a2 Reviewed-by: Volker Hilsheimer (cherry picked from commit 54d81d118997fc4c238b7266571d220d7a6065f1) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/itemmodels/qabstractitemmodel_p.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/corelib/itemmodels/qabstractitemmodel_p.h b/src/corelib/itemmodels/qabstractitemmodel_p.h index edc5ad61169..564862d0eda 100644 --- a/src/corelib/itemmodels/qabstractitemmodel_p.h +++ b/src/corelib/itemmodels/qabstractitemmodel_p.h @@ -181,10 +181,12 @@ template T legacyEnumValueFromModelData(const QVariant &data) { static_assert(std::is_enum_v); - if (data.userType() == qMetaTypeId()) + if (data.userType() == qMetaTypeId()) { return data.value(); - else if (data.userType() == qMetaTypeId()) + } else if (std::is_same_v, int> || + std::is_same_v, uint>) { return T(data.toInt()); + } return T(); } @@ -192,10 +194,12 @@ T legacyEnumValueFromModelData(const QVariant &data) template T legacyFlagValueFromModelData(const QVariant &data) { - if (data.userType() == qMetaTypeId()) + if (data.userType() == qMetaTypeId()) { return data.value(); - else if (data.userType() == qMetaTypeId()) + } else if (std::is_same_v, int> || + std::is_same_v, uint>) { return T::fromInt(data.toInt()); + } return T(); }