diff options
author | Noam Rosenthal <nrosenth@nokia.com> | 2009-06-08 12:28:41 -0700 |
---|---|---|
committer | Noam Rosenthal <nrosenth@nokia.com> | 2009-06-08 12:28:41 -0700 |
commit | 7a41ce5b7a595c67c16ae5ef1711927623602b6a (patch) | |
tree | 5a6917940daa31c04f21bbb67417504674b6418a | |
parent | d0441f605434a89b53735427e4e81182c65debbd (diff) |
some missing files
-rw-r--r-- | examples/blackjack/blackjack.pro | 2 | ||||
-rw-r--r-- | examples/blackjack/blackjack.scxml | 217 | ||||
-rw-r--r-- | examples/blackjack/main.cpp | 4 | ||||
-rw-r--r-- | examples/calc/calc.pro | 2 | ||||
-rw-r--r-- | examples/calc/calc.scxml | 215 | ||||
-rw-r--r-- | examples/calc/main.cpp | 4 | ||||
-rw-r--r-- | examples/examples.pro | 2 | ||||
-rw-r--r-- | examples/mediaplayer/main.cpp | 4 | ||||
-rw-r--r-- | examples/mediaplayer/mediaplayer.pro | 2 | ||||
-rw-r--r-- | src/qscxml.cpp | 125 | ||||
-rw-r--r-- | src/qscxml.pri | 7 | ||||
-rw-r--r-- | src/qscxmlgui.cpp | 2 |
12 files changed, 290 insertions, 296 deletions
diff --git a/examples/blackjack/blackjack.pro b/examples/blackjack/blackjack.pro index 29c7351..71c4409 100644 --- a/examples/blackjack/blackjack.pro +++ b/examples/blackjack/blackjack.pro @@ -9,6 +9,6 @@ CONFIG += console CONFIG -= app_bundle TEMPLATE = app SOURCES += main.cpp -include($$PWD/../../src/qtstatemachine.pri) +include(../../src/qscxml.pri) FORMS += blackjack.ui RESOURCES += bj.qrc diff --git a/examples/blackjack/blackjack.scxml b/examples/blackjack/blackjack.scxml index 6c98eb5..4c73cd4 100644 --- a/examples/blackjack/blackjack.scxml +++ b/examples/blackjack/blackjack.scxml @@ -5,17 +5,15 @@ var Suits = "CDHS"; var Ranks = "-A23456789TJQK"; - function CardToString() - { - return "" + Ranks[this.rank] + Suits[this.suit]; - } - function Card (r,s) { this.rank = r; this.suit = s; this.minValue = Math.min(r,10); - this.toString = CardToString; + this.toString = function() { + return "" + Ranks[this.rank] + Suits[this.suit]; + }; +; } function updateDisplay () @@ -23,88 +21,78 @@ cardsLabel.text = "My Cards: " + myDeck + " Dealer Cards: " + dealerCards; } - function randomSort (a,b) - { - return Math.random() * 3 - 1; - } - - function deckReset() - { - this.clear (); - for (var i=1; i <= 13; ++i) - for (var j = 0; j < 4; ++j) - this.cards.push(new Card(i,j)); - this.cards.sort(randomSort); - } + - function deckDraw () - { - return this.cards.pop(); - } - function deckDrawFrom (d) - { - var c = d.draw (); - this.cards.push(c); - updateDisplay (); - } - - function deckClear () + function Deck() { - this.cards = new Array; - } + this.draw = function() + { + return this.cards.pop(); + }; + this.cards = new Array(); + this.reset = function() + { + this.clear (); + for (var i=1; i <= 13; ++i) + for (var j = 0; j < 4; ++j) + this.cards.push(new Card(i,j)); + this.cards.sort(function (a,b) + { + return Math.random() * 3 - 1; + }); + }; + + this.clear = function() + { + this.cards = new Array; + }; + this.evalMin = function () + { + var minVal = 0; + var cardCount = this.cards.length; + for (c in this.cards) { + minVal += this.cards[c].minValue; + } + if (cardCount > 4 && minVal < 22) + minVal = 21; + return minVal; + }; - function deckEvalMin () - { - var minVal = 0; - var cardCount = this.cards.length; - for (c in this.cards) { - minVal += this.cards[c].minValue; - } - if (cardCount > 4 && minVal < 22) - minVal = 21; - return minVal; - } + this.evalBest = function() + { + var bestVal = this.evalMin(); + if (bestVal > 21) + return 0; + else if (bestVal == 21) + return bestVal; - function deckEvalBest () - { - var bestVal = this.evalMin(); - if (bestVal > 21) - return 0; - else if (bestVal == 21) - return bestVal; - - for (i in this.cards) { - if (this.cards[i].rank == 1) - { - var v = bestVal + 10; - if (v <= 21) - bestVal = v; + for (i in this.cards) { + if (this.cards[i].rank == 1) + { + var v = bestVal + 10; + if (v <= 21) + bestVal = v; + } } - } - return bestVal; - - } + return bestVal; - function deckToString () - { - var s = ""; - for (i in this.cards) - s += this.cards[i].toString() + ":"; + }; + this.toString = function() + { + var s = ""; + for (i in this.cards) + s += this.cards[i].toString() + ":"; - return s; - } + return s; + }; - function Deck() - { - this.draw = deckDraw; - this.cards = new Array(); - this.reset = deckReset; - this.clear = deckClear; - this.evalMin = deckEvalMin; - this.evalBest = deckEvalBest; - this.toString = deckToString; - this.drawFrom = deckDrawFrom; + this.drawFrom = function(d) + { + var c = d.draw (); + this.cards.push(c); + updateDisplay (); + }; } @@ -125,35 +113,34 @@ </script> - </onentry> + </onentry> <invoke type="q-bindings"> <content> [[welcomeLabel,"text","Welcome to Blackjack"]] </content> - </invoke> + </invoke> <transition event="q-signal:newGameButton.clicked()" target="newgame" /> <state id="newgame"> - <onentry> - <script> - points = 1000; - pointsLabel.text = points; - </script> + <onentry> + <script> + points = 1000; + pointsLabel.text = points; + </script> </onentry> <transition target="newround" /> </state> <state id="quitdlg"> <invoke type="q-messagebox"> - <content> - { - "parent" : gameWidget, - "icon" : QMessageBox.Question, - "windowTitle" : "Exit Blackjack", - "text" : "Are you sure?", - "standardButtons" : - QMessageBox.Yes|QMessageBox.No - } - </content> - </invoke> + <content> + { + "parent" : gameWidget, + "icon" : QMessageBox.Question, + "windowTitle" : "Exit Blackjack", + "text" : "Are you sure?", + "standardButtons" : QMessageBox.Yes|QMessageBox.No + } + </content> + </invoke> <transition event="q-messagebox.finished" target="exit" cond="_event.data[0]==QMessageBox.Yes" /> <transition event="q-messagebox.finished" target="gamestate" cond="_event.data[0]==QMessageBox.No" /> </state> @@ -194,24 +181,24 @@ </transition> <transition event="q-signal:surrenderButton.clicked()" target="newround" /> </state> - <state id="betTooHigh"> + <state id="betTooHigh"> <invoke type="q-messagebox"> - <content> - { - "parent" : betEdit, - "icon" : QMessageBox.Warning, - "windowTitle" : "Bet is Too High", - "text" : "Please Place Another Bet", - "standardButtons" : - QMessageBox.Ok - } - </content> - </invoke> + <content> + { + "parent" : betEdit, + "icon" : QMessageBox.Warning, + "windowTitle" : "Bet is Too High", + "text" : "Please Place Another Bet", + "standardButtons" : + QMessageBox.Ok + } + </content> + </invoke> <transition event="q-messagebox.finished" target="waitForBet" /> - <transition event="bth-mb-timeout" target="waitForBet" /> - <onentry> + <transition event="bth-mb-timeout" target="waitForBet" /> + <onentry> <send event="'bth-mb-timeout'" delay="'1500ms'" /> - </onentry> + </onentry> </state> <state id="testCards"> <transition target="loss" cond="myDeck.evalBest() == 0" /> @@ -268,9 +255,9 @@ <invoke type="q-bindings"><content>[[newRoundButton,"enabled",true]]</content></invoke> <transition event="q-signal:newRoundButton.clicked()" target="newround" /> <transition event="timeout" target="newround" /> - <onentry> - <send event="'timeout'" delay="'3s'" /> - </onentry> + <onentry> + <send event="'timeout'" delay="'3s'" /> + </onentry> <state id="win"> <onentry> diff --git a/examples/blackjack/main.cpp b/examples/blackjack/main.cpp index c2e8105..4b5c978 100644 --- a/examples/blackjack/main.cpp +++ b/examples/blackjack/main.cpp @@ -5,14 +5,14 @@ #include <QMessageBox> #include <QUrl> #include <QScriptEngine> -#include "qscriptedstatemachine.h" +#include "qscxml.h" #include "time.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); srand(clock()); - QtScriptedStateMachine *sm = QtScriptedStateMachine::load(":/blackjack.scxml"); + QScxml *sm = QScxml::load(":/blackjack.scxml"); QObject::connect (sm, SIGNAL(finished()), &a, SLOT(quit())); QMessageBox b; QWidget* wdg = new QWidget(); diff --git a/examples/calc/calc.pro b/examples/calc/calc.pro index ff274c2..f20233e 100644 --- a/examples/calc/calc.pro +++ b/examples/calc/calc.pro @@ -7,7 +7,7 @@ TEMPLATE = app win32: CONFIG += console mac:CONFIG -= app_bundle QT = core gui script -include($$PWD/../../src/qtstatemachine.pri) +include($$PWD/../../src/qscxml.pri) # Input SOURCES += main.cpp calc.cpp diff --git a/examples/calc/calc.scxml b/examples/calc/calc.scxml index 35a9b9e..ec732c7 100644 --- a/examples/calc/calc.scxml +++ b/examples/calc/calc.scxml @@ -1,6 +1,3 @@ -<!-- http://www.state-machine.com/devzone/Recipe_DesigningHSM.pdf --> -<!-- events: OPER.PLUS OPER.MINUS OPER.MULTIPLY OPER.DIVIDE DIGIT.0 DIGIT.1_9 EQUALS CE C POINT - ---> <scxml initial="on" profile="ecma" name="calc"> <script> @@ -70,26 +67,26 @@ <datamodel> <data id="long_expr" /> <data id="res" >0</data> - </datamodel> + </datamodel> <onentry> - <script> + <script> var short_expr = 0; _data.res = 0; _data.long_expr = ""; updateDisplay(); - </script> - </onentry> - <state id="ready" initial="begin"> - <state id="begin"> - <transition event="OPER.MINUS" target="negated1" /> - <onentry> - <script> - updateDisplay (); - </script> - </onentry> - </state> - <state id="result"> - </state> + </script> + </onentry> + <state id="ready" initial="begin"> + <state id="begin"> + <transition event="OPER.MINUS" target="negated1" /> + <onentry> + <script> + updateDisplay (); + </script> + </onentry> + </state> + <state id="result"> + </state> <transition event="OPER" target="opEntered" /> <transition event="DIGIT.0" target="zero1"> <script> @@ -107,107 +104,107 @@ </script> </transition> </state> - <state id="negated1"> - <onentry> - <script> - negate (); - </script> - </onentry> - <transition event="DIGIT.0" target="zero1" /> + <state id="negated1"> + <onentry> + <script> + negate (); + </script> + </onentry> + <transition event="DIGIT.0" target="zero1" /> <transition event="DIGIT" target="int1" /> - <transition event="POINT" target="frac1" /> - </state> - <state id="operand1"> - <state id="zero1"> + <transition event="POINT" target="frac1" /> + </state> + <state id="operand1"> + <state id="zero1"> <transition event="DIGIT" cond="_event.name != 'DIGIT.0'" target="int1" /> - <transition event="POINT" target="frac1" /> - </state> - <state id="int1"> - <transition event="POINT" target="frac1" /> + <transition event="POINT" target="frac1" /> + </state> + <state id="int1"> + <transition event="POINT" target="frac1" /> <transition event="DIGIT"> - <script> - insertDigit (); - </script> - </transition> - <onentry> - <script> - insertDigit (); - </script> - </onentry> - </state> - <state id="frac1"> - <onentry> - <script> - insert ('.'); - </script> - </onentry> + <script> + insertDigit (); + </script> + </transition> + <onentry> + <script> + insertDigit (); + </script> + </onentry> + </state> + <state id="frac1"> + <onentry> + <script> + insert ('.'); + </script> + </onentry> <transition event="DIGIT"> - <script> - insertDigit (); - </script> - </transition> - </state> - <transition event="CE" target="ready" /> + <script> + insertDigit (); + </script> + </transition> + </state> + <transition event="CE" target="ready" /> <transition event="OPER" target="opEntered" /> - </state> - <state id="error" /> - <state id="opEntered"> - <transition event="OPER.MINUS" target="negated2" /> - <transition event="POINT" target="frac2" /> - <transition event="DIGIT.0" target="zero2" /> + </state> + <state id="error" /> + <state id="opEntered"> + <transition event="OPER.MINUS" target="negated2" /> + <transition event="POINT" target="frac2" /> + <transition event="DIGIT.0" target="zero2" /> <transition event="DIGIT" target="int2" /> - <onentry> - <script> - insertOp (); - </script> - </onentry> - </state> - <state id="negated2"> - <onentry> - <script> - negate (); - </script> - </onentry> - <transition event="CE" target="opEntered" /> - <transition event="DIGIT.0" target="zero2" /> + <onentry> + <script> + insertOp (); + </script> + </onentry> + </state> + <state id="negated2"> + <onentry> + <script> + negate (); + </script> + </onentry> + <transition event="CE" target="opEntered" /> + <transition event="DIGIT.0" target="zero2" /> <transition event="DIGIT" target="int2" /> - <transition event="POINT" target="frac2" /> - </state> - <state id="operand2"> - <state id="zero2"> + <transition event="POINT" target="frac2" /> + </state> + <state id="operand2"> + <state id="zero2"> <transition event="DIGIT" cond="_event.name != 'DIGIT.0'" target="int2" /> - <transition event="POINT" target="frac2" /> - </state> - <state id="int2"> + <transition event="POINT" target="frac2" /> + </state> + <state id="int2"> <transition event="DIGIT"> - <script> - insertDigit (); - </script> - </transition> - <onentry> - <script> - insertDigit (); - </script> - </onentry> - <transition event="POINT" target="frac2" /> - </state> - <state id="frac2"> - <onentry> - <script> - insert ('.'); - </script> - </onentry> + <script> + insertDigit (); + </script> + </transition> + <onentry> + <script> + insertDigit (); + </script> + </onentry> + <transition event="POINT" target="frac2" /> + </state> + <state id="frac2"> + <onentry> + <script> + insert ('.'); + </script> + </onentry> <transition event="DIGIT"> - <script> - insertDigit (); - </script> - </transition> - </state> + <script> + insertDigit (); + </script> + </transition> + </state> <transition event="OPER" cond="!insertOp()" target="error" /> <transition event="OPER" target="opEntered" /> - <transition event="EQUALS" cond="!calc()" target="error" /> - <transition event="EQUALS" target="result" /> - </state> - <transition event="C" target="on" /> - </state> + <transition event="EQUALS" cond="!calc()" target="error" /> + <transition event="EQUALS" target="result" /> + </state> + <transition event="C" target="on" /> + </state> </scxml> diff --git a/examples/calc/main.cpp b/examples/calc/main.cpp index 9d30c6b..181b792 100644 --- a/examples/calc/main.cpp +++ b/examples/calc/main.cpp @@ -1,11 +1,11 @@ #include <QtGui/QApplication> #include "calc.h" -#include "qscriptedstatemachine.h" +#include "qscxml.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); - QtScriptedStateMachine *sm = QtScriptedStateMachine::load(":/calc.scxml"); + QScxml *sm = QScxml::load(":/calc.scxml"); CalcWidget w; sm->registerObject(&w,"",true); QObject::connect (&w, SIGNAL(command(QString)), sm, SLOT(postNamedEvent(QString))); diff --git a/examples/examples.pro b/examples/examples.pro index a13e798..53d0ca3 100644 --- a/examples/examples.pro +++ b/examples/examples.pro @@ -1,2 +1,2 @@ TEMPLATE = subdirs -SUBDIRS += blackjack calc mediaplayer
\ No newline at end of file +SUBDIRS += blackjack calc mediaplayer
\ No newline at end of file diff --git a/examples/mediaplayer/main.cpp b/examples/mediaplayer/main.cpp index 1eb7b4b..29bc3fc 100644 --- a/examples/mediaplayer/main.cpp +++ b/examples/mediaplayer/main.cpp @@ -1,4 +1,4 @@ -#include "qscriptedstatemachine.h" +#include "qscxml.h" #include "spview.h" #include "spmodel.h" #include "spengine.h" @@ -38,7 +38,7 @@ int main( int argc, char **argv) app.setApplicationName("SCXML-mediaplayer"); SPView* view = new SPView(NULL); - QtScriptedStateMachine *sm = QtScriptedStateMachine::load(":/mediaplayer.scxml"); + QScxml *sm = QScxml::load(":/mediaplayer.scxml"); QObject::connect (sm, SIGNAL(finished()), &app, SLOT(quit())); SPModel* model= new SPModel(NULL); view->setModel(model); diff --git a/examples/mediaplayer/mediaplayer.pro b/examples/mediaplayer/mediaplayer.pro index 355da25..70c06f1 100644 --- a/examples/mediaplayer/mediaplayer.pro +++ b/examples/mediaplayer/mediaplayer.pro @@ -3,7 +3,7 @@ TARGET = scxmlplayer QT += script \ sql \ phonon -include($$PWD/../../src/qtstatemachine.pri) +include(../../src/qscxml.pri) HEADERS += spmodel.h \ spengine.h \ diff --git a/src/qscxml.cpp b/src/qscxml.cpp index 8190056..0651ade 100644 --- a/src/qscxml.cpp +++ b/src/qscxml.cpp @@ -52,6 +52,7 @@ \sa QStateMachine */ +#ifndef QT_NO_STATEMACHINE #include "qscxml.h" #include <QScriptEngine> @@ -111,15 +112,16 @@ class QScxmlTimer : public QObject public: QScxmlTimer(QScriptEngine* engine, const QScriptValue & scr, int delay) : QObject(engine),script(scr) { - startTimer(delay); + QTimer::singleShot(delay,this,SLOT(exec())); } - protected: - void timerEvent(QTimerEvent*) + protected Q_SLOTS: + void exec() { if (script.isFunction()) script.call(); else if (script.isString()) script.engine()->evaluate(script.toString()); + deleteLater(); } private: @@ -198,7 +200,7 @@ static QScriptValue receiveSignal(QScriptContext *context, QScriptEngine *engine { QString eventName = context->thisObject().property("e").toString(); if (!eventName.isEmpty()) { - QScxml* scxml = qobject_cast<QScxml*>(engine->globalObject().property("scxml.stateMachine").toQObject()); + QScxml* scxml = qobject_cast<QScxml*>(engine->globalObject().property("scxml").toQObject()); if (scxml) { QStringList pnames; QVariantList pvals; @@ -216,7 +218,7 @@ static QScriptValue receiveSignal(QScriptContext *context, QScriptEngine *engine static QScriptValue postEvent(QScriptContext *context, QScriptEngine *engine) { - QScxml* scxml = qobject_cast<QScxml*>(engine->globalObject().property("scxml").toQObject()); + QScxml* scxml = qobject_cast<QScxml*>(context->thisObject().toQObject()); if (scxml) { QString eventName,target,type; QStringList pnames; @@ -276,7 +278,7 @@ static QScriptValue postEvent(QScriptContext *context, QScriptEngine *engine) // scxml.invoke (type, target, paramNames, paramValues, content) static QScriptValue invoke(QScriptContext *context, QScriptEngine *engine) { - QScxml* scxml = qobject_cast<QScxml*>(engine->globalObject().property("scxml.stateMachine").toQObject()); + QScxml* scxml = qobject_cast<QScxml*>(context->thisObject().toQObject()); if (scxml) { QString type,target; QStringList pnames; @@ -300,7 +302,6 @@ static QScriptValue invoke(QScriptContext *context, QScriptEngine *engine) cnt = context->argument(4); - QScxmlInvokerFactory* invf = NULL; for (int i=0; i < scxml->pvt->invokerFactories.count() && invf == NULL; ++i) if (scxml->pvt->invokerFactories[i]->isTypeSupported(type)) @@ -327,7 +328,7 @@ static QScriptValue invoke(QScriptContext *context, QScriptEngine *engine) static QScriptValue isInState(QScriptContext *context, QScriptEngine *engine) { - QScxml* scxml = qobject_cast<QScxml*>(engine->globalObject().property("scxml.stateMachine").toQObject()); + QScxml* scxml = qobject_cast<QScxml*>(context->thisObject().toQObject()); if (scxml) { if (context->argumentCount() > 0) { QString name = context->argument(0).toString(); @@ -457,10 +458,10 @@ bool QScxmlTransition::eventTest(QEvent *e) if (!conditionExpression().isEmpty()) { + QScriptValue v = engine->evaluate(conditionExpression(),scxml->baseUrl().toLocalFile()); if (engine->hasUncaughtException()) { - qDebug() << engine->uncaughtException().toString(); QScxmlEvent* e = new QScxmlEvent("error.illegalcond", QStringList()<< "error" << "expr" << "line" << "backtrace", QVariantList() @@ -468,6 +469,7 @@ bool QScxmlTransition::eventTest(QEvent *e) << QVariant(conditionExpression()) << QVariant(engine->uncaughtExceptionLineNumber()) << QVariant(engine->uncaughtExceptionBacktrace())); + qDebug() << engine->uncaughtException().toString(); e->metaData.kind = QScxmlEvent::MetaData::Platform; scxml->postEvent(e); engine->clearExceptions(); @@ -482,7 +484,7 @@ bool QScxmlTransition::eventTest(QEvent *e) class QScxmlDefaultInvoker : public QScxmlInvoker { Q_OBJECT - + public: QScxmlDefaultInvoker(QScxmlEvent* ievent, QScxml* p) : QScxmlInvoker(ievent,p),cancelled(false),childSm(0) @@ -495,8 +497,8 @@ class QScxmlDefaultInvoker : public QScxmlInvoker } } - - + + static void initInvokerFactory(QScxml*) {} @@ -511,14 +513,14 @@ class QScxmlDefaultInvoker : public QScxmlInvoker void cancel () { - cancelled = true; + cancelled = true; if (childSm) childSm->stop(); } - + private: - bool cancelled; + bool cancelled; QScxml* childSm; }; class QScxmlBindingInvoker : public QScxmlInvoker @@ -611,21 +613,20 @@ QScxml::QScxml(QObject* parent) pvt = new QScxmlPrivate; pvt->scriptEng = new QScriptEngine(this); QScriptValue glob = pvt->scriptEng->globalObject(); - QScriptValue utilObj = pvt->scriptEng->newObject(); + QScriptValue scxmlObj = pvt->scriptEng->newQObject(this); glob.setProperty("In",pvt->scriptEng->newFunction(QScxmlFunctions::isInState)); glob.setProperty("_rcvSig",pvt->scriptEng->newFunction(QScxmlFunctions::receiveSignal)); glob.setProperty("print",pvt->scriptEng->newFunction(QScxmlFunctions::script_print)); - utilObj.setProperty("postEvent",pvt->scriptEng->newFunction(QScxmlFunctions::postEvent)); - utilObj.setProperty("invoke",pvt->scriptEng->newFunction(QScxmlFunctions::invoke)); - utilObj.setProperty("cssTime",pvt->scriptEng->newFunction(QScxmlFunctions::cssTime)); - utilObj.setProperty("stateMachine",pvt->scriptEng->newQObject(this)); - utilObj.setProperty("clone",pvt->scriptEng->newFunction(QScxmlFunctions::deepCopy)); - utilObj.setProperty("setTimeout",pvt->scriptEng->newFunction(QScxmlFunctions::setTimeout)); - utilObj.setProperty("clearTimeout",pvt->scriptEng->newFunction(QScxmlFunctions::clearTimeout)); + scxmlObj.setProperty("postEvent",pvt->scriptEng->newFunction(QScxmlFunctions::postEvent)); + scxmlObj.setProperty("invoke",pvt->scriptEng->newFunction(QScxmlFunctions::invoke)); + scxmlObj.setProperty("cssTime",pvt->scriptEng->newFunction(QScxmlFunctions::cssTime)); + scxmlObj.setProperty("clone",pvt->scriptEng->newFunction(QScxmlFunctions::deepCopy)); + scxmlObj.setProperty("setTimeout",pvt->scriptEng->newFunction(QScxmlFunctions::setTimeout)); + scxmlObj.setProperty("clearTimeout",pvt->scriptEng->newFunction(QScxmlFunctions::clearTimeout)); QScriptValue dmObj = pvt->scriptEng->newObject(); glob.setProperty("_data",pvt->scriptEng->newObject()); glob.setProperty("_global",pvt->scriptEng->globalObject()); - glob.setProperty("scxml",utilObj); + glob.setProperty("scxml",scxmlObj); glob.setProperty("connectSignalToEvent",pvt->scriptEng->evaluate("function(sig,ev) {sig.connect({'e':ev},_rcvSig);}")); static QScxmlAutoInvokerFactory<QScxmlDefaultInvoker> _s_defaultInvokerFactory; static QScxmlAutoInvokerFactory<QScxmlBindingInvoker> _s_bindingInvokerFactory; @@ -710,6 +711,7 @@ void QScxml::endMicrostep(QEvent*) pvt->snapshotStack.remove(0,pvt->snapshotStack.size()-100); } pvt->curSnapshot.clear(); +// qDebug() << configuration(); } /*! Returns the script engine attached to the state-machine. */ @@ -757,6 +759,7 @@ void QScxml::postNamedEvent(const QString & event) void QScxml::executeScript (const QString & s) { +// qDebug() << "Executing\n-----------------------------\n"<<s; pvt->scriptEng->evaluate (s,baseUrl().toLocalFile()); if (pvt->scriptEng->hasUncaughtException()) { QScxmlEvent* e = new QScxmlEvent("error.illegalvalue", @@ -770,6 +773,7 @@ void QScxml::executeScript (const QString & s) postEvent(e); pvt->scriptEng->clearExceptions(); } +// qDebug() <<"\n--------------------\n"; } /*! @@ -845,19 +849,19 @@ QScxml::~QScxml() QString QScxmlInvoker::id () const { - return initEvent->metaData.invokeID; + return initEvent->metaData.invokeID; } void QScxmlInvoker::setID(const QString & id) { - initEvent->metaData.invokeID = id; + initEvent->metaData.invokeID = id; } QScxmlInvoker::~QScxmlInvoker() { - if (cancelled) - postParentEvent("CancelResponse"); - else - postParentEvent(QString("done.invoke.%1").arg(initEvent->metaData.invokeID)); + if (cancelled) + postParentEvent("CancelResponse"); + else + postParentEvent(QString("done.invoke.%1").arg(initEvent->metaData.invokeID)); } /*! \property QScxml::baseUrl @@ -911,18 +915,18 @@ struct ScTransitionInfo class QScxmlScriptExec : public QObject { - Q_OBJECT - QString script; - QScxml* scxml; - public: - QScxmlScriptExec(const QString & scr, QScxml* scx) : script(scr),scxml(scx) - { - } - public Q_SLOTS: - void exec() - { - scxml->executeScript(script); - } + Q_OBJECT + QString script; + QScxml* scxml; + public: + QScxmlScriptExec(const QString & scr, QScxml* scx) : script(scr),scxml(scx) + { + } + public Q_SLOTS: + void exec() + { + scxml->executeScript(script); + } }; struct ScStateInfo @@ -979,7 +983,7 @@ class QScxmlLoader QList<ScHistoryInfo> historyInfo; QHash<QString,QAbstractState*> stateByID; QSet<QString> signalEvents; - QSet<QState*> statesWithFinal; + QSet<QState*> statesWithFinal; void loadState (QState* state, QIODevice* dev, const QString & stateID,const QString & filename); QScxml* load (QIODevice* device, QObject* obj = NULL, const QString & filename = ""); @@ -1156,11 +1160,13 @@ void QScxmlLoader::loadState ( QFinalState* f = new QFinalState(curState); f->setObjectName(id); curExecContext.state = f; - statesWithFinal.insert(curState); - QState* gp = qobject_cast<QState*>(curState->parentState()); - if (gp->childMode() == QState::ParallelStates) { - statesWithFinal.insert(gp); - } + statesWithFinal.insert(curState); + QState* gp = qobject_cast<QState*>(curState->parentState()); + if (gp) { + if (gp->childMode() == QState::ParallelStates) { + statesWithFinal.insert(gp); + } + } stateByID[id] = f; } } else if (r.name().toString().compare("script",Qt::CaseInsensitive) == 0) { @@ -1234,7 +1240,7 @@ void QScxmlLoader::loadState ( idLocation = r.attributes().value("idlocation").toString(); if (idLocation.isEmpty()) idLocation = r.attributes().value("invokeid").toString(); - QObject::connect (curState, SIGNAL(exited()),new QScxmlScriptExec(QString("invoke_%1.cancel();").arg(curState->objectName()),stateMachine),SLOT(exec())); + QObject::connect (curState, SIGNAL(exited()),new QScxmlScriptExec(QString("_data.invoke_%1.cancel();").arg(curState->objectName()),stateMachine),SLOT(exec())); QString type = r.attributes().value("type").toString(); if (type.isEmpty()) @@ -1349,9 +1355,9 @@ void QScxmlLoader::loadState ( ti->script = curExecContext.script; curExecContext.type = ScExecContext::None; } else if (r.name().toString().compare("invoke",Qt::CaseInsensitive) == 0) { - curExecContext.script += QString("invoke_%1 = scxml.invoke(srcType,src,paramNames,paramValues,content); }").arg(curState->objectName()); + curExecContext.script += QString("_data.invoke_%1 = scxml.invoke(srcType,src,paramNames,paramValues,content); }").arg(curState->objectName()); if (!idLocation.isEmpty()) { - curExecContext.script += QString("%1 = invoke_%2;").arg(idLocation).arg(curState->objectName()); + curExecContext.script += QString("%1 = _data.invoke_%2;").arg(idLocation).arg(curState->objectName()); } curExecContext.state = curState; curExecContext.type = ScExecContext::StateEntry; @@ -1382,10 +1388,10 @@ QScxml* QScxmlLoader::load(QIODevice* device, QObject* obj, const QString & file QString scr = QString("%1.connect({e:\"%2\"},_rcvSig);\n").arg(sig).arg(s); stateMachine->pvt->startScript += scr; } - - foreach (QState* s, statesWithFinal) { - QObject::connect(s,SIGNAL(finished()),stateMachine,SLOT(handleStateFinished())); - } + + foreach (QState* s, statesWithFinal) { + QObject::connect(s,SIGNAL(finished()),stateMachine,SLOT(handleStateFinished())); + } // resolve transitions @@ -1408,10 +1414,10 @@ QScxml* QScxmlLoader::load(QIODevice* device, QObject* obj, const QString & file void QScxml::handleStateFinished() { - QState* state = qobject_cast<QState*>(sender()); - if (state) { - postEvent(new QScxmlEvent("done.state." + state->objectName())); - } + QState* state = qobject_cast<QState*>(sender()); + if (state) { + postEvent(new QScxmlEvent("done.state." + state->objectName())); + } } /*! @@ -1426,3 +1432,4 @@ QScxml* QScxml::load (const QString & filename, QObject* o) } #include "qscxml.moc" +#endif
\ No newline at end of file diff --git a/src/qscxml.pri b/src/qscxml.pri index effa64d..873c038 100644 --- a/src/qscxml.pri +++ b/src/qscxml.pri @@ -1,6 +1,7 @@ QT += script SOURCES += $$PWD/qscxml.cpp \ - $$PWD/qscxmlgui.cpp - + $$PWD/qscxmlgui.cpp + HEADERS += $$PWD/qscxml.h \ - $$PWD/qscxmlgui.h + $$PWD/qscxmlgui.h +INCLUDEPATH += $$PWD
\ No newline at end of file diff --git a/src/qscxmlgui.cpp b/src/qscxmlgui.cpp index 3fdfabc..ca27692 100644 --- a/src/qscxmlgui.cpp +++ b/src/qscxmlgui.cpp @@ -103,6 +103,7 @@ namespace void QScxmlMenuInvoker::activate () { + qDebug() << "Activating menu"; QScxmlEvent* ie = initEvent; QScriptValue v = ie->content(); QWidget* parent = qobject_cast<QWidget*>(v.property("parent").toQObject()); @@ -119,6 +120,7 @@ void QScxmlMenuInvoker::activate () } void QScxmlMenuInvoker::cancel () { + qDebug() << "QScxmlMenuInvoker::cancel"; if (menu) menu->deleteLater(); QScxmlInvoker::cancel(); |