Fix use of deprecated ItemDataRoles Background/TextColorRole

Replace BackgroundColorRole/TextColorRole with
BackgroundRole/ForegroundRole and explicit deprecate them for 5.13

Change-Id: I6b0d99844a32d2f5fdfd1878317a7b7422b800d3
Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch>
Reviewed-by: Luca Beldi <v.ronin@yahoo.it>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
Christian Ehrlicher 2018-10-18 22:45:09 +02:00
parent f06e0f62fa
commit e9bebc1281
13 changed files with 23 additions and 27 deletions

View File

@ -67,7 +67,7 @@ QVariant CustomSqlModel::data(const QModelIndex &index, int role) const
else if (index.column() == 2)
return value.toString().toUpper();
}
if (role == Qt::TextColorRole && index.column() == 1)
if (role == Qt::ForegroundRole && index.column() == 1)
return QVariant::fromValue(QColor(Qt::blue));
return value;
}

View File

@ -79,7 +79,7 @@ QVariant SpreadSheetItem::data(int role) const
bool isNumber = false;
int number = t.toInt(&isNumber);
if (role == Qt::TextColorRole) {
if (role == Qt::ForegroundRole) {
if (!isNumber)
return QVariant::fromValue(QColor(Qt::black));
else if (number < 0)

View File

@ -1504,9 +1504,11 @@ public:
// Metadata
FontRole = 6,
TextAlignmentRole = 7,
#if QT_DEPRECATED_SINCE(5, 13)
BackgroundColorRole = 8,
BackgroundRole = 8,
TextColorRole = 9,
#endif
BackgroundRole = 8,
ForegroundRole = 9,
CheckStateRole = 10,
// Accessibility

View File

@ -123,11 +123,11 @@ do { \
MODELTESTER_VERIFY(variant.canConvert<QFont>());
// General Purpose roles that should return a QColor or a QBrush
variant = model->data(model->index(0, 0), Qt::BackgroundColorRole);
variant = model->data(model->index(0, 0), Qt::BackgroundRole);
if (variant.isValid())
MODELTESTER_VERIFY(variant.canConvert<QColor>() || variant.canConvert<QBrush>());
variant = model->data(model->index(0, 0), Qt::TextColorRole);
variant = model->data(model->index(0, 0), Qt::ForegroundRole);
if (variant.isValid())
MODELTESTER_VERIFY(variant.canConvert<QColor>() || variant.canConvert<QBrush>());

View File

@ -266,7 +266,7 @@ QSizeF QItemDelegatePrivate::doTextLayout(int lineWidth) const
\row \li \l Qt::AccessibleDescriptionRole \li QString
\row \li \l Qt::AccessibleTextRole \li QString
\endomit
\row \li \l Qt::BackgroundRole \li QBrush
\row \li \l Qt::BackgroundRole \li QBrush (\since 4.2)
\row \li \l Qt::BackgroundColorRole \li QColor (obsolete; use Qt::BackgroundRole instead)
\row \li \l Qt::CheckStateRole \li Qt::CheckState
\row \li \l Qt::DecorationRole \li QIcon, QPixmap and QColor
@ -278,7 +278,7 @@ QSizeF QItemDelegatePrivate::doTextLayout(int lineWidth) const
\row \li \l Qt::StatusTipRole \li
\endomit
\row \li \l Qt::TextAlignmentRole \li Qt::Alignment
\row \li \l Qt::ForegroundRole \li QBrush
\row \li \l Qt::ForegroundRole \li QBrush (\since 4.2)
\row \li \l Qt::TextColorRole \li QColor (obsolete; use Qt::ForegroundRole instead)
\omit
\row \li \l Qt::ToolTipRole

View File

@ -139,7 +139,7 @@ public:
\row \li \l Qt::AccessibleDescriptionRole \li QString
\row \li \l Qt::AccessibleTextRole \li QString
\endomit
\row \li \l Qt::BackgroundRole \li QBrush
\row \li \l Qt::BackgroundRole \li QBrush (\since 4.2)
\row \li \l Qt::BackgroundColorRole \li QColor (obsolete; use Qt::BackgroundRole instead)
\row \li \l Qt::CheckStateRole \li Qt::CheckState
\row \li \l Qt::DecorationRole \li QIcon, QPixmap, QImage and QColor
@ -151,7 +151,7 @@ public:
\row \li \l Qt::StatusTipRole \li
\endomit
\row \li \l Qt::TextAlignmentRole \li Qt::Alignment
\row \li \l Qt::ForegroundRole \li QBrush
\row \li \l Qt::ForegroundRole \li QBrush (\since 4.2)
\row \li \l Qt::TextColorRole \li QColor (obsolete; use Qt::ForegroundRole instead)
\omit
\row \li \l Qt::ToolTipRole

View File

@ -1178,9 +1178,9 @@ QVariant QCalendarModel::data(const QModelIndex &index, int role) const
}
QTextCharFormat fmt = formatForCell(row, column);
if (role == Qt::BackgroundColorRole)
if (role == Qt::BackgroundRole)
return fmt.background().color();
if (role == Qt::TextColorRole)
if (role == Qt::ForegroundRole)
return fmt.foreground().color();
if (role == Qt::FontRole)
return fmt.font();

View File

@ -251,7 +251,7 @@ QModelIndex ModelsToTest::populateTestArea(QAbstractItemModel *model)
QString val = xval + QString::number(y) + QString::number(i);
QModelIndex index = model->index(x, y, parent);
model->setData(index, val);
model->setData(index, blue, Qt::TextColorRole);
model->setData(index, blue, Qt::ForegroundRole);
}
}
*/
@ -276,7 +276,7 @@ QModelIndex ModelsToTest::populateTestArea(QAbstractItemModel *model)
QString val = xval + QString::number(y) + QString::number(i);
QModelIndex index = realModel->index(x, y, parent);
realModel->setData(index, val);
realModel->setData(index, blue, Qt::TextColorRole);
realModel->setData(index, blue, Qt::ForegroundRole);
}
}
*/

