From 4ad6d6cda1c2b32585b79c64292e4726bb15aa69 Mon Sep 17 00:00:00 2001 From: David Rosca Date: Fri, 2 Feb 2018 17:59:03 +0100 Subject: [PATCH] TabTreeModel: Only sync top-level tabs when closing window Otherwise reordering tabs is too distracting when tabbar is visible. --- autotests/tabmodeltest.cpp | 4 ++-- src/lib/tabwidget/tabtreemodel.cpp | 13 +++---------- src/lib/tabwidget/tabtreemodel.h | 4 ++-- src/plugins/VerticalTabs/verticaltabswidget.cpp | 2 +- 4 files changed, 8 insertions(+), 15 deletions(-) diff --git a/autotests/tabmodeltest.cpp b/autotests/tabmodeltest.cpp index 9a8662c6c..c35d1e198 100644 --- a/autotests/tabmodeltest.cpp +++ b/autotests/tabmodeltest.cpp @@ -151,7 +151,7 @@ void TabModelTest::treeModelTest() BrowserWindow *w = mApp->createWindow(Qz::BW_NewWindow); TabModel sourceModel(w); - TabTreeModel model; + TabTreeModel model(w); model.setSourceModel(&sourceModel); ModelTest modelTest(&model); @@ -249,7 +249,7 @@ void TabModelTest::resetTreeModelTest() BrowserWindow *w = mApp->createWindow(Qz::BW_NewWindow); TabModel sourceModel(w); - TabTreeModel model; + TabTreeModel model(w); model.setSourceModel(&sourceModel); ModelTest modelTest(&model); diff --git a/src/lib/tabwidget/tabtreemodel.cpp b/src/lib/tabwidget/tabtreemodel.cpp index c698f7cab..f19c6eaa8 100644 --- a/src/lib/tabwidget/tabtreemodel.cpp +++ b/src/lib/tabwidget/tabtreemodel.cpp @@ -18,6 +18,7 @@ #include "tabtreemodel.h" #include "tabmodel.h" #include "webtab.h" +#include "browserwindow.h" #include #include @@ -81,13 +82,10 @@ void TabTreeModelItem::addChild(TabTreeModelItem *item, int index) } } -TabTreeModel::TabTreeModel(QObject *parent) +TabTreeModel::TabTreeModel(BrowserWindow *window, QObject *parent) : QAbstractProxyModel(parent) { - m_syncTimer = new QTimer(this); - m_syncTimer->setInterval(100); - m_syncTimer->setSingleShot(true); - connect(m_syncTimer, &QTimer::timeout, this, &TabTreeModel::syncTopLevelTabs); + connect(window, &BrowserWindow::aboutToClose, this, &TabTreeModel::syncTopLevelTabs); connect(this, &QAbstractProxyModel::sourceModelChanged, this, &TabTreeModel::init); } @@ -239,7 +237,6 @@ bool TabTreeModel::dropMimeData(const QMimeData *data, Qt::DropAction action, in } m_root->addChild(it, childPos); endMoveRows(); - m_syncTimer->start(); } else { parentItem->tab->addChildTab(tab, row); } @@ -390,7 +387,6 @@ void TabTreeModel::connectTab(WebTab *tab) } m_root->addChild(item, pos); endMoveRows(); - m_syncTimer->start(); }); connect(tab, &WebTab::childTabAdded, this, [=](WebTab *child, int pos) { @@ -407,9 +403,6 @@ void TabTreeModel::connectTab(WebTab *tab) } item->addChild(from, childPos); endMoveRows(); - if (item->parent == m_root) { - m_syncTimer->start(); - } }); } diff --git a/src/lib/tabwidget/tabtreemodel.h b/src/lib/tabwidget/tabtreemodel.h index d59bed1fd..d17501cd6 100644 --- a/src/lib/tabwidget/tabtreemodel.h +++ b/src/lib/tabwidget/tabtreemodel.h @@ -24,6 +24,7 @@ class QTimer; class WebTab; +class BrowserWindow; class TabTreeModelItem; class FALKON_EXPORT TabTreeModel : public QAbstractProxyModel @@ -31,7 +32,7 @@ class FALKON_EXPORT TabTreeModel : public QAbstractProxyModel Q_OBJECT public: - explicit TabTreeModel(QObject *parent = nullptr); + explicit TabTreeModel(BrowserWindow *window, QObject *parent = nullptr); ~TabTreeModel(); QModelIndex tabIndex(WebTab *tab) const; @@ -68,5 +69,4 @@ private: TabTreeModelItem *m_root = nullptr; QHash m_items; - QTimer *m_syncTimer = nullptr; }; diff --git a/src/plugins/VerticalTabs/verticaltabswidget.cpp b/src/plugins/VerticalTabs/verticaltabswidget.cpp index 66e77fa8e..a2ebf00fc 100644 --- a/src/plugins/VerticalTabs/verticaltabswidget.cpp +++ b/src/plugins/VerticalTabs/verticaltabswidget.cpp @@ -63,7 +63,7 @@ void VerticalTabsWidget::setViewType(VerticalTabsPlugin::ViewType type) break; case VerticalTabsPlugin::TabTreeView: - m_treeModel = new TabTreeModel(model); + m_treeModel = new TabTreeModel(m_window, model); m_treeModel->setSourceModel(m_window->tabModel()); model->setSourceModel(m_treeModel); m_normalView->setModel(model);