feat(ProfileShowcase): Sync dirty state with the source model

Whenever the source model becomes identical to the showcase dirty model, the dirty flag is removed
This commit is contained in:
Alex Jbanca 2024-03-10 22:16:15 +02:00 committed by Alex Jbanca
parent 204bfb30b6
commit e7a1f5e831
5 changed files with 19 additions and 15 deletions

View File

@ -193,6 +193,7 @@ QtObject:
if rpcResponseObj{"error"}.kind != JNull and rpcResponseObj{"error"}.getStr != "":
error "Error saving profile showcase preferences", msg = rpcResponseObj{"error"}
return
self.requestProfileShowcasePreferences()
except Exception as e:
error "Error saving profile showcase preferences", msg = e.msg

View File

@ -192,7 +192,7 @@ void WritableProxyModelPrivate::createProxyToSourceRowMap()
bool WritableProxyModelPrivate::contains(const QModelIndex& sourceIndex, const QVector<int>& roles) const {
if (cache.contains(sourceIndex)) {
auto valueMap = cache[sourceIndex];
return std::all_of(roles.begin(), roles.end(), [&valueMap](int role) { return valueMap.contains(role); });
return std::any_of(roles.begin(), roles.end(), [&valueMap](int role) { return valueMap.contains(role); });
}
if (insertedRows.contains(q.mapFromSource(sourceIndex))) {
@ -289,7 +289,7 @@ void WritableProxyModelPrivate::checkForDirtyRemoval(const QModelIndex& sourceIn
{
if (cachedData.contains(role) && cachedData[role] == q.sourceModel()->data(sourceIndex, role))
cachedData.remove(role);
}
}
if (cachedData.isEmpty()) {
cache.remove(sourceIndex);
@ -605,7 +605,7 @@ bool WritableProxyModel::set(int at, const QVariantMap& data)
return false;
auto index = this->index(at, 0);
auto itemData = this->itemData(index);
QMap<int, QVariant> itemData;
auto roleNames = this->roleNames();
for (auto it = data.begin(); it != data.end(); ++it)

View File

@ -36,7 +36,7 @@ QObject {
/**
* Returns dirty state of the showcase model.
*/
readonly property bool dirty: writable.dirty || !visibleModel.synced
readonly property bool dirty: writable.dirty
/**
* It sets up a searcher filter on top of both the visible and hidden models.
@ -49,9 +49,6 @@ QObject {
}
function currentState() {
if (visible.synced) {
return writable.currentState()
}
return writable.currentState()
}

View File

@ -49,18 +49,25 @@ WritableProxyModel {
return
// hiding, changing visibility level
if (visibility === visibilityHidden
|| oldVisibility !== visibilityHidden) {
set(sourceIdx, { showcaseVisibility: visibility })
if (visibility === visibilityHidden) {
set(sourceIdx, { showcaseVisibility: undefined, showcasePosition: undefined})
return
}
// unhiding
const positions = d.getVisibleEntries().map(e => e.showcasePosition)
const position = Math.max(-1, ...positions) + 1
set(sourceIdx, { showcaseVisibility: visibility, showcasePosition: position })
if (oldVisibility === visibilityHidden || oldVisibility === undefined) {
// unhiding
const positions = d.getVisibleEntries().map(e => e.showcasePosition)
const position = Math.max(-1, ...positions) + 1
set(sourceIdx, { showcaseVisibility: visibility, showcasePosition: position })
return
}
// changing visibility level
set(sourceIdx, { showcaseVisibility: visibility })
}
syncedRemovals: true
readonly property QtObject d_: QtObject {
id: d

View File

@ -166,7 +166,6 @@ SettingsContentBase {
profileHeader.cropRect.y.toFixed(),
(profileHeader.cropRect.x + profileHeader.cropRect.width).toFixed(),
(profileHeader.cropRect.y + profileHeader.cropRect.height).toFixed())
reset()
}
}