[games/chessament] src: Remove moves from last time control period
Manuel Alcaraz Zambrano <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit cdbd2d604f9db88503155ca22bf4545ddc38779a by Manuel Alcaraz Zambrano.
Committed on 28/07/2026 at 14:16.
Pushed by manuelal into branch 'master'.
Remove moves from last time control period
M +4 -2 src/qml/components/TimeControlDelegate.qml
M +3 -0 src/timecontrolmodel.cpp
M +6 -0 src/tournament/timecontrol.cpp
https://invent.kde.org/games/chessament/-/commit/cdbd2d604f9db88503155ca22bf4545ddc38779a
diff --git a/src/qml/components/TimeControlDelegate.qml b/src/qml/components/TimeControlDelegate.qml
index e471630..04b261a 100644
--- a/src/qml/components/TimeControlDelegate.qml
+++ b/src/qml/components/TimeControlDelegate.qml
@@ -3,6 +3,7 @@
pragma ComponentBehavior: Bound
+import Qt.labs.synchronizer
import QtQuick
import QtQuick.Controls as Controls
import QtQuick.Layouts
@@ -39,8 +40,9 @@ FormCard.AbstractFormDelegate {
Layout.fillWidth: true
from: 0
to: 100
- value: delegate.moves
- onValueModified: delegate.moves = value
+ Synchronizer on value {
+ property alias source: delegate.moves
+ }
}
}
diff --git a/src/timecontrolmodel.cpp b/src/timecontrolmodel.cpp
index 5e14753..d069095 100644
--- a/src/timecontrolmodel.cpp
+++ b/src/timecontrolmodel.cpp
@@ -104,6 +104,9 @@ void TimeControlModel::deletePeriod(int row)
m_tournament->timeControl().removePeriod(row);
endRemoveRows();
+ const int lastRow = rowCount() - 1;
+ Q_EMIT dataChanged(index(lastRow), index(lastRow), {TimeControlModel::Roles::Moves});
+
m_tournament->saveTimeControl();
}
diff --git a/src/tournament/timecontrol.cpp b/src/tournament/timecontrol.cpp
index be9c490..ea0bef5 100644
--- a/src/tournament/timecontrol.cpp
+++ b/src/tournament/timecontrol.cpp
@@ -146,8 +146,14 @@ void TimeControl::removePeriod(int index)
Q_ASSERT(value.isArray());
auto periods = value.toArray();
+ Q_ASSERT(periods.size() > 1);
+
periods.erase(periods.begin() + index);
+ auto lastPeriod = periods.last().toObject();
+ lastPeriod.remove("moves"_L1);
+ periods[periods.size() - 1] = lastPeriod;
+
value = periods;
}