2024-02-16 11:31:40 +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 11:31:40 +00:00
|
|
|
/**
|
|
|
|
* Building block for managing temporary state in the "Profile Showcase"
|
|
|
|
* functionality. Provides combining raw source model (like e.g. communities
|
|
|
|
* model or accounts model) with lean showcase model (providing info regarding
|
|
|
|
* visibility and position), managing dirty state (visibility, position) and
|
|
|
|
* providing two output models - one containing visible items sorted by
|
|
|
|
* position, second one containing hidden items.
|
|
|
|
*/
|
|
|
|
QObject {
|
2024-03-03 16:34:08 +00:00
|
|
|
id: root
|
|
|
|
|
2024-03-29 11:43:49 +00:00
|
|
|
property alias sourceModel: writable.sourceModel
|
2024-02-16 11:31:40 +00:00
|
|
|
/**
|
|
|
|
* Model holding elements from 'sourceModel' intended to be visible in the
|
|
|
|
* showcase, sorted by 'position' role. Includes roles from both input models.
|
|
|
|
*/
|
2024-04-19 09:46:23 +00:00
|
|
|
readonly property alias visibleModel: visibleSFPM
|
2024-02-16 11:31:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Model holding elements from 'sourceModel' intended to be hidden, no
|
|
|
|
* sorting applied. Includes roles from both input models.
|
|
|
|
*/
|
|
|
|
readonly property alias hiddenModel: hidden
|
|
|
|
|
2024-02-28 12:01:31 +00:00
|
|
|
/**
|
|
|
|
* Returns dirty state of the showcase model.
|
|
|
|
*/
|
2024-03-10 20:16:15 +00:00
|
|
|
readonly property bool dirty: writable.dirty
|
2024-02-28 12:01:31 +00:00
|
|
|
|
|
|
|
function revert() {
|
|
|
|
writable.revert()
|
|
|
|
}
|
|
|
|
|
2024-03-08 09:27:45 +00:00
|
|
|
function currentState(roleNames = []) {
|
|
|
|
return writable.currentState(roleNames)
|
2024-02-16 11:31:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function setVisibility(key, visibility) {
|
|
|
|
writable.setVisibility(key, visibility)
|
|
|
|
}
|
|
|
|
|
2024-02-29 07:43:38 +00:00
|
|
|
function changePosition(from, to) {
|
2024-04-19 09:46:23 +00:00
|
|
|
const writableIndex = d.visibleIndexToWritable(from)
|
|
|
|
writable.changePosition(writableIndex, to)
|
2024-02-16 11:31:40 +00:00
|
|
|
}
|
|
|
|
|
2024-03-08 09:27:45 +00:00
|
|
|
function append(obj) {
|
|
|
|
writable.append(obj)
|
|
|
|
}
|
|
|
|
|
|
|
|
function remove(index) {
|
|
|
|
const writableIndex = d.visibleIndexToWritable(index)
|
|
|
|
writable.remove(writableIndex)
|
|
|
|
}
|
|
|
|
|
|
|
|
function update(index, obj) {
|
|
|
|
const writableIndex = d.visibleIndexToWritable(index)
|
|
|
|
writable.set(writableIndex, obj)
|
|
|
|
}
|
|
|
|
|
2024-02-16 11:31:40 +00:00
|
|
|
// internals, debug purpose only
|
|
|
|
readonly property alias writable_: writable
|
|
|
|
|
2024-02-20 13:26:56 +00:00
|
|
|
component HiddenFilter: AnyOf {
|
|
|
|
UndefinedFilter {
|
2024-03-04 22:07:09 +00:00
|
|
|
roleName: "showcaseVisibility"
|
2024-02-20 13:26:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ValueFilter {
|
2024-03-04 22:07:09 +00:00
|
|
|
roleName: "showcaseVisibility"
|
2024-02-20 13:26:56 +00:00
|
|
|
value: Constants.ShowcaseVisibility.NoOne
|
|
|
|
}
|
2024-02-16 11:31:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VisibilityAndPositionDirtyStateModel {
|
|
|
|
id: writable
|
|
|
|
|
2024-02-20 13:26:56 +00:00
|
|
|
visibilityHidden: Constants.ShowcaseVisibility.NoOne
|
2024-02-16 11:31:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SortFilterProxyModel {
|
2024-02-29 07:43:38 +00:00
|
|
|
id: visibleSFPM
|
2024-02-16 11:31:40 +00:00
|
|
|
|
|
|
|
sourceModel: writable
|
|
|
|
delayed: true
|
|
|
|
|
2024-02-20 13:26:56 +00:00
|
|
|
filters: HiddenFilter { inverted: true }
|
2024-03-04 22:07:09 +00:00
|
|
|
sorters: RoleSorter { roleName: "showcasePosition" }
|
2024-02-16 11:31:40 +00:00
|
|
|
}
|
|
|
|
|
2024-03-03 16:34:08 +00:00
|
|
|
SortFilterProxyModel {
|
|
|
|
id: hidden
|
|
|
|
|
2024-04-19 09:46:23 +00:00
|
|
|
sourceModel: writable
|
2024-03-03 16:34:08 +00:00
|
|
|
delayed: true
|
2024-02-16 11:31:40 +00:00
|
|
|
|
2024-02-20 13:26:56 +00:00
|
|
|
filters: HiddenFilter {}
|
2024-02-16 11:31:40 +00:00
|
|
|
}
|
2024-03-08 09:27:45 +00:00
|
|
|
|
|
|
|
QtObject {
|
|
|
|
id: d
|
|
|
|
|
|
|
|
function visibleIndexToWritable(index) {
|
2024-04-19 09:46:23 +00:00
|
|
|
return visibleSFPM.mapToSource(index)
|
2024-03-08 09:27:45 +00:00
|
|
|
}
|
|
|
|
}
|
2024-02-16 11:31:40 +00:00
|
|
|
}
|