mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +01:00
TabTreeModel: Reset model when source resets
This commit is contained in:
parent
ebaab19f88
commit
59dbfc1f48
|
@ -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)
|
||||
|
|
|
@ -30,4 +30,5 @@ private slots:
|
|||
void basicTest();
|
||||
void dataTest();
|
||||
void treeModelTest();
|
||||
void resetTreeModelTest();
|
||||
};
|
||||
|
|
|
@ -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<WebTab*>();
|
||||
|
|
|
@ -57,6 +57,7 @@ private:
|
|||
void sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user