diff options
author | Olivier Goffart <ogoffart@trolltech.com> | 2009-10-27 10:39:51 (GMT) |
---|---|---|
committer | Olivier Goffart <ogoffart@trolltech.com> | 2009-10-27 11:52:43 (GMT) |
commit | 5ff7b773a0f59e174001da1f0550a7f0c2b6f485 (patch) | |
tree | eae96c4bed07a43fccff54ada1ce99e5d750403f /src/gui/itemviews/qtreeview.cpp | |
parent | 11b1ced7cdc2af028164381d43c146ec79919f19 (diff) | |
download | Qt-5ff7b773a0f59e174001da1f0550a7f0c2b6f485.zip Qt-5ff7b773a0f59e174001da1f0550a7f0c2b6f485.tar.gz Qt-5ff7b773a0f59e174001da1f0550a7f0c2b6f485.tar.bz2 |
Fixes QTreeView: stylesheet :has-children pseudo selector doesn't works for the ::item pseudo-class
The State_Children was not set on the QStyleOption.
Refactorized a little bit the way it was computed.
Reviewed-by: Thierry
Task-number: 234930
Task-number: QTBUG-3129
Diffstat (limited to 'src/gui/itemviews/qtreeview.cpp')
-rw-r--r-- | src/gui/itemviews/qtreeview.cpp | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/src/gui/itemviews/qtreeview.cpp b/src/gui/itemviews/qtreeview.cpp index f37d8c7..49c8e34 100644 --- a/src/gui/itemviews/qtreeview.cpp +++ b/src/gui/itemviews/qtreeview.cpp @@ -1422,8 +1422,8 @@ void QTreeView::drawTree(QPainter *painter, const QRegion ®ion) const for (; i < viewItems.count() && y <= area.bottom(); ++i) { const int itemHeight = d->itemHeight(i); option.rect.setRect(0, y, viewportWidth, itemHeight); - option.state = state | (viewItems.at(i).expanded - ? QStyle::State_Open : QStyle::State_None); + option.state = state | (viewItems.at(i).expanded ? QStyle::State_Open : QStyle::State_None) + | (viewItems.at(i).hasChildren ? QStyle::State_Children : QStyle::State_None ); d->current = i; d->spanning = viewItems.at(i).spanning; if (!multipleRects || !drawn.contains(i)) { @@ -1748,8 +1748,7 @@ void QTreeView::drawBranches(QPainter *painter, const QRect &rect, opt.rect = primitive; const bool expanded = viewItem.expanded; - const bool children = (((expanded && viewItem.total > 0)) // already laid out and has children - || d->hasVisibleChildren(index)); // not laid out yet, so we don't know + const bool children = viewItem.hasChildren; bool moreSiblings = false; if (d->hiddenIndexes.isEmpty()) moreSiblings = (d->model->rowCount(parent) - 1 > index.row()); @@ -3135,17 +3134,22 @@ void QTreeViewPrivate::layout(int i) last = j - hidden + children; } else { last = j - hidden + children; - viewItems[last].index = current; - viewItems[last].level = level; - viewItems[last].height = 0; - viewItems[last].spanning = q->isFirstColumnSpanned(current.row(), parent); - viewItems[last].expanded = false; - viewItems[last].total = 0; + QTreeViewItem *item = &viewItems[last]; + item->index = current; + item->level = level; + item->height = 0; + item->spanning = q->isFirstColumnSpanned(current.row(), parent); + item->expanded = false; + item->total = 0; if (isIndexExpanded(current)) { - viewItems[last].expanded = true; + item->expanded = true; layout(last); - children += viewItems[last].total; + item = &viewItems[last]; + children += item->total; + item->hasChildren = item->total > 0; last = j - hidden + children; + } else { + item->hasChildren = hasVisibleChildren(current); } } } |