trnList();
}
+struct QtCTrans{
+ QString cn;//class name
+ QString cnp;//private class name
+ QString defparm;//default interface name
+ //code store
+ QString hcd;//header: class decl
+ QString hdi;//header includes
+ QString pcd;//private class decl
+ QString scd;//cpp source
+ QString sri;//cpp includes
+ //in/out params
+ QStringList in,out;
+ QString inlist;//input param list for function calls (type1 val1,type2 val2,...)
+ QString clist;//input param list, but call values only (val1,val2,...)
+ QString xinlist;//input params plus interface name
+ QString xclist;//input params plus interface name
+ //transaction itself
+ const WocTransaction&trn;
+ QtCTrans(const WocTransaction&t,QString cn_,QString cnp_):trn(t){
+ in=trn.inputNames();
+ out=trn.outputNames();
+ cn=cn_;cnp=cnp_;
+ }
+};
+
void WocQtClientTransaction::newTransaction(const WocTransaction&trn)
{
QString cn=m_prefix+"T"+trn.name();
QString cnp=cn+"_Private";
addFile(cn);
-// addFile(WocQtOut::Header,"prv"+cn+".h");
MFile hdr(m_basedir+"/"+m_subdir+"/src"+cn+".h");
-// MFile hdp(m_basedir+"/"+m_subdir+"/prv"+cn+".h");
MFile src(m_basedir+"/"+m_subdir+"/src"+cn+".cpp");
if(!hdr.open(QIODevice::WriteOnly|QIODevice::Truncate) ||
-// !hdp.open(QIODevice::WriteOnly|QIODevice::Truncate) ||
!src.open(QIODevice::WriteOnly|QIODevice::Truncate)){
qDebug("Error: cannot create class files for transaction %s.",cn.toAscii().data());
emit errorFound();
return;
}
//basics
- QStringList in=trn.inputNames();
- QStringList out=trn.outputNames();
+ QtCTrans ct(trn,cn,cnp);
+ initList(ct);
//lead in
hdr.write(QByteArray(HDRSTART).replace("%",cn.toAscii()));
-// hdp.write(QByteArray(HDRSTART).replace("%",cnp.toAscii()));
src.write(QByteArray(SRCSTART).replace("%",cn.toAscii()));
//start constructing code
- QString hcd;//header: class decl
- QString hdi;//header includes
- QString pcd;//private class decl
- QString scd;//cpp source
- QString sri;//cpp includes
- hdi="#include \""+m_transbase+"\"\n";
-// pcd="#include \"src"+cn+".h\"\n";
- sri+="#include \"WTransaction_Private\"\n";
-// sri+="#include \"prv"+cn+".h\"\n";
- sri+="#include \"WInterface\"\n";
- sri+="#include <QCoreApplication>\n\n";
- for(int i=0;i<in.size();i++){
- QString tp=qtobjtype(trn,in[i],WocQtOut::In);
- if(tp!="")hdi+="#include <"+tp+">\n";
- }
- for(int i=0;i<out.size();i++){
- QString tp=qtobjtype(trn,out[i],WocQtOut::Out);
- if(tp!="")hdi+="#include <"+tp+">\n";
- }
- hcd+="\nclass "+cnp+";\n";
- hcd+="\nclass "+cn+":public "+m_transbase+"\n{\n";
- pcd+="\nclass "+cnp+":public WTransaction_PrivateBase\n{\n";
+
+ //include section
+ genInclude(ct);
+ //start of class
+ ct.hcd+="\nclass "+cnp+";\n";
+ ct.hcd+="\nclass "+cn+":public "+m_transbase+"\n{\n Q_OBJECT\n";
+ ct.pcd+="\nclass "+cnp+":public WTransaction_PrivateBase\n{\n";
//create properties
- QString inlist,clist;
- hcd+=" private:\n\t"+cnp+"*p;\n\tfriend class "+cnp+";\n";
- pcd+=" protected:\n\tfriend class "+cn+";\n";
- pcd+="\t"+cnp+"("+cn+"*parent){parent->p=this;}\n";
- pcd+="\tvoid attach("+cn+"*parent){parent->p=this;WTransaction_PrivateBase::attach();}\n";
- pcd+="\tvoid detach("+cn+"*parent){parent->p=0;WTransaction_PrivateBase::detach();}\n";
- for(int i=0;i<in.size();i++){
- pcd+="\t"+qttype(trn,in[i],WocQtOut::In)+"in_"+in[i]+";\n";
- if(i){inlist+=",";clist+=",";}
- inlist+="const "+qttype(trn,in[i],WocQtOut::In)+"&a"+in[i];
- clist+="a"+in[i];
- }
- for(int i=0;i<out.size();i++)
- pcd+="\t"+qttype(trn,out[i],WocQtOut::Out)+"out_"+out[i]+";\n";
+ genProperties(ct);
- //query method decl
- hcd+="\tvoid netquery();\n\tvoid asyncnetquery();\n";
- hcd+="\tQByteArray encodeData();\n\tvoid decodeData(QByteArray);\n";
- hcd+=" protected:\n\tvirtual void endQuery();\n";
+ //create constructors
+ ct.defparm="=\""+WocProcessor::instance()->projectName()+"\"";
+ genTors(ct);
- //global interface code
- QString sif=" "+cn+" query"+trn.name()+"("+inlist+")\n\t";
- sif+="{return "+cn+"::query("+clist+(clist!=""?",":"")+"name());}\n";
- m_iface.write(sif.toAscii());sif.clear();
+ //query method implemented
+ genQuery(ct);
+
+ //create getters
+ genGetters(ct);
- //create constructors
- if(inlist!="")inlist+=",";
- inlist+="QString iface";
- if(clist!="")clist+=",";
- clist+="iface";
- QString defparm="=\""+WocProcessor::instance()->projectName()+"\"";
+ //create scripting
+ genScripting(ct);
+
+ //button class up
+ ct.hcd+="};\n\n";
+ ct.pcd+="};\n\n";
+
+ //make meta object...
+ ct.hcd+="Q_DECLARE_METATYPE("+cn+")\n";
+ ct.scd+="static int mymetatypeid=qRegisterMetaType<"+cn+">();\n";
+
+ //write code
+ hdr.write(ct.hdi.toAscii());
+ hdr.write(ct.hcd.toAscii());
+ src.write(ct.sri.toAscii());
+ src.write(ct.pcd.toAscii());
+ src.write(ct.scd.toAscii());
+
+ //lead out
+ hdr.write(QByteArray(HDREND).replace("%",cn.toAscii()));
+ src.write(QByteArray(SRCEND).replace("%",cn.toAscii()));
+}
+
+void WocQtClientTransaction::initList(QtCTrans& ct)
+{
+ for(int i=0;i<ct.in.size();i++){
+ if(i){ct.inlist+=",";ct.clist+=",";}
+ ct.inlist+="const "+qttype(ct.trn,ct.in[i],WocQtOut::In)+"&a"+ct.in[i];
+ ct.clist+="a"+ct.in[i];
+ }
+ ct.xinlist=ct.inlist;
+ ct.xclist=ct.clist;
+ if(ct.xinlist!="")ct.xinlist+=",";
+ ct.xinlist+="QString iface";
+ if(ct.xclist!="")ct.xclist+=",";
+ ct.xclist+="iface";
+}
+
+
+void WocQtClientTransaction::genInclude(QtCTrans&ct)
+{
+ ct.hdi+="#include \""+m_transbase+"\"\n";
+ ct.sri+="#include \"WTransaction_Private\"\n";
+ ct.sri+="#include \"WInterface\"\n";
+ ct.sri+="#include <QCoreApplication>\n\n";
+ for(int i=0;i<ct.in.size();i++){
+ QString tp=qtobjtype(ct.trn,ct.in[i],WocQtOut::In);
+ if(tp!="")ct.hdi+="#include <"+tp+">\n";
+ }
+ for(int i=0;i<ct.out.size();i++){
+ QString tp=qtobjtype(ct.trn,ct.out[i],WocQtOut::Out);
+ if(tp!="")ct.hdi+="#include <"+tp+">\n";
+ }
+}
+
+void WocQtClientTransaction::genProperties(QtCTrans&ct)
+{
+ ct.hcd+=" private:\n\t"+ct.cnp+"*p;\n\tfriend class "+ct.cnp+";\n";
+ ct.pcd+=" protected:\n\tfriend class "+ct.cn+";\n";
+ ct.pcd+="\t"+ct.cnp+"("+ct.cn+"*parent){parent->p=this;}\n";
+ ct.pcd+="\tvoid attach("+ct.cn+"*parent){parent->p=this;WTransaction_PrivateBase::attach();}\n";
+ ct.pcd+="\tvoid detach("+ct.cn+"*parent){parent->p=0;WTransaction_PrivateBase::detach();}\n";
+ for(int i=0;i<ct.in.size();i++){
+ ct.pcd+="\t"+qttype(ct.trn,ct.in[i],WocQtOut::In)+"in_"+ct.in[i]+";\n";
+ }
+ for(int i=0;i<ct.out.size();i++)
+ ct.pcd+="\t"+qttype(ct.trn,ct.out[i],WocQtOut::Out)+"out_"+ct.out[i]+";\n";
+}
+
+void WocQtClientTransaction::genTors(QtCTrans&ct)
+{
//define parametric constructor
- hcd+="\t"+cn+"("+inlist+");\n";
+ ct.hcd+=" protected:\n";
+ ct.hcd+="\t"+ct.cn+"("+ct.xinlist+");\n";
//parametric constructor implementation
- scd+=cn+"::"+cn+"("+inlist+")\n\t:"+m_transbase+"(iface)\n{\n";
- scd+="\tnew "+cnp+"(this);\n";
- for(int i=0;i<in.size();i++){
- scd+="\tp->in_"+in[i]+"=a"+in[i]+";\n";
+ ct.scd+=ct.cn+"::"+ct.cn+"("+ct.xinlist+")\n\t:"+m_transbase+"(iface)\n{\n";
+ ct.scd+="\tnew "+ct.cnp+"(this);\n";
+ for(int i=0;i<ct.in.size();i++){
+ ct.scd+="\tp->in_"+ct.in[i]+"=a"+ct.in[i]+";\n";
}
- scd+="}\n\n";
+ ct.scd+="}\n\n";
//decl default constructor
- hcd+=" public:\n";
- hcd+="\t"+cn+"();\n";
- scd+=cn+"::"+cn+"()\n{\n\tnew "+cnp+"(this);\n}\n\n";
+ ct.hcd+=" public:\n";
+ ct.hcd+="\t"+ct.cn+"();\n";
+ ct.scd+=ct.cn+"::"+ct.cn+"()\n{\n\tnew "+ct.cnp+"(this);\n}\n\n";
//decl copy constructor
- hcd+="\t"+cn+"(const "+cn+"&);\n";
+ ct.hcd+="\t"+ct.cn+"(const "+ct.cn+"&);\n";
//copy constructor implementation
- scd+=cn+"::"+cn+"(const "+cn+"&t)\n\t:"+m_transbase+"(t)\n{\n";
- scd+="\tt.p->attach(this);\n";
- scd+="}\n\n";
+ ct.scd+=ct.cn+"::"+ct.cn+"(const "+ct.cn+"&t)\n\t:"+m_transbase+"(t)\n{\n";
+ ct.scd+="\tt.p->attach(this);\n";
+ ct.scd+="}\n\n";
//decl copy operator
- hcd+="\t"+cn+"& operator=(const "+cn+"&);\n";
+ ct.hcd+="\t"+ct.cn+"& operator=(const "+ct.cn+"&);\n";
//copy operator implemented
- scd+=cn+"& "+cn+"::operator=(const "+cn+"&t)\n{\n";
- scd+="\t"+m_transbase+"::operator=(t);\n";
- scd+="\tp->detach(this);t.p->attach(this);\n";
- scd+="\treturn *this;\n}\n\n";
+ ct.scd+=ct.cn+"& "+ct.cn+"::operator=(const "+ct.cn+"&t)\n{\n";
+ ct.scd+="\t"+m_transbase+"::operator=(t);\n";
+ ct.scd+="\tp->detach(this);t.p->attach(this);\n";
+ ct.scd+="\treturn *this;\n}\n\n";
//destructor
- hcd+="\t~"+cn+"();\n";
- scd+=cn+"::~"+cn+"()\n{\n\tp->detach(this);\n}\n\n";
-
- //query method implemented
- scd+="void "+cn+"::netquery()\n{\n";
- scd+="\tWTransaction::Log log(this,\""+trn.name()+"\");\n";
- scd+="\tQByteArray enc=encodeData();\n";
- scd+="\tif(enc.isEmpty()){\n\t\temit finished();\n\t\treturn;\n\t}\n";
- scd+="\texecuteQuery(\""+trn.name()+"\",enc);\n";
- scd+="}\n";
+ ct.hcd+="\t~"+ct.cn+"();\n";
+ ct.scd+=ct.cn+"::~"+ct.cn+"()\n{\n\tp->detach(this);\n}\n\n";
+}
+
+void WocQtClientTransaction::genQuery(QtCTrans& ct)
+{
+ //global interface code
+ QString sif=" Q_SLOT "+ct.cn+" query"+ct.trn.name()+"("+ct.inlist+")\n\t";
+ sif+="{return "+ct.cn+"::query("+ct.clist+(ct.clist!=""?",":"")+"name());}\n";
+ m_iface.write(sif.toAscii());sif.clear();
+ //query method decl
+ ct.hcd+=" private:\n";
+ ct.hcd+="\tvoid netquery();\n\tvoid asyncnetquery();\n";
+ ct.hcd+="\tQByteArray encodeData();\n\tvoid decodeData(QByteArray);\n";
+ ct.hcd+=" protected:\n\tvirtual void endQuery();\n";
+ //sync query
+ ct.scd+="void "+ct.cn+"::netquery()\n{\n";
+ ct.scd+="\tWTransaction::Log log(this,\""+ct.trn.name()+"\");\n";
+ ct.scd+="\tQByteArray enc=encodeData();\n";
+ ct.scd+="\tif(enc.isEmpty()){\n\t\temit finished();\n\t\treturn;\n\t}\n";
+ ct.scd+="\texecuteQuery(\""+ct.trn.name()+"\",enc);\n";
+ ct.scd+="}\n";
//async query method implemented
- scd+="void "+cn+"::asyncnetquery()\n{\n";
- scd+="\tnew WTransaction::Log(this,\""+trn.name()+"\");\n";
- scd+="\tQByteArray enc=encodeData();\n";
- scd+="\tif(enc.isEmpty()){\n\t\temit finished();\n\t\treturn;\n\t}\n";
- scd+="\tstartQuery(\""+trn.name()+"\",enc);\n";
- scd+="}\n";
+ ct.scd+="void "+ct.cn+"::asyncnetquery()\n{\n";
+ ct.scd+="\tnew WTransaction::Log(this,\""+ct.trn.name()+"\");\n";
+ ct.scd+="\tQByteArray enc=encodeData();\n";
+ ct.scd+="\tif(enc.isEmpty()){\n\t\temit finished();\n\t\treturn;\n\t}\n";
+ ct.scd+="\tstartQuery(\""+ct.trn.name()+"\",enc);\n";
+ ct.scd+="}\n";
//encode input
- scd+="QByteArray "+cn+"::encodeData()\n{\n";
- scd+=trnInput(trn);
- scd+="}\n";
+ ct.scd+="QByteArray "+ct.cn+"::encodeData()\n{\n";
+ ct.scd+=trnInput(ct.trn);
+ ct.scd+="}\n";
//decode output
- scd+="void "+cn+"::decodeData(QByteArray rba)\n{\n";
- scd+=trnOutput(trn);
- scd+="}\n";
- scd+="void "+cn+"::endQuery()\n{\n";
- scd+="\tdecodeData(d->m_rspdata.trimmed());\n";
- scd+="\temit finished();\n}\n";
-
-
- //create getters
- for(int i=0;i<out.size();i++){
- QString tp=qttype(trn,out[i],WocQtOut::Out);
- hcd+="\t"+tp+" get"+out[i]+"();\n";
- scd+=tp+" "+cn+"::get"+out[i]+"(){return p->out_"+out[i]+";}\n";
- }
-
+ ct.scd+="void "+ct.cn+"::decodeData(QByteArray rba)\n{\n";
+ ct.scd+=trnOutput(ct.trn);
+ ct.scd+="}\n";
+ ct.scd+="void "+ct.cn+"::endQuery()\n{\n";
+ ct.scd+="\tdecodeData(d->m_rspdata.trimmed());\n";
+ ct.scd+="\temit finished();\n}\n";
//create queries
- hcd+="\tstatic "+cn+" query("+inlist+defparm+");\n";
- scd+=cn+" "+cn+"::query("+inlist+")\n{\n";
- scd+="\t"+cn;
- if(clist!="")scd+=" r("+clist+");\n";else scd+=" r;\n";
- scd+="\tr.netquery();\n\treturn r;\n}\n";
- hcd+="\tstatic "+cn+" asyncQuery("+inlist+defparm+");\n";
- scd+=cn+" "+cn+"::asyncQuery("+inlist+")\n{\n";
- scd+="\t"+cn;
- if(clist!="")scd+=" r("+clist+");\n";else scd+=" r;\n";
- scd+="\tr.asyncnetquery();\n\treturn r;\n}\n";
-
- //button up
- hcd+="};\n\n";
- pcd+="};\n\n";
-
- //write code
- hdr.write(hdi.toAscii());
- hdr.write(hcd.toAscii());
-// hdp.write(pcd.toAscii());
- src.write(sri.toAscii());
- src.write(pcd.toAscii());
- src.write(scd.toAscii());
-
- //lead out
- hdr.write(QByteArray(HDREND).replace("%",cn.toAscii()));
-// hdp.write(QByteArray(HDREND).replace("%",cnp.toAscii()));
- src.write(QByteArray(SRCEND).replace("%",cn.toAscii()));
+ ct.hcd+=" public:\n";
+ ct.hcd+="\tstatic "+ct.cn+" query("+ct.xinlist+ct.defparm+");\n";
+ ct.scd+=ct.cn+" "+ct.cn+"::query("+ct.xinlist+")\n{\n";
+ ct.scd+="\t"+ct.cn;
+ ct.scd+=" r("+ct.xclist+");\n";
+ ct.scd+="\tr.netquery();\n\treturn r;\n}\n";
+ ct.hcd+="\tstatic "+ct.cn+" asyncQuery("+ct.xinlist+ct.defparm+");\n";
+ ct.scd+=ct.cn+" "+ct.cn+"::asyncQuery("+ct.xinlist+")\n{\n";
+ ct.scd+="\t"+ct.cn;
+ ct.scd+=" r("+ct.xclist+");\n";
+ ct.scd+="\tr.asyncnetquery();\n\treturn r;\n}\n";
+}
+
+void WocQtClientTransaction::genGetters(QtCTrans& ct)
+{
+ for(int i=0;i<ct.out.size();i++){
+ QString tp=qttype(ct.trn,ct.out[i],WocQtOut::Out);
+ ct.hcd+="\tQ_SLOT "+tp+" get"+ct.out[i]+"();\n";
+ ct.scd+=tp+" "+ct.cn+"::get"+ct.out[i]+"(){return p->out_"+ct.out[i]+";}\n";
+ }
+}
+
+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+="\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"
+ );
}
QString WocQtClientTransaction::trnInput(const WocTransaction&trn)
{
QString code;
//header
+ code+=" Q_ENUMS(Right)\n";
code+=" enum Right {\n NoRight";
QStringList r=WocProcessor::instance()->transactionNames();
QStringList p=WocProcessor::instance()->privilegeNames();
for(int i=0;i<p.size();i++)
code+=",\n P"+pp[i].replace(':',"_");
code+="\n };\n";
- code+=" static QString rightToString(Right);\n";
- code+=" static QString rightToLocalString(Right);\n";
- code+=" static Right stringToRight(QString);\n";
- code+=" static QStringList allKnownRightsString();\n";
- code+=" static QList<Right> allKnownRights();\n";
- m_iface.write(code.toAscii());
+ code+=" typedef QList<Right> RightList;\n";
+ code+=" Q_INVOKABLE static QString rightToString(Right);\n";
+ code+=" Q_INVOKABLE static QString rightToLocalString(Right);\n";
+ code+=" Q_INVOKABLE static Right stringToRight(QString);\n";
+ code+=" Q_INVOKABLE static QStringList allKnownRightsString();\n";
+ code+=" Q_INVOKABLE static "+m_parent->ifaceClassName()+"::RightList allKnownRights();\n";
+ m_iface.write(code.toAscii());code.clear();
- code="QString "+m_prefix+"Interface::rightToString(Right r)\n{\n\tswitch(r){\n";
+ code+="static int righttypeid=";
+ code+="qRegisterMetaType<"+m_parent->ifaceClassName()+"::RightList>()+";
+ 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";
for(int i=0;i<p.size();i++)
code+="\t\tcase P"+pp[i]+":return \""+p[i]+"\";\n";
code+="\t\tdefault:return \"\";\n\t}\n}\n";
- code+="QString "+m_prefix+"Interface::rightToLocalString(Right r)\n{\n\tswitch(r){\n";
+ code+="QString "+m_parent->ifaceClassName()+"::rightToLocalString(Right r)\n{\n\tswitch(r){\n";
for(int i=0;i<r.size();i++)
code+="\t\tcase R"+r[i]+":return tr(\""+r[i]+"\");\n";
for(int i=0;i<p.size();i++)
code+="\t\tcase P"+pp[i]+":return tr(\""+p[i]+"\");\n";
code+="\t\tdefault:return \"\";\n\t}\n}\n";
- code+=m_prefix+"Interface::Right "+m_prefix+"Interface::stringToRight(QString s)\n{\n";
+ code+=m_parent->ifaceClassName()+"::Right "+m_prefix+"Interface::stringToRight(QString s)\n{\n";
for(int i=0;i<r.size();i++)
code+="\tif(s==\""+r[i]+"\")return R"+r[i]+";else\n";
for(int i=0;i<p.size();i++)
code+="\tif(s==\""+p[i]+"\")return P"+pp[i]+";else\n";
code+="\treturn NoRight;\n}\n";
- code+="QList<"+m_prefix+"Interface::Right> "+m_prefix+"Interface::allKnownRights()\n{\n";
+ code+="QList<"+m_parent->ifaceClassName()+"::Right> "+m_parent->ifaceClassName()+"::allKnownRights()\n{\n";
code+="\tQList<Right> ret;ret";
for(int i=0;i<r.size();i++)
code+="<<R"+r[i];
for(int i=0;i<p.size();i++)
code+="<<P"+pp[i];
code+=";\n\treturn ret;\n}\n";
- code+="QStringList "+m_prefix+"Interface::allKnownRightsString()\n{\n";
+ code+="QStringList "+m_parent->ifaceClassName()+"::allKnownRightsString()\n{\n";
code+="\tQStringList ret;ret";
for(int i=0;i<r.size();i++)
code+="<<\""+r[i]+"\"";
m_clean=str2bool(el.attribute("clean","0"));
m_prefix=el.attribute("classPrefix","Wob");
m_transbase=el.attribute("transactionBase","WTransaction");
+ m_genscript=str2bool(el.attribute("scriptable","0"));
//get/create directory
QDir d(m_basedir+"/"+m_subdir);
if(!d.exists())QDir(".").mkpath(m_basedir+"/"+m_subdir);
//create interface class
WocProcessor*woc=WocProcessor::instance();
QString pn=woc->projectName();
- m_ifacecpp.setFileName(m_basedir+"/"+m_subdir+"/src"+m_prefix+"Interface.cpp");
+ m_ifacecpp.setFileName(m_basedir+"/"+m_subdir+"/src"+ifaceClassName()+".cpp");
if(!m_ifacecpp.open(QIODevice::WriteOnly|QIODevice::Truncate)){
qDebug("Error: cannot create Qt interface file %s.",m_ifacecpp.fileName().toAscii().data());
emit errorFound();
return;
}
- m_ifacecpp.write(QByteArray(SRCSTART).replace('%',m_prefix+"Interface"));
- m_iface.setFileName(m_basedir+"/"+m_subdir+"/src"+m_prefix+"Interface.h");
+ m_ifacecpp.write(QByteArray(SRCSTART).replace('%',ifaceClassName()));
+ m_iface.setFileName(m_basedir+"/"+m_subdir+"/src"+ifaceClassName()+".h");
if(!m_iface.open(QIODevice::WriteOnly|QIODevice::Truncate)){
qDebug("Error: cannot create Qt interface file %s.",m_iface.fileName().toAscii().data());
emit errorFound();
m_iface.write(QByteArray(HDRSTART).replace("%",m_prefix.toAscii()+"INTERFACE_H"));
m_iface.write(QByteArray("#include \""+m_prefix.toAscii()+"IncludeAll\"\n#include \"WInterface\"\n"));
m_iface.write(QByteArray("#include <QStringList>\n"));
- m_iface.write(QString("class "+m_prefix+"Interface:public WInterface\n{\n Q_OBJECT\n").toAscii());
- m_iface.write(QString(" public:\n "+m_prefix+"Interface(QString name=\""+pn+"\"):WInterface(name){}\n").toAscii());
- m_iface.write(QString(" static "+m_prefix+"Interface*instance(QString name=\""+pn+"\")\n\t{return qobject_cast<"+m_prefix+"Interface*>(WInterface::instance(name));}\n\n").toAscii());
- m_iface.write(QString(" static QString commVersion(){return \""+woc->verComm()+"\";}\n").toAscii());
- m_iface.write(QString(" static QString needCommVersion(){return \""+woc->verNeedComm()+"\";}\n").toAscii());
- m_iface.write(QString(" static QString version(){return \""+woc->verHR()+"\";}\n").toAscii());
- m_iface.write(QString(" static QString svnVersion(){return \""+woc->svnRevision()+"\";}\n\n").toAscii());
- m_iface.write(QString(" static QString svnRepositoryRoot(){return \""+woc->svnRepositoryRoot()+"\";}\n\n").toAscii());
- m_iface.write(QString(" static QString svnRepositoryUrl(){return \""+woc->svnRepositoryUrl()+"\";}\n\n").toAscii());
+ if(m_genscript)
+ m_iface.write(QByteArray("class QScriptEngine;\n"));
+ m_iface.write(QString("class "+ifaceClassName()+":public WInterface\n{\n Q_OBJECT\n").toAscii());
+ m_iface.write(QString(" public:\n "+ifaceClassName()+"(QString name=\""+pn+"\"):WInterface(name){}\n").toAscii());
+ m_iface.write(QString(" static "+ifaceClassName()+"*instance(QString name=\""+pn+"\")\n\t{return qobject_cast<"+ifaceClassName()+"*>(WInterface::instance(name));}\n\n").toAscii());
+ m_iface.write(QString(" Q_INVOKABLE static QString commVersion(){return \""+woc->verComm()+"\";}\n").toAscii());
+ m_iface.write(QString(" Q_INVOKABLE static QString needCommVersion(){return \""+woc->verNeedComm()+"\";}\n").toAscii());
+ m_iface.write(QString(" Q_INVOKABLE static QString version(){return \""+woc->verHR()+"\";}\n").toAscii());
+ m_iface.write(QString(" Q_INVOKABLE static QString svnVersion(){return \""+woc->svnRevision()+"\";}\n\n").toAscii());
+ m_iface.write(QString(" Q_INVOKABLE static QString svnRepositoryRoot(){return \""+woc->svnRepositoryRoot()+"\";}\n\n").toAscii());
+ m_iface.write(QString(" Q_INVOKABLE static QString svnRepositoryUrl(){return \""+woc->svnRepositoryUrl()+"\";}\n\n").toAscii());
+
+ //init scripting
+ m_scriptcode="#include <QScriptEngine>\n";
+ m_scriptcode+="void "+ifaceClassName()+"::initScriptEngine(QScriptEngine*engine)\n{\n";
+ m_scriptcode+="\tQScriptValue gval=engine->globalObject();\n";
+ m_scriptcode+="\tgval.setProperty(\"Interface\",engine->newQMetaObject(this->metaObject()));\n";
+ m_scriptcode+="\tgval.setProperty(\"interface\",engine->newQObject(this,QScriptEngine::QtOwnership, QScriptEngine::ExcludeDeleteLater));\n";
//create all includer
m_hdr.setFileName(m_basedir+"/"+m_subdir+"/"+m_prefix+"IncludeAll");
return;
}
m_hdr.write(QByteArray(HDRSTART).replace("%",m_prefix.toAscii()+"INCLUDE_H"));
- addFile(m_prefix.toAscii()+"Interface");
+ addFile(ifaceClassName().toAscii());
}
WocQtOut::~WocQtOut(){}
void WocQtOut::finalize()
{
+ //finish sub-classes
if(qclass)qclass->finalize();
if(qtable)qtable->finalize();
if(qtrans)qtrans->finalize();
+ //finish scripting stuff
+ if(m_genscript){
+ m_iface.write(QByteArray(" void initScriptEngine(QScriptEngine*);\n"));
+ m_scriptcode+="}\n\n";
+ m_ifacecpp.write(m_scriptcode.toAscii());
+ }
//finish sources
m_ifacecpp.write(SRCEND);
m_ifacecpp.close();
- m_iface.write(QByteArray("};\n")+HDREND);
+ m_iface.write(QByteArray("};\n"));
+ m_iface.write(m_postiface.toAscii());
+ m_iface.write(HDREND);
m_iface.close();
m_pri.write(QByteArray("\n#END OF AUTOGENERATED PRI FILE\n"));
m_pri.close();
}
}
+void WocQtOut::addPostIface(QString s)
+{
+ m_postiface+=s;
+}
+
+
void WocQtOut::newTable(const WocTable&tbl)
{
if(qtable)qtable->newTable(tbl);