2024-02-16 12:08:45 +00:00
|
|
|
import QtQml 2.15
|
|
|
|
|
|
|
|
import StatusQ 0.1
|
|
|
|
import StatusQ.Core.Utils 0.1
|
|
|
|
|
|
|
|
import SortFilterProxyModel 0.2
|
|
|
|
|
2024-02-20 13:26:56 +00:00
|
|
|
import utils 1.0
|
|
|
|
|
2024-02-16 12:08:45 +00:00
|
|
|
QObject {
|
|
|
|
id: root
|
|
|
|
|
2024-02-28 12:01:31 +00:00
|
|
|
// GENERAL
|
|
|
|
readonly property bool dirty: communities.dirty || accounts.dirty || collectibles.dirty
|
|
|
|
|
|
|
|
function revert() {
|
|
|
|
communities.revert()
|
|
|
|
accounts.revert()
|
|
|
|
collectibles.revert()
|
|
|
|
}
|
|
|
|
|
2024-02-16 12:08:45 +00:00
|
|
|
// COMMUNITIES
|
|
|
|
|
|
|
|
// Input models
|
2024-02-28 12:01:31 +00:00
|
|
|
property alias communitiesSourceModel: modelAdapter.communitiesSourceModel
|
|
|
|
property alias communitiesShowcaseModel: modelAdapter.communitiesShowcaseModel
|
2024-02-16 12:08:45 +00:00
|
|
|
|
|
|
|
// Output models
|
|
|
|
readonly property alias communitiesVisibleModel: communities.visibleModel
|
|
|
|
readonly property alias communitiesHiddenModel: communities.hiddenModel
|
|
|
|
|
|
|
|
// Methods
|
|
|
|
function communitiesCurrentState() {
|
|
|
|
return communities.currentState()
|
|
|
|
}
|
|
|
|
|
|
|
|
function setCommunityVisibility(key, visibility) {
|
|
|
|
communities.setVisibility(key, visibility)
|
|
|
|
}
|
|
|
|
|
|
|
|
function changeCommunityPosition(key, to) {
|
|
|
|
communities.changePosition(key, to)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ACCOUNTS
|
|
|
|
|
|
|
|
// Input models
|
2024-02-28 12:01:31 +00:00
|
|
|
property alias accountsSourceModel: modelAdapter.accountsSourceModel
|
|
|
|
property alias accountsShowcaseModel: modelAdapter.accountsShowcaseModel
|
2024-02-16 12:08:45 +00:00
|
|
|
|
|
|
|
// Output models
|
|
|
|
readonly property alias accountsVisibleModel: accounts.visibleModel
|
|
|
|
readonly property alias accountsHiddenModel: accounts.hiddenModel
|
|
|
|
|
|
|
|
// Methods
|
|
|
|
function accountsCurrentState() {
|
|
|
|
return accounts.currentState()
|
|
|
|
}
|
|
|
|
|
|
|
|
function setAccountVisibility(key, visibility) {
|
|
|
|
accounts.setVisibility(key, visibility)
|
|
|
|
}
|
|
|
|
|
|
|
|
function changeAccountPosition(key, to) {
|
|
|
|
accounts.changePosition(key, to)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Other
|
|
|
|
readonly property alias visibleAccountsList:
|
|
|
|
visibleAccountsConnections.visibleAccountsList
|
|
|
|
|
|
|
|
readonly property alias accountsVisibilityMap:
|
|
|
|
visibleAccountsConnections.accountsVisibilityMap
|
|
|
|
|
|
|
|
// COLLECTIBLES
|
|
|
|
|
|
|
|
// Input models
|
2024-02-28 12:01:31 +00:00
|
|
|
property alias collectiblesSourceModel: modelAdapter.collectiblesSourceModel
|
|
|
|
property alias collectiblesShowcaseModel: modelAdapter.collectiblesShowcaseModel
|
2024-02-16 12:08:45 +00:00
|
|
|
|
|
|
|
// Output models
|
|
|
|
readonly property alias collectiblesVisibleModel: collectibles.visibleModel
|
|
|
|
readonly property alias collectiblesHiddenModel: collectibles.hiddenModel
|
|
|
|
|
|
|
|
// Methods
|
|
|
|
function collectiblesCurrentState() {
|
|
|
|
return collectibles.currentState()
|
|
|
|
}
|
|
|
|
|
|
|
|
function setCollectibleVisibility(key, visibility) {
|
|
|
|
collectibles.setVisibility(key, visibility)
|
|
|
|
}
|
|
|
|
|
|
|
|
function changeCollectiblePosition(key, to) {
|
|
|
|
collectibles.changePosition(key, to)
|
|
|
|
}
|
|
|
|
|
2024-02-28 12:01:31 +00:00
|
|
|
ProfileShowcaseModelAdapter {
|
|
|
|
id: modelAdapter
|
|
|
|
}
|
|
|
|
|
2024-02-16 12:08:45 +00:00
|
|
|
ProfileShowcaseDirtyState {
|
|
|
|
id: communities
|
2024-02-28 12:01:31 +00:00
|
|
|
|
|
|
|
sourceModel: modelAdapter.adaptedCommunitiesSourceModel
|
|
|
|
showcaseModel: modelAdapter.adaptedCommunitiesShowcaseModel
|
2024-02-16 12:08:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ProfileShowcaseDirtyState {
|
|
|
|
id: accounts
|
2024-02-28 12:01:31 +00:00
|
|
|
|
|
|
|
sourceModel: modelAdapter.adaptedAccountsSourceModel
|
|
|
|
showcaseModel: modelAdapter.adaptedAccountsShowcaseModel
|
2024-02-16 12:08:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ProfileShowcaseDirtyState {
|
|
|
|
id: collectibles
|
|
|
|
|
|
|
|
sourceModel: collectiblesFilter
|
2024-02-28 12:01:31 +00:00
|
|
|
showcaseModel: modelAdapter.adaptedCollectiblesShowcaseModel
|
2024-02-16 12:08:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SortFilterProxyModel {
|
|
|
|
id: collectiblesFilter
|
|
|
|
|
|
|
|
delayed: true
|
2024-02-28 12:01:31 +00:00
|
|
|
sourceModel: modelAdapter.adaptedCollectiblesSourceModel
|
2024-02-16 12:08:45 +00:00
|
|
|
proxyRoles: FastExpressionRole {
|
|
|
|
name: "maxVisibility"
|
|
|
|
|
2024-02-20 13:26:56 +00:00
|
|
|
// singletons cannot be used in expressions
|
|
|
|
readonly property int hidden: Constants.ShowcaseVisibility.NoOne
|
|
|
|
|
2024-02-16 12:08:45 +00:00
|
|
|
expression: {
|
2024-02-20 13:26:56 +00:00
|
|
|
const visibilityMap = root.accountsVisibilityMap
|
2024-02-16 12:08:45 +00:00
|
|
|
const accounts = model.accounts.split(":")
|
2024-02-20 13:26:56 +00:00
|
|
|
const visibilities = accounts.map(a => visibilityMap[a]).filter(
|
|
|
|
v => v !== undefined)
|
2024-02-16 12:08:45 +00:00
|
|
|
|
2024-02-20 13:26:56 +00:00
|
|
|
return visibilities.length ? Math.min(...visibilities) : hidden
|
2024-02-16 12:08:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
expectedRoles: ["accounts"]
|
|
|
|
}
|
|
|
|
|
2024-02-20 13:26:56 +00:00
|
|
|
filters: ValueFilter {
|
2024-02-16 12:08:45 +00:00
|
|
|
roleName: "maxVisibility"
|
2024-02-20 13:26:56 +00:00
|
|
|
value: Constants.ShowcaseVisibility.NoOne
|
|
|
|
inverted: true
|
2024-02-16 12:08:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
id: visibleAccountsConnections
|
|
|
|
|
|
|
|
target: accounts.visibleModel
|
|
|
|
|
|
|
|
property var visibleAccountsList: []
|
|
|
|
property var accountsVisibilityMap: ({})
|
|
|
|
|
|
|
|
function updateAccountsList() {
|
|
|
|
const keysAndVisibility = ModelUtils.modelToArray(
|
|
|
|
accounts.visibleModel, ["key", "visibility"])
|
|
|
|
|
|
|
|
visibleAccountsList = keysAndVisibility.map(e => e.key)
|
|
|
|
|
|
|
|
accountsVisibilityMap = keysAndVisibility.reduce(
|
|
|
|
(acc, val) => Object.assign(
|
|
|
|
acc, {[val.key]: val.visibility}), {})
|
|
|
|
}
|
|
|
|
|
|
|
|
function onDataChanged() {
|
|
|
|
updateAccountsList()
|
|
|
|
}
|
|
|
|
|
|
|
|
function onRowsInserted() {
|
|
|
|
updateAccountsList()
|
|
|
|
}
|
|
|
|
|
|
|
|
function onRowsRemoved() {
|
|
|
|
updateAccountsList()
|
|
|
|
}
|
|
|
|
|
|
|
|
function onModelReset() {
|
|
|
|
updateAccountsList()
|
|
|
|
}
|
|
|
|
|
|
|
|
Component.onCompleted: updateAccountsList()
|
|
|
|
}
|
|
|
|
}
|