Make it possible to explicitely sort categories
This commit is contained in:
parent
a3bfc97079
commit
055d341760
@ -82,16 +82,19 @@ class BaseCompletionModel(QStandardItemModel):
|
|||||||
marks = self._get_marks(needle, haystack)
|
marks = self._get_marks(needle, haystack)
|
||||||
self.setData(index, marks, Role.marks)
|
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.
|
"""Add a new category to the model.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
name: The name of the category to add.
|
name: The name of the category to add.
|
||||||
|
sort: The value to use for the sort role.
|
||||||
|
|
||||||
Return:
|
Return:
|
||||||
The created QStandardItem.
|
The created QStandardItem.
|
||||||
"""
|
"""
|
||||||
cat = QStandardItem(name)
|
cat = QStandardItem(name)
|
||||||
|
if sort is not None:
|
||||||
|
cat.setData(sort, Role.sort)
|
||||||
self.appendRow(cat)
|
self.appendRow(cat)
|
||||||
return cat
|
return cat
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ class SettingValueCompletionModel(BaseCompletionModel):
|
|||||||
|
|
||||||
def __init__(self, section, option=None, parent=None):
|
def __init__(self, section, option=None, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
cur_cat = self.new_category("Current")
|
cur_cat = self.new_category("Current", sort=0)
|
||||||
value = config.get(section, option, raw=True)
|
value = config.get(section, option, raw=True)
|
||||||
if not value:
|
if not value:
|
||||||
value = '""'
|
value = '""'
|
||||||
@ -104,7 +104,7 @@ class SettingValueCompletionModel(BaseCompletionModel):
|
|||||||
# Different type for each value (KeyValue)
|
# Different type for each value (KeyValue)
|
||||||
vals = configdata.DATA[section][option].typ.complete()
|
vals = configdata.DATA[section][option].typ.complete()
|
||||||
if vals is not None:
|
if vals is not None:
|
||||||
cat = self.new_category("Allowed")
|
cat = self.new_category("Allowed", sort=1)
|
||||||
for (val, desc) in vals:
|
for (val, desc) in vals:
|
||||||
self.new_item(cat, val, desc)
|
self.new_item(cat, val, desc)
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ Contains:
|
|||||||
|
|
||||||
from PyQt5.QtCore import QSortFilterProxyModel, QModelIndex
|
from PyQt5.QtCore import QSortFilterProxyModel, QModelIndex
|
||||||
|
|
||||||
|
from qutebrowser.models.basecompletion import Role
|
||||||
from qutebrowser.utils.log import completion as logger
|
from qutebrowser.utils.log import completion as logger
|
||||||
|
|
||||||
|
|
||||||
@ -146,6 +147,12 @@ class CompletionFilterModel(QSortFilterProxyModel):
|
|||||||
Return:
|
Return:
|
||||||
True if left < right, else False
|
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)
|
left = self.srcmodel.data(lindex)
|
||||||
right = self.srcmodel.data(rindex)
|
right = self.srcmodel.data(rindex)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user