Make it possible to explicitely sort categories

This commit is contained in:
Florian Bruhin 2014-06-04 07:11:20 +02:00
parent a3bfc97079
commit 055d341760
3 changed files with 13 additions and 3 deletions

View File

@ -82,16 +82,19 @@ class BaseCompletionModel(QStandardItemModel):
marks = self._get_marks(needle, haystack)
self.setData(index, marks, Role.marks)
def new_category(self, name):
def new_category(self, name, sort=None):
"""Add a new category to the model.
Args:
name: The name of the category to add.
sort: The value to use for the sort role.
Return:
The created QStandardItem.
"""
cat = QStandardItem(name)
if sort is not None:
cat.setData(sort, Role.sort)
self.appendRow(cat)
return cat

View File

@ -89,7 +89,7 @@ class SettingValueCompletionModel(BaseCompletionModel):
def __init__(self, section, option=None, parent=None):
super().__init__(parent)
cur_cat = self.new_category("Current")
cur_cat = self.new_category("Current", sort=0)
value = config.get(section, option, raw=True)
if not value:
value = '""'
@ -104,7 +104,7 @@ class SettingValueCompletionModel(BaseCompletionModel):
# Different type for each value (KeyValue)
vals = configdata.DATA[section][option].typ.complete()
if vals is not None:
cat = self.new_category("Allowed")
cat = self.new_category("Allowed", sort=1)
for (val, desc) in vals:
self.new_item(cat, val, desc)

View File

@ -23,6 +23,7 @@ Contains:
from PyQt5.QtCore import QSortFilterProxyModel, QModelIndex
from qutebrowser.models.basecompletion import Role
from qutebrowser.utils.log import completion as logger
@ -146,6 +147,12 @@ class CompletionFilterModel(QSortFilterProxyModel):
Return:
True if left < right, else False
"""
left_sort = self.srcmodel.data(lindex, role=Role.sort)
right_sort = self.srcmodel.data(rindex, role=Role.sort)
if left_sort is not None and right_sort is not None:
return left_sort < right_sort
left = self.srcmodel.data(lindex)
right = self.srcmodel.data(rindex)