summaryrefslogtreecommitdiffstats
path: root/examples/widgets/painting/fontsampler/mainwindow.cpp
diff options
context:
space:
mode:
authorDavid Faure <david.faure@kdab.com>2015-01-20 13:56:58 +0100
committerDavid Faure <david.faure@kdab.com>2015-01-25 12:38:04 +0100
commitb65a415e674df75821600c8ac0bcdfdfc0703a2b (patch)
treecbf50f4bbd7e15574892a4478d9df65847cf661f /examples/widgets/painting/fontsampler/mainwindow.cpp
parentdd23d9f161deda1e72c1f6c4eccf1c6d598bf752 (diff)
Simplify fontsampler example by using the automatic tristate feature.
All the features implemented here are done by QTreeWidget, which also sets PartiallyChecked when appropriate. Change-Id: I8c8b515478708d1b7a853e7b8d963dd8fc9863fb Reviewed-by: Jarek Kobus <jaroslaw.kobus@theqtcompany.com>
Diffstat (limited to 'examples/widgets/painting/fontsampler/mainwindow.cpp')
-rw-r--r--examples/widgets/painting/fontsampler/mainwindow.cpp41
1 files changed, 1 insertions, 40 deletions
diff --git a/examples/widgets/painting/fontsampler/mainwindow.cpp b/examples/widgets/painting/fontsampler/mainwindow.cpp
index bb7b7c7c28..0d2631aa9d 100644
--- a/examples/widgets/painting/fontsampler/mainwindow.cpp
+++ b/examples/widgets/painting/fontsampler/mainwindow.cpp
@@ -80,6 +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);
foreach (QString style, styles) {
QTreeWidgetItem *styleItem = new QTreeWidgetItem(familyItem);
@@ -169,51 +170,11 @@ void MainWindow::updateStyles(QTreeWidgetItem *item, int column)
QTreeWidgetItem *parent = item->parent();
if (parent) {
-
// Only count style items.
if (state == Qt::Checked)
++markedCount;
else
--markedCount;
-
- if (state == Qt::Checked && parent->checkState(0) == Qt::Unchecked) {
- // Mark parent items when child items are checked.
- parent->setCheckState(0, Qt::Checked);
-
- } else if (state == Qt::Unchecked && parent->checkState(0) == Qt::Checked) {
-
- bool marked = false;
- for (int row = 0; row < parent->childCount(); ++row) {
- if (parent->child(row)->checkState(0) == Qt::Checked) {
- marked = true;
- break;
- }
- }
- // Unmark parent items when all child items are unchecked.
- if (!marked)
- parent->setCheckState(0, Qt::Unchecked);
- }
- } else {
- int row;
- int number = 0;
- for (row = 0; row < item->childCount(); ++row) {
- if (item->child(row)->checkState(0) == Qt::Checked)
- ++number;
- }
-
- // Mark/unmark all child items when marking/unmarking top-level
- // items.
- if (state == Qt::Checked && number == 0) {
- for (row = 0; row < item->childCount(); ++row) {
- if (item->child(row)->checkState(0) == Qt::Unchecked)
- item->child(row)->setCheckState(0, Qt::Checked);
- }
- } else if (state == Qt::Unchecked && number > 0) {
- for (row = 0; row < item->childCount(); ++row) {
- if (item->child(row)->checkState(0) == Qt::Checked)
- item->child(row)->setCheckState(0, Qt::Unchecked);
- }
- }
}
printAction->setEnabled(markedCount > 0);