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-02-16 11:31:40 +00:00
|
|
|
property alias sourceModel: joined.leftModel
|
|
|
|
property alias showcaseModel: joined.rightModel
|
|
|
|
|
2024-03-08 09:27:45 +00:00
|
|
|
/**
|
|
|
|
* True if the showcase model is in single model mode, i.e. the showcase
|
|
|
|
* model is part of the source model. False if the showcase model is a
|
|
|
|
* separate model.
|
|
|
|
*/
|
|
|
|
property bool singleModelMode: !joined.rightModel
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
readonly property alias visibleModel: visible
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
2024-03-03 16:34:08 +00:00
|
|
|
/**
|
|
|
|
* It sets up a searcher filter on top of both the visible and hidden models.
|
|
|
|
*/
|
|
|
|
property FastExpressionFilter searcherFilter
|
|
|
|
|
2024-02-28 12:01:31 +00:00
|
|
|
function revert() {
|
2024-03-04 22:07:09 +00:00
|
|
|
visible.syncOrder()
|
2024-02-28 12:01:31 +00:00
|
|
|
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) {
|
|
|
|
visible.move(from, to)
|
2024-03-08 20:11:48 +00:00
|
|
|
|
|
|
|
// Sync writable with movable new positions:
|
|
|
|
const newOrder = visible.order()
|
|
|
|
let writableIndexes = []
|
|
|
|
|
|
|
|
for (var i = 0; i < newOrder.length; i++) {
|
|
|
|
writableIndexes.push(visibleSFPM.mapToSource(newOrder[i]))
|
|
|
|
}
|
|
|
|
|
2024-03-08 09:27:45 +00:00
|
|
|
for (var i = 0; i < newOrder.length; i++) {
|
|
|
|
writable.set(writableIndexes[i], { "showcasePosition": i})
|
2024-03-08 20:11:48 +00:00
|
|
|
}
|
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
|
|
|
|
readonly property alias joined_: joined
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
LeftJoinModel {
|
|
|
|
id: joined
|
|
|
|
|
2024-03-04 22:07:09 +00:00
|
|
|
joinRole: "showcaseKey"
|
2024-02-16 11:31:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VisibilityAndPositionDirtyStateModel {
|
|
|
|
id: writable
|
|
|
|
|
2024-03-08 09:27:45 +00:00
|
|
|
sourceModel: root.singleModelMode ? root.sourceModel : joined
|
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: searcherVisibleSFPM
|
|
|
|
|
|
|
|
sourceModel: visibleSFPM
|
|
|
|
delayed: true
|
|
|
|
filters: root.searcherFilter
|
|
|
|
}
|
|
|
|
|
2024-02-29 07:43:38 +00:00
|
|
|
MovableModel {
|
|
|
|
id: visible
|
|
|
|
|
2024-03-03 16:34:08 +00:00
|
|
|
sourceModel: searcherVisibleSFPM
|
2024-02-29 07:43:38 +00:00
|
|
|
}
|
|
|
|
|
2024-02-16 11:31:40 +00:00
|
|
|
SortFilterProxyModel {
|
2024-03-03 16:34:08 +00:00
|
|
|
id: searcherHiddenSFPM
|
2024-02-16 11:31:40 +00:00
|
|
|
|
|
|
|
sourceModel: writable
|
|
|
|
delayed: true
|
2024-03-03 16:34:08 +00:00
|
|
|
filters: root.searcherFilter
|
|
|
|
}
|
|
|
|
|
|
|
|
SortFilterProxyModel {
|
|
|
|
id: hidden
|
|
|
|
|
|
|
|
sourceModel: searcherHiddenSFPM
|
|
|
|
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) {
|
|
|
|
const newOrder = visible.order()
|
|
|
|
const sfpmIndex = newOrder[index]
|
|
|
|
|
|
|
|
return visibleSFPM.mapToSource(sfpmIndex)
|
|
|
|
}
|
|
|
|
}
|
2024-02-16 11:31:40 +00:00
|
|
|
}
|