Get rid of _model in completion widget

This commit is contained in:
Florian Bruhin 2014-06-03 12:53:07 +02:00
parent ff06e753df
commit 2648f283b9

View File

@ -48,7 +48,6 @@ class CompletionView(QTreeView):
Attributes: Attributes:
completer: The Completer instance to use. completer: The Completer instance to use.
_ignore_change: Whether to ignore the next completion update. _ignore_change: Whether to ignore the next completion update.
_model: The currently active filter model.
_lastmodel: The model set in the last iteration. _lastmodel: The model set in the last iteration.
_enabled: Whether showing the CompletionView is enabled. _enabled: Whether showing the CompletionView is enabled.
_height: The height to use for the CompletionView. _height: The height to use for the CompletionView.
@ -105,7 +104,6 @@ class CompletionView(QTreeView):
self.completer = Completer(self) self.completer = Completer(self)
self._enabled = config.get('completion', 'show') self._enabled = config.get('completion', 'show')
self._ignore_change = False self._ignore_change = False
self._model = None
self._lastmodel = None self._lastmodel = None
self._delegate = CompletionItemDelegate(self) self._delegate = CompletionItemDelegate(self)
@ -150,14 +148,14 @@ class CompletionView(QTreeView):
idx = self.selectionModel().currentIndex() idx = self.selectionModel().currentIndex()
if not idx.isValid(): if not idx.isValid():
# No item selected yet # No item selected yet
return self._model.first_item() return self.model().first_item()
while True: while True:
idx = self.indexAbove(idx) if upwards else self.indexBelow(idx) idx = self.indexAbove(idx) if upwards else self.indexBelow(idx)
# wrap around if we arrived at beginning/end # wrap around if we arrived at beginning/end
if not idx.isValid() and upwards: if not idx.isValid() and upwards:
return self._model.last_item() return self.model().last_item()
elif not idx.isValid() and not upwards: elif not idx.isValid() and not upwards:
idx = self._model.first_item() idx = self.model().first_item()
self.scrollTo(idx.parent()) self.scrollTo(idx.parent())
return idx return idx
elif idx.parent().isValid(): elif idx.parent().isValid():
@ -191,11 +189,10 @@ class CompletionView(QTreeView):
""" """
logger.debug("Setting model to {}".format(model.__class__.__name__)) logger.debug("Setting model to {}".format(model.__class__.__name__))
self.setModel(model) self.setModel(model)
self._model = model
self.expandAll() self.expandAll()
self._resize_columns() self._resize_columns()
self._model.rowsRemoved.connect(self.resize_completion) model.rowsRemoved.connect(self.resize_completion)
self._model.rowsInserted.connect(self.resize_completion) model.rowsInserted.connect(self.resize_completion)
self.resize_completion.emit() self.resize_completion.emit()
@pyqtSlot(str, str) @pyqtSlot(str, str)
@ -250,13 +247,13 @@ class CompletionView(QTreeView):
pattern = parts[cursor_part] if parts else '' pattern = parts[cursor_part] if parts else ''
logger.debug("pattern: {}".format(pattern)) logger.debug("pattern: {}".format(pattern))
self._model.pattern = pattern self.model().pattern = pattern
if self._model.item_count == 0: if self.model().item_count == 0:
self.hide() self.hide()
return return
self._model.mark_all_items(pattern) self.model().mark_all_items(pattern)
if self._enabled: if self._enabled:
self.show() self.show()
@ -292,9 +289,9 @@ class CompletionView(QTreeView):
""" """
indexes = selected.indexes() indexes = selected.indexes()
if indexes: if indexes:
data = self._model.data(indexes[0]) data = self.model().data(indexes[0])
if data is not None: if data is not None:
if self._model.item_count == 1 and config.get( if self.model().item_count == 1 and config.get(
'completion', 'quick-complete'): 'completion', 'quick-complete'):
# If we only have one item, we want to apply it immediately # If we only have one item, we want to apply it immediately
# and go on to the next part. # and go on to the next part.