From 3ec51b9253d99d2ff7fcda51efd31b451b70bc9d Mon Sep 17 00:00:00 2001 From: miruka Date: Sun, 14 Apr 2019 14:32:51 -0400 Subject: [PATCH] Fix room subtitle reloading Replace the "reloadThis" ListModel hack by an actual signal, works when the subtitle is displayed in more than one place (e.g. two accounts in the same room connected). --- harmonyqml/backend/model/list_model.py | 24 ++++++++----------- .../components/side_pane/RoomDelegate.qml | 12 ++++++++-- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/harmonyqml/backend/model/list_model.py b/harmonyqml/backend/model/list_model.py index 2d7f1e44..d4e76021 100644 --- a/harmonyqml/backend/model/list_model.py +++ b/harmonyqml/backend/model/list_model.py @@ -5,13 +5,16 @@ from typing import ( from namedlist import namedlist from PyQt5.QtCore import ( - QAbstractListModel, QModelIndex, QObject, Qt, pyqtProperty, pyqtSlot + QAbstractListModel, QModelIndex, QObject, Qt, pyqtProperty, pyqtSignal, + pyqtSlot ) NewValue = Union[Mapping[str, Any], Sequence] class ListModel(QAbstractListModel): + changed = pyqtSignal() + def __init__(self, initial_data: Optional[List[NewValue]] = None, parent: Optional[QObject] = None) -> None: @@ -20,8 +23,6 @@ class ListModel(QAbstractListModel): self._roles: Tuple[str, ...] = () self._list: list = [] - self._update_count: int = 0 - if initial_data: self.extend(initial_data) @@ -115,7 +116,7 @@ class ListModel(QAbstractListModel): self.beginInsertRows(QModelIndex(), index, index) self._list.insert(index, value) self.endInsertRows() - self._update_count += 1 + self.changed.emit() @pyqtSlot(list) @@ -135,7 +136,7 @@ class ListModel(QAbstractListModel): value = self._convert_new_value(value) self._list[index] = value self.dataChanged.emit(qidx, qidx, self.roleNames()) - self._update_count += 1 + self.changed.emit() @pyqtSlot(int, str, "QVariant") @@ -143,7 +144,7 @@ class ListModel(QAbstractListModel): self._list[index][self._roles.index(prop)] = value qidx = QAbstractListModel.index(self, index, 0) self.dataChanged.emit(qidx, qidx, self.roleNames()) - self._update_count += 1 + self.changed.emit() # pylint: disable=invalid-name @@ -173,7 +174,7 @@ class ListModel(QAbstractListModel): self._list[to:to] = cut self.endMoveRows() - self._update_count += 1 + self.changed.emit() @pyqtSlot(int) @@ -181,7 +182,7 @@ class ListModel(QAbstractListModel): self.beginRemoveRows(QModelIndex(), index, index) del self._list[index] self.endRemoveRows() - self._update_count += 1 + self.changed.emit() @pyqtSlot() @@ -190,9 +191,4 @@ class ListModel(QAbstractListModel): self.beginRemoveRows(QModelIndex(), 0, self.rowCount()) self._list.clear() self.endRemoveRows() - self._update_count += 1 - - - @pyqtProperty(int, constant=True) - def reloadThis(self): - return self._update_count + self.changed.emit() diff --git a/harmonyqml/components/side_pane/RoomDelegate.qml b/harmonyqml/components/side_pane/RoomDelegate.qml index d5b88ba2..e6ef8934 100644 --- a/harmonyqml/components/side_pane/RoomDelegate.qml +++ b/harmonyqml/components/side_pane/RoomDelegate.qml @@ -39,10 +39,18 @@ MouseArea { rightPadding: leftPadding } Base.HLabel { + function get_text() { + return SidePaneJS.get_last_room_event_text(room_id) + } + + Connections { + target: Backend.models.roomEvents.get(room_id) + onChanged: subtitleLabel.text = subtitleLabel.get_text() + } + id: subtitleLabel visible: text !== "" - text: Backend.models.roomEvents.get(room_id).reloadThis, - SidePaneJS.get_last_room_event_text(room_id) + text: get_text() textFormat: Text.StyledText font.pixelSize: smallSize