From 24e6fe3d389ac80a0e8fbae623fc417fbf3f0e5d Mon Sep 17 00:00:00 2001 From: Juraj Oravec Date: Fri, 21 Jul 2023 00:58:15 +0200 Subject: [PATCH] SessionRestore: Set tab title after at the end This change saves a lot of recalculations which is done after each tab is added. Signed-off-by: Juraj Oravec --- src/lib/tabwidget/tabbar.cpp | 15 ++++++++++++--- src/lib/tabwidget/tabbar.h | 1 + src/lib/tabwidget/tabwidget.cpp | 21 ++++++++++++++------- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/lib/tabwidget/tabbar.cpp b/src/lib/tabwidget/tabbar.cpp index dc012c007..4cd227f78 100644 --- a/src/lib/tabwidget/tabbar.cpp +++ b/src/lib/tabwidget/tabbar.cpp @@ -326,7 +326,7 @@ WebTab* TabBar::webTab(int index) const void TabBar::showCloseButton(int index) { - if (!validIndex(index) || m_isRestoring) { + if (!validIndex(index)) { return; } @@ -358,7 +358,7 @@ void TabBar::contextMenuEvent(QContextMenuEvent* event) void TabBar::hideCloseButton(int index) { - if (!validIndex(index) || tabsClosable() || m_isRestoring) { + if (!validIndex(index) || tabsClosable()) { return; } @@ -422,7 +422,7 @@ void TabBar::currentTabChanged(int index) } // Don't hide close buttons when dragging tabs - if (m_dragStartPosition.isNull()) { + if (m_dragStartPosition.isNull() && !m_isRestoring) { showCloseButton(index); if (m_lastTab) { hideCloseButton(m_lastTab->tabIndex()); @@ -436,6 +436,10 @@ void TabBar::currentTabChanged(int index) void TabBar::setTabText(int index, const QString &text) { + if (m_isRestoring) { + return; + } + QString tabText = text; // Avoid Alt+letter shortcuts @@ -735,4 +739,9 @@ void TabBar::setIsRestoring(bool restoring) m_isRestoring = restoring; } +bool TabBar::isRestoring() +{ + return m_isRestoring; +} + #include "tabbar.moc" diff --git a/src/lib/tabwidget/tabbar.h b/src/lib/tabwidget/tabbar.h index 7e967aea2..139ff6b3a 100644 --- a/src/lib/tabwidget/tabbar.h +++ b/src/lib/tabwidget/tabbar.h @@ -44,6 +44,7 @@ public: void wheelEvent(QWheelEvent* event) override; void setIsRestoring(bool restoring); + bool isRestoring(); Q_SIGNALS: void moveAddTabButton(int posX); diff --git a/src/lib/tabwidget/tabwidget.cpp b/src/lib/tabwidget/tabwidget.cpp index e6fb36d2f..b1cd09e3a 100644 --- a/src/lib/tabwidget/tabwidget.cpp +++ b/src/lib/tabwidget/tabwidget.cpp @@ -507,17 +507,19 @@ void TabWidget::currentTabChanged(int index) m_lastBackgroundTab = nullptr; m_currentTabFresh = false; - WebTab* webTab = weTab(index); - webTab->tabActivated(); + if (!m_tabBar->isRestoring()) { + WebTab* webTab = weTab(index); + webTab->tabActivated(); - LocationBar* locBar = webTab->locationBar(); + LocationBar* locBar = webTab->locationBar(); - if (locBar && m_locationBars->indexOf(locBar) != -1) { - m_locationBars->setCurrentWidget(locBar); + if (locBar && m_locationBars->indexOf(locBar) != -1) { + m_locationBars->setCurrentWidget(locBar); + } + + m_window->currentTabChanged(); } - m_window->currentTabChanged(); - Q_EMIT changed(); } @@ -874,6 +876,11 @@ bool TabWidget::restoreState(const QVector &tabs, int currentT m_tabBar->setIsRestoring(false); + auto const l_allTabs = allTabs(); + for (const WebTab* tab : l_allTabs) { + m_tabBar->setTabText(tab->tabIndex(), tab->title()); + } + setCurrentIndex(currentTab); QTimer::singleShot(0, m_tabBar, SLOT(ensureVisible(int,int)));