sourcemodel and logging updates
This commit is contained in:
parent
bd4dba1ed3
commit
e33b87f713
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
"""The base completion model for completion in the command line."""
|
"""The base completion model for completion in the command line."""
|
||||||
|
|
||||||
|
import logging
|
||||||
from PyQt5.QtCore import Qt, QVariant, QAbstractItemModel, QModelIndex
|
from PyQt5.QtCore import Qt, QVariant, QAbstractItemModel, QModelIndex
|
||||||
|
|
||||||
|
|
||||||
@ -160,11 +161,7 @@ class CompletionModel(QAbstractItemModel):
|
|||||||
if not parent.isValid():
|
if not parent.isValid():
|
||||||
pitem = self._root
|
pitem = self._root
|
||||||
else:
|
else:
|
||||||
try:
|
|
||||||
pitem = self._id_map[parent.internalId()]
|
pitem = self._id_map[parent.internalId()]
|
||||||
except KeyError:
|
|
||||||
from qutebrowser.utils.debug import set_trace; set_trace()
|
|
||||||
|
|
||||||
return len(pitem.children)
|
return len(pitem.children)
|
||||||
|
|
||||||
def data(self, index, role=Qt.DisplayRole):
|
def data(self, index, role=Qt.DisplayRole):
|
||||||
@ -273,6 +270,9 @@ class CompletionModel(QAbstractItemModel):
|
|||||||
A generated QModelIndex or an invalid QModelIndex on failure.
|
A generated QModelIndex or an invalid QModelIndex on failure.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
if parent.model() is not None and parent.model() is not self:
|
||||||
|
logging.debug("row {}, column {}, parent {}, parentmodel {}, self {}".format(row, column, parent, parent.model(), self))
|
||||||
|
from qutebrowser.utils.debug import set_trace; set_trace()
|
||||||
if (0 <= row < self.rowCount(parent) and
|
if (0 <= row < self.rowCount(parent) and
|
||||||
0 <= column < self.columnCount(parent)):
|
0 <= column < self.columnCount(parent)):
|
||||||
pass
|
pass
|
||||||
|
@ -22,6 +22,8 @@ Contains:
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
from PyQt5.QtCore import QSortFilterProxyModel, QModelIndex
|
from PyQt5.QtCore import QSortFilterProxyModel, QModelIndex
|
||||||
|
|
||||||
|
|
||||||
@ -31,13 +33,11 @@ class CompletionFilterModel(QSortFilterProxyModel):
|
|||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
_pattern: The pattern to filter with, used in pattern property.
|
_pattern: The pattern to filter with, used in pattern property.
|
||||||
_srcmodel: The source model, accessed via the srcmodel property.
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self._srcmodel = None
|
|
||||||
self._pattern = ''
|
self._pattern = ''
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -61,31 +61,13 @@ class CompletionFilterModel(QSortFilterProxyModel):
|
|||||||
self._pattern = val
|
self._pattern = val
|
||||||
self.invalidateFilter()
|
self.invalidateFilter()
|
||||||
sortcol = 0
|
sortcol = 0
|
||||||
if self.srcmodel is not None:
|
if self.sourceModel() is not None:
|
||||||
try:
|
try:
|
||||||
self.srcmodel.sort(sortcol)
|
self.sourceModel().sort(sortcol)
|
||||||
except NotImplementedError:
|
except NotImplementedError:
|
||||||
self.sort(sortcol)
|
self.sort(sortcol)
|
||||||
self.invalidate()
|
self.invalidate()
|
||||||
|
|
||||||
@property
|
|
||||||
def srcmodel(self):
|
|
||||||
"""Getter for srcmodel."""
|
|
||||||
return self._srcmodel
|
|
||||||
|
|
||||||
@srcmodel.setter
|
|
||||||
def srcmodel(self, model):
|
|
||||||
"""Set a new source model and clear the pattern.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
model: The new source model.
|
|
||||||
|
|
||||||
"""
|
|
||||||
# FIXME change this to a property
|
|
||||||
self.setSourceModel(model)
|
|
||||||
self._srcmodel = model
|
|
||||||
self.pattern = ''
|
|
||||||
|
|
||||||
def first_item(self):
|
def first_item(self):
|
||||||
"""Return the first item in the model."""
|
"""Return the first item in the model."""
|
||||||
cat = self.index(0, 0)
|
cat = self.index(0, 0)
|
||||||
@ -96,6 +78,11 @@ class CompletionFilterModel(QSortFilterProxyModel):
|
|||||||
cat = self.index(self.rowCount() - 1, 0)
|
cat = self.index(self.rowCount() - 1, 0)
|
||||||
return self.index(self.rowCount(cat) - 1, 0, cat)
|
return self.index(self.rowCount(cat) - 1, 0, cat)
|
||||||
|
|
||||||
|
def setSourceModel(self, model):
|
||||||
|
logging.debug("Setting source model: {}".format(model))
|
||||||
|
self.pattern = ''
|
||||||
|
super().setSourceModel(model)
|
||||||
|
|
||||||
def filterAcceptsRow(self, row, parent):
|
def filterAcceptsRow(self, row, parent):
|
||||||
"""Custom filter implementation.
|
"""Custom filter implementation.
|
||||||
|
|
||||||
@ -112,8 +99,8 @@ class CompletionFilterModel(QSortFilterProxyModel):
|
|||||||
"""
|
"""
|
||||||
if parent == QModelIndex():
|
if parent == QModelIndex():
|
||||||
return True
|
return True
|
||||||
idx = self.srcmodel.index(row, 0, parent)
|
idx = self.sourceModel().index(row, 0, parent)
|
||||||
data = self.srcmodel.data(idx).value()
|
data = self.sourceModel().data(idx).value()
|
||||||
# TODO more sophisticated filtering
|
# TODO more sophisticated filtering
|
||||||
if not self.pattern:
|
if not self.pattern:
|
||||||
return True
|
return True
|
||||||
@ -133,8 +120,8 @@ class CompletionFilterModel(QSortFilterProxyModel):
|
|||||||
True if left < right, else False
|
True if left < right, else False
|
||||||
|
|
||||||
"""
|
"""
|
||||||
left = self.srcmodel.data(lindex).value()
|
left = self.sourceModel().data(lindex).value()
|
||||||
right = self.srcmodel.data(rindex).value()
|
right = self.sourceModel().data(rindex).value()
|
||||||
|
|
||||||
leftstart = left.startswith(self.pattern)
|
leftstart = left.startswith(self.pattern)
|
||||||
rightstart = right.startswith(self.pattern)
|
rightstart = right.startswith(self.pattern)
|
||||||
|
@ -160,7 +160,7 @@ class CompletionView(QTreeView):
|
|||||||
model: A QAbstractItemModel with available completions.
|
model: A QAbstractItemModel with available completions.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self.model.srcmodel = self._completion_models[model]
|
self.model.setSourceModel(self._completion_models[model])
|
||||||
self.expandAll()
|
self.expandAll()
|
||||||
self.resizeColumnToContents(0)
|
self.resizeColumnToContents(0)
|
||||||
|
|
||||||
@ -201,7 +201,7 @@ class CompletionView(QTreeView):
|
|||||||
if text:
|
if text:
|
||||||
text = text.split()[-1]
|
text = text.split()[-1]
|
||||||
self.model.pattern = text
|
self.model.pattern = text
|
||||||
self.model.srcmodel.mark_all_items(text)
|
self.model.sourceModel().mark_all_items(text)
|
||||||
if self._enabled:
|
if self._enabled:
|
||||||
self.show()
|
self.show()
|
||||||
|
|
||||||
|
@ -111,6 +111,7 @@ class CrashDialog(QDialog):
|
|||||||
]
|
]
|
||||||
chunks = []
|
chunks = []
|
||||||
for (header, body) in outputs:
|
for (header, body) in outputs:
|
||||||
|
if body is not None:
|
||||||
h = '==== {} ===='.format(header)
|
h = '==== {} ===='.format(header)
|
||||||
chunks.append('\n'.join([h, body]))
|
chunks.append('\n'.join([h, body]))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user