1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

VerticalTabs: Expand subtree when new tab is inserted

This commit is contained in:
David Rosca 2018-02-02 14:25:54 +01:00
parent 072d3c28ee
commit 805c23ddb9
No known key found for this signature in database
GPG Key ID: EBC3FC294452C6D8
2 changed files with 24 additions and 1 deletions

View File

@ -23,6 +23,7 @@
#include "webtab.h"
#include "tabcontextmenu.h"
#include <QTimer>
#include <QToolTip>
#include <QHoverEvent>
@ -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<QModelIndex> 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()) {

View File

@ -36,7 +36,7 @@ private:
void drawBranches(QPainter *painter, const QRect &rect, const QModelIndex &index) const override;
void currentChanged(const QModelIndex &current, const QModelIndex &previous) override;
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>()) override;
void rowsInserted(const QModelIndex &parent, int start, int end) override;
bool viewportEvent(QEvent *event) override;
enum DelegateButton {