mirror of
https://invent.kde.org/marcoa/a-la-karte.git
synced 2026-02-09 21:13:08 +00:00
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:
parent
394227f9a5
commit
ccffb1e49c
2 changed files with 91 additions and 5 deletions
|
|
@ -209,6 +209,71 @@ void GameModel::addGame(Game *game)
|
||||||
|
|
||||||
game->setParent(this);
|
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);
|
m_games.append(game);
|
||||||
applyFilter();
|
applyFilter();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,10 @@ Kirigami.Dialog {
|
||||||
standardButtons: Kirigami.Dialog.NoButton
|
standardButtons: Kirigami.Dialog.NoButton
|
||||||
|
|
||||||
width: Math.min(parent.width - Kirigami.Units.gridUnit * 4, Kirigami.Units.gridUnit * 30)
|
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: [
|
customFooterActions: [
|
||||||
Kirigami.Action {
|
Kirigami.Action {
|
||||||
|
|
@ -63,6 +67,21 @@ Kirigami.Dialog {
|
||||||
|
|
||||||
property string selectedCoverPath: ""
|
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 {
|
ColumnLayout {
|
||||||
spacing: 0
|
spacing: 0
|
||||||
|
|
||||||
|
|
@ -72,7 +91,7 @@ Kirigami.Dialog {
|
||||||
FormCard.FormTextFieldDelegate {
|
FormCard.FormTextFieldDelegate {
|
||||||
id: nameField
|
id: nameField
|
||||||
label: i18n("Name")
|
label: i18n("Name")
|
||||||
text: isEditing && game ? game.name : ""
|
text: ""
|
||||||
placeholderText: i18n("Game title")
|
placeholderText: i18n("Game title")
|
||||||
onAccepted: developerField.forceActiveFocus()
|
onAccepted: developerField.forceActiveFocus()
|
||||||
}
|
}
|
||||||
|
|
@ -82,7 +101,7 @@ Kirigami.Dialog {
|
||||||
FormCard.FormTextFieldDelegate {
|
FormCard.FormTextFieldDelegate {
|
||||||
id: developerField
|
id: developerField
|
||||||
label: i18n("Developer")
|
label: i18n("Developer")
|
||||||
text: isEditing && game ? (game.developer || "") : ""
|
text: ""
|
||||||
placeholderText: i18n("Optional")
|
placeholderText: i18n("Optional")
|
||||||
onAccepted: executableField.forceActiveFocus()
|
onAccepted: executableField.forceActiveFocus()
|
||||||
}
|
}
|
||||||
|
|
@ -92,7 +111,7 @@ Kirigami.Dialog {
|
||||||
FormCard.FormTextFieldDelegate {
|
FormCard.FormTextFieldDelegate {
|
||||||
id: executableField
|
id: executableField
|
||||||
label: i18n("Executable")
|
label: i18n("Executable")
|
||||||
text: isEditing && game ? game.launchCommand : ""
|
text: ""
|
||||||
placeholderText: i18n("/path/to/game or command")
|
placeholderText: i18n("/path/to/game or command")
|
||||||
onAccepted: if (nameField.text.trim() !== "" && text.trim() !== "") {
|
onAccepted: if (nameField.text.trim() !== "" && text.trim() !== "") {
|
||||||
dialog.customFooterActions[0].trigger()
|
dialog.customFooterActions[0].trigger()
|
||||||
|
|
@ -112,7 +131,7 @@ Kirigami.Dialog {
|
||||||
FormCard.FormTextFieldDelegate {
|
FormCard.FormTextFieldDelegate {
|
||||||
id: workingDirField
|
id: workingDirField
|
||||||
label: i18n("Working Directory")
|
label: i18n("Working Directory")
|
||||||
text: isEditing && game ? (game.workingDirectory || "") : ""
|
text: ""
|
||||||
placeholderText: i18n("Optional")
|
placeholderText: i18n("Optional")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -252,7 +271,9 @@ Kirigami.Dialog {
|
||||||
}
|
}
|
||||||
|
|
||||||
onOpened: {
|
onOpened: {
|
||||||
|
loadFields()
|
||||||
nameField.forceActiveFocus()
|
nameField.forceActiveFocus()
|
||||||
selectedCoverPath = ""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onGameChanged: loadFields()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue