From 805c23ddb9ba1ea7bcbd046e70161d1dd0ec3bce Mon Sep 17 00:00:00 2001 From: David Rosca Date: Fri, 2 Feb 2018 14:25:54 +0100 Subject: [PATCH] VerticalTabs: Expand subtree when new tab is inserted --- src/plugins/VerticalTabs/tabtreeview.cpp | 23 +++++++++++++++++++++++ src/plugins/VerticalTabs/tabtreeview.h | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/plugins/VerticalTabs/tabtreeview.cpp b/src/plugins/VerticalTabs/tabtreeview.cpp index e187ae6c6..c8c28545c 100644 --- a/src/plugins/VerticalTabs/tabtreeview.cpp +++ b/src/plugins/VerticalTabs/tabtreeview.cpp @@ -23,6 +23,7 @@ #include "webtab.h" #include "tabcontextmenu.h" +#include #include #include @@ -77,6 +78,28 @@ void TabTreeView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bot } } +void TabTreeView::rowsInserted(const QModelIndex &parent, int start, int end) +{ + QTreeView::rowsInserted(parent, start, end); + + // Parent for WebTab is set after insertTab is emitted + const QPersistentModelIndex index = model()->index(start, 0, parent); + QTimer::singleShot(0, this, [=]() { + if (!index.isValid()) { + return; + } + QModelIndex idx = index; + QVector stack; + do { + stack.append(idx); + idx = idx.parent(); + } while (idx.isValid()); + for (const QModelIndex &index : qAsConst(stack)) { + expand(index); + } + }); +} + bool TabTreeView::viewportEvent(QEvent *event) { switch (event->type()) { diff --git a/src/plugins/VerticalTabs/tabtreeview.h b/src/plugins/VerticalTabs/tabtreeview.h index 186c8c30a..8219b552f 100644 --- a/src/plugins/VerticalTabs/tabtreeview.h +++ b/src/plugins/VerticalTabs/tabtreeview.h @@ -36,7 +36,7 @@ private: void drawBranches(QPainter *painter, const QRect &rect, const QModelIndex &index) const override; void currentChanged(const QModelIndex ¤t, const QModelIndex &previous) override; void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles = QVector()) override; - + void rowsInserted(const QModelIndex &parent, int start, int end) override; bool viewportEvent(QEvent *event) override; enum DelegateButton {