[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [falkon] /: TabModel: Remove ParentTabRole and ChildTabsRole
From: David Rosca <null () kde ! org>
Date: 2018-01-31 20:10:36
Message-ID: E1egyiK-0002Fo-Ob () code ! kde ! org
[Download RAW message or body]
Git commit a8bda61f3e8719232422f53974c0f71d2727a8cc by David Rosca.
Committed on 31/01/2018 at 20:00.
Pushed by drosca into branch 'master'.
TabModel: Remove ParentTabRole and ChildTabsRole
M +0 -15 autotests/tabmodeltest.cpp
M +27 -29 src/lib/tabwidget/tabmodel.cpp
M +3 -4 src/lib/tabwidget/tabmodel.h
https://commits.kde.org/falkon/a8bda61f3e8719232422f53974c0f71d2727a8cc
diff --git a/autotests/tabmodeltest.cpp b/autotests/tabmodeltest.cpp
index 66b07b73..541f68e0 100644
--- a/autotests/tabmodeltest.cpp
+++ b/autotests/tabmodeltest.cpp
@@ -116,21 +116,6 @@ void TabModelTest::dataTest()
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;
}
diff --git a/src/lib/tabwidget/tabmodel.cpp b/src/lib/tabwidget/tabmodel.cpp
index 4f0d95b8..160deefb 100644
--- a/src/lib/tabwidget/tabmodel.cpp
+++ b/src/lib/tabwidget/tabmodel.cpp
@@ -30,9 +30,18 @@ TabModel::TabModel(BrowserWindow *window, QObject *parent)
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
@@ -40,7 +49,7 @@ int TabModel::rowCount(const QModelIndex &parent) const
if (parent.isValid()) {
return 0;
}
- return m_window ? m_window->tabCount() : 0;
+ return m_tabs.count();
}
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
{
- if (!m_window || index.row() < 0 || index.row() > m_window->tabCount()) {
+ if (index.row() < 0 || index.row() > m_tabs.count()) {
return QVariant();
}
- WebTab *tab = webTab(index.row());
- if (!tab) {
+ WebTab *t = tab(index);
+ if (!t) {
return QVariant();
}
switch (role) {
case WebTabRole:
- return QVariant::fromValue(tab);
+ return QVariant::fromValue(t);
case TitleRole:
case Qt::DisplayRole:
- return tab->title();
+ return t->title();
case IconRole:
case Qt::DecorationRole:
- return tab->icon();
+ return t->icon();
case PinnedRole:
- return tab->isPinned();
+ return t->isPinned();
case RestoredRole:
- return tab->isRestored();
-
- case ParentTabRole:
- return QVariant::fromValue(tab->parentTab());
-
- case ChildTabsRole:
- return QVariant::fromValue(tab->childTabs());
+ return t->isRestored();
default:
return QVariant();
@@ -134,11 +137,11 @@ bool TabModel::dropMimeData(const QMimeData *data, \
Qt::DropAction action, int ro
QVector<WebTab*> tabs;
while (!stream.atEnd()) {
- int index;
- stream >> index;
- WebTab *tab = webTab(index);
- if (tab) {
- tabs.append(tab);
+ int idx;
+ stream >> idx;
+ WebTab *t = tab(index(idx));
+ if (t) {
+ tabs.append(t);
}
}
@@ -169,9 +172,7 @@ void TabModel::init()
connect(m_window, &QObject::destroyed, this, [this]() {
beginResetModel();
m_window = nullptr;
- for (WebTab *tab : qAsConst(m_tabs)) {
- tab->disconnect(this);
- }
+ m_tabs.clear();
endResetModel();
});
}
@@ -185,7 +186,7 @@ void TabModel::tabInserted(int index)
endInsertRows();
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});
};
@@ -195,9 +196,6 @@ void TabModel::tabInserted(int index)
connect(tab, &WebTab::iconChanged, this, std::bind(emitDataChanged, tab, \
IconRole));
connect(tab, &WebTab::pinnedChanged, this, std::bind(emitDataChanged, tab, \
PinnedRole));
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)
diff --git a/src/lib/tabwidget/tabmodel.h b/src/lib/tabwidget/tabmodel.h
index 140460e3..984be754 100644
--- a/src/lib/tabwidget/tabmodel.h
+++ b/src/lib/tabwidget/tabmodel.h
@@ -34,14 +34,13 @@ public:
TitleRole = Qt::UserRole + 2,
IconRole = Qt::UserRole + 3,
PinnedRole = Qt::UserRole + 4,
- RestoredRole = Qt::UserRole + 5,
- ParentTabRole = Qt::UserRole + 6,
- ChildTabsRole = Qt::UserRole + 7
+ RestoredRole = Qt::UserRole + 5
};
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;
Qt::ItemFlags flags(const QModelIndex &index) const override;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic