generate most docu tags in Qt output
authorKonrad Rosenbaum <konrad@silmor.de>
Sat, 18 Feb 2012 14:21:46 +0000 (15:21 +0100)
committerKonrad Rosenbaum <konrad@silmor.de>
Sat, 18 Feb 2012 14:21:46 +0000 (15:21 +0100)
woc/doxyout.h [new file with mode: 0644]
woc/htmlout.cpp
woc/proc/procclass.cpp
woc/proc/procclass.h
woc/qt/qtclass.cpp
woc/qt/qtctrans.cpp
woc/qt/qtout.cpp
woc/qt/qtout.h

diff --git a/woc/doxyout.h b/woc/doxyout.h
new file mode 100644 (file)
index 0000000..4b2064f
--- /dev/null
@@ -0,0 +1,40 @@
+// Copyright (C) 2012 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.
+//
+
+#ifndef WOC_DOXYOUT_H
+#define WOC_DOXYOUT_H
+#include <QStringList>
+
+inline QString doxyFormat(const QString&in,int level=0)
+{
+       //split to lines
+       QStringList inl=in.trimmed().split('\n');
+       QString pre,ret;
+       //create indent and comment prefix
+       for(int i=0;i<level;i++)pre+='\t';
+       pre+="/// ";
+       //add comment
+       foreach(QString line,inl){
+               ret+=pre;
+               ret+=line;
+               ret+="\n";
+       }
+       //done
+       return ret;
+}
+
+inline QString doxyFormat(const QStringList&inl,int level=0)
+{
+       QString ret;
+       foreach(QString in,inl){
+               in=in.trimmed();
+               if(in.isEmpty())continue;
+               if(!ret.isEmpty())ret+=doxyFormat("",level);
+               ret+=doxyFormat(in,level);
+       }
+       return ret;
+}
+
+#endif
index 8c94b4b..495ee90 100644 (file)
@@ -256,6 +256,7 @@ void WocHtmlOut::classEnums(const WocClass&cls,QFile&hdr)
        for(int i=0;i<k.size();i++){
                //type
                hcd+="<h3>enum "+k[i]+"</h3>\n";
+               hcd+="<p>"+cls.enumDoc(k[i])+"</p>\n";
                hcd+="<table frame=\"1\" border=\"1\">";
                hcd+="<tr><td><b>Symbol</b></td><td><b>Value</b></td><td><b>Docu</b></td></tr>\n";
                QList<WocEnum>ev=cls.enumValues(k[i]);
index f820f02..56d7d25 100644 (file)
@@ -104,6 +104,7 @@ WocClass::WocClass(const QDomElement&cls)
                }
                QList<WocEnum>ev;
                //check whether there is a reference
+               QString coldoc;
                if(el.hasAttribute("refColumn")){
                        QStringList ref=el.attribute("refColumn").split(":");
                        if(ref.size()!=2){
@@ -123,6 +124,9 @@ WocClass::WocClass(const QDomElement&cls)
                                return;
                        }
                        ev=tab.columnEnums(ref[1]);
+                       coldoc+="Generated from table "+tab.name()+", column "+ref[1]+".\n\n";
+                       coldoc=tab.columnDoc(ref[1]);
+                       coldoc=coldoc.trimmed();
                }
                //scan values
                QList<QDomElement> nl2=elementsByTagName(el,"Value");
@@ -141,6 +145,20 @@ WocClass::WocClass(const QDomElement&cls)
                        //TODO: check that value name does not exist yet
                }
                m_enumvals.insert(nm,ev);
+               //scan docu
+               QString doc;
+               foreach(QDomElement el2,elementsByTagName(el,"Doc")){
+                       QString d=el2.text().trimmed();
+                       if(d.size()>0){
+                               if(doc.size()>0)doc+="\n\n";
+                               doc+=d;
+                       }
+               }
+               if(coldoc.size()>0){
+                       if(doc.size()>0)doc+="\n\n";
+                       doc+=coldoc;
+               }
+               m_enumdoc.insert(nm,doc);
        }
        //scan mappings
        nl=elementsByTagName(cls,"Mapping");
index 456ffa1..ba23640 100644 (file)
@@ -100,6 +100,9 @@ class WocClass
                /**returns documentation for a property*/
                QString propDoc(QString p)const
                {if(m_propdoc.contains(p))return m_propdoc[p];else return "";}
+               /**returns base documentation for enums*/
+               QString enumDoc(QString e)const
+               {if(m_enumdoc.contains(e))return m_enumdoc[e];else return QString();}
                
        private:
                //valid: parsing the WOLF succeeded
@@ -125,6 +128,8 @@ class WocClass
                QMap<QString,QList<s_map> >m_maps;
                //enum types: "type-name" => List of ("constant-name",int-constant-value)
                QMap<QString,QList<WocEnum> >m_enumvals;
+               //enum types: "type-name" => "documentation"
+               QMap<QString,QString>m_enumdoc;
                //serializers: "name" => List of properties (syntax Objects: "propertyname/Serializer"
 //             QMap<QString,QStringList> m_serial;
 
index df29844..405e0e0 100644 (file)
@@ -10,6 +10,7 @@
 #include <QDomElement>
 
 #include "qtconst.h"
+#include "doxyout.h"
 
 WocQtClass::WocQtClass(WocQtOut* p)
 {
@@ -32,6 +33,8 @@ void WocQtClass::newClass(const WocClass&cls)
        QString cna=cn;
        if(cls.isAbstract(m_lang))cna+="Abstract";
        addFile(cna);
+       m_parent->addIfaceHeaderPrefix("class "+cn+";\n");
+       if(cn!=cna)m_parent->addIfaceHeaderPrefix("class "+cna+";\n");
        MFile hdr(m_basedir+"/"+m_subdir+"/src"+cna+".h");
        MFile src(m_basedir+"/"+m_subdir+"/src"+cna+".cpp");
        if(!hdr.open(QIODevice::WriteOnly|QIODevice::Truncate) ||
@@ -55,6 +58,7 @@ void WocQtClass::newClass(const WocClass&cls)
 
        //class declaration
        QString cnb=cls.baseClass(m_lang,m_prefix+"O");
+       hcd+=doxyFormat(cls.docStrings());
        hcd+="class "+cna+":public "+cnb+"\n{\n  Q_OBJECT\n";
        hdr.write(hcd.toAscii());
        
@@ -107,8 +111,10 @@ void WocQtClass::classScripting(const WocClass& cls, MFile& hdr, MFile& src, QSt
        }
        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";
@@ -137,7 +143,8 @@ void WocQtClass::classEnums(const WocClass&cls,MFile&hdr,MFile&src,QString cn)
                scd+="static int enum_"+k[i]+"_metatypeid=qRegisterMetaType<"+cn+"::"+k[i]+">();\n";
                scd+="static int enum_"+k[i]+"_metatypeid2=qRegisterMetaType<QList<"+cn+"::"+k[i]+"> >();\n";
                //type
-               hcd+="\tenum "+k[i]+"{";
+               hcd+=doxyFormat(cls.enumDoc(k[i]),1);
+               hcd+="\tenum "+k[i]+"{\n";
                QList<WocEnum>ev=cls.enumValues(k[i]);
                if(ev.size()<1){
                        qDebug("Error: enums must have at least one member - class %s enum %s",cls.name().toAscii().data(),k[i].toAscii().data());
@@ -145,12 +152,15 @@ void WocQtClass::classEnums(const WocClass&cls,MFile&hdr,MFile&src,QString cn)
                        return;
                }
                for(int j=0;j<ev.size();j++){
-                       if(j)hcd+=",";
-                       hcd+="\n\t\t"+ev[j].name+"="+QString::number(ev[j].val);
+                       if(j)hcd+=",\n";
+                       hcd+=doxyFormat(ev[j].doc,2);
+                       hcd+="\t\t"+ev[j].name+"="+QString::number(ev[j].val);
                }
                hcd+="\n\t};\n";
                //string converters
+               hcd+="\t/// Converts string into the corresponding enum "+k[i]+" value.\n";
                hcd+="\tstatic "+k[i]+" str2"+k[i]+"(QString,bool*ok=0);\n";
+               hcd+="\t/// Converts enum "+k[i]+" value into the corresponding string.\n";
                hcd+="\tstatic QString "+k[i]+"2str("+k[i]+");\n";
                scd+=cn+"::"+k[i]+" "+cn+"::str2"+k[i]+"(QString s,bool*ok)\n{\n";
                scd+="\ts=s.toLower();if(ok)*ok=true;\n";
@@ -164,7 +174,9 @@ void WocQtClass::classEnums(const WocClass&cls,MFile&hdr,MFile&src,QString cn)
                }
                scd+="\treturn \"\";\n}\n";
                //localized string converters
+               hcd+="\t/// Converts a localized string into the corresponding enum "+k[i]+" value.\n";
                hcd+="\tstatic "+k[i]+" locstr2"+k[i]+"(QString,bool*ok=0);\n";
+               hcd+="\t/// Converts enum "+k[i]+" value into the corresponding localized string.\n";
                hcd+="\tstatic QString "+k[i]+"2locstr("+k[i]+");\n";
                scd+=cn+"::"+k[i]+" "+cn+"::locstr2"+k[i]+"(QString s,bool*ok)\n{\n";
                scd+="\ts=s.toLower();if(ok)*ok=true;\n";
@@ -189,6 +201,7 @@ void WocQtClass::classProperties(const WocClass&cls,MFile&hdr,MFile&)
        QString hcd,scd;
        //declare property
        for(int i=0;i<k.size();i++){
+               hcd+=doxyFormat(cls.propDoc(k[i]),1);
                hcd+="\tQ_PROPERTY("+qttype(cls,k[i])+" "+k[i]+" READ "+k[i]+" WRITE set"+k[i]+")\n";
        }
        //declare members
@@ -199,11 +212,13 @@ void WocQtClass::classProperties(const WocClass&cls,MFile&hdr,MFile&)
        //declare getters
        hcd+="  public:\n";
        for(int i=0;i<k.size();i++){
+               hcd+=doxyFormat(cls.propDoc(k[i]),1);
                hcd+="\tvirtual "+qttype(cls,k[i])+" "+k[i]+"()const{return mp_"+k[i]+";}\n";
        }
        
        //declare setters
        for(int i=0;i<k.size();i++){
+               hcd+=doxyFormat(cls.propDoc(k[i]),1);
                hcd+="\tvirtual void set"+k[i]+"("+qttype(cls,k[i])+" s){mp_"+k[i]+"=s;}\n";
                if(cls.propertyIsList(k[i])){
                        hcd+="\tvirtual void clear"+k[i]+"(){mp_"+k[i]+".clear();}\n";
@@ -220,15 +235,18 @@ void WocQtClass::classDeserializer(const WocClass&cls,MFile&hdr,MFile&src,QStrin
        hcd="  public:\n";
        //this is needed to allow WObjects to be Nullable and some other operations...
        QString cnb=cls.baseClass(m_lang,m_prefix+"O");
+       hcd+="\t/// default constructor: constructs an invalid instance of "+cn+"\n";
        hcd+="\t"+cn+"():"+cnb+"(){}\n";
 
        //implement copiers
        QStringList k=cls.propertyNames();
+       hcd+="\t/// copy constructor: creates a (deep) copy of the object\n";
        hcd+="\t"+cn+"(const "+cn+"&);\n";
        scd+=cn+"::"+cn+"(const "+cn+"&o)\n\t:"+cnb+"(o)\n{\n";
        for(int i=0;i<k.size();i++)
                scd+="\tmp_"+k[i]+"=o.mp_"+k[i]+";\n";
        scd+="}\n";
+       hcd+="\t/// copy assignment: creates a (deep) copy of the object\n";
        hcd+="\t"+cn+"& operator=(const "+cn+"&);\n";
        scd+=cn+"& "+cn+"::operator=(const "+cn+"&o)\n{\n";
        scd+="\tif(this == &o)return *this;\n";
@@ -238,7 +256,8 @@ void WocQtClass::classDeserializer(const WocClass&cls,MFile&hdr,MFile&src,QStrin
        scd+="\treturn *this;\n}\n";
 
        //implement deserializer (as constructor)
-       hcd+="\t"+cn+"(const QDomElement&);\n";
+       hcd+="\t/// special constructor: create from the XML representation, deserializing the object\n";
+       hcd+="\texplicit "+cn+"(const QDomElement&);\n";
        scd+=cn+"::"+cn+"(const QDomElement&root)\n\t:"+cnb+"(root)\n{\n";
        scd+="\tQList<QDomElement> nl;\n";
        for(int i=0;i<k.size();i++){
@@ -328,6 +347,7 @@ void WocQtClass::classDeserializer(const WocClass&cls,MFile&hdr,MFile&src,QStrin
                }
        }
        scd+="}\n";
+       hcd+="\t/// destructor: deletes this copy of the object\n";
        hcd+="\tvirtual ~"+cn+"(){}\n";
        
        //write it...
@@ -339,11 +359,16 @@ void WocQtClass::classSerializers(const WocClass&cls,MFile&hdr,MFile&src,QString
 {
        QString hcd="  public:\n";
        QString scd;
+       hcd+="\t/// Serializes the object to XML and returns the string representation of that XML.\n";
        hcd+="\tQString toString();\n";
        scd+="QString "+cn+"::toString()\n{\n";
        scd+="\tQDomDocument doc;\n\tdoc.appendChild(toXml(doc));\n";
        scd+="\treturn doc.toString();\n}\n";
-       hcd+="\tQDomElement toXml(QDomDocument&,QString name=\""+cls.name()+"\");\n";
+       hcd+="\t/// Transforms the object into its XML representation, the element node returned is not appended to the document - you have to do that yourself.\n";
+       hcd+="\t/// \\param doc the DOM document node for which to generate the element\n";
+       hcd+="\t/// \\param name the name to give the generated element, per default \""+cn+"\" is used\n";
+       hcd+="\tQDomElement toXml(QDomDocument&doc,QString name=\""+cls.name()+"\");\n";
+       hcd+="\t/// Serializes the object into the given element.\n";
        hcd+="\tvoid toXml(QDomDocument&,QDomElement&);\n";
        scd+="QDomElement "+cn+"::toXml(QDomDocument&doc,QString name)\n{\n";
        scd+="\tQDomElement r=doc.createElement(name);\n\ttoXml(doc,r);\n";
index 03a48d2..e6cd087 100644 (file)
@@ -10,6 +10,7 @@
 #include <QDomElement>
 
 #include "qtconst.h"
+#include "doxyout.h"
 
 WocQtClientTransaction::WocQtClientTransaction(WocQtOut*p)
        :WocQtTransaction(p)
@@ -37,6 +38,7 @@ struct QtCTrans{
        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
+       QString indoc,ifcdoc;//docu for input params
        //transaction itself
        const WocTransaction&trn;
        QtCTrans(const WocTransaction&t,QString cn_,QString cnp_):trn(t){
@@ -72,7 +74,8 @@ void WocQtClientTransaction::newTransaction(const WocTransaction&trn)
        genInclude(ct);
        //start of class
        ct.hcd+="\nclass "+cnp+";\n";
-       ct.hcd+="\nclass "+cn+":public "+m_transbase+"\n{\n  Q_OBJECT\n";
+       ct.hcd+="\n"+doxyFormat(trn.docStrings());
+       ct.hcd+="class "+cn+":public "+m_transbase+"\n{\n  Q_OBJECT\n";
        ct.pcd+="\nclass "+cnp+":public WTransaction_PrivateBase\n{\n";
        
        //create properties
@@ -117,6 +120,9 @@ void WocQtClientTransaction::initList(QtCTrans& ct)
                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.indoc+="\t/// \\param a"+ct.in[i]+" ";
+               ct.indoc+=ct.trn.inputDoc(ct.in[i]).replace('\n',' ').replace('\r',' ');
+               ct.indoc+="\n";
        }
        ct.xinlist=ct.inlist;
        ct.xclist=ct.clist;
@@ -124,6 +130,7 @@ void WocQtClientTransaction::initList(QtCTrans& ct)
        ct.xinlist+="QString iface";
        if(ct.xclist!="")ct.xclist+=",";
        ct.xclist+="iface";
+       ct.ifcdoc="\t/// \\param iface ID of the interface that the transaction will be sent on\n";
 }
 
 
@@ -161,6 +168,8 @@ void WocQtClientTransaction::genTors(QtCTrans&ct)
 {
        //define parametric constructor
        ct.hcd+="  protected:\n";
+       ct.hcd+="\t/// generates an instance from its properties\n";
+       ct.hcd+=ct.indoc+ct.ifcdoc;
        ct.hcd+="\texplicit "+ct.cn+"("+ct.xinlist+");\n";
        //parametric constructor implementation
        ct.scd+=ct.cn+"::"+ct.cn+"("+ct.xinlist+")\n\t:"+m_transbase+"(iface)\n{\n";
@@ -171,15 +180,18 @@ void WocQtClientTransaction::genTors(QtCTrans&ct)
        ct.scd+="}\n\n";
        //decl default constructor
        ct.hcd+="  public:\n";
+       ct.hcd+="\t/// default constructor: generates an invalid transaction\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
+       ct.hcd+="\t/// copy constructor: the two copies share their state\n";
        ct.hcd+="\t"+ct.cn+"(const "+ct.cn+"&);\n";
        //copy constructor implementation
        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
+       ct.hcd+="\t/// copy assignment: the copy shares the state of the original object\n";
        ct.hcd+="\t"+ct.cn+"& operator=(const "+ct.cn+"&);\n";
        //copy operator implemented
        ct.scd+=ct.cn+"& "+ct.cn+"::operator=(const "+ct.cn+"&t)\n{\n";
@@ -189,6 +201,7 @@ void WocQtClientTransaction::genTors(QtCTrans&ct)
        ct.scd+="\treturn *this;\n}\n\n";
        
        //destructor
+       ct.hcd+="\t/// deletes this instance\n";
        ct.hcd+="\tvirtual ~"+ct.cn+"();\n";
        ct.scd+=ct.cn+"::~"+ct.cn+"()\n{\n\tp->detach(this);\n}\n\n";
 }
@@ -196,9 +209,11 @@ void WocQtClientTransaction::genTors(QtCTrans&ct)
 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();
+       m_parent->addIfaceHeaderPrefix("class "+ct.cn+";\n");
+//     m_parent->addIfaceImpl("#include \"src"+ct.cn+".h\"\n");
+       m_parent->addIfaceHeaderClass("  /// convenience call to query "+ct.cn+" synchronously\n");
+       m_parent->addIfaceHeaderClass("  "+ct.cn+" query"+ct.trn.name()+"("+ct.inlist+");\n");
+       m_parent->addIfaceImpl(ct.cn+" "+ m_parent->ifaceClassName()+"::query"+ct.trn.name()+ "("+ct.inlist+ ")\n{return "+ct.cn+"::query("+ ct.clist+(ct.clist!=""?",":"")+"name());}\n\n");
        //query method decl
        ct.hcd+="  private:\n";
        ct.hcd+="\tvoid netquery();\n\tvoid asyncnetquery();\n";
@@ -231,11 +246,15 @@ void WocQtClientTransaction::genQuery(QtCTrans& ct)
        ct.scd+="\temit finished();\n}\n";
        //create queries
        ct.hcd+="  public:\n";
+       ct.hcd+="\t/// emits the query over the network and returns the finished transaction object\n";
+       ct.hcd+=ct.indoc+ct.ifcdoc;
        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+="\t/// emits the query over the network and returns the transaction object, use isFinished() to check for the transaction's state\n";
+       ct.hcd+=ct.indoc+ct.ifcdoc;
        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;
@@ -247,6 +266,7 @@ 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+=doxyFormat(ct.trn.outputDoc(ct.out[i]),1);
                ct.hcd+="\tQ_SLOT "+tp+" get"+ct.out[i]+"()const;\n";
                ct.scd+=tp+" "+ct.cn+"::get"+ct.out[i]+"()const{return p->out_"+ct.out[i]+";}\n";
        }
@@ -260,7 +280,9 @@ void WocQtClientTransaction::genScripting(QtCTrans& ct)
        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";
@@ -415,14 +437,19 @@ void WocQtClientTransaction::trnList()
        QString code;
        //header
        code+="  Q_ENUMS(Right)\n";
-       code+="  enum Right {\n    NoRight";
+       code+="  /// This enum represents transactions and the right to use them.\n"
+       code+="  enum Right {\n    /// dummy as a fall back for no transaction\n    NoRight";
        QStringList r=WocProcessor::instance()->transactionNames();
        QStringList p=WocProcessor::instance()->privilegeNames();
        QStringList pp=p;
-       for(int i=0;i<r.size();i++)
-               code+=",\n    R"+r[i];
-       for(int i=0;i<p.size();i++)
+       for(int i=0;i<r.size();i++){
+               code+=",\n\t/// transaction "+r[i]+", see class "+m_prefix+"T"+r[i]+"\n";
+               code+="\tR"+r[i];
+       }
+       for(int i=0;i<p.size();i++){
+               //TODO
                code+=",\n    P"+pp[i].replace(':',"_");
+       }
        code+="\n  };\n";
        code+="  typedef QList<Right> RightList;\n";
        code+="  Q_INVOKABLE static QString rightToString(Right);\n";
@@ -430,7 +457,7 @@ void WocQtClientTransaction::trnList()
        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();
+       m_parent->addIfaceHeaderClass(code);code.clear();
        
        code+="static int righttypeid=";
        code+="qRegisterMetaType<"+m_parent->ifaceClassName()+"::RightList>()+";
@@ -470,5 +497,5 @@ void WocQtClientTransaction::trnList()
        for(int i=0;i<p.size();i++)
                code+="<<\""+p[i]+"\"";
        code+=";\n\treturn ret;\n}\n";
-       m_ifacecpp.write(code.toAscii());
+       m_parent->addIfaceImpl(code);
 }
index b368f77..f3189bb 100644 (file)
@@ -14,6 +14,7 @@
 
 #define QT_OUT_NO_WRAP
 #include "qtconst.h"
+#include "doxyout.h"
 
 WocQtOut::WocQtOut(QDomElement&el)
 {
@@ -57,27 +58,30 @@ WocQtOut::WocQtOut(QDomElement&el)
                return;
        }
        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 \"WInterface\"\n"));
        m_iface.write(QByteArray("#include <QStringList>\n"));
        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());
+       addIfaceHeaderClass(doxyFormat(pn+" interface class."));
+       addIfaceHeaderClass(QString("class "+ifaceClassName()+":public WInterface\n{\n Q_OBJECT\n"));
+       addIfaceHeaderClass(QString(" public:\n  "+ifaceClassName()+"(QString name=\""+pn+"\"):WInterface(name){}\n"));
+       addIfaceHeaderClass("  /// convenience override: returns a pointer to an instance with the given name if it is of the correct type, otherwise nullptr\n");
+       addIfaceHeaderClass("  static "+ifaceClassName()+"*instance(QString name=\""+pn+"\")\n\t{return qobject_cast<"+ifaceClassName()+"*>(WInterface::instance(name));}\n\n");
        //version info, static
-       m_iface.write(QByteArray("  Q_INVOKABLE static QString staticVersionInfo(WOb::VersionInfo);\n"));
+       addIfaceHeaderClass("  /// returns version information of this interface\n");
+       addIfaceHeaderClass("  Q_INVOKABLE static QString staticVersionInfo(WOb::VersionInfo);\n");
+       m_ifacecpp.write(QByteArray("#include \""+m_prefix.toAscii()+"IncludeAll\"\n"));
        m_ifacecpp.write(QByteArray("#include \"staticVersion.h\"\n"));
        m_ifacecpp.write(QString("QString "+ifaceClassName()+"::staticVersionInfo(WOb::VersionInfo vi){return WOCgenerated_versionInfo(vi);}\n").toAscii());
-       m_iface.write(QByteArray("  Q_INVOKABLE static QString staticWocVersionInfo(WOb::VersionInfo);\n"));
+       addIfaceHeaderClass("  /// returns version information about the WOC that created the interface class\n");
+       addIfaceHeaderClass("  Q_INVOKABLE static QString staticWocVersionInfo(WOb::VersionInfo);\n");
        m_ifacecpp.write(QString("QString "+ifaceClassName()+"::staticWocVersionInfo(WOb::VersionInfo vi){return WOCcopied_versionInfo(vi);}\n").toAscii());
        //version info, virtual
-       m_iface.write(QByteArray("  Q_INVOKABLE QString versionInfo(WOb::VersionInfo)const;\n"));
-       m_ifacecpp.write(QByteArray("#include \"staticVersion.h\"\n"));
+       addIfaceHeaderClass("  /// returns version information of this interface\n");
+       addIfaceHeaderClass("  Q_INVOKABLE QString versionInfo(WOb::VersionInfo)const;\n");
        m_ifacecpp.write(QString("QString "+ifaceClassName()+"::versionInfo(WOb::VersionInfo vi)const{return WOCgenerated_versionInfo(vi);}\n").toAscii());
-       m_iface.write(QByteArray("  Q_INVOKABLE QString wocVersionInfo(WOb::VersionInfo)const;\n"));
+       addIfaceHeaderClass("  /// returns version information about the WOC that created the interface class\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").toAscii());
        
        //init scripting
@@ -103,7 +107,7 @@ void WocQtOut::finalize()
        if(qtrans)qtrans->finalize();
        //finish scripting stuff
        if(m_genscript){
-               m_iface.write(QByteArray("  void initScriptEngine(QScriptEngine*);\n"));
+               addIfaceHeaderClass("  void initScriptEngine(QScriptEngine*);\n");
                m_scriptcode+="}\n\n";
                m_ifacecpp.write(m_scriptcode.toAscii());
        }
@@ -114,6 +118,8 @@ void WocQtOut::finalize()
        //finish sources
        m_ifacecpp.write(SRCEND);
        m_ifacecpp.close();
+       m_iface.write(m_iface_prefix.toAscii());
+       m_iface.write(m_iface_class.toAscii());
        m_iface.write(QByteArray("};\n"));
        m_iface.write(m_postiface.toAscii());
        m_iface.write(HDREND);
@@ -333,3 +339,18 @@ void WocQtOut::initVersionH()
        //close file
        vhf.write(QByteArray(HDREND));
 }