View File

@ -576,12 +576,12 @@ void tst_QItemModel::data()
alignment == Qt::AlignJustify);
}
QVariant colorVariant = currentModel->data(currentModel->index(0,0), Qt::BackgroundColorRole);
QVariant colorVariant = currentModel->data(currentModel->index(0,0), Qt::BackgroundRole);
if (colorVariant.isValid()) {
QVERIFY(colorVariant.canConvert<QColor>());
}
colorVariant = currentModel->data(currentModel->index(0,0), Qt::TextColorRole);
colorVariant = currentModel->data(currentModel->index(0,0), Qt::ForegroundRole);
if (colorVariant.isValid()) {
QVERIFY(colorVariant.canConvert<QColor>());
}

View File

@ -202,9 +202,7 @@ void tst_QStandardItem::getSetData()
QCOMPARE(qvariant_cast<QSize>(item.data(Qt::SizeHintRole)), sizeHint);
QCOMPARE(qvariant_cast<QFont>(item.data(Qt::FontRole)), font);
QCOMPARE(qvariant_cast<int>(item.data(Qt::TextAlignmentRole)), int(textAlignment));
QCOMPARE(qvariant_cast<QBrush>(item.data(Qt::BackgroundColorRole)), QBrush(backgroundColor));
QCOMPARE(qvariant_cast<QBrush>(item.data(Qt::BackgroundRole)), QBrush(backgroundColor));
QCOMPARE(qvariant_cast<QBrush>(item.data(Qt::TextColorRole)), QBrush(textColor));
QCOMPARE(qvariant_cast<QBrush>(item.data(Qt::ForegroundRole)), QBrush(textColor));
QCOMPARE(qvariant_cast<int>(item.data(Qt::CheckStateRole)), int(checkState));
QCOMPARE(qvariant_cast<QString>(item.data(Qt::AccessibleTextRole)), accessibleText);
@ -236,9 +234,7 @@ void tst_QStandardItem::getSetData()
QCOMPARE(item.data(Qt::SizeHintRole), QVariant());
QCOMPARE(item.data(Qt::FontRole), QVariant());
QCOMPARE(item.data(Qt::TextAlignmentRole), QVariant());
QCOMPARE(item.data(Qt::BackgroundColorRole), QVariant());
QCOMPARE(item.data(Qt::BackgroundRole), QVariant());
QCOMPARE(item.data(Qt::TextColorRole), QVariant());
QCOMPARE(item.data(Qt::ForegroundRole), QVariant());
QCOMPARE(item.data(Qt::CheckStateRole), QVariant());
QCOMPARE(item.data(Qt::AccessibleTextRole), QVariant());

