ListModel.updateItem() ignore_roles → no_update

This commit is contained in:
miruka 2019-05-14 19:44:40 -04:00
parent 0b32bf2738
commit 606771735a
3 changed files with 13 additions and 13 deletions

View File

@ -26,15 +26,15 @@ class RoomCategory(ListItem):
class Room(ListItem): class Room(ListItem):
_required_init_values = {"roomId", "displayName"} _required_init_values = {"roomId", "displayName", "members"}
_constant = {"roomId"} _constant = {"roomId", "members"}
roomId: str = "" roomId: str = ""
displayName: str = "" displayName: str = ""
topic: Optional[str] = None topic: Optional[str] = None
lastEventDateTime: Optional[QDateTime] = None lastEventDateTime: Optional[QDateTime] = None
typingMembers: List[str] = [] typingMembers: List[str] = []
members: List[str] = [] members: ListModel = ListModel()
inviter: Optional[Dict[str, str]] = None inviter: Optional[Dict[str, str]] = None
leftEvent: Optional[Dict[str, str]] = None leftEvent: Optional[Dict[str, str]] = None

View File

@ -281,7 +281,7 @@ class ListModel(QAbstractListModel):
def updateItem(self, def updateItem(self,
index: Index, index: Index,
value: NewItem, value: NewItem,
ignore_roles: Sequence[str] = ()) -> int: no_update: Sequence[str] = ()) -> int:
value = self._convert_new_value(value) value = self._convert_new_value(value)
i_index: int = self.indexWhere(index, _can_use_default_factory=False) \ i_index: int = self.indexWhere(index, _can_use_default_factory=False) \
@ -292,7 +292,7 @@ class ListModel(QAbstractListModel):
updated_roles: Set[int] = set() updated_roles: Set[int] = set()
for role_name, role_num in self.roleNumbers().items(): for role_name, role_num in self.roleNumbers().items():
if role_name not in ignore_roles: if role_name not in no_update:
old_value = getattr(to_update, role_name) old_value = getattr(to_update, role_name)
new_value = getattr(value, role_name) new_value = getattr(value, role_name)
@ -321,10 +321,10 @@ class ListModel(QAbstractListModel):
update_with: NewItem, update_with: NewItem,
new_index_if_insert: Optional[int] = None, new_index_if_insert: Optional[int] = None,
new_index_if_update: Optional[int] = None, new_index_if_update: Optional[int] = None,
ignore_roles: Sequence[str] = ()) -> None: no_update: Sequence[str] = ()) -> None:
try: try:
index = self.updateItem( index = self.updateItem(
where_main_key_is, update_with, ignore_roles where_main_key_is, update_with, no_update
) )
except (IndexError, ValueError): except (IndexError, ValueError):
self.insert(new_index_if_insert or len(self), update_with) self.insert(new_index_if_insert or len(self), update_with)

View File

@ -148,7 +148,7 @@ class SignalManager(QObject):
displayName = get_displayname(self, user), displayName = get_displayname(self, user),
devices = ListModel() devices = ListModel()
), ),
ignore_roles = ("devices",), no_update = ("devices",),
) )
@ -175,7 +175,7 @@ class SignalManager(QObject):
lastEventDateTime = QDateTime.currentDateTime(), # FIXME lastEventDateTime = QDateTime.currentDateTime(), # FIXME
members = list(nio_room.users.keys()), members = list(nio_room.users.keys()),
), ),
ignore_roles = ("typingMembers"), no_update = ("typingMembers"),
) )
signal = self.roomCategoryChanged signal = self.roomCategoryChanged
@ -202,7 +202,7 @@ class SignalManager(QObject):
topic = nio_room.topic, topic = nio_room.topic,
members = list(nio_room.users.keys()), members = list(nio_room.users.keys()),
), ),
ignore_roles = ("typingMembers", "lastEventDateTime"), no_update = ("typingMembers", "lastEventDateTime"),
) )
signal = self.roomCategoryChanged signal = self.roomCategoryChanged
@ -237,7 +237,7 @@ class SignalManager(QObject):
if left_time else QDateTime.currentDateTime() if left_time else QDateTime.currentDateTime()
), ),
), ),
ignore_roles = ("members", "lastEventDateTime"), no_update = ("members", "lastEventDateTime"),
) )
signal = self.roomCategoryChanged signal = self.roomCategoryChanged