summaryrefslogtreecommitdiff
path: root/dev-python/qtstatemachine/files/qstatemachines_fix_compound_state.patch_002
blob: 917bbf4326d3569d8f71a8cadf00d18f04b5bd2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
--- src/qstatemachine_history_fixed.cpp	2009-07-26 18:21:12.000000000 +0200
+++ src/qstatemachine.cpp	2009-07-27 15:46:45.000000000 +0200
@@ -273,6 +273,27 @@
     }
 }
 
+QtState *QtStateMachinePrivate::findActiveLCA(const QList<QtAbstractState*> &states)
+{
+    if (states.isEmpty())
+        return rootState;
+    QList<QtState*> ancestors = properAncestors(states.at(0), 0);
+    for (int i = 0; i < ancestors.size(); ++i) {
+        QtState *anc = ancestors.at(i);
+        if (!configuration.contains(anc))
+            continue;
+        bool ok = true;
+        for (int j = states.size() - 1; (j > 0) && ok; --j) {
+            const QtAbstractState *s = states.at(j);
+            if (!isDescendantOf(s, anc))
+                ok = false;
+        }
+        if (ok)
+            return anc;
+    }
+    return rootState;
+}
+
 QtState *QtStateMachinePrivate::findLCA(const QList<QtAbstractState*> &states)
 {
     if (states.isEmpty())
@@ -378,8 +399,18 @@
         QList<QtAbstractState*> lst = t->targetStates();
         if (lst.isEmpty())
             continue;
-        lst.prepend(t->sourceState());
-        QtAbstractState *lca = findLCA(lst);
+        QtAbstractState *lca;
+        if (isDescendantOf(t->targetState(), t->sourceState()))
+        {
+            lst.prepend(t->targetState());
+            lca = findActiveLCA(lst);
+        }
+        else
+        {
+            lst.prepend(t->sourceState());
+            lca = findLCA(lst);
+        }
+
         {
             QSet<QtAbstractState*>::const_iterator it;
             for (it = configuration.constBegin(); it != configuration.constEnd(); ++it) {
@@ -451,8 +482,17 @@
         QList<QtAbstractState*> lst = t->targetStates();
         if (lst.isEmpty())
             continue;
-        lst.prepend(t->sourceState());
-        QtState *lca = findLCA(lst);
+        QtState *lca;
+        if (isDescendantOf(t->targetState(), t->sourceState()))
+        {
+            lst.prepend(t->targetState());
+            lca = findActiveLCA(lst);
+        }
+        else
+        {
+            lst.prepend(t->sourceState());
+            lca = findLCA(lst);
+        }
         for (int j = 1; j < lst.size(); ++j) {
             QtAbstractState *s = lst.at(j);
             addStatesToEnter(s, lca, statesToEnter, statesForDefaultEntry);
diff -ru src_old/qstatemachine_p.h src/qstatemachine_p.h
--- src_old/qstatemachine_p.h	2009-07-26 18:38:06.000000000 +0200
+++ src/qstatemachine_p.h	2009-07-26 18:37:15.000000000 +0200
@@ -109,6 +109,7 @@
 
     static QtStateMachinePrivate *get(QtStateMachine *q);
 
+    QtState *findActiveLCA(const QList<QtAbstractState*> &states);
     static QtState *findLCA(const QList<QtAbstractState*> &states);
 
     static bool stateEntryLessThan(QtAbstractState *s1, QtAbstractState *s2);