diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index c770fa9cc..b46791980 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -48,6 +48,8 @@ Changed mode and is not hidden anymore. - `minimal_webkit_testbrowser.py` now has a `--webengine` switch to test QtWebEngine if it's installed. +- The column width percentages for the completion view now depend on the + completion model. Fixed ~~~~~ diff --git a/qutebrowser/completion/completionwidget.py b/qutebrowser/completion/completionwidget.py index a3bea931a..36de445ac 100644 --- a/qutebrowser/completion/completionwidget.py +++ b/qutebrowser/completion/completionwidget.py @@ -28,6 +28,7 @@ from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt, QItemSelectionModel from qutebrowser.config import config, style from qutebrowser.completion import completiondelegate, completer +from qutebrowser.completion.models import base from qutebrowser.utils import qtutils, objreg, utils @@ -38,15 +39,13 @@ class CompletionView(QTreeView): Based on QTreeView but heavily customized so root elements show as category headers, and children show as flat list. - Class attributes: - COLUMN_WIDTHS: A list of column widths, in percent. - Attributes: enabled: Whether showing the CompletionView is enabled. _win_id: The ID of the window this CompletionView is associated with. _height: The height to use for the CompletionView. _height_perc: Either None or a percentage if height should be relative. _delegate: The item delegate used. + _column_widths: A list of column widths, in percent. Signals: resize_completion: Emitted when the completion should be resized. @@ -82,7 +81,6 @@ class CompletionView(QTreeView): border: 0px; } """ - COLUMN_WIDTHS = (20, 70, 10) # FIXME style scrollbar # https://github.com/The-Compiler/qutebrowser/issues/117 @@ -103,6 +101,8 @@ class CompletionView(QTreeView): # FIXME handle new aliases. # objreg.get('config').changed.connect(self.init_command_completion) + self._column_widths = base.BaseCompletionModel.COLUMN_WIDTHS + self._delegate = completiondelegate.CompletionItemDelegate(self) self.setItemDelegate(self._delegate) style.set_register_stylesheet(self) @@ -128,9 +128,9 @@ class CompletionView(QTreeView): return utils.get_repr(self) def _resize_columns(self): - """Resize the completion columns based on COLUMN_WIDTHS.""" + """Resize the completion columns based on column_widths.""" width = self.size().width() - pixel_widths = [(width * perc // 100) for perc in self.COLUMN_WIDTHS] + pixel_widths = [(width * perc // 100) for perc in self._column_widths] if self.verticalScrollBar().isVisible(): pixel_widths[-1] -= self.style().pixelMetric( QStyle.PM_ScrollBarExtent) + 5 @@ -203,6 +203,8 @@ class CompletionView(QTreeView): sel_model.deleteLater() for i in range(model.rowCount()): self.expand(model.index(i, 0)) + + self._column_widths = model.srcmodel.COLUMN_WIDTHS self._resize_columns() self.maybe_resize_completion() diff --git a/qutebrowser/completion/models/base.py b/qutebrowser/completion/models/base.py index 0d4bf7fca..a35c7f063 100644 --- a/qutebrowser/completion/models/base.py +++ b/qutebrowser/completion/models/base.py @@ -39,8 +39,14 @@ class BaseCompletionModel(QStandardItemModel): Used for showing completions later in the CompletionView. Supports setting marks and adding new categories/items easily. + + Class Attributes: + COLUMN_WIDTHS: The width percentages of the columns used in the + completion view. """ + COLUMN_WIDTHS = (30, 70, 0) + def __init__(self, parent=None): super().__init__(parent) self.setColumnCount(3) diff --git a/qutebrowser/completion/models/configmodel.py b/qutebrowser/completion/models/configmodel.py index 6d39fed7b..0c45d817b 100644 --- a/qutebrowser/completion/models/configmodel.py +++ b/qutebrowser/completion/models/configmodel.py @@ -32,6 +32,8 @@ class SettingSectionCompletionModel(base.BaseCompletionModel): # pylint: disable=abstract-method + COLUMN_WIDTHS = (20, 70, 10) + def __init__(self, parent=None): super().__init__(parent) cat = self.new_category("Sections") @@ -51,6 +53,8 @@ class SettingOptionCompletionModel(base.BaseCompletionModel): # pylint: disable=abstract-method + COLUMN_WIDTHS = (20, 70, 10) + def __init__(self, section, parent=None): super().__init__(parent) cat = self.new_category(section) @@ -104,6 +108,8 @@ class SettingValueCompletionModel(base.BaseCompletionModel): # pylint: disable=abstract-method + COLUMN_WIDTHS = (20, 70, 10) + def __init__(self, section, option, parent=None): super().__init__(parent) self._section = section diff --git a/qutebrowser/completion/models/urlmodel.py b/qutebrowser/completion/models/urlmodel.py index 2da1d0b71..ca1ef31fe 100644 --- a/qutebrowser/completion/models/urlmodel.py +++ b/qutebrowser/completion/models/urlmodel.py @@ -40,6 +40,8 @@ class UrlCompletionModel(base.BaseCompletionModel): TEXT_COLUMN = 1 TIME_COLUMN = 2 + COLUMN_WIDTHS = (40, 50, 10) + def __init__(self, parent=None): super().__init__(parent) diff --git a/tests/completion/test_column_widths.py b/tests/completion/test_column_widths.py new file mode 100644 index 000000000..c9a219e78 --- /dev/null +++ b/tests/completion/test_column_widths.py @@ -0,0 +1,53 @@ +# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: + +# Copyright 2015 Alexander Cogneau +# +# This file is part of qutebrowser. +# +# qutebrowser is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# qutebrowser is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with qutebrowser. If not, see . + +"""Tests for qutebrowser.completion.models column widths""" + +import pytest + +from qutebrowser.completion.models.base import BaseCompletionModel +from qutebrowser.completion.models.configmodel import ( + SettingOptionCompletionModel, SettingSectionCompletionModel, + SettingValueCompletionModel) +from qutebrowser.completion.models.miscmodels import ( + CommandCompletionModel, HelpCompletionModel, QuickmarkCompletionModel, + BookmarkCompletionModel, SessionCompletionModel) +from qutebrowser.completion.models.urlmodel import UrlCompletionModel + + +class TestColumnWidths: + + """Tests for the column widths of the completion models""" + + CLASSES = [BaseCompletionModel, SettingOptionCompletionModel, + SettingOptionCompletionModel, SettingSectionCompletionModel, + SettingValueCompletionModel, CommandCompletionModel, + HelpCompletionModel, QuickmarkCompletionModel, + BookmarkCompletionModel, SessionCompletionModel, + UrlCompletionModel] + + @pytest.mark.parametrize("model", CLASSES) + def test_list_size(self, model): + """Test if there are 3 items in the COLUMN_WIDTHS property""" + assert len(model.COLUMN_WIDTHS) == 3 + + @pytest.mark.parametrize("model", CLASSES) + def test_column_width_sum(self, model): + """Test if the sum of the widths asserts to 100""" + assert sum(model.COLUMN_WIDTHS) == 100