View File

@ -1160,7 +1160,7 @@ void tst_QStandardItemModel::getSetItemData()
QColor backgroundColor(Qt::blue);
roles.insert(Qt::BackgroundRole, backgroundColor);
QColor textColor(Qt::green);
roles.insert(Qt::TextColorRole, textColor);
roles.insert(Qt::ForegroundRole, textColor);
Qt::CheckState checkState(Qt::PartiallyChecked);
roles.insert(Qt::CheckStateRole, int(checkState));
QLatin1String accessibleText("accessibleText");

View File

@ -249,7 +249,7 @@ void tst_QItemView::populate()
for (int y = 0; y < treeModel->columnCount(); ++y) {
QModelIndex index = treeModel->index(x, y, parent);
treeModel->setData(index, xS + QLatin1Char('_') + QString::number(y) + QLatin1Char('_') + iS);
treeModel->setData(index, QVariant(QColor(Qt::blue)), Qt::TextColorRole);
treeModel->setData(index, QVariant(QColor(Qt::blue)), Qt::ForegroundRole);
}
}
}

View File

@ -1885,9 +1885,8 @@ void tst_QTreeWidget::setData()
QCOMPARE(qvariant_cast<QSize>(item->data(j, Qt::SizeHintRole)), sizeHint);
QCOMPARE(qvariant_cast<QFont>(item->data(j, Qt::FontRole)), font);
QCOMPARE(qvariant_cast<int>(item->data(j, Qt::TextAlignmentRole)), int(textAlignment));
QCOMPARE(qvariant_cast<QBrush>(item->data(j, Qt::BackgroundColorRole)), QBrush(backgroundColor));
QCOMPARE(qvariant_cast<QBrush>(item->data(j, Qt::BackgroundRole)), QBrush(backgroundColor));
QCOMPARE(qvariant_cast<QColor>(item->data(j, Qt::TextColorRole)), textColor);
QCOMPARE(qvariant_cast<QColor>(item->data(j, Qt::ForegroundRole)), textColor);
QCOMPARE(qvariant_cast<int>(item->data(j, Qt::CheckStateRole)), int(checkState));
item->setBackground(j, pixmap);
@ -1907,8 +1906,8 @@ void tst_QTreeWidget::setData()
item->setData(j, Qt::SizeHintRole, QVariant());
item->setData(j, Qt::FontRole, QVariant());
item->setData(j, Qt::TextAlignmentRole, QVariant());
item->setData(j, Qt::BackgroundColorRole, QVariant());
item->setData(j, Qt::TextColorRole, QVariant());
item->setData(j, Qt::BackgroundRole, QVariant());
item->setData(j, Qt::ForegroundRole, QVariant());
item->setData(j, Qt::CheckStateRole, QVariant());
QCOMPARE(itemChangedSpy.count(), 11);
itemChangedSpy.clear();
@ -1921,9 +1920,8 @@ void tst_QTreeWidget::setData()
QCOMPARE(item->data(j, Qt::SizeHintRole), QVariant());
QCOMPARE(item->data(j, Qt::FontRole), QVariant());
QCOMPARE(item->data(j, Qt::TextAlignmentRole), QVariant());
QCOMPARE(item->data(j, Qt::BackgroundColorRole), QVariant());
QCOMPARE(item->data(j, Qt::BackgroundRole), QVariant());
QCOMPARE(item->data(j, Qt::TextColorRole), QVariant());
QCOMPARE(item->data(j, Qt::ForegroundRole), QVariant());
QCOMPARE(item->data(j, Qt::CheckStateRole), QVariant());
}
}