diff --git a/examples/widgets/painting/fontsampler/mainwindow.cpp b/examples/widgets/painting/fontsampler/mainwindow.cpp index bff8ae9c229..53a2aac82eb 100644 --- a/examples/widgets/painting/fontsampler/mainwindow.cpp +++ b/examples/widgets/painting/fontsampler/mainwindow.cpp @@ -80,7 +80,7 @@ void MainWindow::setupFontTree() QTreeWidgetItem *familyItem = new QTreeWidgetItem(fontTree); familyItem->setText(0, family); familyItem->setCheckState(0, Qt::Unchecked); - familyItem->setFlags(familyItem->flags() | Qt::ItemIsTristate); + familyItem->setFlags(familyItem->flags() | Qt::ItemIsAutoTristate); foreach (QString style, styles) { QTreeWidgetItem *styleItem = new QTreeWidgetItem(familyItem); diff --git a/src/corelib/global/qnamespace.h b/src/corelib/global/qnamespace.h index 32b2a269929..123e2edf0ec 100644 --- a/src/corelib/global/qnamespace.h +++ b/src/corelib/global/qnamespace.h @@ -1458,7 +1458,10 @@ Qt { ItemIsDropEnabled = 8, ItemIsUserCheckable = 16, ItemIsEnabled = 32, - ItemIsTristate = 64, + ItemIsAutoTristate = 64, +#if QT_DEPRECATED_SINCE(5, 6) + ItemIsTristate = ItemIsAutoTristate, +#endif ItemNeverHasChildren = 128, ItemIsUserTristate = 256 }; diff --git a/src/corelib/global/qnamespace.qdoc b/src/corelib/global/qnamespace.qdoc index e22ed24e58c..d4d7b631adf 100644 --- a/src/corelib/global/qnamespace.qdoc +++ b/src/corelib/global/qnamespace.qdoc @@ -2642,10 +2642,12 @@ \value ItemIsDropEnabled It can be used as a drop target. \value ItemIsUserCheckable It can be checked or unchecked by the user. \value ItemIsEnabled The user can interact with the item. - \value ItemIsTristate The item can show three separate states. + \value ItemIsAutoTristate The item's state depends on the state of its children. This enables automatic management of the state of parent items in QTreeWidget (checked if all children are checked, unchecked if all children are unchecked, or partially checked if only some children are checked). + \value ItemIsTristate \e{This enum value is deprecated.} Use Qt::ItemIsAutoTristate + instead. \value ItemNeverHasChildren The item never has child items. \value ItemIsUserTristate The user can cycle through three separate states. This value has been added in Qt 5.5. diff --git a/src/gui/itemmodels/qstandarditemmodel.cpp b/src/gui/itemmodels/qstandarditemmodel.cpp index ed2479302eb..2bd19fb49ee 100644 --- a/src/gui/itemmodels/qstandarditemmodel.cpp +++ b/src/gui/itemmodels/qstandarditemmodel.cpp @@ -1258,7 +1258,7 @@ void QStandardItem::setCheckable(bool checkable) void QStandardItem::setTristate(bool tristate) { Q_D(QStandardItem); - d->changeFlags(tristate, Qt::ItemIsTristate); + d->changeFlags(tristate, Qt::ItemIsAutoTristate); } /*! diff --git a/src/gui/itemmodels/qstandarditemmodel.h b/src/gui/itemmodels/qstandarditemmodel.h index 3dd613f907d..d9530ac0bf4 100644 --- a/src/gui/itemmodels/qstandarditemmodel.h +++ b/src/gui/itemmodels/qstandarditemmodel.h @@ -159,7 +159,7 @@ class Q_GUI_EXPORT QStandardItem void setCheckable(bool checkable); inline bool isTristate() const { - return (flags() & Qt::ItemIsTristate) != 0; + return (flags() & Qt::ItemIsAutoTristate) != 0; } void setTristate(bool tristate); diff --git a/src/widgets/itemviews/qtreewidget.cpp b/src/widgets/itemviews/qtreewidget.cpp index bf736bc3876..1366a003184 100644 --- a/src/widgets/itemviews/qtreewidget.cpp +++ b/src/widgets/itemviews/qtreewidget.cpp @@ -1720,12 +1720,12 @@ void QTreeWidgetItem::setData(int column, int role, const QVariant &value) } } break; case Qt::CheckStateRole: - if ((itemFlags & Qt::ItemIsTristate) && value != Qt::PartiallyChecked) { + if ((itemFlags & Qt::ItemIsAutoTristate) && value != Qt::PartiallyChecked) { for (int i = 0; i < children.count(); ++i) { QTreeWidgetItem *child = children.at(i); if (child->data(column, role).isValid()) {// has a CheckState Qt::ItemFlags f = itemFlags; // a little hack to avoid multiple dataChanged signals - itemFlags &= ~Qt::ItemIsTristate; + itemFlags &= ~Qt::ItemIsAutoTristate; child->setData(column, role, value); itemFlags = f; } @@ -1760,7 +1760,7 @@ void QTreeWidgetItem::setData(int column, int role, const QVariant &value) model->emitDataChanged(this, column); if (role == Qt::CheckStateRole) { QTreeWidgetItem *p; - for (p = par; p && (p->itemFlags & Qt::ItemIsTristate); p = p->par) + for (p = par; p && (p->itemFlags & Qt::ItemIsAutoTristate); p = p->par) model->emitDataChanged(p, column); } } @@ -1779,7 +1779,7 @@ QVariant QTreeWidgetItem::data(int column, int role) const break; case Qt::CheckStateRole: // special case for check state in tristate - if (children.count() && (itemFlags & Qt::ItemIsTristate)) + if (children.count() && (itemFlags & Qt::ItemIsAutoTristate)) return childrenCheckState(column); // fallthrough intended default: diff --git a/tests/auto/gui/itemmodels/qstandarditem/tst_qstandarditem.cpp b/tests/auto/gui/itemmodels/qstandarditem/tst_qstandarditem.cpp index 5dce228ca0e..7693964c6aa 100644 --- a/tests/auto/gui/itemmodels/qstandarditem/tst_qstandarditem.cpp +++ b/tests/auto/gui/itemmodels/qstandarditem/tst_qstandarditem.cpp @@ -279,7 +279,7 @@ void tst_QStandardItem::getSetFlags() QVERIFY(item.flags() & Qt::ItemIsUserCheckable); item.setTristate(true); QVERIFY(item.isTristate()); - QVERIFY(item.flags() & Qt::ItemIsTristate); + QVERIFY(item.flags() & Qt::ItemIsAutoTristate); #ifndef QT_NO_DRAGANDDROP item.setDragEnabled(true); QVERIFY(item.isDragEnabled()); @@ -308,7 +308,7 @@ void tst_QStandardItem::getSetFlags() QVERIFY(item.isTristate()); item.setTristate(false); QVERIFY(!item.isTristate()); - QVERIFY(!(item.flags() & Qt::ItemIsTristate)); + QVERIFY(!(item.flags() & Qt::ItemIsAutoTristate)); #ifndef QT_NO_DRAGANDDROP QVERIFY(item.isDragEnabled()); item.setDragEnabled(false); diff --git a/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp b/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp index 439eeff0051..3bd41121226 100644 --- a/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp +++ b/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp @@ -1154,7 +1154,7 @@ void tst_QItemDelegate::editorEvent_data() QTest::newRow("unchecked, tristate, release") << (int)(Qt::Unchecked) - << (int)(defaultFlags | Qt::ItemIsTristate) + << (int)(defaultFlags | Qt::ItemIsAutoTristate) << true << (int)(QEvent::MouseButtonRelease) << (int)(Qt::LeftButton) @@ -1163,7 +1163,7 @@ void tst_QItemDelegate::editorEvent_data() QTest::newRow("partially checked, tristate, release") << (int)(Qt::PartiallyChecked) - << (int)(defaultFlags | Qt::ItemIsTristate) + << (int)(defaultFlags | Qt::ItemIsAutoTristate) << true << (int)(QEvent::MouseButtonRelease) << (int)(Qt::LeftButton) @@ -1172,7 +1172,7 @@ void tst_QItemDelegate::editorEvent_data() QTest::newRow("checked, tristate, release") << (int)(Qt::Checked) - << (int)(defaultFlags | Qt::ItemIsTristate) + << (int)(defaultFlags | Qt::ItemIsAutoTristate) << true << (int)(QEvent::MouseButtonRelease) << (int)(Qt::LeftButton) diff --git a/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp b/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp index 5c881369a0a..b63d6b5b895 100644 --- a/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp +++ b/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp @@ -1037,7 +1037,7 @@ void tst_QTreeWidget::checkState() QCOMPARE(firstChild->checkState(0), Qt::Checked); QCOMPARE(seccondChild->checkState(0), Qt::Unchecked); - item->setFlags(item->flags()|Qt::ItemIsTristate); + item->setFlags(item->flags()|Qt::ItemIsAutoTristate); QCOMPARE(item->checkState(0), Qt::PartiallyChecked); QCOMPARE(firstChild->checkState(0), Qt::Checked); QCOMPARE(seccondChild->checkState(0), Qt::Unchecked); @@ -3155,11 +3155,11 @@ void tst_QTreeWidget::setSelectionModel() void tst_QTreeWidget::task217309() { QTreeWidgetItem item; - item.setFlags(item.flags() | Qt::ItemIsTristate); + item.setFlags(item.flags() | Qt::ItemIsAutoTristate); QTreeWidgetItem subitem1; - subitem1.setFlags(subitem1.flags() | Qt::ItemIsTristate); + subitem1.setFlags(subitem1.flags() | Qt::ItemIsAutoTristate); QTreeWidgetItem subitem2; - subitem2.setFlags(subitem2.flags() | Qt::ItemIsTristate); + subitem2.setFlags(subitem2.flags() | Qt::ItemIsAutoTristate); item.addChild(&subitem1); item.addChild(&subitem2); subitem1.setCheckState(0, Qt::Checked); @@ -3180,7 +3180,7 @@ void tst_QTreeWidget::nonEditableTristate() QTreeWidget *tree = new QTreeWidget; QTreeWidgetItem *item = new QTreeWidgetItem(); tree->insertTopLevelItem(0, item); - item->setFlags(item->flags() | Qt::ItemIsTristate); + item->setFlags(item->flags() | Qt::ItemIsAutoTristate); item->setCheckState(0, Qt::Unchecked); QTreeWidgetItem *subitem1 = new QTreeWidgetItem(item); subitem1->setCheckState(0, Qt::Unchecked);