feat(ProfileShowcase): Update ProfileShowcaseModels to support nim models

1. Adapt and unify model rolenames
2. Add support for dirty state
3. Add reset
This commit is contained in:
Alex Jbanca 2024-02-28 14:01:31 +02:00 committed by Alex Jbanca
parent 5a3bca9a51
commit fbcd90ef3b
4 changed files with 249 additions and 7 deletions

View File

@ -31,6 +31,15 @@ QObject {
*/
readonly property alias hiddenModel: hidden
/**
* Returns dirty state of the showcase model.
*/
readonly property alias dirty: writable.dirty
function revert() {
writable.revert()
}
function currentState() {
return writable.currentState()
}

View File

@ -0,0 +1,212 @@
import QtQml 2.15
import StatusQ 0.1
import StatusQ.Core.Utils 0.1
import SortFilterProxyModel 0.2
QObject {
id: root
// input models
property alias communitiesSourceModel: communityRenamingSource.sourceModel
property alias communitiesShowcaseModel: communityRenamingShowcase.sourceModel
// adapted models
readonly property alias adaptedCommunitiesSourceModel: communityRenamingSource
readonly property alias adaptedCommunitiesShowcaseModel: communityRenamingShowcase
// input models
property alias accountsSourceModel: accountsRenamingSource.sourceModel
property alias accountsShowcaseModel: accountsRenamingShowcase.sourceModel
// adapted models
readonly property alias adaptedAccountsSourceModel: accountsRenamingSource
readonly property alias adaptedAccountsShowcaseModel: accountsRenamingShowcase
// input models
property alias collectiblesSourceModel: collectiblesRenamingSource.sourceModel
property alias collectiblesShowcaseModel: collectiblesRenamingShowcase.sourceModel
// adapted models
readonly property alias adaptedCollectiblesSourceModel: collectiblesRenamingSource
readonly property alias adaptedCollectiblesShowcaseModel: collectiblesRenamingShowcase
RolesRenamingModel {
id: communityRenamingSource
mapping: [
RoleRename {
from: "id"
to: "key"
}
]
}
RolesRenamingModel {
id: communityRenamingShowcase
mapping: [
RoleRename {
from: "id"
to: "key"
},
RoleRename {
from: "order"
to: "position"
},
RoleRename {
from: "showcaseVisibility"
to: "visibility"
},
// Removing model duplicates
// TODO: remove this when the lightweigth model is used
// https://github.com/status-im/status-desktop/issues/13688
RoleRename {
from: "name"
to: "_name"
},
RoleRename {
from: "memberRole"
to: "_memberRole"
},
RoleRename {
from: "image"
to: "_image"
},
RoleRename {
from: "color"
to: "_color"
},
RoleRename {
from: "description"
to: "_description"
},
RoleRename {
from: "membersCount"
to: "_membersCount"
},
RoleRename {
from: "loading"
to: "_loading"
}
]
}
RolesRenamingModel {
id: accountsRenamingSource
mapping: [
RoleRename {
from: "address"
to: "key"
},
RoleRename {
from: "position"
to: "positions"
}
]
}
RolesRenamingModel {
id: accountsRenamingShowcase
mapping: [
RoleRename {
from: "address"
to: "key"
},
RoleRename {
from: "order"
to: "position"
},
RoleRename {
from: "showcaseVisibility"
to: "visibility"
},
// Removing model duplicates
// TODO: remove this when the lightweigth model is used
// https://github.com/status-im/status-desktop/issues/13688
RoleRename {
from: "name"
to: "_name"
},
RoleRename {
from: "emoji"
to: "_emoji"
},
RoleRename {
from: "colorId"
to: "_colorId"
}
]
}
RolesRenamingModel {
id: collectiblesRenamingSource
sourceModel: root.collectiblesSourceModel
mapping: [
RoleRename {
from: "uid"
to: "key"
}
]
}
RolesRenamingModel {
id: collectiblesRenamingShowcase
sourceModel: root.collectiblesShowcaseModel
mapping: [
RoleRename {
from: "uid"
to: "key"
},
RoleRename {
from: "order"
to: "position"
},
RoleRename {
from: "showcaseVisibility"
to: "visibility"
},
// Removing model duplicates
// TODO: remove this when the lightweigth model is used
// https://github.com/status-im/status-desktop/issues/13688
RoleRename {
from: "chainId"
to: "_chainId"
},
RoleRename {
from: "contractAddress"
to: "_contractAddress"
},
RoleRename {
from: "tokenId"
to: "_tokenId"
},
RoleRename {
from: "name"
to: "_name"
},
RoleRename {
from: "imageUrl"
to: "_imageUrl"
},
RoleRename {
from: "backgroundColor"
to: "_backgroundColor"
},
RoleRename {
from: "collectionName"
to: "_collectionName"
},
RoleRename {
from: "isLoading"
to: "_isLoading"
},
RoleRename {
from: "communityId"
to: "_communityId"
}
]
}
}

View File

@ -10,11 +10,20 @@ import utils 1.0
QObject {
id: root
// GENERAL
readonly property bool dirty: communities.dirty || accounts.dirty || collectibles.dirty
function revert() {
communities.revert()
accounts.revert()
collectibles.revert()
}
// COMMUNITIES
// Input models
property alias communitiesSourceModel: communities.sourceModel
property alias communitiesShowcaseModel: communities.showcaseModel
property alias communitiesSourceModel: modelAdapter.communitiesSourceModel
property alias communitiesShowcaseModel: modelAdapter.communitiesShowcaseModel
// Output models
readonly property alias communitiesVisibleModel: communities.visibleModel
@ -36,8 +45,8 @@ QObject {
// ACCOUNTS
// Input models
property alias accountsSourceModel: accounts.sourceModel
property alias accountsShowcaseModel: accounts.showcaseModel
property alias accountsSourceModel: modelAdapter.accountsSourceModel
property alias accountsShowcaseModel: modelAdapter.accountsShowcaseModel
// Output models
readonly property alias accountsVisibleModel: accounts.visibleModel
@ -66,8 +75,8 @@ QObject {
// COLLECTIBLES
// Input models
property alias collectiblesSourceModel: collectiblesFilter.sourceModel
property alias collectiblesShowcaseModel: collectibles.showcaseModel
property alias collectiblesSourceModel: modelAdapter.collectiblesSourceModel
property alias collectiblesShowcaseModel: modelAdapter.collectiblesShowcaseModel
// Output models
readonly property alias collectiblesVisibleModel: collectibles.visibleModel
@ -86,25 +95,36 @@ QObject {
collectibles.changePosition(key, to)
}
ProfileShowcaseModelAdapter {
id: modelAdapter
}
ProfileShowcaseDirtyState {
id: communities
sourceModel: modelAdapter.adaptedCommunitiesSourceModel
showcaseModel: modelAdapter.adaptedCommunitiesShowcaseModel
}
ProfileShowcaseDirtyState {
id: accounts
sourceModel: modelAdapter.adaptedAccountsSourceModel
showcaseModel: modelAdapter.adaptedAccountsShowcaseModel
}
ProfileShowcaseDirtyState {
id: collectibles
sourceModel: collectiblesFilter
showcaseModel: modelAdapter.adaptedCollectiblesShowcaseModel
}
SortFilterProxyModel {
id: collectiblesFilter
delayed: true
sourceModel: modelAdapter.adaptedCollectiblesSourceModel
proxyRoles: FastExpressionRole {
name: "maxVisibility"

View File

@ -1,3 +1,4 @@
ProfileShowcaseDirtyState 1.0 ProfileShowcaseDirtyState.qml
ProfileShowcaseModelAdapter 1.0 ProfileShowcaseModelAdapter.qml
ProfileShowcaseModels 1.0 ProfileShowcaseModels.qml
VisibilityAndPositionDirtyStateModel 1.0 VisibilityAndPositionDirtyStateModel.qml