From 35006bd2465b9dce3a894d4c3c67ec44b05ab605 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Fri, 2 May 2014 16:23:11 +0200 Subject: [PATCH] Add a misc column to models. --- qutebrowser/models/basecompletion.py | 14 ++++++++++++-- qutebrowser/models/completion.py | 13 +++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/qutebrowser/models/basecompletion.py b/qutebrowser/models/basecompletion.py index 06090a10e..5f7c73358 100644 --- a/qutebrowser/models/basecompletion.py +++ b/qutebrowser/models/basecompletion.py @@ -44,7 +44,7 @@ class BaseCompletionModel(QStandardItemModel): def __init__(self, parent=None): super().__init__(parent) - self.setColumnCount(2) + self.setColumnCount(3) def _get_marks(self, needle, haystack): """Return the marks for needle in haystack. @@ -95,19 +95,29 @@ class BaseCompletionModel(QStandardItemModel): self.appendRow(cat) return cat - def new_item(self, cat, name, desc=''): + def new_item(self, cat, name, desc='', misc=None): """Add a new item to a category. Args: cat: The parent category. name: The name of the item. desc: The description of the item. + misc: Misc text to display. + + Return: + A (nameitem, descitem, miscitem) tuple. """ nameitem = QStandardItem(name) descitem = QStandardItem(desc) + if misc is None: + miscitem = QStandardItem() + else: + miscitem = QStandardItem(misc) idx = cat.rowCount() cat.setChild(idx, 0, nameitem) cat.setChild(idx, 1, descitem) + cat.setChild(idx, 2, miscitem) + return nameitem, descitem, miscitem def flags(self, index): """Return the item flags for index. diff --git a/qutebrowser/models/completion.py b/qutebrowser/models/completion.py index a6e71280c..3da459ff2 100644 --- a/qutebrowser/models/completion.py +++ b/qutebrowser/models/completion.py @@ -40,12 +40,17 @@ class SettingSectionCompletionModel(BaseCompletionModel): class SettingOptionCompletionModel(BaseCompletionModel): - """A CompletionModel filled with settings and their descriptions.""" + """A CompletionModel filled with settings and their descriptions. + + Attributes: + misc_items: A dict of the misc. column items which will be set later. + """ # pylint: disable=abstract-method def __init__(self, section, parent=None): super().__init__(parent) + self.misc_items = {} cat = self.new_category("Config options for {}".format(section)) sectdata = configdata.DATA[section] for name, _ in sectdata.items(): @@ -53,7 +58,11 @@ class SettingOptionCompletionModel(BaseCompletionModel): desc = sectdata.descriptions[name] except (KeyError, AttributeError): desc = "" - self.new_item(cat, name, desc) + value = config.get(section, name, raw=True) + _valitem, _descitem, miscitem = self.new_item(cat, name, desc, + value) + self.misc_items[section] = {} + self.misc_items[section][name] = miscitem class SettingValueCompletionModel(BaseCompletionModel):