summaryrefslogtreecommitdiff
path: root/dev-python/qtstatemachine/files/qstatemachines_fix_history.patch_001
blob: fff31346170476606028d94c412f4d0d34a2d554 (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
--- src/qstatemachine_orig.cpp	2009-07-26 11:41:00.000000000 +0200
+++ src/qstatemachine.cpp	2009-07-26 12:41:26.000000000 +0200
@@ -455,37 +455,7 @@
         QtState *lca = findLCA(lst);
         for (int j = 1; j < lst.size(); ++j) {
             QtAbstractState *s = lst.at(j);
-            if (QtHistoryState *h = qobject_cast<QtHistoryState*>(s)) {
-                QList<QtAbstractState*> hconf = QtHistoryStatePrivate::get(h)->configuration;
-                if (!hconf.isEmpty()) {
-                    for (int k = 0; k < hconf.size(); ++k) {
-                        QtAbstractState *s0 = hconf.at(k);
-                        addStatesToEnter(s0, lca, statesToEnter, statesForDefaultEntry);
-                    }
-#ifdef QSTATEMACHINE_DEBUG
-                    qDebug() << q << ": restoring"
-                            << ((QtHistoryStatePrivate::get(h)->historyType == QtState::DeepHistory) ? "deep" : "shallow")
-                            << "history from" << s << ":" << hconf;
-#endif
-                } else {
-                    QList<QtAbstractState*> hlst;
-                    if (QtHistoryStatePrivate::get(h)->defaultState)
-                        hlst.append(QtHistoryStatePrivate::get(h)->defaultState);
-                    if (hlst.isEmpty()) {
-                        setError(QtStateMachine::NoDefaultStateInHistoryState, h);
-                    } else {
-                        for (int k = 0; k < hlst.size(); ++k) {
-                            QtAbstractState *s0 = hlst.at(k);
-                            addStatesToEnter(s0, lca, statesToEnter, statesForDefaultEntry);
-                        }
-#ifdef QSTATEMACHINE_DEBUG
-                        qDebug() << q << ": initial history targets for" << s << ":" << hlst;                    
-#endif
-                    }
-                }
-            } else {
-                addStatesToEnter(s, lca, statesToEnter, statesForDefaultEntry);
-            }
+            addStatesToEnter(s, lca, statesToEnter, statesForDefaultEntry);
             if (isParallel(lca)) {
                 QList<QtAbstractState*> lcac = QtStatePrivate::get(lca)->childStates();
                 foreach (QtAbstractState* child,lcac) {
@@ -566,45 +536,78 @@
                                             QSet<QtAbstractState*> &statesToEnter,
                                             QSet<QtAbstractState*> &statesForDefaultEntry)
 {
-    statesToEnter.insert(s);
-    if (isParallel(s)) {
-        QtState *grp = qobject_cast<QtState*>(s);
-        QList<QtAbstractState*> lst = QtStatePrivate::get(grp)->childStates();
-        for (int i = 0; i < lst.size(); ++i) {
-            QtAbstractState *child = lst.at(i);
-            addStatesToEnter(child, grp, statesToEnter, statesForDefaultEntry);
-        }
-    } else if (isCompound(s)) {
-        statesForDefaultEntry.insert(s);
-        QtState *grp = qobject_cast<QtState*>(s);
-        QtAbstractState *initial = grp->initialState();
-        if (initial != 0) {
-            addStatesToEnter(initial, grp, statesToEnter, statesForDefaultEntry);
+#ifdef QSTATEMACHINE_DEBUG
+    Q_Q(QtStateMachine);
+#endif
+    if (QtHistoryState *h = qobject_cast<QtHistoryState*>(s)) {
+        QList<QtAbstractState*> hconf = QtHistoryStatePrivate::get(h)->configuration;
+        if (!hconf.isEmpty()) {
+            for (int k = 0; k < hconf.size(); ++k) {
+                QtAbstractState *s0 = hconf.at(k);
+                addStatesToEnter(s0, root, statesToEnter, statesForDefaultEntry);
+            }
+#ifdef QSTATEMACHINE_DEBUG
+            qDebug() << q << ": restoring"
+                << ((QtHistoryStatePrivate::get(h)->historyType == QtState::DeepHistory) ? "deep" : "shallow")
+                << "history from" << s << ":" << hconf;
+#endif
         } else {
-            setError(QtStateMachine::NoInitialStateError, grp);
-            return;
+            QList<QtAbstractState*> hlst;
+            if (QtHistoryStatePrivate::get(h)->defaultState)
+                hlst.append(QtHistoryStatePrivate::get(h)->defaultState);
+            if (hlst.isEmpty()) {
+                setError(QtStateMachine::NoDefaultStateInHistoryState, h);
+            } else {
+                for (int k = 0; k < hlst.size(); ++k) {
+                    QtAbstractState *s0 = hlst.at(k);
+                    addStatesToEnter(s0, root, statesToEnter, statesForDefaultEntry);
+                }
+#ifdef QSTATEMACHINE_DEBUG
+                qDebug() << q << ": initial history targets for" << s << ":" << hlst;                    
+#endif
+            }
         }
-    }
-    QList<QtState*> ancs = properAncestors(s, root);
-    for (int i = 0; i < ancs.size(); ++i) {
-        QtState *anc = ancs.at(i);
-        if (!anc->parentState())
-            continue;
-        statesToEnter.insert(anc);
-        if (isParallel(anc)) {
-            QList<QtAbstractState*> lst = QtStatePrivate::get(anc)->childStates();
-            for (int j = 0; j < lst.size(); ++j) {
-                QtAbstractState *child = lst.at(j);
-                bool hasDescendantInList = false;
-                QSet<QtAbstractState*>::const_iterator it;
-                for (it = statesToEnter.constBegin(); it != statesToEnter.constEnd(); ++it) {
-                    if (isDescendantOf(*it, child)) {
-                        hasDescendantInList = true;
-                        break;
+    } else { 
+        statesToEnter.insert(s);
+        if (isParallel(s)) {
+            QtState *grp = qobject_cast<QtState*>(s);
+            QList<QtAbstractState*> lst = QtStatePrivate::get(grp)->childStates();
+            for (int i = 0; i < lst.size(); ++i) {
+                QtAbstractState *child = lst.at(i);
+                addStatesToEnter(child, grp, statesToEnter, statesForDefaultEntry);
+            }
+        } else if (isCompound(s)) {
+            statesForDefaultEntry.insert(s);
+            QtState *grp = qobject_cast<QtState*>(s);
+            QtAbstractState *initial = grp->initialState();
+            if (initial != 0) {
+                addStatesToEnter(initial, grp, statesToEnter, statesForDefaultEntry);
+            } else {
+                setError(QtStateMachine::NoInitialStateError, grp);
+                return;
+            }
+        }
+        QList<QtState*> ancs = properAncestors(s, root);
+        for (int i = 0; i < ancs.size(); ++i) {
+            QtState *anc = ancs.at(i);
+            if (!anc->parentState())
+                continue;
+            statesToEnter.insert(anc);
+            if (isParallel(anc)) {
+                QList<QtAbstractState*> lst = QtStatePrivate::get(anc)->childStates();
+                for (int j = 0; j < lst.size(); ++j) {
+                    QtAbstractState *child = lst.at(j);
+                    bool hasDescendantInList = false;
+                    QSet<QtAbstractState*>::const_iterator it;
+                    for (it = statesToEnter.constBegin(); it != statesToEnter.constEnd(); ++it) {
+                        if (isDescendantOf(*it, child)) {
+                            hasDescendantInList = true;
+                            break;
+                        }
                     }
+                    if (!hasDescendantInList)
+                        addStatesToEnter(child, anc, statesToEnter, statesForDefaultEntry);
                 }
-                if (!hasDescendantInList)
-                    addStatesToEnter(child, anc, statesToEnter, statesForDefaultEntry);
             }
         }
     }