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 {
|
|
|
|
property alias sourceModel: joined.leftModel
|
|
|
|
property alias showcaseModel: joined.rightModel
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-04 22:07:09 +00:00
|
|
|
readonly property bool dirty: writable.dirty || !visibleModel.synced
|
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-02-16 11:31:40 +00:00
|
|
|
function currentState() {
|
2024-03-04 22:07:09 +00:00
|
|
|
if (visibleModel.synced) {
|
|
|
|
return writable.currentState()
|
|
|
|
}
|
|
|
|
const newOrder = visible.order()
|
|
|
|
let writableIndexes = []
|
|
|
|
|
|
|
|
for (var i = 0; i < newOrder.length; i++) {
|
|
|
|
writableIndexes.push(visibleSFPM.mapFromSource(newOrder[i]))
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0; i < newOrder.length; i++) {
|
|
|
|
writable.set(writableIndexes[i], { "showcasePosition": i})
|
|
|
|
}
|
|
|
|
|
2024-02-16 11:31:40 +00:00
|
|
|
return writable.currentState()
|
|
|
|
}
|
|
|
|
|
|
|
|
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-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
|
|
|
|
|
|
|
|
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-02-29 07:43:38 +00:00
|
|
|
MovableModel {
|
|
|
|
id: visible
|
|
|
|
|
|
|
|
sourceModel: visibleSFPM
|
|
|
|
}
|
|
|
|
|
2024-02-16 11:31:40 +00:00
|
|
|
SortFilterProxyModel {
|
2024-03-04 22:07:09 +00:00
|
|
|
id: hidden
|
2024-02-16 11:31:40 +00:00
|
|
|
|
|
|
|
sourceModel: writable
|
|
|
|
delayed: true
|
|
|
|
|
2024-02-20 13:26:56 +00:00
|
|
|
filters: HiddenFilter {}
|
2024-02-16 11:31:40 +00:00
|
|
|
}
|
|
|
|
}
|