feat(ProfileShowcase): Adding the MovableModel to the ProfileShowcaseModels to intercept the SFPM events

This is needed for the DND.
This commit is contained in:
Alex Jbanca 2024-02-29 09:43:38 +02:00 committed by Alex Jbanca
parent c916bfa84e
commit 4a4a5d5c4b
6 changed files with 30 additions and 63 deletions

View File

@ -70,20 +70,8 @@ SplitView {
SplitView.fillHeight: true
emptyInShowcasePlaceholderText: "No items in showcase"
emptyHiddenPlaceholderText: "No hidden items"
onChangePositionRequested: function (key, to) {
for (var i = 0; i < inShowcaseModelItem.count; i++) {
if (inShowcaseModelItem.get(i).key === key) {
inShowcaseModelItem.move(i, to, 1)
break
}
}
for (var i = 0; i < hiddenModelItem.count; i++) {
if (hiddenModelItem.get(i).key === key) {
hiddenModelItem.move(from, to, 1)
break
}
}
onChangePositionRequested: function (from, to) {
inShowcaseModelItem.move(from, to, 1)
}
onSetVisibilityRequested: function (key, toVisibility) {
for (var i = 0; i < inShowcaseModelItem.count; i++) {

View File

@ -34,7 +34,7 @@ QObject {
/**
* Returns dirty state of the showcase model.
*/
readonly property alias dirty: writable.dirty
readonly property bool dirty: writable.dirty || !visibleModel.synced || !hiddenModel.synced
function revert() {
writable.revert()
@ -48,8 +48,8 @@ QObject {
writable.setVisibility(key, visibility)
}
function changePosition(key, to) {
writable.changePosition(key, to)
function changePosition(from, to) {
visible.move(from, to)
}
// internals, debug purpose only
@ -81,7 +81,7 @@ QObject {
}
SortFilterProxyModel {
id: visible
id: visibleSFPM
sourceModel: writable
delayed: true
@ -90,12 +90,24 @@ QObject {
sorters: RoleSorter { roleName: "position" }
}
MovableModel {
id: visible
sourceModel: visibleSFPM
}
SortFilterProxyModel {
id: hidden
id: hiddenSFPM
sourceModel: writable
delayed: true
filters: HiddenFilter {}
}
MovableModel {
id: hidden
sourceModel: hiddenSFPM
}
}

View File

@ -91,8 +91,8 @@ QObject {
collectibles.setVisibility(key, visibility)
}
function changeCollectiblePosition(key, to) {
collectibles.changePosition(key, to)
function changeCollectiblePosition(from, to) {
collectibles.changePosition(from, to)
}
ProfileShowcaseModelAdapter {

View File

@ -61,39 +61,6 @@ WritableProxyModel {
set(sourceIdx, { visibility, position })
}
/* Sets the position of the item. The "to" parameter is expected to be
* a target index in the list and must be in range [0; count - 1].
*/
function changePosition(key, to) {
const visible = d.getVisibleEntries()
visible.sort((a, b) => a.position - b.position)
const idx = visible.findIndex(item => item.key === key)
if (idx === -1) {
console.warn(`Entry with key ${key} not found`)
return
}
const count = visible.length
if (to < 0 || to >= count) {
console.warn(`Destination position out of range: ${to}`)
return
}
// swap
[visible[idx], visible[to]] = [visible[to], visible[idx]]
visible.forEach((e, i) => {
if (e.position === i)
return
const idx = d.indexByKey(e.key)
set(idx, { position: i })
})
}
readonly property QtObject d_: QtObject {
id: d

View File

@ -31,7 +31,7 @@ DoubleFlickableWithFolding {
property string emptyHiddenPlaceholderText
// Signal to requst position change of the visible items
signal changePositionRequested(var key, int to)
signal changePositionRequested(int from, int to)
// Signal to request visibility change of the items
signal setVisibilityRequested(var key, int toVisibility)
@ -46,7 +46,7 @@ DoubleFlickableWithFolding {
Drag.keys: dragKeys
dragParent: root
dragParent: dragParentData
visualIndex: visualIndexData
dragAxis: Drag.YAxis
showcaseVisibility: model ? model.visibility ?? Constants.ShowcaseVisibility.NoOne :
@ -322,7 +322,7 @@ DoubleFlickableWithFolding {
var to = visualIndex
if (to === from)
return
root.changePositionRequested(drag.source.key, to)
root.changePositionRequested(drag.source.visualIndex, to)
}
drag.accept()
}

View File

@ -204,8 +204,8 @@ SettingsContentBase {
inShowcaseModel: priv.showcaseModels.communitiesVisibleModel
hiddenModel: priv.showcaseModels.communitiesHiddenModel
onChangePositionRequested: function (key, to) {
priv.showcaseModels.changeCommunityPosition(key, to)
onChangePositionRequested: function (from, to) {
priv.showcaseModels.changeCommunityPosition(from, to)
}
onSetVisibilityRequested: function (key, toVisibility) {
priv.showcaseModels.setCommunityVisibility(key, toVisibility)
@ -219,8 +219,8 @@ SettingsContentBase {
hiddenModel: priv.showcaseModels.accountsHiddenModel
currentWallet: root.walletStore.overview.mixedcaseAddress
onChangePositionRequested: function (key, to) {
priv.showcaseModels.changeAccountPosition(key, to)
onChangePositionRequested: function (from, to) {
priv.showcaseModels.changeAccountPosition(from, to)
}
onSetVisibilityRequested: function (key, toVisibility) {
@ -238,8 +238,8 @@ SettingsContentBase {
inShowcaseModel: priv.showcaseModels.collectiblesVisibleModel
hiddenModel: priv.showcaseModels.collectiblesHiddenModel
onChangePositionRequested: function (key, to) {
priv.showcaseModels.changeCollectiblePosition(key, to)
onChangePositionRequested: function (from, to) {
priv.showcaseModels.changeCollectiblePosition(from, to)
}
onSetVisibilityRequested: function (key, toVisibility) {