From 9a50c13ad99d40115bb023aa1a89a9f0c1a352bb Mon Sep 17 00:00:00 2001 From: No'am Rosenthal Date: Thu, 26 Nov 2009 15:26:27 -0800 Subject: removed fringe features --- src/qscxml.cpp | 144 ++++----------------------------------------------------- 1 file changed, 10 insertions(+), 134 deletions(-) (limited to 'src/qscxml.cpp') diff --git a/src/qscxml.cpp b/src/qscxml.cpp index cbb9c7c..ec78f9a 100644 --- a/src/qscxml.cpp +++ b/src/qscxml.cpp @@ -186,16 +186,6 @@ class QScxmlPrivate { public: - enum { MaxSnapshots = 200}; - - struct AnchorSnapshot - { - QAbstractState* state; - QString location; - QScriptValue snapshot; - QString anchorType; - }; - void initScriptEngine(QScxml* thiz); QScriptValue dataObj; @@ -209,12 +199,6 @@ class QScxmlPrivate QSet knownEvents; - - QStack snapshotStack; - QMultiHash anchorTransitions; - QHash curSnapshot; - - static QHash sessions; }; QHash QScxmlPrivate::sessions; @@ -871,16 +855,6 @@ void QScxml::beginSelectTransitions(QEvent* ev) scriptEngine()->globalObject().setProperty("_event",eventObj); QHash curTargets; - - for (int i = pvt->snapshotStack.size()-1; i >= 0 && curTargets.size() < pvt->anchorTransitions.keys().size(); --i) { - if (!curTargets.contains(pvt->snapshotStack.at(i).anchorType)) { - curTargets[pvt->snapshotStack.at(i).anchorType] = pvt->snapshotStack.at(i).state; - } - } - for (QMultiHash::const_iterator it = pvt->anchorTransitions.constBegin(); it != pvt->anchorTransitions.constEnd(); ++it) { - it.value()->setTargetState(curTargets[it.key()]); - } - } static QString _q_configToString (QAbstractState* from,int level, const QSet & config) @@ -917,24 +891,8 @@ static QString _q_configToString (QAbstractState* from,int level, const QSetglobalObject().setProperty("_event",QScriptValue()); - for (QHash::iterator - it = pvt->curSnapshot.begin(); - it != pvt->curSnapshot.end(); ++it) { - - pvt->snapshotStack.push(it.value()); - } - if (pvt->snapshotStack.size() > QScxmlPrivate::MaxSnapshots) { - pvt->snapshotStack.remove(0,pvt->snapshotStack.size()-100); - } - pvt->curSnapshot.clear(); - qDebug() << configuration(); emit configurationChanged(); - /* - if (e->type() == QScxmlEvent::eventType()) { - qDebug() << "\n" + _q_configToString(rootState(),-1,configuration()); - } - */ } /*! Returns the script engine attached to the state-machine. */ @@ -991,7 +949,7 @@ void QScxml::setData(const QString & id, const QVariant & val) void QScxml::executeScript (const QScriptProgram & s) { - qDebug() << "Executing\n--------------------------\n"<scriptEng->evaluate (s); if (pvt->scriptEng->hasUncaughtException()) { QScxmlEvent* e = new QScxmlEvent("error.illegalvalue", @@ -1151,7 +1109,6 @@ struct ScTransitionInfo QScxmlTransition* transition; QStringList targets; - QString anchor; QString script; ScTransitionInfo() : transition(NULL) {} }; @@ -1239,76 +1196,7 @@ class QScxmlLoader } }; -class QScxmlAnchorSave : public QObject -{ - Q_OBJECT - public: - QScxml* sm; - QScxmlPrivate* pvt; - QScxmlPrivate::AnchorSnapshot anchorSnapshot; - QScxmlAnchorSave(QScxml* p,QScxmlPrivate* pv, - const QString & type, const QString & loc, - QAbstractState* s) : - QObject(p),sm(p),pvt(pv) - { - anchorSnapshot.anchorType = type; - anchorSnapshot.location = loc; - anchorSnapshot.state = s; - } - - public Q_SLOTS: - void save() - { - if (!anchorSnapshot.location.isEmpty()) { - anchorSnapshot.snapshot = _q_deepCopy(sm->scriptEngine()->evaluate(anchorSnapshot.location)); - } - pvt->curSnapshot[anchorSnapshot.anchorType] = anchorSnapshot; - } -}; - -class QScxmlAnchorRestore : public QObject -{ - Q_OBJECT - public: - QScxml* sm; - QScxmlPrivate* pvt; - QString anchorType; - QScxmlAnchorRestore(QScxml* p,QScxmlPrivate* pv, - const QString & type) : - QObject(p),sm(p),pvt(pv),anchorType(type) - { - - } - - public Q_SLOTS: - void restore () - { - pvt->curSnapshot.clear(); - while (!pvt->snapshotStack.isEmpty()) { - QScxmlPrivate::AnchorSnapshot s = pvt->snapshotStack.pop(); - if (s.anchorType == anchorType) { - if (s.location != "") { - sm->scriptEngine()->globalObject().setProperty("_snapshot",s.snapshot); - sm->scriptEngine()->evaluate(QString ("%1 = _snapshot;").arg(s.location)); - sm->scriptEngine()->globalObject().setProperty("_snapshot",QScriptValue()); - } - break; - } - } - } -}; - -static QString sanitize (const QString & str) -{ - return str; -// return QString("eval(unescape(\"%1\"))"). -// arg(QString::fromAscii(str.trimmed().toUtf8().toPercentEncoding(QByteArray("[]()<>;:#/'`_-., \t@!^&*{}")))); -} -static QString sanitize (const QStringRef & str) -{ - return sanitize(str.toString()); -} void QScxmlLoader::loadState ( QState* stateParam, @@ -1423,9 +1311,9 @@ void QScxmlLoader::loadState ( } else if (r.name().toString().compare("log",Qt::CaseInsensitive) == 0) { curExecContext.script += QString("scxml.print('[' + %1 + '][' + %2 + ']' + %3);") - .arg(sanitize(r.attributes().value("label"))) - .arg(sanitize(r.attributes().value("level"))) - .arg(sanitize(r.attributes().value("expr"))); + .arg(r.attributes().value("label").toString()) + .arg(r.attributes().value("level").toString()) + .arg(r.attributes().value("expr").toString()); } else if (r.name().toString().compare("assign",Qt::CaseInsensitive) == 0) { QString locattr = r.attributes().value("location").toString(); @@ -1435,16 +1323,16 @@ void QScxmlLoader::loadState ( locattr = "_data." + locattr; } if (!locattr.isEmpty()) { - curExecContext.script += QString ("%1 = %2;").arg(locattr).arg(sanitize(r.attributes().value("expr"))); + curExecContext.script += QString ("%1 = %2;").arg(locattr).arg(r.attributes().value("expr").toString()); } } else if (r.name().toString().compare("if",Qt::CaseInsensitive) == 0) { - curExecContext.script += QString("if (%1) {").arg(sanitize(r.attributes().value("cond"))); + curExecContext.script += QString("if (%1) {").arg(r.attributes().value("cond").toString()); } else if (r.name().toString().compare("elseif",Qt::CaseInsensitive) == 0) { - curExecContext.script += QString("} elseif (%1) {").arg(sanitize(r.attributes().value("cond"))); + curExecContext.script += QString("} elseif (%1) {").arg(r.attributes().value("cond").toString()); } else if (r.name().toString().compare("else",Qt::CaseInsensitive) == 0) { curExecContext.script += " } else { "; } else if (r.name().toString().compare("cancel",Qt::CaseInsensitive) == 0) { - curExecContext.script += QString("scxml.clearTimeout (%1);").arg(sanitize(r.attributes().value("id"))); + curExecContext.script += QString("scxml.clearTimeout (%1);").arg(r.attributes().value("id").toString()); } else if (r.name().toString().compare("onentry",Qt::CaseInsensitive) == 0) { curExecContext.type = ScExecContext::StateEntry; curExecContext.script = ""; @@ -1538,11 +1426,6 @@ void QScxmlLoader::loadState ( stateMachine->pvt->knownEvents.insert(pfx); } curExecContext.trans = curTransition; - QString anc = r.attributes().value("anchor").toString(); - if (!anc.isEmpty()) { - stateMachine->pvt->anchorTransitions.insert(anc,curTransition); - QObject::connect (curTransition, SIGNAL(triggered()),new QScxmlAnchorRestore(stateMachine,stateMachine->pvt,anc),SLOT(restore())); - } inf.transition = curTransition; transitions.append(inf); foreach (QString prefix, curTransition->eventPrefixes()) { @@ -1550,11 +1433,9 @@ void QScxmlLoader::loadState ( signalEvents.insert(prefix); } } - curTransition->setObjectName(QString ("%1 to %2 on %3 if %4 (anchor=%5)").arg(curState->objectName()).arg(inf.targets.join(" ")).arg(curTransition->eventPrefixes().join(" ")).arg(curTransition->conditionExpression()).arg(anc)); + curTransition->setObjectName(QString ("%1 to %2 on %3 if %4").arg(curState->objectName()).arg(inf.targets.join(" ")).arg(curTransition->eventPrefixes().join(" ")).arg(curTransition->conditionExpression())); } - } else if (r.name().toString().compare("anchor",Qt::CaseInsensitive) == 0) { - QObject::connect(curState,SIGNAL(exited()),new QScxmlAnchorSave(stateMachine,stateMachine->pvt,r.attributes().value("type").toString(),r.attributes().value("snapshot").toString(),curState),SLOT(save())); - } else if (r.name().toString().compare("data",Qt::CaseInsensitive) == 0) { + } else if (r.name().toString().compare("data",Qt::CaseInsensitive) == 0) { QScriptValue val = qScriptValueFromValue(stateMachine->scriptEngine(),"") ; QString id = r.attributes().value("id").toString(); if (r.attributes().value("src").length()) @@ -1570,7 +1451,6 @@ void QScxmlLoader::loadState ( } QScriptValue func = stateMachine->scriptEngine()->newFunction(QScxmlFunctions::dataAccess); func.setProperty("key",id); - qDebug() << id << val.toVariant(); stateMachine->pvt->dataObj.setProperty(id,func,QScriptValue::PropertyGetter|QScriptValue::PropertySetter); stateMachine->pvt->dataObj.setProperty(id,val); } else if (r.name().toString().compare("param",Qt::CaseInsensitive) == 0) { @@ -1628,10 +1508,6 @@ void QScxmlLoader::loadState ( curExecContext.type = ScExecContext::Transition; curExecContext.applyScript(); } - - ScTransitionInfo* ti = &(transitions.last()); - if (!curExecContext.script.isEmpty() && ti->anchor != "") - ti->script = curExecContext.script; curExecContext.type = ScExecContext::None; } else if (r.name().toString().compare("invoke",Qt::CaseInsensitive) == 0) { QString pnames; -- cgit v1.2.3