examples/clock/qts/clockserv
examples/clock/qtc/clock.exe
examples/clock/qts/clockserv.exe
+.qmake.stash
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 QList<QDomElement>elementsByTagName(const QDomElement&,QString);
#include <QObject>
#include <QList>
+#include <QCoreApplication>
#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 QList<QDomElement>elementsByTagName(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*/
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
#include "WHelper"
-#include <QDomElement>
-#include <QDomNode>
+#include "helper_p.h"
QList<QDomElement>WHelper::elementsByTagName(const QDomElement&root,QString tag)
{
- QDomNodeList cn=root.childNodes();
- QList<QDomElement>ret;
- for(int i=0;i<cn.size();i++){
- QDomElement e=cn.at(i).toElement();
- if(e.isNull())continue;
- if(e.tagName()!=tag)continue;
- ret<<e;
- }
- return ret;
+ return helper_elementsByTagName(root,tag);
}
bool WHelper::str2bool(QString s)
{
- s=s.trimmed().toLower();
- bool ok;
- int i=s.toInt(&ok);
- if(ok)return i!=0;
- if(s=="true" || s=="yes")return true;
- else return false;
+ return helper_str2bool(s);
}
--- /dev/null
+#ifndef WOB_HELPER_PH
+#define WOB_HELPER_PH
+
+#include <QDomElement>
+#include <QDomNode>
+
+static inline QList<QDomElement>helper_elementsByTagName(const QDomElement&root,QString tag)
+{
+ QDomNodeList cn=root.childNodes();
+ QList<QDomElement>ret;
+ for(int i=0;i<cn.size();i++){
+ QDomElement e=cn.at(i).toElement();
+ if(e.isNull())continue;
+ if(e.tagName()!=tag)continue;
+ ret<<e;
+ }
+ return ret;
+}
+
+static inline bool helper_str2bool(QString s)
+{
+ s=s.trimmed().toLower();
+ bool ok;
+ int i=s.toInt(&ok);
+ if(ok)return i!=0;
+ if(s=="true" || s=="yes")return true;
+ else return false;
+}
+
+
+#endif
+++ /dev/null
-//start: nullscript.cpp
-//
-//this adapts PACK nullable values to be usable with QtScript
-//
-//currently this file is copied verbatim into the generated
-//interface code, in the future it may be included there instead
-
-#include <QScriptEngine>
-#include <Nullable>
-
-static QScriptValue Bool_toScriptValue(QScriptEngine*,const Nullable<bool>&obj)
-{
- if(obj.isNull())return QScriptValue::NullValue;
- else return QScriptValue(obj.value());
-}
-
-static void Bool_fromScriptValue(const QScriptValue&val,Nullable<bool>&obj)
-{
- if(val.isNull())obj=Nullable<bool>();
- if(val.isBool())obj=val.toBool();
- else obj=Nullable<bool>();
-}
-
-static QScriptValue String_toScriptValue(QScriptEngine*,const Nullable<QString>&obj)
-{
- if(obj.isNull())return QScriptValue::NullValue;
- else return QScriptValue(obj.value());
-}
-
-static void String_fromScriptValue(const QScriptValue&val,Nullable<QString>&obj)
-{
- if(val.isNull())obj=Nullable<QString>();
- if(val.isString())obj=val.toString();
- else obj=Nullable<QString>();
-}
-
-static QScriptValue Int32_toScriptValue(QScriptEngine*,const Nullable<qint32>&obj)
-{
- if(obj.isNull())return QScriptValue::NullValue;
- else return QScriptValue(obj.value());
-}
-
-static void Int32_fromScriptValue(const QScriptValue&val,Nullable<qint32>&obj)
-{
- if(val.isNull())obj=Nullable<qint32>();
- if(val.isNumber())obj=val.toInt32();
- else obj=Nullable<qint32>();
-}
-
-static QScriptValue UInt32_toScriptValue(QScriptEngine*,const Nullable<quint32>&obj)
-{
- if(obj.isNull())return QScriptValue::NullValue;
- else return QScriptValue(obj.value());
-}
-
-static void UInt32_fromScriptValue(const QScriptValue&val,Nullable<quint32>&obj)
-{
- if(val.isNull())obj=Nullable<quint32>();
- if(val.isNumber())obj=val.toUInt32();
- else obj=Nullable<quint32>();
-}
-
-static QScriptValue Int64_toScriptValue(QScriptEngine*,const Nullable<qint64>&obj)
-{
- if(obj.isNull())return QScriptValue::NullValue;
- else return QScriptValue(qsreal(obj.value()));
-}
-
-static void Int64_fromScriptValue(const QScriptValue&val,Nullable<qint64>&obj)
-{
- if(val.isNull())obj=Nullable<qint64>();
- if(val.isNumber())obj=(qint64)val.toNumber();
- else obj=Nullable<qint64>();
-}
-
-static QScriptValue UInt64_toScriptValue(QScriptEngine*,const Nullable<quint64>&obj)
-{
- if(obj.isNull())return QScriptValue::NullValue;
- else return QScriptValue(qsreal(obj.value()));
-}
-
-static void UInt64_fromScriptValue(const QScriptValue&val,Nullable<quint64>&obj)
-{
- if(val.isNull())obj=Nullable<quint64>();
- if(val.isNumber())obj=(quint64)val.toNumber();
- else obj=Nullable<quint64>();
-}
-
-//TODO: copy the QByteArray wrapper from the Qt tutorials
-static QScriptValue BA_toScriptValue(QScriptEngine*engine,const Nullable<QByteArray>&obj)
-{
- if(obj.isNull())return QScriptValue::NullValue;
- else return engine->newVariant(obj.value());
-}
-
-static void BA_fromScriptValue(const QScriptValue&val,Nullable<QByteArray>&obj)
-{
- if(val.isNull())obj=Nullable<QByteArray>();
- if(val.isVariant())obj=val.toVariant().toByteArray();
- else obj=Nullable<QByteArray>();
-}
-
-
-//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
return doc.createElement(name);
}
+#include "helper_p.h"
+
+QList<QDomElement>WObject::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"<<b;return b;}
static int itype0=
qRegisterMetaType<Nullable<bool> >();
static bool btype0=
+ //NULLABLE
//String/bytes to self
QMetaType::registerConverter<Nullable<QString>,QString>(&Nullable<QString>::valueOrDefault)|
QMetaType::registerConverter<Nullable<QByteArray>,QByteArray>(&Nullable<QByteArray>::valueOrDefault)|
QMetaType::registerConverter<Nullable<qint64>,QString>([](Nullable<qint64> v)->QString{return QString::number(v.valueOrDefault());})|
QMetaType::registerConverter<Nullable<quint32>,QString>([](Nullable<quint32> v)->QString{return QString::number(v.valueOrDefault());})|
QMetaType::registerConverter<Nullable<quint64>,QString>([](Nullable<quint64> v)->QString{return QString::number(v.valueOrDefault());})|
+ //LIST
+ //string is predefined
+ //int/bool
+ QMetaType::registerConverter<QList<bool>,QVariantList>([](const QList<bool>&n){QVariantList r;for(auto v:n)r<<QVariant::fromValue(v);return r;})|
+ QMetaType::registerConverter<QList<qint32>,QVariantList>([](const QList<qint32>&n){QVariantList r;for(auto v:n)r<<QVariant::fromValue(v);return r;})|
+ QMetaType::registerConverter<QList<qint64>,QVariantList>([](const QList<qint64>&n){QVariantList r;for(auto v:n)r<<QVariant::fromValue(v);return r;})|
+ QMetaType::registerConverter<QList<quint32>,QVariantList>([](const QList<quint32>&n){QVariantList r;for(auto v:n)r<<QVariant::fromValue(v);return r;})|
+ QMetaType::registerConverter<QList<quint64>,QVariantList>([](const QList<quint64>&n){QVariantList r;for(auto v:n)r<<QVariant::fromValue(v);return r;})|
+ QMetaType::registerConverter<QList<int>,QVariantList>([](const QList<int>&n){QVariantList r;for(auto v:n)r<<QVariant::fromValue(v);return r;})|
true;
include/server.h \
src/server_p.h \
src/wobnam.h \
- src/wobnam_p.h
+ src/wobnam_p.h \
+ src/helper_p.h
SOURCES += \
src/object.cpp \
qt/qtctrans.h \
qt/qtstrans.cpp
-RESOURCES += qt/qtfiles.qrc
-
-INCLUDEPATH += qt
\ No newline at end of file
+INCLUDEPATH += qt
//class declaration
QString cnb=cls.baseClass(m_parent->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
//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<QList<"+cna+"> >()+";
- scd+="qRegisterMetaType<Nullable<"+cna+"> >();\n";
+ scd+="\tqRegisterMetaType<"+cna+">()+";
+ scd+="\tqRegisterMetaType<QList<"+cna+"> >()+";
+ scd+="\tqRegisterMetaType<Nullable<"+cna+"> >();\n";
+ scd+="static bool class_converter=QMetaType::registerConverter<Nullable<"+cna+">,"+cna+">([](const Nullable<"+cna+">&n){return n.value();})|\n";
+ scd+="\tQMetaType::registerConverter<QList<"+cna+">,QVariantList>([](const QList<"+cna+">&n){QVariantList r;for(auto v:n)r<<QVariant::fromValue(v);return r;});\n";
//end of class, aux stuff, meta types
hdr.write(QByteArray("\n};\n"));
src.write(QByteArray(SRCEND).replace("%",cna.toLatin1()));
}
-void WocQtClass::classScripting(const WocClass& cls, MFile& hdr, MFile& src, QString cna,QString cn)
-{
- Q_UNUSED(cna);Q_UNUSED(hdr);Q_UNUSED(cls);
- if(!m_parent->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 <QScriptValue>\n";
- scd+="#include <QScriptEngine>\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<QList<"+cn+"> >(engine);\n"
- );
-}
-
-
void WocQtClass::classEnums(const WocClass&cls,MFile&hdr,MFile&src,QString cn)
{
QStringList k=cls.enumTypes();
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();
"//DO NOT EDIT THIS FILE DIRECTLY, USE THE XML SOURCE!\n"
"#include \"%\"\n"
"#include <QDomElement>\n"
- "#include <QDomDocument>\n";
+ "#include <QDomDocument>\n"
+ "#include <QVariant>\n";
//end section of all source files
static const QByteArray SRCEND="\n//END OF AUTOMATICALLY GENERATED FILE\n";
//create getters
genGetters(ct);
- //create scripting
- genScripting(ct);
-
//create log control
genLogCtrl(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 <QScriptValue>\n";
- ct.sri+="#include <QScriptEngine>\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;
code+="qRegisterMetaType<QList<"+m_parent->ifaceClassName()+"::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<QList<RightList> >(engine);\n");
code+="QString "+m_parent->ifaceClassName()+"::rightToString(Right r)\n{\n\tswitch(r){\n";
for(int i=0;i<r.size();i++)
code+="\t\tcase R"+r[i]+":return \""+r[i]+"\";\n";
void genQuery(QtCTrans&);
///helper: generate getter methods
void genGetters(QtCTrans&);
- ///helper: generate QtScript glue code
- void genScripting(QtCTrans&);
///helper: generate log control
void genLogCtrl(QtCTrans&);
///helper: initialize data in the transaction wrapper
+++ /dev/null
-<!DOCTYPE RCC>
-<!--
-// Copyright (C) 2009-2011 by Konrad Rosenbaum <konrad@silmor.de>
-// protected under the GNU GPL version 3 or at your option any newer.
-// See COPYING.GPL file that comes with this distribution.
- -->
-<RCC version="1.0">
- <qresource>
- <file alias="nullscript.cpp">../../qtbase/src/nullscript.cpp</file>
- </qresource>
-</RCC>
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);
m_iface.write(QByteArray("#include \"WInterface\"\n"));
m_iface.write(QByteArray("#include <QStringList>\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"));
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)){
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
connect(this,SIGNAL(errorFound()),p,SIGNAL(errorFound()));
}
-void WocQtOut::initScripting()
-{
-// m_scriptcode="#include <QScriptEngine>\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
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;}
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:
genGetters(ct);
genSetters(ct);
- //create scripting
- genScripting(ct);
-
//create log control
genLogCtrl(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 <QScriptValue>\n";
- ct.sri+="#include <QScriptEngine>\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;
code+="qRegisterMetaType<QList<"+m_parent->ifaceClassName()+"::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<QList<RightList> >(engine);\n");
//implement rights
code+="QString "+m_parent->ifaceClassName()+"::rightToString(Right r)\n{\n\tswitch(r){\n";
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&);
};