Only apply visibility toggle if we have >10 tabs
This commit is contained in:
parent
3081d017ce
commit
a5f9115b2f
@ -21,6 +21,7 @@
|
||||
|
||||
import functools
|
||||
import enum
|
||||
import contextlib
|
||||
|
||||
import attr
|
||||
from PyQt5.QtCore import (pyqtSignal, pyqtSlot, Qt, QSize, QRect, QPoint,
|
||||
@ -214,20 +215,36 @@ class TabWidget(QTabWidget):
|
||||
fields['scroll_pos'] = scroll_pos
|
||||
return fields
|
||||
|
||||
def update_tab_titles(self):
|
||||
"""Update all texts."""
|
||||
# Every single call to setTabText calls the size hinting functions for
|
||||
# every single tab, which are slow. Since we know we are updating all
|
||||
# the tab's titles, we can delay this processing by making the tab
|
||||
# non-visible. To avoid flickering, disable repaint updates whlie we
|
||||
# work.
|
||||
@contextlib.contextmanager
|
||||
def _toggle_visibility(self, force_toggle=False):
|
||||
"""Toggle visibility while running.
|
||||
|
||||
Every single call to setTabText calls the size hinting functions for
|
||||
every single tab, which are slow. Since we know we are updating all
|
||||
the tab's titles, we can delay this processing by making the tab
|
||||
non-visible. To avoid flickering, disable repaint updates whlie we
|
||||
work.
|
||||
|
||||
Args:
|
||||
force_toggle: Whether to always force the toggle, or only do it
|
||||
if we have enough tabs for it to matter
|
||||
"""
|
||||
if self.count() > 10:
|
||||
force_toggle = True
|
||||
if force_toggle:
|
||||
self.setUpdatesEnabled(False)
|
||||
self.setVisible(False)
|
||||
for idx in range(self.count()):
|
||||
self.update_tab_title(idx)
|
||||
yield
|
||||
if force_toggle:
|
||||
self.setVisible(True)
|
||||
self.setUpdatesEnabled(True)
|
||||
|
||||
def update_tab_titles(self):
|
||||
"""Update all texts."""
|
||||
with self._toggle_visibility():
|
||||
for idx in range(self.count()):
|
||||
self.update_tab_title(idx)
|
||||
|
||||
def tabInserted(self, idx):
|
||||
"""Update titles when a tab was inserted."""
|
||||
super().tabInserted(idx)
|
||||
|
@ -24,7 +24,7 @@ import functools
|
||||
import pytest
|
||||
from PyQt5.QtGui import QIcon, QPixmap
|
||||
|
||||
from qutebrowser.mainwindow import tabwidget, tabbedbrowser
|
||||
from qutebrowser.mainwindow import tabwidget
|
||||
from qutebrowser.utils import usertypes
|
||||
|
||||
|
||||
@ -108,7 +108,7 @@ class TestTabWidget:
|
||||
assert first_size == widget.tabBar().tabSizeHint(i)
|
||||
assert first_size_min == widget.tabBar().minimumTabSizeHint(i)
|
||||
|
||||
@pytest.mark.parametrize("num_tabs", [4, 10])
|
||||
@pytest.mark.parametrize("num_tabs", [4, 10, 50, 100])
|
||||
def test_update_tab_titles_benchmark(self, benchmark, widget,
|
||||
qtbot, fake_web_tab, num_tabs):
|
||||
"""Benchmark for update_tab_titles."""
|
||||
@ -120,7 +120,7 @@ class TestTabWidget:
|
||||
|
||||
benchmark(widget.update_tab_titles)
|
||||
|
||||
@pytest.mark.parametrize("num_tabs", [4, 10])
|
||||
@pytest.mark.parametrize("num_tabs", [4, 100])
|
||||
@pytest.mark.parametrize("rev", [True, False])
|
||||
def test_add_remove_tab_benchmark(self, benchmark, widget,
|
||||
qtbot, fake_web_tab, num_tabs, rev):
|
||||
|
Loading…
Reference in New Issue
Block a user