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.
This commit is contained in:
Marco Allegretti 2026-01-20 10:59:29 +01:00
parent 394227f9a5
commit ccffb1e49c
2 changed files with 91 additions and 5 deletions

View file

@ -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();
}

View file

@ -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()
}