From 29afc5ca5eb425565e0859a231939854aadcc13a Mon Sep 17 00:00:00 2001 From: Konrad Rosenbaum Date: Sun, 17 Jul 2016 16:46:15 +0200 Subject: [PATCH] remove Qt scripting; add common converters for QVariant; make WObjects gadgets instead of QObjects --- .gitignore | 1 + qtbase/include/helper.h | 1 + qtbase/include/object.h | 30 +++++------- qtbase/src/helper.cpp | 20 +------- qtbase/src/helper_p.h | 31 ++++++++++++ qtbase/src/nullscript.cpp | 118 --------------------------------------------- qtbase/src/object.cpp | 23 +++++++++ qtbase/wbase.pro | 3 +- woc/qt/qt.pri | 4 +- woc/qt/qtclass.cpp | 46 ++--------------- woc/qt/qtclass.h | 2 - woc/qt/qtconst.h | 3 +- woc/qt/qtctrans.cpp | 29 ----------- woc/qt/qtctrans.h | 2 - woc/qt/qtfiles.qrc | 11 ---- woc/qt/qtout.cpp | 32 ------------ woc/qt/qtout.h | 10 +--- woc/qt/qtstrans.cpp | 27 ---------- woc/qt/qtstrans.h | 2 - 19 files changed, 84 insertions(+), 311 deletions(-) create mode 100644 qtbase/src/helper_p.h delete mode 100644 qtbase/src/nullscript.cpp delete mode 100644 woc/qt/qtfiles.qrc diff --git a/.gitignore b/.gitignore index 512b7db..9ca99a4 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,4 @@ examples/clock/qtc/clock examples/clock/qts/clockserv examples/clock/qtc/clock.exe examples/clock/qts/clockserv.exe +.qmake.stash diff --git a/qtbase/include/helper.h b/qtbase/include/helper.h index df24b21..0a420c9 100644 --- a/qtbase/include/helper.h +++ b/qtbase/include/helper.h @@ -19,6 +19,7 @@ class QDomNode; class WOLF_BASE_EXPORT WHelper:public QObject { + Q_OBJECT protected: /**helper for de-serializers: returns direct child elements with given tag name (necessary because QDomElement::elementsByTagName traverses all children)*/ static QListelementsByTagName(const QDomElement&,QString); diff --git a/qtbase/include/object.h b/qtbase/include/object.h index 391baee..0ff7d0e 100644 --- a/qtbase/include/object.h +++ b/qtbase/include/object.h @@ -8,27 +8,32 @@ #include #include +#include #include "nullable.h" #include "exception.h" -#include "WHelper" class QDomElement; class QDomDocument; -class QScriptValue; -class QScriptEngine; /**base class of all web based objects*/ -class WOLF_BASE_EXPORT WObject:public WHelper +class WOLF_BASE_EXPORT WObject { + Q_GADGET protected: WObject(){} - WObject(const WObject&):WHelper(){} + WObject(const WObject&){} WObject(const QDomElement&){} virtual ~WObject(){} virtual QDomElement toXml(QDomDocument&,QString name="Object"); virtual WObject& operator=(const WObject&){return *this;} virtual void toXml(QDomDocument&,QDomElement&){} + + /**helper for de-serializers: returns direct child elements with given tag name (necessary because QDomElement::elementsByTagName traverses all children)*/ + static QListelementsByTagName(const QDomElement&,QString); + + /**helper for XML decoding: transforms string to boolean*/ + bool str2bool(QString s); }; /**this exception is thrown if the deserialization of an object fails on the XML parser level*/ @@ -46,19 +51,8 @@ class WOLF_BASE_EXPORT WDeserializerException:public WException wob(const QDomElement&w):wob ## Abstract(w){} \ wob& operator=(const wob&w){wob ## Abstract::operator=(w);return *this;} \ wob& operator=(const wob ## Abstract&w){wob ## Abstract::operator=(w);return *this;} \ - private: - - -#define WOSCRIPT(wob) public: \ - static QScriptValue toScriptValue(QScriptEngine*,const wob &); \ - static void fromScriptValue(const QScriptValue&,wob &); \ - private: +private:\ + QString tr(const char*text,const char*comment=nullptr)const{return QCoreApplication::translate("" # wob ,text,comment);} -#define WOSCRIPT_IMP(wob) -/* QScriptValue wob::toScriptValue(QScriptEngine*engine,const wob &obj){\ - return engine->newQObject(new wob (obj),QScriptEngine::ScriptOwnership);}\ - void wob::fromScriptValue(const QScriptValue&val,wob &obj){\ - wob *xobj=qobject_cast< wob *>(val.toQObject());\ - if(xobj!=0 && &obj!=xobj)obj = *xobj;}*/ #endif diff --git a/qtbase/src/helper.cpp b/qtbase/src/helper.cpp index 9023a52..28f3e7a 100644 --- a/qtbase/src/helper.cpp +++ b/qtbase/src/helper.cpp @@ -5,28 +5,14 @@ #include "WHelper" -#include -#include +#include "helper_p.h" QListWHelper::elementsByTagName(const QDomElement&root,QString tag) { - QDomNodeList cn=root.childNodes(); - QListret; - for(int i=0;i +#include + +static inline QListhelper_elementsByTagName(const QDomElement&root,QString tag) +{ + QDomNodeList cn=root.childNodes(); + QListret; + for(int i=0;i -#include - -static QScriptValue Bool_toScriptValue(QScriptEngine*,const Nullable&obj) -{ - if(obj.isNull())return QScriptValue::NullValue; - else return QScriptValue(obj.value()); -} - -static void Bool_fromScriptValue(const QScriptValue&val,Nullable&obj) -{ - if(val.isNull())obj=Nullable(); - if(val.isBool())obj=val.toBool(); - else obj=Nullable(); -} - -static QScriptValue String_toScriptValue(QScriptEngine*,const Nullable&obj) -{ - if(obj.isNull())return QScriptValue::NullValue; - else return QScriptValue(obj.value()); -} - -static void String_fromScriptValue(const QScriptValue&val,Nullable&obj) -{ - if(val.isNull())obj=Nullable(); - if(val.isString())obj=val.toString(); - else obj=Nullable(); -} - -static QScriptValue Int32_toScriptValue(QScriptEngine*,const Nullable&obj) -{ - if(obj.isNull())return QScriptValue::NullValue; - else return QScriptValue(obj.value()); -} - -static void Int32_fromScriptValue(const QScriptValue&val,Nullable&obj) -{ - if(val.isNull())obj=Nullable(); - if(val.isNumber())obj=val.toInt32(); - else obj=Nullable(); -} - -static QScriptValue UInt32_toScriptValue(QScriptEngine*,const Nullable&obj) -{ - if(obj.isNull())return QScriptValue::NullValue; - else return QScriptValue(obj.value()); -} - -static void UInt32_fromScriptValue(const QScriptValue&val,Nullable&obj) -{ - if(val.isNull())obj=Nullable(); - if(val.isNumber())obj=val.toUInt32(); - else obj=Nullable(); -} - -static QScriptValue Int64_toScriptValue(QScriptEngine*,const Nullable&obj) -{ - if(obj.isNull())return QScriptValue::NullValue; - else return QScriptValue(qsreal(obj.value())); -} - -static void Int64_fromScriptValue(const QScriptValue&val,Nullable&obj) -{ - if(val.isNull())obj=Nullable(); - if(val.isNumber())obj=(qint64)val.toNumber(); - else obj=Nullable(); -} - -static QScriptValue UInt64_toScriptValue(QScriptEngine*,const Nullable&obj) -{ - if(obj.isNull())return QScriptValue::NullValue; - else return QScriptValue(qsreal(obj.value())); -} - -static void UInt64_fromScriptValue(const QScriptValue&val,Nullable&obj) -{ - if(val.isNull())obj=Nullable(); - if(val.isNumber())obj=(quint64)val.toNumber(); - else obj=Nullable(); -} - -//TODO: copy the QByteArray wrapper from the Qt tutorials -static QScriptValue BA_toScriptValue(QScriptEngine*engine,const Nullable&obj) -{ - if(obj.isNull())return QScriptValue::NullValue; - else return engine->newVariant(obj.value()); -} - -static void BA_fromScriptValue(const QScriptValue&val,Nullable&obj) -{ - if(val.isNull())obj=Nullable(); - if(val.isVariant())obj=val.toVariant().toByteArray(); - else obj=Nullable(); -} - - -//list of supported types -static void initNullableScripting(QScriptEngine*engine) -{ - QScriptValue gval=engine->globalObject(); - qScriptRegisterMetaType(engine,Bool_toScriptValue,Bool_fromScriptValue); - qScriptRegisterMetaType(engine,String_toScriptValue,String_fromScriptValue); - qScriptRegisterMetaType(engine,Int32_toScriptValue,Int32_fromScriptValue); - qScriptRegisterMetaType(engine,UInt32_toScriptValue,UInt32_fromScriptValue); - qScriptRegisterMetaType(engine,Int64_toScriptValue,Int64_fromScriptValue); - qScriptRegisterMetaType(engine,UInt64_toScriptValue,UInt64_fromScriptValue); - qScriptRegisterMetaType(engine,BA_toScriptValue,BA_fromScriptValue); -} - - -//end: nullscript.cpp diff --git a/qtbase/src/object.cpp b/qtbase/src/object.cpp index 490c017..e2a8a41 100644 --- a/qtbase/src/object.cpp +++ b/qtbase/src/object.cpp @@ -15,6 +15,19 @@ QDomElement WObject::toXml(QDomDocument&doc,QString name) return doc.createElement(name); } +#include "helper_p.h" + +QListWObject::elementsByTagName(const QDomElement&root,QString tag) +{ + return helper_elementsByTagName(root,tag); +} + +bool WObject::str2bool(QString s) +{ + return helper_str2bool(s); +} + + static inline bool w(bool b){qDebug()<<"registering"< >(); static bool btype0= + //NULLABLE //String/bytes to self QMetaType::registerConverter,QString>(&Nullable::valueOrDefault)| QMetaType::registerConverter,QByteArray>(&Nullable::valueOrDefault)| @@ -54,4 +68,13 @@ static bool btype0= QMetaType::registerConverter,QString>([](Nullable v)->QString{return QString::number(v.valueOrDefault());})| QMetaType::registerConverter,QString>([](Nullable v)->QString{return QString::number(v.valueOrDefault());})| QMetaType::registerConverter,QString>([](Nullable v)->QString{return QString::number(v.valueOrDefault());})| + //LIST + //string is predefined + //int/bool + QMetaType::registerConverter,QVariantList>([](const QList&n){QVariantList r;for(auto v:n)r<,QVariantList>([](const QList&n){QVariantList r;for(auto v:n)r<,QVariantList>([](const QList&n){QVariantList r;for(auto v:n)r<,QVariantList>([](const QList&n){QVariantList r;for(auto v:n)r<,QVariantList>([](const QList&n){QVariantList r;for(auto v:n)r<,QVariantList>([](const QList&n){QVariantList r;for(auto v:n)r<languageSpec(),m_parent->namePrefix()+"O"); hcd+=doxyFormat(cls.docStrings()); - hcd+="class "+m_parent->exportSymbol()+" "+cna+":public "+cnb+"\n{\n Q_OBJECT\n"; + hcd+="class "+m_parent->exportSymbol()+" "+cna+":public "+cnb+"\n{\n Q_GADGET\n"; hdr.write(hcd.toLatin1()); //enums @@ -75,17 +75,16 @@ void WocQtClass::newClass(const WocClass&cls) //deserializer (constructor) classDeserializer(cls,hdr,src,cna); - //scripting - classScripting(cls,hdr,src,cna,cn); - //meta types m_aux+="Q_DECLARE_METATYPE("+cna+")\n"; m_aux+="Q_DECLARE_METATYPE(QList<"+cna+">)\n"; m_aux+="Q_DECLARE_METATYPE(Nullable<"+cna+">)\n"; scd="static int class_metatypeid="; - scd+="qRegisterMetaType<"+cna+">()+"; - scd+="qRegisterMetaType >()+"; - scd+="qRegisterMetaType >();\n"; + scd+="\tqRegisterMetaType<"+cna+">()+"; + scd+="\tqRegisterMetaType >()+"; + scd+="\tqRegisterMetaType >();\n"; + scd+="static bool class_converter=QMetaType::registerConverter,"+cna+">([](const Nullable<"+cna+">&n){return n.value();})|\n"; + scd+="\tQMetaType::registerConverter,QVariantList>([](const QList<"+cna+">&n){QVariantList r;for(auto v:n)r<doGenerateScripting())return; - //converters - QString hcd,scd; - if(cna==cn){ - hcd+=" public:\n"; - hcd+="\tstatic QScriptValue toScriptValue(QScriptEngine*,const "+cna+"&);\n"; - hcd+="\tstatic void fromScriptValue(const QScriptValue&,"+cna+"&);\n"; - }else{ - scd+="#include \""+cn+"\"\n"; - } - scd+="#include \n"; - scd+="#include \n"; - scd+=doxyFormat("Convert "+cn+" to a value usable with the Qt script engine."); - scd+="QScriptValue "+cn+"::toScriptValue(QScriptEngine*engine,const "+cn+"&obj)\n{\n"; - scd+="\treturn engine->newQObject(new "+cn+"(obj),QScriptEngine::ScriptOwnership);\n}\n"; - scd+=doxyFormat("Convert from a Qt script engine value back to a "+cn+"."); - scd+="void "+cn+"::fromScriptValue(const QScriptValue&val,"+cn+"&obj)\n{\n"; - scd+="\t"+cn+"*xobj=qobject_cast<"+cn+"*>(val.toQObject());\n"; - scd+="\tif(xobj!=0 && &obj!=xobj)obj = *xobj;\n}\n"; - hdr.write(hcd.toLatin1()); - src.write(scd.toLatin1()); - //scripting registry - m_parent->addScriptInit( - "\tgval.setProperty(\""+cn+"\",engine->newQMetaObject(&"+cn+"::staticMetaObject));\n" - "\tqScriptRegisterMetaType(engine,"+cn+"::toScriptValue,"+cn+"::fromScriptValue);\n" - "\tqScriptRegisterSequenceMetaType >(engine);\n" - ); -} - - void WocQtClass::classEnums(const WocClass&cls,MFile&hdr,MFile&src,QString cn) { QStringList k=cls.enumTypes(); diff --git a/woc/qt/qtclass.h b/woc/qt/qtclass.h index 97f0403..8ff5a25 100644 --- a/woc/qt/qtclass.h +++ b/woc/qt/qtclass.h @@ -37,8 +37,6 @@ class WocQtClass:public QObject void classDeserializer(const WocClass&,MFile&,MFile&,QString); /**helper: generate serializers*/ void classSerializers(const WocClass&,MFile&,MFile&,QString); - ///helper: generate scripting stuff - void classScripting(const WocClass&,MFile&,MFile&,QString,QString); signals: ///emitted if something is wrong, aborts the processor void errorFound(); diff --git a/woc/qt/qtconst.h b/woc/qt/qtconst.h index a46bb49..5162ffb 100644 --- a/woc/qt/qtconst.h +++ b/woc/qt/qtconst.h @@ -21,7 +21,8 @@ static const QByteArray SRCSTART= "//DO NOT EDIT THIS FILE DIRECTLY, USE THE XML SOURCE!\n" "#include \"%\"\n" "#include \n" - "#include \n"; + "#include \n" + "#include \n"; //end section of all source files static const QByteArray SRCEND="\n//END OF AUTOMATICALLY GENERATED FILE\n"; diff --git a/woc/qt/qtctrans.cpp b/woc/qt/qtctrans.cpp index 01cfac6..3a8c73f 100644 --- a/woc/qt/qtctrans.cpp +++ b/woc/qt/qtctrans.cpp @@ -113,9 +113,6 @@ void WocQtClientTransaction::newTransaction(const WocTransaction&trn) //create getters genGetters(ct); - //create scripting - genScripting(ct); - //create log control genLogCtrl(ct); @@ -304,31 +301,6 @@ void WocQtClientTransaction::genGetters(QtCTrans& ct) } } -void WocQtClientTransaction::genScripting(QtCTrans& ct) -{ - if(!m_parent->doGenerateScripting())return; - //converters between transaction and script values - ct.hdi+="class QScriptValue;\n"; - ct.hdi+="class QScriptEngine;\n"; - ct.sri+="#include \n"; - ct.sri+="#include \n"; - ct.hcd+="\t/// Wraps the transaction so it can be used from scripts.\n"; - ct.hcd+="\tstatic QScriptValue toScriptValue(QScriptEngine*,const "+ct.cn+"&);\n"; - ct.hcd+="\t/// Unwraps the transaction in the script value, so it can be used in C++ again.\n"; - ct.hcd+="\tstatic void fromScriptValue(const QScriptValue&,"+ct.cn+"&);\n"; - ct.scd+="QScriptValue "+ct.cn+"::toScriptValue(QScriptEngine*engine,const "+ct.cn+"&obj)\n{\n"; - ct.scd+="\treturn engine->newQObject(new "+ct.cn+"(obj),QScriptEngine::ScriptOwnership);\n}\n"; - ct.scd+="void "+ct.cn+"::fromScriptValue(const QScriptValue&val,"+ct.cn+"&obj)\n{\n"; - ct.scd+="\t"+ct.cn+"*xobj=qobject_cast<"+ct.cn+"*>(val.toQObject());\n"; - ct.scd+="\tif(xobj!=0 && &obj!=xobj)obj = *xobj;\n}\n"; - //add to engine - m_parent->addScriptInit( - "\t{QScriptValue mo=engine->newQMetaObject(&"+ct.cn+"::staticMetaObject);\n" - "\tgval.setProperty(\""+ct.cn+"\",mo);\n" - "\tqScriptRegisterMetaType(engine,"+ct.cn+"::toScriptValue,"+ct.cn+"::fromScriptValue);}\n" - ); -} - void WocQtClientTransaction::genLogCtrl(QtCTrans& ct) { if(ct.trn.logMode()==WocTransaction::LogAll)return; @@ -518,7 +490,6 @@ void WocQtClientTransaction::trnList() code+="qRegisterMetaTypeifaceClassName()+"::RightList> >();\n"; m_parent->addPostIface("Q_DECLARE_METATYPE("+m_parent->ifaceClassName()+"::RightList)\n"); m_parent->addPostIface("Q_DECLARE_METATYPE(QList<"+ m_parent->ifaceClassName()+ "::RightList>)\n"); - m_parent->addScriptInit("\tqScriptRegisterSequenceMetaType >(engine);\n"); code+="QString "+m_parent->ifaceClassName()+"::rightToString(Right r)\n{\n\tswitch(r){\n"; for(int i=0;i - - - - ../../qtbase/src/nullscript.cpp - - diff --git a/woc/qt/qtout.cpp b/woc/qt/qtout.cpp index c7f95cc..68b2536 100644 --- a/woc/qt/qtout.cpp +++ b/woc/qt/qtout.cpp @@ -27,7 +27,6 @@ WocQtOut::WocQtOut(QDomElement&el) m_prefix=el.attribute("classPrefix","Wob"); m_cprefix=el.attribute("shareObjects",m_prefix); m_transbase=el.attribute("transactionBase","WTransaction"); - m_genscript=str2bool(el.attribute("scriptable","0")); m_export=str2bool(el.attribute("enableExport","0")); //get/create directory QDir d(m_basedir+"/"+m_subdir); @@ -65,8 +64,6 @@ WocQtOut::WocQtOut(QDomElement&el) m_iface.write(QByteArray("#include \"WInterface\"\n")); m_iface.write(QByteArray("#include \n")); m_iface.write(exportLines()); - if(m_genscript) - m_iface.write(QByteArray("class QScriptEngine;\n")); addIfaceHeaderClass(doxyFormat(pn+" interface class.")); addIfaceHeaderClass(QString("class "+exportSymbol()+" "+ifaceClassName()+":public WInterface\n{\n Q_OBJECT\n")); addIfaceHeaderClass(QString(" public:\n "+ifaceClassName()+"(QString name=\""+pn+"\"):WInterface(name){}\n")); @@ -89,9 +86,6 @@ WocQtOut::WocQtOut(QDomElement&el) addIfaceHeaderClass(" Q_INVOKABLE QString wocVersionInfo(WOb::VersionInfo)const;\n"); m_ifacecpp.write(QString("QString "+ifaceClassName()+"::wocVersionInfo(WOb::VersionInfo vi)const{return WOCcopied_versionInfo(vi);}\n").toLatin1()); - //init scripting - initScripting(); - //create all includer m_hdr.setFileName(m_basedir+"/"+m_subdir+"/"+m_prefix+"IncludeAll"); if(!m_hdr.open(QIODevice::WriteOnly|QIODevice::Truncate)){ @@ -110,13 +104,6 @@ void WocQtOut::finalize() if(qclass)qclass->finalize(); if(qtable)qtable->finalize(); if(qtrans)qtrans->finalize(); - //finish scripting stuff - if(m_genscript){ - addIfaceHeaderClass(" /// use this call to initialize a script engine that needs access to the interface\n"); - addIfaceHeaderClass(" void initScriptEngine(QScriptEngine*);\n"); - m_scriptcode+="}\n\n"; - m_ifacecpp.write(m_scriptcode.toLatin1()); - } //generate versionInfo initVersionH(); //add interface class @@ -270,25 +257,6 @@ WocQtTransaction::WocQtTransaction(WocQtOut*p) connect(this,SIGNAL(errorFound()),p,SIGNAL(errorFound())); } -void WocQtOut::initScripting() -{ -// m_scriptcode="#include \n"; - //script converters for nullables - QFile nscr(":/nullscript.cpp");nscr.open(QIODevice::ReadOnly); - m_scriptcode+=QString::fromLatin1(nscr.readAll()); - m_scriptcode+="\n\n"; - nscr.close(); - //initializer routine - m_scriptcode+="void "+ifaceClassName()+"::initScriptEngine(QScriptEngine*engine)\n{\n"; - m_scriptcode+="\tQScriptValue gval=engine->newObject();\n"; - m_scriptcode+="\tengine->globalObject().setProperty(\"wob\",gval);\n"; - //register interfacce itself - m_scriptcode+="\tgval.setProperty(\"Interface\",engine->newQMetaObject(this->metaObject()));\n"; - m_scriptcode+="\tgval.setProperty(\"interface\",engine->newQObject(this,QScriptEngine::QtOwnership, QScriptEngine::ExcludeDeleteLater));\n"; - //register nullables - m_scriptcode+="\tinitNullableScripting(engine);\n"; -} - #ifndef NO_PACK_VERSION_H #include "../../vinfo/staticVersion.h" #endif diff --git a/woc/qt/qtout.h b/woc/qt/qtout.h index 16a277f..9515317 100644 --- a/woc/qt/qtout.h +++ b/woc/qt/qtout.h @@ -96,10 +96,6 @@ class WocQtOut:public WocOutput void addPostIface(QString); /**helper: returns the class name of the interface class*/ QString ifaceClassName()const{return m_prefix+"Interface";} - /**helper: adds a line to the script initializer; this is ignored if scripting is inactive*/ - void addScriptInit(QString s){m_scriptcode+=s;} - ///helper: returns true if sub-classes are supposed to create scripting code - inline bool doGenerateScripting()const{return m_genscript;} ///returns the class name prefix configured for this output inline QString namePrefix()const{return m_prefix;} @@ -122,15 +118,13 @@ class WocQtOut:public WocOutput QString exportSymbol()const; private: - ///internal: init the scripting env - void initScripting(); ///internal: generate the static header for version info void initVersionH(); private: - QString m_basedir,m_subdir,m_prefix,m_cprefix,m_transbase,m_postiface,m_scriptcode; + QString m_basedir,m_subdir,m_prefix,m_cprefix,m_transbase,m_postiface; mutable QString m_exportsym; - bool m_clean,m_genscript,m_export; + bool m_clean,m_export; MFile m_pri,m_iface,m_ifacecpp,m_hdr; QString m_iface_prefix,m_iface_class; protected: diff --git a/woc/qt/qtstrans.cpp b/woc/qt/qtstrans.cpp index b131a7b..0e7df8c 100644 --- a/woc/qt/qtstrans.cpp +++ b/woc/qt/qtstrans.cpp @@ -97,9 +97,6 @@ void WocQtServerTransaction::newTransaction(const WocTransaction&trn) genGetters(ct); genSetters(ct); - //create scripting - genScripting(ct); - //create log control genLogCtrl(ct); @@ -269,29 +266,6 @@ void WocQtServerTransaction::genSetters(QtSTrans& ct) } } -void WocQtServerTransaction::genScripting(QtSTrans& ct) -{ - if(!m_parent->doGenerateScripting())return; - //converters between transaction and script values - ct.hdi+="class QScriptValue;\n"; - ct.hdi+="class QScriptEngine;\n"; - ct.sri+="#include \n"; - ct.sri+="#include \n"; - ct.hcd+="\tstatic QScriptValue toScriptValue(QScriptEngine*,const "+ct.cn+"&);\n"; - ct.hcd+="\tstatic void fromScriptValue(const QScriptValue&,"+ct.cn+"&);\n"; - ct.scd+="QScriptValue "+ct.cn+"::toScriptValue(QScriptEngine*engine,const "+ct.cn+"&obj)\n{\n"; - ct.scd+="\treturn engine->newQObject(new "+ct.cn+"(obj),QScriptEngine::ScriptOwnership);\n}\n"; - ct.scd+="void "+ct.cn+"::fromScriptValue(const QScriptValue&val,"+ct.cn+"&obj)\n{\n"; - ct.scd+="\t"+ct.cn+"*xobj=qobject_cast<"+ct.cn+"*>(val.toQObject());\n"; - ct.scd+="\tif(xobj!=0 && &obj!=xobj)obj = *xobj;\n}\n"; - //add to engine - m_parent->addScriptInit( - "\t{QScriptValue mo=engine->newQMetaObject(&"+ct.cn+"::staticMetaObject);\n" - "\tgval.setProperty(\""+ct.cn+"\",mo);\n" - "\tqScriptRegisterMetaType(engine,"+ct.cn+"::toScriptValue,"+ct.cn+"::fromScriptValue);}\n" - ); -} - void WocQtServerTransaction::genLogCtrl(QtSTrans& ct) { if(ct.trn.logMode()==WocTransaction::LogAll)return; @@ -464,7 +438,6 @@ void WocQtServerTransaction::trnList() code+="qRegisterMetaTypeifaceClassName()+"::RightList> >();\n"; m_parent->addPostIface("Q_DECLARE_METATYPE("+m_parent->ifaceClassName()+"::RightList)\n"); m_parent->addPostIface("Q_DECLARE_METATYPE(QList<"+ m_parent->ifaceClassName()+ "::RightList>)\n"); - m_parent->addScriptInit("\tqScriptRegisterSequenceMetaType >(engine);\n"); //implement rights code+="QString "+m_parent->ifaceClassName()+"::rightToString(Right r)\n{\n\tswitch(r){\n"; diff --git a/woc/qt/qtstrans.h b/woc/qt/qtstrans.h index 656a59d..ab5d1cb 100644 --- a/woc/qt/qtstrans.h +++ b/woc/qt/qtstrans.h @@ -40,8 +40,6 @@ class WocQtServerTransaction:public WocQtTransaction void genGetters(QtSTrans&); ///helper: generate setter methods void genSetters(QtSTrans&); - ///helper: generate QtScript glue code - void genScripting(QtSTrans&); ///helper: generate log control void genLogCtrl(QtSTrans&); }; -- 1.7.2.5