[Interest] Qml SpinBox Control 2 undo/redo
Furkan Uzumcu
furkanuzumcu at gmail.com
Wed Mar 18 16:20:23 CET 2020
Not very sophisticated but something like the following might work for you:
1 SpinBox {
2 id: spin
3
4 property var history: []
5 property bool _internalUpdate: false
6
7 from: 0
8 to: 100
9 onValueChanged: {
10 if (!spin._internalUpdate) {
11 spin.history.push(value)
12 }
13 }
14 Component.onCompleted: {
15 spin.history.push(value)
16 }
17 }
18
19 Button {
20 text: <="" span="">
21 onClicked: {
22 if (spin.history.length > 0) {
23 spin._internalUpdate = true
24 spin.value = spin.history[
25 Math.max(0, spin.history.length - 2)
26 ]
27 spin._internalUpdate = false
28 if (spin.history.length > 1) {
29 spin.history.splice(spin.history.length - 1, 1)
30 }
31 }
32 }
Regards,
Furkan Üzümcü
On Mar 17, 2020, 16:26 -0400, Jérôme Godbout <godboutj at amotus.ca>, wrote:
> Hi,
> I’m trying to make an undo redo, I manage to have my whole thing working for user mouse drag n drop, add remove part into my model. One thing that bug me with the control 2 is the spinbox, the value is bind to the mode and the model get changed too, not sure this is the optimal way (I so wish we got 2 way binding like C# one day, this is so deeply needed and not have everybody reimplement there own way).
>
> SpinBox
> {
> id: sequenceIndex_
>
> value: opsModel.index
>
> onValueChanged:
> {
> // This is called before value modified
> }
>
> onValueModified:
> {
> // The value is already modified, how can I get previous value to make my undo/redo ? seem too late and the value changed as already been called
> }
>
> Binding
> {
> target: ops_model
> property: "index"
> value: sequenceIndex_.value
> }
> }
>
> How does one manage to do it with this control?! I guess I will have the same challenge with the ComboBox and all the selector controls (button are fairly easy since I can capture the previous value before doing the action).
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> https://lists.qt-project.org/listinfo/interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20200318/b294e3bf/attachment.html>
More information about the Interest
mailing list