diff --git a/autotests/tabmodeltest.cpp b/autotests/tabmodeltest.cpp index 77756eb7a..adff8dab9 100644 --- a/autotests/tabmodeltest.cpp +++ b/autotests/tabmodeltest.cpp @@ -116,8 +116,6 @@ void TabModelTest::dataTest() w->tabWidget()->addView(QUrl("http://test.com")); - WebTab *tab1 = w->weView(1)->webTab(); - QTest::qWait(10); delete w; } @@ -219,4 +217,21 @@ void TabModelTest::treeModelTest() delete w; } +void TabModelTest::resetTreeModelTest() +{ + BrowserWindow *w = mApp->createWindow(Qz::BW_NewWindow); + + TabModel sourceModel(w); + TabTreeModel model; + model.setSourceModel(&sourceModel); + ModelTest modelTest(&model); + + QTRY_COMPARE(model.rowCount(QModelIndex()), 1); + + QTest::qWait(1); + delete w; + + QCOMPARE(model.rowCount(QModelIndex()), 0); +} + FALKONTEST_MAIN(TabModelTest) diff --git a/autotests/tabmodeltest.h b/autotests/tabmodeltest.h index 384d54309..f11c82c05 100644 --- a/autotests/tabmodeltest.h +++ b/autotests/tabmodeltest.h @@ -30,4 +30,5 @@ private slots: void basicTest(); void dataTest(); void treeModelTest(); + void resetTreeModelTest(); }; diff --git a/src/lib/tabwidget/tabtreemodel.cpp b/src/lib/tabwidget/tabtreemodel.cpp index d697e8e5f..f48f17e93 100644 --- a/src/lib/tabwidget/tabtreemodel.cpp +++ b/src/lib/tabwidget/tabtreemodel.cpp @@ -261,9 +261,10 @@ void TabTreeModel::init() connectTab(item->tab); } - connect(sourceModel(), &QAbstractItemModel::dataChanged, this, &TabTreeModel::sourceDataChanged); - connect(sourceModel(), &QAbstractItemModel::rowsInserted, this, &TabTreeModel::sourceRowsInserted); - connect(sourceModel(), &QAbstractItemModel::rowsAboutToBeRemoved, this, &TabTreeModel::sourceRowsAboutToBeRemoved); + connect(sourceModel(), &QAbstractItemModel::dataChanged, this, &TabTreeModel::sourceDataChanged, Qt::UniqueConnection); + connect(sourceModel(), &QAbstractItemModel::rowsInserted, this, &TabTreeModel::sourceRowsInserted, Qt::UniqueConnection); + connect(sourceModel(), &QAbstractItemModel::rowsAboutToBeRemoved, this, &TabTreeModel::sourceRowsAboutToBeRemoved, Qt::UniqueConnection); + connect(sourceModel(), &QAbstractItemModel::modelReset, this, &TabTreeModel::sourceReset, Qt::UniqueConnection); } QModelIndex TabTreeModel::index(TabTreeModelItem *item) const @@ -311,6 +312,13 @@ void TabTreeModel::sourceRowsAboutToBeRemoved(const QModelIndex &parent, int sta } } +void TabTreeModel::sourceReset() +{ + beginResetModel(); + init(); + endResetModel(); +} + void TabTreeModel::insertIndex(const QModelIndex &sourceIndex) { WebTab *tab = sourceIndex.data(TabModel::WebTabRole).value(); diff --git a/src/lib/tabwidget/tabtreemodel.h b/src/lib/tabwidget/tabtreemodel.h index 3e1e86edb..4ca362b04 100644 --- a/src/lib/tabwidget/tabtreemodel.h +++ b/src/lib/tabwidget/tabtreemodel.h @@ -57,6 +57,7 @@ private: void sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles); void sourceRowsInserted(const QModelIndex &parent, int start, int end); void sourceRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end); + void sourceReset(); void insertIndex(const QModelIndex &sourceIndex); void removeIndex(const QModelIndex &sourceIndex);