Use an enum for user model roles.
This commit is contained in:
parent
83d8bc47c0
commit
a3bfc97079
@ -18,13 +18,16 @@
|
||||
"""The base completion model for completion in the command line.
|
||||
|
||||
Module attributes:
|
||||
ROLE_MARKS: The role index used for marks.
|
||||
Role: An enum of user defined model roles.
|
||||
"""
|
||||
|
||||
from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtGui import QStandardItemModel, QStandardItem
|
||||
|
||||
ROLE_MARKS = Qt.UserRole
|
||||
from qutebrowser.utils.usertypes import enum
|
||||
|
||||
|
||||
Role = enum('marks', 'sort', start=Qt.UserRole)
|
||||
|
||||
|
||||
class NoCompletionsError(Exception):
|
||||
@ -77,7 +80,7 @@ class BaseCompletionModel(QStandardItemModel):
|
||||
"""
|
||||
haystack = self.data(index)
|
||||
marks = self._get_marks(needle, haystack)
|
||||
self.setData(index, marks, ROLE_MARKS)
|
||||
self.setData(index, marks, Role.marks)
|
||||
|
||||
def new_category(self, name):
|
||||
"""Add a new category to the model.
|
||||
|
@ -38,7 +38,7 @@ class CompletionView(QTreeView):
|
||||
Based on QTreeView but heavily customized so root elements show as category
|
||||
headers, and children show as flat list.
|
||||
|
||||
Highlights completions based on marks in the ROLE_MARKS data.
|
||||
Highlights completions based on marks in the Role.marks data.
|
||||
|
||||
Class attributes:
|
||||
STYLESHEET: The stylesheet template for the CompletionView.
|
||||
|
@ -27,7 +27,7 @@ from PyQt5.QtGui import (QIcon, QPalette, QTextDocument, QTextOption,
|
||||
QTextCursor, QColor, QAbstractTextDocumentLayout)
|
||||
|
||||
import qutebrowser.config.config as config
|
||||
from qutebrowser.models.basecompletion import ROLE_MARKS
|
||||
from qutebrowser.models.basecompletion import Role
|
||||
from qutebrowser.config.style import get_stylesheet
|
||||
|
||||
|
||||
@ -188,7 +188,7 @@ class CompletionItemDelegate(QStyledItemDelegate):
|
||||
self._doc.setDocumentMargin(2)
|
||||
|
||||
if index.column() == 0:
|
||||
marks = index.data(ROLE_MARKS)
|
||||
marks = index.data(Role.marks)
|
||||
if marks is None:
|
||||
return
|
||||
for mark in marks:
|
||||
|
Loading…
Reference in New Issue
Block a user