From e9bebc12812b5c50346952cd9128bdd08ddd0b9d Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Thu, 18 Oct 2018 22:45:09 +0200 Subject: 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 Reviewed-by: Luca Beldi Reviewed-by: Richard Moe Gustavsen --- examples/sql/querymodel/customsqlmodel.cpp | 2 +- examples/widgets/itemviews/spreadsheet/spreadsheetitem.cpp | 2 +- src/corelib/global/qnamespace.h | 4 +++- src/testlib/qabstractitemmodeltester.h | 4 ++-- src/widgets/itemviews/qitemdelegate.cpp | 4 ++-- src/widgets/itemviews/qstyleditemdelegate.cpp | 4 ++-- src/widgets/widgets/qcalendarwidget.cpp | 4 ++-- tests/auto/corelib/itemmodels/qitemmodel/modelstotest.cpp | 4 ++-- tests/auto/corelib/itemmodels/qitemmodel/tst_qitemmodel.cpp | 4 ++-- tests/auto/gui/itemmodels/qstandarditem/tst_qstandarditem.cpp | 4 ---- .../itemmodels/qstandarditemmodel/tst_qstandarditemmodel.cpp | 2 +- tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp | 2 +- tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp | 10 ++++------ 13 files changed, 23 insertions(+), 27 deletions(-) diff --git a/examples/sql/querymodel/customsqlmodel.cpp b/examples/sql/querymodel/customsqlmodel.cpp index 21bedee727..7be0a65882 100644 --- a/examples/sql/querymodel/customsqlmodel.cpp +++ b/examples/sql/querymodel/customsqlmodel.cpp @@ -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; } diff --git a/examples/widgets/itemviews/spreadsheet/spreadsheetitem.cpp b/examples/widgets/itemviews/spreadsheet/spreadsheetitem.cpp index 4c18fa8251..92cbaff031 100644 --- a/examples/widgets/itemviews/spreadsheet/spreadsheetitem.cpp +++ b/examples/widgets/itemviews/spreadsheet/spreadsheetitem.cpp @@ -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) diff --git a/src/corelib/global/qnamespace.h b/src/corelib/global/qnamespace.h index ce6771d700..41b94bf15a 100644 --- a/src/corelib/global/qnamespace.h +++ b/src/corelib/global/qnamespace.h @@ -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 diff --git a/src/testlib/qabstractitemmodeltester.h b/src/testlib/qabstractitemmodeltester.h index 757074c6ae..57b8f283bc 100644 --- a/src/testlib/qabstractitemmodeltester.h +++ b/src/testlib/qabstractitemmodeltester.h @@ -123,11 +123,11 @@ do { \ MODELTESTER_VERIFY(variant.canConvert()); // 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() || variant.canConvert()); - 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() || variant.canConvert()); diff --git a/src/widgets/itemviews/qitemdelegate.cpp b/src/widgets/itemviews/qitemdelegate.cpp index 9c65d5fddd..16d4a21f50 100644 --- a/src/widgets/itemviews/qitemdelegate.cpp +++ b/src/widgets/itemviews/qitemdelegate.cpp @@ -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 diff --git a/src/widgets/itemviews/qstyleditemdelegate.cpp b/src/widgets/itemviews/qstyleditemdelegate.cpp index 0f7566e8ec..22067851cb 100644 --- a/src/widgets/itemviews/qstyleditemdelegate.cpp +++ b/src/widgets/itemviews/qstyleditemdelegate.cpp @@ -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 diff --git a/src/widgets/widgets/qcalendarwidget.cpp b/src/widgets/widgets/qcalendarwidget.cpp index 4946969360..0553972591 100644 --- a/src/widgets/widgets/qcalendarwidget.cpp +++ b/src/widgets/widgets/qcalendarwidget.cpp @@ -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(); diff --git a/tests/auto/corelib/itemmodels/qitemmodel/modelstotest.cpp b/tests/auto/corelib/itemmodels/qitemmodel/modelstotest.cpp index 6ea7a38137..dbc7173028 100644 --- a/tests/auto/corelib/itemmodels/qitemmodel/modelstotest.cpp +++ b/tests/auto/corelib/itemmodels/qitemmodel/modelstotest.cpp @@ -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); } } */ diff --git a/tests/auto/corelib/itemmodels/qitemmodel/tst_qitemmodel.cpp b/tests/auto/corelib/itemmodels/qitemmodel/tst_qitemmodel.cpp index 7cd220e684..da13b9f33f 100644 --- a/tests/auto/corelib/itemmodels/qitemmodel/tst_qitemmodel.cpp +++ b/tests/auto/corelib/itemmodels/qitemmodel/tst_qitemmodel.cpp @@ -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()); } - colorVariant = currentModel->data(currentModel->index(0,0), Qt::TextColorRole); + colorVariant = currentModel->data(currentModel->index(0,0), Qt::ForegroundRole); if (colorVariant.isValid()) { QVERIFY(colorVariant.canConvert()); } diff --git a/tests/auto/gui/itemmodels/qstandarditem/tst_qstandarditem.cpp b/tests/auto/gui/itemmodels/qstandarditem/tst_qstandarditem.cpp index d19aa9b54f..2deb84fa5f 100644 --- a/tests/auto/gui/itemmodels/qstandarditem/tst_qstandarditem.cpp +++ b/tests/auto/gui/itemmodels/qstandarditem/tst_qstandarditem.cpp @@ -202,9 +202,7 @@ void tst_QStandardItem::getSetData() QCOMPARE(qvariant_cast(item.data(Qt::SizeHintRole)), sizeHint); QCOMPARE(qvariant_cast(item.data(Qt::FontRole)), font); QCOMPARE(qvariant_cast(item.data(Qt::TextAlignmentRole)), int(textAlignment)); - QCOMPARE(qvariant_cast(item.data(Qt::BackgroundColorRole)), QBrush(backgroundColor)); QCOMPARE(qvariant_cast(item.data(Qt::BackgroundRole)), QBrush(backgroundColor)); - QCOMPARE(qvariant_cast(item.data(Qt::TextColorRole)), QBrush(textColor)); QCOMPARE(qvariant_cast(item.data(Qt::ForegroundRole)), QBrush(textColor)); QCOMPARE(qvariant_cast(item.data(Qt::CheckStateRole)), int(checkState)); QCOMPARE(qvariant_cast(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()); diff --git a/tests/auto/gui/itemmodels/qstandarditemmodel/tst_qstandarditemmodel.cpp b/tests/auto/gui/itemmodels/qstandarditemmodel/tst_qstandarditemmodel.cpp index e2d7a41bd1..550f70890e 100644 --- a/tests/auto/gui/itemmodels/qstandarditemmodel/tst_qstandarditemmodel.cpp +++ b/tests/auto/gui/itemmodels/qstandarditemmodel/tst_qstandarditemmodel.cpp @@ -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"); diff --git a/tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp b/tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp index bbdaac5c6f..071665a5e3 100644 --- a/tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp +++ b/tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp @@ -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); } } } diff --git a/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp b/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp index c5ccbc0d0b..e0a9684d13 100644 --- a/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp +++ b/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp @@ -1885,9 +1885,8 @@ void tst_QTreeWidget::setData() QCOMPARE(qvariant_cast(item->data(j, Qt::SizeHintRole)), sizeHint); QCOMPARE(qvariant_cast(item->data(j, Qt::FontRole)), font); QCOMPARE(qvariant_cast(item->data(j, Qt::TextAlignmentRole)), int(textAlignment)); - QCOMPARE(qvariant_cast(item->data(j, Qt::BackgroundColorRole)), QBrush(backgroundColor)); QCOMPARE(qvariant_cast(item->data(j, Qt::BackgroundRole)), QBrush(backgroundColor)); - QCOMPARE(qvariant_cast(item->data(j, Qt::TextColorRole)), textColor); + QCOMPARE(qvariant_cast(item->data(j, Qt::ForegroundRole)), textColor); QCOMPARE(qvariant_cast(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()); } } -- cgit v1.2.3