mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 10:46:35 +01:00
WebTab: Add parentTab and childTabs properties
This commit is contained in:
parent
2377503517
commit
e44877d4c7
@ -112,6 +112,25 @@ void TabModelTest::dataTest()
|
|||||||
QCOMPARE(model.index(0, 0).data(TabModel::PinnedRole).toBool(), tab0->isPinned());
|
QCOMPARE(model.index(0, 0).data(TabModel::PinnedRole).toBool(), tab0->isPinned());
|
||||||
QCOMPARE(model.index(0, 0).data(TabModel::RestoredRole).toBool(), tab0->isRestored());
|
QCOMPARE(model.index(0, 0).data(TabModel::RestoredRole).toBool(), tab0->isRestored());
|
||||||
|
|
||||||
|
w->tabWidget()->addView(QUrl("http://test.com"));
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,12 +38,12 @@ int TabModel::rowCount(const QModelIndex &parent) const
|
|||||||
if (parent.isValid()) {
|
if (parent.isValid()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return m_window->tabCount();
|
return m_window ? m_window->tabCount() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant TabModel::data(const QModelIndex &index, int role) const
|
QVariant TabModel::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
if (index.row() < 0 || index.row() > m_window->tabCount()) {
|
if (!m_window || index.row() < 0 || index.row() > m_window->tabCount()) {
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,6 +70,12 @@ QVariant TabModel::data(const QModelIndex &index, int role) const
|
|||||||
case RestoredRole:
|
case RestoredRole:
|
||||||
return tab->isRestored();
|
return tab->isRestored();
|
||||||
|
|
||||||
|
case ParentTabRole:
|
||||||
|
return QVariant::fromValue(tab->parentTab());
|
||||||
|
|
||||||
|
case ChildTabsRole:
|
||||||
|
return QVariant::fromValue(tab->childTabs());
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
@ -84,6 +90,15 @@ void TabModel::init()
|
|||||||
connect(m_window->tabWidget(), &TabWidget::tabInserted, this, &TabModel::tabInserted);
|
connect(m_window->tabWidget(), &TabWidget::tabInserted, this, &TabModel::tabInserted);
|
||||||
connect(m_window->tabWidget(), &TabWidget::tabRemoved, this, &TabModel::tabRemoved);
|
connect(m_window->tabWidget(), &TabWidget::tabRemoved, this, &TabModel::tabRemoved);
|
||||||
connect(m_window->tabWidget(), &TabWidget::tabMoved, this, &TabModel::tabMoved);
|
connect(m_window->tabWidget(), &TabWidget::tabMoved, this, &TabModel::tabMoved);
|
||||||
|
|
||||||
|
connect(m_window, &QObject::destroyed, this, [this]() {
|
||||||
|
beginResetModel();
|
||||||
|
m_window = nullptr;
|
||||||
|
for (WebTab *tab : qAsConst(m_tabs)) {
|
||||||
|
tab->disconnect(this);
|
||||||
|
}
|
||||||
|
endResetModel();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabModel::tabInserted(int index)
|
void TabModel::tabInserted(int index)
|
||||||
@ -95,7 +110,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(tab->tabIndex(), 0);
|
const QModelIndex idx = TabModel::index(m_tabs.indexOf(tab), 0);
|
||||||
emit dataChanged(idx, idx, {role});
|
emit dataChanged(idx, idx, {role});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -105,6 +120,9 @@ 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)
|
||||||
|
@ -35,6 +35,8 @@ public:
|
|||||||
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);
|
||||||
|
@ -170,6 +170,18 @@ WebTab::WebTab(BrowserWindow* window)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WebTab::~WebTab()
|
||||||
|
{
|
||||||
|
if (m_parentTab) {
|
||||||
|
m_parentTab->m_childTabs.removeOne(this);
|
||||||
|
emit m_parentTab->childTabRemoved(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (WebTab *child : qAsConst(m_childTabs)) {
|
||||||
|
child->setParentTab(nullptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TabbedWebView* WebTab::webView() const
|
TabbedWebView* WebTab::webView() const
|
||||||
{
|
{
|
||||||
return m_webView;
|
return m_webView;
|
||||||
@ -377,6 +389,37 @@ TabIcon* WebTab::tabIcon() const
|
|||||||
return m_tabIcon;
|
return m_tabIcon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WebTab *WebTab::parentTab() const
|
||||||
|
{
|
||||||
|
return m_parentTab;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebTab::setParentTab(WebTab *tab)
|
||||||
|
{
|
||||||
|
if (m_parentTab == tab) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_parentTab) {
|
||||||
|
m_parentTab->m_childTabs.removeOne(this);
|
||||||
|
emit m_parentTab->childTabRemoved(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_parentTab = tab;
|
||||||
|
|
||||||
|
if (m_parentTab) {
|
||||||
|
m_parentTab->m_childTabs.append(this);
|
||||||
|
emit m_parentTab->childTabAdded(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
emit parentTabChanged(m_parentTab);
|
||||||
|
}
|
||||||
|
|
||||||
|
QVector<WebTab*> WebTab::childTabs() const
|
||||||
|
{
|
||||||
|
return m_childTabs;
|
||||||
|
}
|
||||||
|
|
||||||
bool WebTab::isRestored() const
|
bool WebTab::isRestored() const
|
||||||
{
|
{
|
||||||
return !m_savedTab.isValid();
|
return !m_savedTab.isValid();
|
||||||
|
@ -58,11 +58,17 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
explicit WebTab(BrowserWindow* window);
|
explicit WebTab(BrowserWindow* window);
|
||||||
|
~WebTab();
|
||||||
|
|
||||||
TabbedWebView* webView() const;
|
TabbedWebView* webView() const;
|
||||||
LocationBar* locationBar() const;
|
LocationBar* locationBar() const;
|
||||||
TabIcon* tabIcon() const;
|
TabIcon* tabIcon() const;
|
||||||
|
|
||||||
|
WebTab *parentTab() const;
|
||||||
|
void setParentTab(WebTab *tab);
|
||||||
|
|
||||||
|
QVector<WebTab*> childTabs() const;
|
||||||
|
|
||||||
QUrl url() const;
|
QUrl url() const;
|
||||||
QString title(bool allowEmpty = false) const;
|
QString title(bool allowEmpty = false) const;
|
||||||
QIcon icon(bool allowNull = false) const;
|
QIcon icon(bool allowNull = false) const;
|
||||||
@ -115,6 +121,9 @@ signals:
|
|||||||
void iconChanged(const QIcon &icon);
|
void iconChanged(const QIcon &icon);
|
||||||
void pinnedChanged(bool pinned);
|
void pinnedChanged(bool pinned);
|
||||||
void restoredChanged(bool restored);
|
void restoredChanged(bool restored);
|
||||||
|
void parentTabChanged(WebTab *tab);
|
||||||
|
void childTabAdded(WebTab *tab);
|
||||||
|
void childTabRemoved(WebTab *tab);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void titleWasChanged(const QString &title);
|
void titleWasChanged(const QString &title);
|
||||||
@ -131,6 +140,9 @@ private:
|
|||||||
TabBar* m_tabBar;
|
TabBar* m_tabBar;
|
||||||
QWidget *m_notificationWidget;
|
QWidget *m_notificationWidget;
|
||||||
|
|
||||||
|
WebTab *m_parentTab = nullptr;
|
||||||
|
QVector<WebTab*> m_childTabs;
|
||||||
|
|
||||||
SavedTab m_savedTab;
|
SavedTab m_savedTab;
|
||||||
bool m_isPinned;
|
bool m_isPinned;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user