QAbstractItemModelTester: use the right types for some roles

Models are expected to return Qt::Alignment and Qt::CheckState
when asked for the text alignment / check state roles, respectively.
However, for legacy reasons, models may return `int` for either
possibility. Extend the tester to cover this.

Task-number: QTBUG-75172
Change-Id: I64bfc898466e8bb4d4a8a35726986ae610a8ffbe
Pick-to: 6.2 6.3
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
Giuseppe D'Angelo 2022-03-21 14:33:47 +01:00
parent 3ec95f943a
commit 56f2407dc0

View File

@ -41,6 +41,7 @@
#include "qabstractitemmodeltester.h"
#include <private/qobject_p.h>
#include <private/qabstractitemmodel_p.h>
#include <QtCore/QPointer>
#include <QtCore/QAbstractItemModel>
#include <QtCore/QStack>
@ -674,14 +675,14 @@ void QAbstractItemModelTesterPrivate::data()
// Check that the alignment is one we know about
QVariant textAlignmentVariant = model->data(model->index(0, 0), Qt::TextAlignmentRole);
if (textAlignmentVariant.isValid()) {
Qt::Alignment alignment = qvariant_cast<Qt::Alignment>(textAlignmentVariant);
Qt::Alignment alignment = QtPrivate::legacyFlagValueFromModelData<Qt::Alignment>(textAlignmentVariant);
MODELTESTER_COMPARE(alignment, (alignment & (Qt::AlignHorizontal_Mask | Qt::AlignVertical_Mask)));
}
// Check that the "check state" is one we know about.
QVariant checkStateVariant = model->data(model->index(0, 0), Qt::CheckStateRole);
if (checkStateVariant.isValid()) {
int state = checkStateVariant.toInt();
Qt::CheckState state = QtPrivate::legacyEnumValueFromModelData<Qt::CheckState>(checkStateVariant);
MODELTESTER_VERIFY(state == Qt::Unchecked
|| state == Qt::PartiallyChecked
|| state == Qt::Checked);