sourcemodel and logging updates

This commit is contained in:
Florian Bruhin 2014-03-06 00:06:28 +01:00
parent bd4dba1ed3
commit e33b87f713
4 changed files with 23 additions and 35 deletions

View File

@ -17,6 +17,7 @@
"""The base completion model for completion in the command line."""
import logging
from PyQt5.QtCore import Qt, QVariant, QAbstractItemModel, QModelIndex
@ -160,11 +161,7 @@ class CompletionModel(QAbstractItemModel):
if not parent.isValid():
pitem = self._root
else:
try:
pitem = self._id_map[parent.internalId()]
except KeyError:
from qutebrowser.utils.debug import set_trace; set_trace()
pitem = self._id_map[parent.internalId()]
return len(pitem.children)
def data(self, index, role=Qt.DisplayRole):
@ -273,6 +270,9 @@ class CompletionModel(QAbstractItemModel):
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
0 <= column < self.columnCount(parent)):
pass

View File

@ -22,6 +22,8 @@ Contains:
"""
import logging
from PyQt5.QtCore import QSortFilterProxyModel, QModelIndex
@ -31,13 +33,11 @@ class CompletionFilterModel(QSortFilterProxyModel):
Attributes:
_pattern: The pattern to filter with, used in pattern property.
_srcmodel: The source model, accessed via the srcmodel property.
"""
def __init__(self, parent=None):
super().__init__(parent)
self._srcmodel = None
self._pattern = ''
@property
@ -61,31 +61,13 @@ class CompletionFilterModel(QSortFilterProxyModel):
self._pattern = val
self.invalidateFilter()
sortcol = 0
if self.srcmodel is not None:
if self.sourceModel() is not None:
try:
self.srcmodel.sort(sortcol)
self.sourceModel().sort(sortcol)
except NotImplementedError:
self.sort(sortcol)
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):
"""Return the first item in the model."""
cat = self.index(0, 0)
@ -96,6 +78,11 @@ class CompletionFilterModel(QSortFilterProxyModel):
cat = self.index(self.rowCount() - 1, 0)
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):
"""Custom filter implementation.
@ -112,8 +99,8 @@ class CompletionFilterModel(QSortFilterProxyModel):
"""
if parent == QModelIndex():
return True
idx = self.srcmodel.index(row, 0, parent)
data = self.srcmodel.data(idx).value()
idx = self.sourceModel().index(row, 0, parent)
data = self.sourceModel().data(idx).value()
# TODO more sophisticated filtering
if not self.pattern:
return True
@ -133,8 +120,8 @@ class CompletionFilterModel(QSortFilterProxyModel):
True if left < right, else False
"""
left = self.srcmodel.data(lindex).value()
right = self.srcmodel.data(rindex).value()
left = self.sourceModel().data(lindex).value()
right = self.sourceModel().data(rindex).value()
leftstart = left.startswith(self.pattern)
rightstart = right.startswith(self.pattern)

View File

@ -160,7 +160,7 @@ class CompletionView(QTreeView):
model: A QAbstractItemModel with available completions.
"""
self.model.srcmodel = self._completion_models[model]
self.model.setSourceModel(self._completion_models[model])
self.expandAll()
self.resizeColumnToContents(0)
@ -201,7 +201,7 @@ class CompletionView(QTreeView):
if text:
text = text.split()[-1]
self.model.pattern = text
self.model.srcmodel.mark_all_items(text)
self.model.sourceModel().mark_all_items(text)
if self._enabled:
self.show()

View File

@ -111,7 +111,8 @@ class CrashDialog(QDialog):
]
chunks = []
for (header, body) in outputs:
h = '==== {} ===='.format(header)
chunks.append('\n'.join([h, body]))
if body is not None:
h = '==== {} ===='.format(header)
chunks.append('\n'.join([h, body]))
return '\n\n'.join(chunks)