From 61299c89b60c2815c18e80622fc11fb86ab093c2 Mon Sep 17 00:00:00 2001 From: David Rosca Date: Tue, 30 Jan 2018 16:41:30 +0100 Subject: [PATCH] WebTab: Save parent tab index in session file --- src/lib/tabwidget/tabwidget.cpp | 13 +++++++++++-- src/lib/webtab/webtab.cpp | 9 ++++++++- src/lib/webtab/webtab.h | 1 + 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/lib/tabwidget/tabwidget.cpp b/src/lib/tabwidget/tabwidget.cpp index 1360436ff..791b37729 100644 --- a/src/lib/tabwidget/tabwidget.cpp +++ b/src/lib/tabwidget/tabwidget.cpp @@ -790,10 +790,19 @@ bool TabWidget::restoreState(const QVector &tabs, int currentT return false; } + QVector> parentTabs; + for (int i = 0; i < tabs.size(); ++i) { WebTab::SavedTab tab = tabs.at(i); - int index = addView(QUrl(), Qz::NT_CleanSelectedTab, false, tab.isPinned); - weTab(index)->restoreTab(tab); + WebTab *webTab = weTab(addView(QUrl(), Qz::NT_CleanSelectedTab, false, tab.isPinned)); + webTab->restoreTab(tab); + if (tab.parentTab >= 0) { + parentTabs.append({webTab, tab.parentTab}); + } + } + + for (const auto p : qAsConst(parentTabs)) { + p.first->setParentTab(weTab(p.second)); } setCurrentIndex(currentTab); diff --git a/src/lib/webtab/webtab.cpp b/src/lib/webtab/webtab.cpp index a3120a559..42d993677 100644 --- a/src/lib/webtab/webtab.cpp +++ b/src/lib/webtab/webtab.cpp @@ -36,11 +36,12 @@ #include #include -static const int savedTabVersion = 3; +static const int savedTabVersion = 4; WebTab::SavedTab::SavedTab() : isPinned(false) , zoomLevel(qzSettings->defaultZoomLevel) + , parentTab(-1) { } @@ -52,6 +53,7 @@ WebTab::SavedTab::SavedTab(WebTab* webTab) history = webTab->historyData(); isPinned = webTab->isPinned(); zoomLevel = webTab->zoomLevel(); + parentTab = webTab->parentTab() ? webTab->parentTab()->tabIndex() : -1; } bool WebTab::SavedTab::isValid() const @@ -67,6 +69,7 @@ void WebTab::SavedTab::clear() history.clear(); isPinned = false; zoomLevel = qzSettings->defaultZoomLevel; + parentTab = -1; } QDataStream &operator <<(QDataStream &stream, const WebTab::SavedTab &tab) @@ -78,6 +81,7 @@ QDataStream &operator <<(QDataStream &stream, const WebTab::SavedTab &tab) stream << tab.history; stream << tab.isPinned; stream << tab.zoomLevel; + stream << tab.parentTab; return stream; } @@ -102,6 +106,9 @@ QDataStream &operator >>(QDataStream &stream, WebTab::SavedTab &tab) if (version >= 3) stream >> tab.zoomLevel; + if (version >= 4) + stream >> tab.parentTab; + tab.icon = QIcon(pixmap); return stream; diff --git a/src/lib/webtab/webtab.h b/src/lib/webtab/webtab.h index d2b8d2b7d..903d82aa6 100644 --- a/src/lib/webtab/webtab.h +++ b/src/lib/webtab/webtab.h @@ -46,6 +46,7 @@ public: QByteArray history; bool isPinned; int zoomLevel; + int parentTab; SavedTab(); SavedTab(WebTab* webTab);