+
+void WocQtOut::addToPriFile ( const QByteArray& a )
+{
+       m_pri.write(a);
+}
+
+void WocQtOut::addToIncludeAllFile ( const QByteArray& a )
+{
+       m_hdr.write(a);
+}
+
+void WocQtOut::addIfaceImpl ( const QString& s )
+{
+       m_ifacecpp.write(s.toAscii());
+}
index 7c0b3da..7f72c0e 100644 (file)
@@ -35,6 +35,13 @@ class WocQtOut:public WocOutput
        public:
                WocQtOut(QDomElement&);
                ~WocQtOut();
+               
+               void addIfaceHeaderPrefix(const QString&s){m_iface_prefix+=s;}
+               void addIfaceHeaderClass(const QString&s){m_iface_class+=s;}
+               void addIfaceImpl(const QString&);
+               
+               void addToPriFile(const QByteArray&a);
+               void addToIncludeAllFile(const QByteArray&a);
        protected:
                virtual void finalize();
                virtual void newClass(const WocClass&);
@@ -48,7 +55,6 @@ class WocQtOut:public WocOutput
                friend class WocQtTable;
                
                QString m_basedir,m_subdir,m_prefix,m_transbase,m_lang,m_postiface,m_scriptcode;
-               MFile m_pri,m_iface,m_ifacecpp,m_hdr;
                bool m_clean,m_genscript;
                
                ///types of files generated
@@ -89,6 +95,9 @@ class WocQtOut:public WocOutput
                WocQtClass*qclass;
                WocQtTable*qtable;
                WocQtTransaction*qtrans;
+       private:
+               MFile m_pri,m_iface,m_ifacecpp,m_hdr;
+               QString m_iface_prefix,m_iface_class;
 };
 
 class WocQtClientOut:public WocQtOut