From 95f6350e8ff6a1d66f6acbfcd47c193389a4771d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Tinkl?= Date: Thu, 7 Sep 2023 15:48:57 +0200 Subject: [PATCH] feat: Passing an empty seq to dataChanged doesn't apply all roles When calling `QAIM.dataChanged(index, index, [roles])`, passing nothing (ie omitting the paramater altogether), an empty array `[]`, or an empty sequence `@[]` means "all roles", just like the C++ counterpart in https://doc.qt.io/qt-5/qabstractitemmodel.html#dataChanged Fixes #11830 --- .../main/browser_section/bookmark/model.nim | 3 +- .../models/curated_community_model.nim | 18 ++-------- .../profile_section/wallet/accounts/model.nim | 5 ++- .../wallet_section/send/network_model.nim | 15 +++----- .../shared_models/link_preview_model.nim | 16 +-------- .../modules/shared_models/message_model.nim | 10 ++---- .../shared_models/message_reaction_model.nim | 8 ++--- .../modules/shared_models/section_model.nim | 34 +------------------ .../shared_models/token_permissions_model.nim | 4 +-- vendor/DOtherSide/lib/src/DOtherSide.cpp | 7 ++-- vendor/nimqml | 2 +- 11 files changed, 27 insertions(+), 95 deletions(-) diff --git a/src/app/modules/main/browser_section/bookmark/model.nim b/src/app/modules/main/browser_section/bookmark/model.nim index 4718a67fbb..22c6eca7f7 100644 --- a/src/app/modules/main/browser_section/bookmark/model.nim +++ b/src/app/modules/main/browser_section/bookmark/model.nim @@ -123,6 +123,5 @@ QtObject: defer: bottomRight.delete self.items[index] = item - self.dataChanged(topLeft, bottomRight, @[ModelRole.Name.int, ModelRole.Url.int, ModelRole.ImageUrl.int]) + self.dataChanged(topLeft, bottomRight) self.modelChanged() - diff --git a/src/app/modules/main/communities/models/curated_community_model.nim b/src/app/modules/main/communities/models/curated_community_model.nim index b962862d9e..77023ba30f 100644 --- a/src/app/modules/main/communities/models/curated_community_model.nim +++ b/src/app/modules/main/communities/models/curated_community_model.nim @@ -136,21 +136,9 @@ QtObject: let idx = self.findIndexById(item.getId()) if idx > -1: let index = self.createIndex(idx, 0, nil) + defer: index.delete self.items[idx] = item - self.dataChanged(index, index, @[ - ModelRole.Name.int, - ModelRole.Available.int, - ModelRole.Description.int, - ModelRole.Icon.int, - ModelRole.Banner.int, - ModelRole.Featured.int, - ModelRole.Members.int, - ModelRole.ActiveMembers.int, - ModelRole.Color.int, - ModelRole.Popularity.int, - ModelRole.Tags.int, - ModelRole.Permissions.int, - ]) + self.dataChanged(index, index) else: let parentModelIndex = newQModelIndex() defer: parentModelIndex.delete @@ -164,4 +152,4 @@ QtObject: if idx == -1: echo "Tried to set permission items on an item that doesn't exist. Item ID: ", itemId return - self.items[idx].setPermissionModelItems(items) \ No newline at end of file + self.items[idx].setPermissionModelItems(items) diff --git a/src/app/modules/main/profile_section/wallet/accounts/model.nim b/src/app/modules/main/profile_section/wallet/accounts/model.nim index 9a3639df91..617e5fcf45 100644 --- a/src/app/modules/main/profile_section/wallet/accounts/model.nim +++ b/src/app/modules/main/profile_section/wallet/accounts/model.nim @@ -74,9 +74,8 @@ QtObject: item.colorId = account.colorId item.emoji = account.emoji let index = self.createIndex(i, 0, nil) - self.dataChanged(index, index, @[ModelRole.Name.int]) - self.dataChanged(index, index, @[ModelRole.ColorId.int]) - self.dataChanged(index, index, @[ModelRole.Emoji.int]) + defer: index.delete + self.dataChanged(index, index, @[ModelRole.Name.int, ModelRole.ColorId.int, ModelRole.Emoji.int]) break i.inc diff --git a/src/app/modules/main/wallet_section/send/network_model.nim b/src/app/modules/main/wallet_section/send/network_model.nim index 2b653e7fd5..2309dfa2e0 100644 --- a/src/app/modules/main/wallet_section/send/network_model.nim +++ b/src/app/modules/main/wallet_section/send/network_model.nim @@ -143,14 +143,12 @@ QtObject: proc reset*(self: NetworkModel) = for i in 0 ..< self.items.len: let index = self.createIndex(i, 0, nil) + defer: index.delete self.items[i].amountIn = "" self.items[i].amountOut = "" self.items[i].resetToNetworks() self.items[i].hasGas = true - self.dataChanged(index, index, @[ModelRole.AmountIn.int]) - self.dataChanged(index, index, @[ModelRole.ToNetworks.int]) - self.dataChanged(index, index, @[ModelRole.HasGas.int]) - self.dataChanged(index, index, @[ModelRole.AmountOut.int]) + self.dataChanged(index, index, @[ModelRole.AmountIn.int, ModelRole.ToNetworks.int, ModelRole.HasGas.int, ModelRole.AmountOut.int]) proc updateTokenBalanceForSymbol*(self: NetworkModel, chainId: int, tokenBalance: CurrencyAmount) = for i in 0 ..< self.items.len: @@ -163,14 +161,12 @@ QtObject: for i in 0 ..< self.items.len: if path.getfromNetwork() == self.items[i].getChainId(): let index = self.createIndex(i, 0, nil) + defer: index.delete self.items[i].amountIn = path.getAmountIn() self.items[i].toNetworks = path.getToNetwork() self.items[i].hasGas = hasGas self.items[i].locked = path.getAmountInLocked() - self.dataChanged(index, index, @[ModelRole.AmountIn.int]) - self.dataChanged(index, index, @[ModelRole.ToNetworks.int]) - self.dataChanged(index, index, @[ModelRole.HasGas.int]) - self.dataChanged(index, index, @[ModelRole.Locked.int]) + self.dataChanged(index, index, @[ModelRole.AmountIn.int, ModelRole.ToNetworks.int, ModelRole.HasGas.int, ModelRole.Locked.int]) proc updateToNetworks*(self: NetworkModel, path: SuggestedRouteItem) = for i in 0 ..< self.items.len: @@ -211,8 +207,7 @@ QtObject: if $self.items[i].getChainId() == chainID: self.items[i].isPreferred = true self.items[i].isEnabled = true - self.dataChanged(index, index, @[ModelRole.IsPreferred.int]) - self.dataChanged(index, index, @[ModelRole.IsEnabled.int]) + self.dataChanged(index, index, @[ModelRole.IsPreferred.int, ModelRole.IsEnabled.int]) except: discard diff --git a/src/app/modules/shared_models/link_preview_model.nim b/src/app/modules/shared_models/link_preview_model.nim index 42698f4311..0a3b3eb458 100644 --- a/src/app/modules/shared_models/link_preview_model.nim +++ b/src/app/modules/shared_models/link_preview_model.nim @@ -74,20 +74,6 @@ QtObject: ModelRole.ThumbnailDataUri.int:"thumbnailDataUri", }.toTable - method allLinkPreviewRoles(self: Model): seq[int] = - return @[ - ModelRole.Url.int, - ModelRole.Unfurled.int, - ModelRole.Hostname.int, - ModelRole.Title.int, - ModelRole.Description.int, - ModelRole.LinkType.int, - ModelRole.ThumbnailWidth.int, - ModelRole.ThumbnailHeight.int, - ModelRole.ThumbnailUrl.int, - ModelRole.ThumbnailDataUri.int, - ] - method data(self: Model, index: QModelIndex, role: int): QVariant = if (not index.isValid): return @@ -148,4 +134,4 @@ QtObject: item.linkPreview = linkPreviews[item.linkPreview.url] let modelIndex = self.createIndex(row, 0, nil) defer: modelIndex.delete - self.dataChanged(modelIndex, modelIndex, self.allLinkPreviewRoles()) + self.dataChanged(modelIndex, modelIndex) diff --git a/src/app/modules/shared_models/message_model.nim b/src/app/modules/shared_models/message_model.nim index a5332e021d..becb4cd080 100644 --- a/src/app/modules/shared_models/message_model.nim +++ b/src/app/modules/shared_models/message_model.nim @@ -69,7 +69,6 @@ QtObject: type Model* = ref object of QAbstractListModel items*: seq[Item] - allKeys: seq[int] firstUnseenMessageId: string proc delete(self: Model) = @@ -82,12 +81,6 @@ QtObject: proc newModel*(): Model = new(result, delete) result.setup - - # This is just a clean way to have all roles in a seq, without typing long seq manualy, and this way we're sure that - # all new added roles will be included here as well. - for i in result.roleNames().keys: - result.allKeys.add(i) - result.firstUnseenMessageId = "" proc `$`*(self: Model): string = @@ -320,7 +313,8 @@ QtObject: proc updateItemAtIndex(self: Model, index: int) = let ind = self.createIndex(index, 0, nil) - self.dataChanged(ind, ind, self.allKeys) + defer: ind.delete + self.dataChanged(ind, ind) proc findIndexForMessageId*(self: Model, messageId: string): int = result = -1 diff --git a/src/app/modules/shared_models/message_reaction_model.nim b/src/app/modules/shared_models/message_reaction_model.nim index 7f05957356..353ae4d8a6 100644 --- a/src/app/modules/shared_models/message_reaction_model.nim +++ b/src/app/modules/shared_models/message_reaction_model.nim @@ -114,8 +114,8 @@ QtObject: return self.items[ind].addReaction(didIReactWithThisEmoji, userPublicKey, userDisplayName, reactionId) let index = self.createIndex(ind, 0, nil) - self.dataChanged(index, index, @[ModelRole.EmojiId.int, ModelRole.DidIReactWithThisEmoji.int, - ModelRole.NumberOfReactions.int, ModelRole.JsonArrayOfUsersReactedWithThisEmoji.int]) + defer: index.delete + self.dataChanged(index, index) else: let parentModelIndex = newQModelIndex() defer: parentModelIndex.delete @@ -147,5 +147,5 @@ QtObject: self.countChanged() else: let index = self.createIndex(ind, 0, nil) - self.dataChanged(index, index, @[ModelRole.EmojiId.int, ModelRole.DidIReactWithThisEmoji.int, - ModelRole.NumberOfReactions.int, ModelRole.JsonArrayOfUsersReactedWithThisEmoji.int]) + defer: index.delete + self.dataChanged(index, index) diff --git a/src/app/modules/shared_models/section_model.nim b/src/app/modules/shared_models/section_model.nim index 1a64eb215d..3b52115c8d 100644 --- a/src/app/modules/shared_models/section_model.nim +++ b/src/app/modules/shared_models/section_model.nim @@ -272,38 +272,7 @@ QtObject: self.items[index] = item let dataIndex = self.createIndex(index, 0, nil) defer: dataIndex.delete - self.dataChanged(dataIndex, dataIndex, @[ - ModelRole.Name.int, - ModelRole.MemberRole.int, - ModelRole.IsControlNode.int, - ModelRole.Description.int, - ModelRole.IntroMessage.int, - ModelRole.OutroMessage.int, - ModelRole.Image.int, - ModelRole.BannerImageData.int, - ModelRole.Icon.int, - ModelRole.Color.int, - ModelRole.Tags.int, - ModelRole.HasNotification.int, - ModelRole.NotificationsCount.int, - ModelRole.IsMember.int, - ModelRole.CanJoin.int, - ModelRole.Joined.int, - ModelRole.Spectated.int, - ModelRole.Access.int, - ModelRole.EnsOnly.int, - ModelRole.Muted.int, - ModelRole.MembersModel.int, - ModelRole.PendingRequestsToJoinModel.int, - ModelRole.HistoryArchiveSupportEnabled.int, - ModelRole.PinMessageAllMembersEnabled.int, - ModelRole.BannedMembersModel.int, - ModelRole.Encrypted.int, - ModelRole.CommunityTokensModel.int, - ModelRole.PendingMemberRequestsModel.int, - ModelRole.DeclinedMemberRequestsModel.int, - ModelRole.AmIBanned.int, - ]) + self.dataChanged(dataIndex, dataIndex) proc getNthEnabledItem*(self: SectionModel, nth: int): SectionItem = if nth >= 0 and nth < self.items.len: @@ -454,4 +423,3 @@ QtObject: for pubkey, revealedAccounts in communityMembersAirdropAddress.pairs: self.items[index].members.setAirdropAddress(pubkey, revealedAccounts) - diff --git a/src/app/modules/shared_models/token_permissions_model.nim b/src/app/modules/shared_models/token_permissions_model.nim index 14503df60a..19272bcd18 100644 --- a/src/app/modules/shared_models/token_permissions_model.nim +++ b/src/app/modules/shared_models/token_permissions_model.nim @@ -145,11 +145,11 @@ QtObject: self.items[idx].tokenCriteriaMet = item.tokenCriteriaMet let index = self.createIndex(idx, 0, nil) + defer: index.delete self.dataChanged(index, index, @[ - ModelRole.Id.int, - ModelRole.Key.int, ModelRole.Type.int, ModelRole.TokenCriteria.int, + ModelRole.ChatList.int, ModelRole.IsPrivate.int, ModelRole.TokenCriteriaMet.int ]) diff --git a/vendor/DOtherSide/lib/src/DOtherSide.cpp b/vendor/DOtherSide/lib/src/DOtherSide.cpp index b0989ee3cc..fade1155ab 100644 --- a/vendor/DOtherSide/lib/src/DOtherSide.cpp +++ b/vendor/DOtherSide/lib/src/DOtherSide.cpp @@ -1301,8 +1301,11 @@ void dos_qabstractitemmodel_dataChanged(::DosQAbstractItemModel *vptr, auto model = dynamic_cast(object); auto topLeft = static_cast(topLeftIndex); auto bottomRight = static_cast(bottomRightIndex); - auto roles = QVector(rolesArrayPtr, rolesArrayPtr + rolesArrayLength); - model->publicDataChanged(*topLeft, *bottomRight, roles); + if (rolesArrayPtr && rolesArrayLength > 0) { + model->publicDataChanged(*topLeft, *bottomRight, {rolesArrayPtr, rolesArrayPtr + rolesArrayLength}); + } else { + model->publicDataChanged(*topLeft, *bottomRight); + } } DosQModelIndex *dos_qabstractitemmodel_createIndex(::DosQAbstractItemModel *vptr, diff --git a/vendor/nimqml b/vendor/nimqml index 3f61ec4add..90f19ac030 160000 --- a/vendor/nimqml +++ b/vendor/nimqml @@ -1 +1 @@ -Subproject commit 3f61ec4addbd1e59c6936658258214a58b768c4a +Subproject commit 90f19ac030c28bbb4f89bf014afba344ca2941cb