mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +01:00
TabModel: Remove ParentTabRole and ChildTabsRole
This commit is contained in:
parent
2b994920ad
commit
a8bda61f3e
|
@ -116,21 +116,6 @@ void TabModelTest::dataTest()
|
||||||
|
|
||||||
WebTab *tab1 = w->weView(1)->webTab();
|
WebTab *tab1 = w->weView(1)->webTab();
|
||||||
|
|
||||||
QSignalSpy dataChangedSpy(&model, &TabModel::dataChanged);
|
|
||||||
|
|
||||||
tab1->setParentTab(tab0);
|
|
||||||
|
|
||||||
QCOMPARE(dataChangedSpy.count(), 2);
|
|
||||||
QCOMPARE(dataChangedSpy.at(0).at(0).value<QModelIndex>(), model.index(0, 0));
|
|
||||||
QCOMPARE(dataChangedSpy.at(0).at(1).value<QModelIndex>(), model.index(0, 0));
|
|
||||||
QCOMPARE(dataChangedSpy.at(0).at(2).value<QVector<int>>(), QVector<int>{TabModel::ChildTabsRole});
|
|
||||||
QCOMPARE(model.index(0, 0).data(TabModel::ChildTabsRole).value<QVector<WebTab*>>(), QVector<WebTab*>{tab1});
|
|
||||||
|
|
||||||
QCOMPARE(dataChangedSpy.at(1).at(0).value<QModelIndex>(), model.index(1, 0));
|
|
||||||
QCOMPARE(dataChangedSpy.at(1).at(1).value<QModelIndex>(), model.index(1, 0));
|
|
||||||
QCOMPARE(dataChangedSpy.at(1).at(2).value<QVector<int>>(), QVector<int>{TabModel::ParentTabRole});
|
|
||||||
QCOMPARE(model.index(1, 0).data(TabModel::ParentTabRole).value<WebTab*>(), tab0);
|
|
||||||
|
|
||||||
delete w;
|
delete w;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,9 +30,18 @@ TabModel::TabModel(BrowserWindow *window, QObject *parent)
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
WebTab *TabModel::webTab(int row) const
|
QModelIndex TabModel::tabIndex(WebTab *tab) const
|
||||||
{
|
{
|
||||||
return m_tabs.value(row);
|
const int idx = m_tabs.indexOf(tab);
|
||||||
|
if (idx < 0) {
|
||||||
|
return QModelIndex();
|
||||||
|
}
|
||||||
|
return index(idx);
|
||||||
|
}
|
||||||
|
|
||||||
|
WebTab *TabModel::tab(const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
return m_tabs.value(index.row());
|
||||||
}
|
}
|
||||||
|
|
||||||
int TabModel::rowCount(const QModelIndex &parent) const
|
int TabModel::rowCount(const QModelIndex &parent) const
|
||||||
|
@ -40,7 +49,7 @@ int TabModel::rowCount(const QModelIndex &parent) const
|
||||||
if (parent.isValid()) {
|
if (parent.isValid()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return m_window ? m_window->tabCount() : 0;
|
return m_tabs.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
Qt::ItemFlags TabModel::flags(const QModelIndex &index) const
|
Qt::ItemFlags TabModel::flags(const QModelIndex &index) const
|
||||||
|
@ -53,38 +62,32 @@ Qt::ItemFlags TabModel::flags(const QModelIndex &index) const
|
||||||
|
|
||||||
QVariant TabModel::data(const QModelIndex &index, int role) const
|
QVariant TabModel::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
if (!m_window || index.row() < 0 || index.row() > m_window->tabCount()) {
|
if (index.row() < 0 || index.row() > m_tabs.count()) {
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
WebTab *tab = webTab(index.row());
|
WebTab *t = tab(index);
|
||||||
if (!tab) {
|
if (!t) {
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case WebTabRole:
|
case WebTabRole:
|
||||||
return QVariant::fromValue(tab);
|
return QVariant::fromValue(t);
|
||||||
|
|
||||||
case TitleRole:
|
case TitleRole:
|
||||||
case Qt::DisplayRole:
|
case Qt::DisplayRole:
|
||||||
return tab->title();
|
return t->title();
|
||||||
|
|
||||||
case IconRole:
|
case IconRole:
|
||||||
case Qt::DecorationRole:
|
case Qt::DecorationRole:
|
||||||
return tab->icon();
|
return t->icon();
|
||||||
|
|
||||||
case PinnedRole:
|
case PinnedRole:
|
||||||
return tab->isPinned();
|
return t->isPinned();
|
||||||
|
|
||||||
case RestoredRole:
|
case RestoredRole:
|
||||||
return tab->isRestored();
|
return t->isRestored();
|
||||||
|
|
||||||
case ParentTabRole:
|
|
||||||
return QVariant::fromValue(tab->parentTab());
|
|
||||||
|
|
||||||
case ChildTabsRole:
|
|
||||||
return QVariant::fromValue(tab->childTabs());
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
@ -134,11 +137,11 @@ bool TabModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int ro
|
||||||
|
|
||||||
QVector<WebTab*> tabs;
|
QVector<WebTab*> tabs;
|
||||||
while (!stream.atEnd()) {
|
while (!stream.atEnd()) {
|
||||||
int index;
|
int idx;
|
||||||
stream >> index;
|
stream >> idx;
|
||||||
WebTab *tab = webTab(index);
|
WebTab *t = tab(index(idx));
|
||||||
if (tab) {
|
if (t) {
|
||||||
tabs.append(tab);
|
tabs.append(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,9 +172,7 @@ void TabModel::init()
|
||||||
connect(m_window, &QObject::destroyed, this, [this]() {
|
connect(m_window, &QObject::destroyed, this, [this]() {
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
m_window = nullptr;
|
m_window = nullptr;
|
||||||
for (WebTab *tab : qAsConst(m_tabs)) {
|
m_tabs.clear();
|
||||||
tab->disconnect(this);
|
|
||||||
}
|
|
||||||
endResetModel();
|
endResetModel();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -185,7 +186,7 @@ void TabModel::tabInserted(int index)
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
|
|
||||||
auto emitDataChanged = [this](WebTab *tab, int role) {
|
auto emitDataChanged = [this](WebTab *tab, int role) {
|
||||||
const QModelIndex idx = TabModel::index(m_tabs.indexOf(tab), 0);
|
const QModelIndex idx = tabIndex(tab);
|
||||||
emit dataChanged(idx, idx, {role});
|
emit dataChanged(idx, idx, {role});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -195,9 +196,6 @@ void TabModel::tabInserted(int index)
|
||||||
connect(tab, &WebTab::iconChanged, this, std::bind(emitDataChanged, tab, IconRole));
|
connect(tab, &WebTab::iconChanged, this, std::bind(emitDataChanged, tab, IconRole));
|
||||||
connect(tab, &WebTab::pinnedChanged, this, std::bind(emitDataChanged, tab, PinnedRole));
|
connect(tab, &WebTab::pinnedChanged, this, std::bind(emitDataChanged, tab, PinnedRole));
|
||||||
connect(tab, &WebTab::restoredChanged, this, std::bind(emitDataChanged, tab, RestoredRole));
|
connect(tab, &WebTab::restoredChanged, this, std::bind(emitDataChanged, tab, RestoredRole));
|
||||||
connect(tab, &WebTab::parentTabChanged, this, std::bind(emitDataChanged, tab, ParentTabRole));
|
|
||||||
connect(tab, &WebTab::childTabAdded, this, std::bind(emitDataChanged, tab, ChildTabsRole));
|
|
||||||
connect(tab, &WebTab::childTabRemoved, this, std::bind(emitDataChanged, tab, ChildTabsRole));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabModel::tabRemoved(int index)
|
void TabModel::tabRemoved(int index)
|
||||||
|
|
|
@ -34,14 +34,13 @@ public:
|
||||||
TitleRole = Qt::UserRole + 2,
|
TitleRole = Qt::UserRole + 2,
|
||||||
IconRole = Qt::UserRole + 3,
|
IconRole = Qt::UserRole + 3,
|
||||||
PinnedRole = Qt::UserRole + 4,
|
PinnedRole = Qt::UserRole + 4,
|
||||||
RestoredRole = Qt::UserRole + 5,
|
RestoredRole = Qt::UserRole + 5
|
||||||
ParentTabRole = Qt::UserRole + 6,
|
|
||||||
ChildTabsRole = Qt::UserRole + 7
|
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit TabModel(BrowserWindow *window, QObject *parent = nullptr);
|
explicit TabModel(BrowserWindow *window, QObject *parent = nullptr);
|
||||||
|
|
||||||
WebTab *webTab(int row) const;
|
QModelIndex tabIndex(WebTab *tab) const;
|
||||||
|
WebTab *tab(const QModelIndex &index) const;
|
||||||
|
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user