1
mirror of https://invent.kde.org/network/falkon.git synced 2024-09-21 09:42:10 +02:00

TabTreeModel: Reset model when source resets

This commit is contained in:
David Rosca 2018-01-31 20:21:00 +01:00
parent ebaab19f88
commit 59dbfc1f48
No known key found for this signature in database
GPG Key ID: EBC3FC294452C6D8
4 changed files with 30 additions and 5 deletions

View File

@ -116,8 +116,6 @@ void TabModelTest::dataTest()
w->tabWidget()->addView(QUrl("http://test.com")); w->tabWidget()->addView(QUrl("http://test.com"));
WebTab *tab1 = w->weView(1)->webTab();
QTest::qWait(10); QTest::qWait(10);
delete w; delete w;
} }
@ -219,4 +217,21 @@ void TabModelTest::treeModelTest()
delete w; 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) FALKONTEST_MAIN(TabModelTest)

View File

@ -30,4 +30,5 @@ private slots:
void basicTest(); void basicTest();
void dataTest(); void dataTest();
void treeModelTest(); void treeModelTest();
void resetTreeModelTest();
}; };

View File

@ -261,9 +261,10 @@ void TabTreeModel::init()
connectTab(item->tab); connectTab(item->tab);
} }
connect(sourceModel(), &QAbstractItemModel::dataChanged, this, &TabTreeModel::sourceDataChanged); connect(sourceModel(), &QAbstractItemModel::dataChanged, this, &TabTreeModel::sourceDataChanged, Qt::UniqueConnection);
connect(sourceModel(), &QAbstractItemModel::rowsInserted, this, &TabTreeModel::sourceRowsInserted); connect(sourceModel(), &QAbstractItemModel::rowsInserted, this, &TabTreeModel::sourceRowsInserted, Qt::UniqueConnection);
connect(sourceModel(), &QAbstractItemModel::rowsAboutToBeRemoved, this, &TabTreeModel::sourceRowsAboutToBeRemoved); connect(sourceModel(), &QAbstractItemModel::rowsAboutToBeRemoved, this, &TabTreeModel::sourceRowsAboutToBeRemoved, Qt::UniqueConnection);
connect(sourceModel(), &QAbstractItemModel::modelReset, this, &TabTreeModel::sourceReset, Qt::UniqueConnection);
} }
QModelIndex TabTreeModel::index(TabTreeModelItem *item) const 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) void TabTreeModel::insertIndex(const QModelIndex &sourceIndex)
{ {
WebTab *tab = sourceIndex.data(TabModel::WebTabRole).value<WebTab*>(); WebTab *tab = sourceIndex.data(TabModel::WebTabRole).value<WebTab*>();

View File

@ -57,6 +57,7 @@ private:
void sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles); void sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles);
void sourceRowsInserted(const QModelIndex &parent, int start, int end); void sourceRowsInserted(const QModelIndex &parent, int start, int end);
void sourceRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end); void sourceRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
void sourceReset();
void insertIndex(const QModelIndex &sourceIndex); void insertIndex(const QModelIndex &sourceIndex);
void removeIndex(const QModelIndex &sourceIndex); void removeIndex(const QModelIndex &sourceIndex);