From ccffb1e49c6289e9d169550b212c7c242e7db406 Mon Sep 17 00:00:00 2001 From: Marco Allegretti Date: Tue, 20 Jan 2026 10:59:29 +0100 Subject: [PATCH] Fix editing update and dialog state Ensure editing a game updates the library view and the edit dialog reliably. - Refresh the model when a Game emits change signals so filtering/sorting stays in sync. - Reload edit fields on open/game change to avoid stale values after typing. - Center the edit dialog with an explicit size. --- src/gamemodel.cpp | 65 ++++++++++++++++++++++++++++++++++++++ src/qml/GameEditDialog.qml | 31 +++++++++++++++--- 2 files changed, 91 insertions(+), 5 deletions(-) diff --git a/src/gamemodel.cpp b/src/gamemodel.cpp index 1cb509e..dc21d64 100644 --- a/src/gamemodel.cpp +++ b/src/gamemodel.cpp @@ -209,6 +209,71 @@ void GameModel::addGame(Game *game) game->setParent(this); + connect( + game, + &Game::nameChanged, + this, + [this]() { + applyFilter(); + }, + Qt::QueuedConnection); + connect( + game, + &Game::developerChanged, + this, + [this]() { + applyFilter(); + }, + Qt::QueuedConnection); + connect( + game, + &Game::publisherChanged, + this, + [this]() { + applyFilter(); + }, + Qt::QueuedConnection); + connect( + game, + &Game::favoriteChanged, + this, + [this]() { + applyFilter(); + }, + Qt::QueuedConnection); + connect( + game, + &Game::hiddenChanged, + this, + [this]() { + applyFilter(); + }, + Qt::QueuedConnection); + connect( + game, + &Game::platformChanged, + this, + [this]() { + applyFilter(); + }, + Qt::QueuedConnection); + connect( + game, + &Game::lastPlayedChanged, + this, + [this]() { + applyFilter(); + }, + Qt::QueuedConnection); + connect( + game, + &Game::playTimeChanged, + this, + [this]() { + applyFilter(); + }, + Qt::QueuedConnection); + m_games.append(game); applyFilter(); } diff --git a/src/qml/GameEditDialog.qml b/src/qml/GameEditDialog.qml index fe4ec6e..20fc14f 100644 --- a/src/qml/GameEditDialog.qml +++ b/src/qml/GameEditDialog.qml @@ -22,6 +22,10 @@ Kirigami.Dialog { standardButtons: Kirigami.Dialog.NoButton width: Math.min(parent.width - Kirigami.Units.gridUnit * 4, Kirigami.Units.gridUnit * 30) + height: Math.min(parent.height - Kirigami.Units.gridUnit * 4, implicitHeight) + + x: Math.round((parent.width - width) / 2) + y: Math.round((parent.height - height) / 2) customFooterActions: [ Kirigami.Action { @@ -63,6 +67,21 @@ Kirigami.Dialog { property string selectedCoverPath: "" + function loadFields() { + selectedCoverPath = "" + if (isEditing && game) { + nameField.text = game.name || "" + developerField.text = game.developer || "" + executableField.text = game.launchCommand || "" + workingDirField.text = game.workingDirectory || "" + } else { + nameField.text = "" + developerField.text = "" + executableField.text = "" + workingDirField.text = "" + } + } + ColumnLayout { spacing: 0 @@ -72,7 +91,7 @@ Kirigami.Dialog { FormCard.FormTextFieldDelegate { id: nameField label: i18n("Name") - text: isEditing && game ? game.name : "" + text: "" placeholderText: i18n("Game title") onAccepted: developerField.forceActiveFocus() } @@ -82,7 +101,7 @@ Kirigami.Dialog { FormCard.FormTextFieldDelegate { id: developerField label: i18n("Developer") - text: isEditing && game ? (game.developer || "") : "" + text: "" placeholderText: i18n("Optional") onAccepted: executableField.forceActiveFocus() } @@ -92,7 +111,7 @@ Kirigami.Dialog { FormCard.FormTextFieldDelegate { id: executableField label: i18n("Executable") - text: isEditing && game ? game.launchCommand : "" + text: "" placeholderText: i18n("/path/to/game or command") onAccepted: if (nameField.text.trim() !== "" && text.trim() !== "") { dialog.customFooterActions[0].trigger() @@ -112,7 +131,7 @@ Kirigami.Dialog { FormCard.FormTextFieldDelegate { id: workingDirField label: i18n("Working Directory") - text: isEditing && game ? (game.workingDirectory || "") : "" + text: "" placeholderText: i18n("Optional") } } @@ -252,7 +271,9 @@ Kirigami.Dialog { } onOpened: { + loadFields() nameField.forceActiveFocus() - selectedCoverPath = "" } + + onGameChanged: loadFields() }