Use a Deque for roomEvents's ListModel

- Take a custom container callable for ListModel __init__ (defaults to
  list, must be a MutableSequence)

- Use a Deque for roomEvents, which is much faster for inserting
  new items at the beginning.
This commit is contained in:
miruka
2019-04-17 17:07:20 -04:00
parent f0dab1801a
commit 9e5e2c6718
4 changed files with 31 additions and 28 deletions

View File

@@ -1,4 +1,4 @@
from typing import Any, DefaultDict
from typing import Any, Callable, DefaultDict, MutableSequence
from PyQt5.QtCore import QObject, pyqtSlot
@@ -6,12 +6,14 @@ from .list_model import ListModel
class ListModelMap(QObject):
def __init__(self) -> None:
def __init__(self, models_container: Callable[..., MutableSequence] = list
) -> None:
super().__init__()
# Set the parent to prevent item garbage-collection on the C++ side
self.dict: DefaultDict[Any, ListModel] = \
DefaultDict(lambda: ListModel(parent=self))
DefaultDict(lambda: ListModel(parent = self,
container = models_container))
@pyqtSlot(str, result="QVariant")