diff options
Diffstat (limited to 'client/formatparser.cc')
-rw-r--r-- | client/formatparser.cc | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/client/formatparser.cc b/client/formatparser.cc index 260a2bf..233a694 100644 --- a/client/formatparser.cc +++ b/client/formatparser.cc @@ -26,6 +26,8 @@ */ #include "formatparser.h" +#include <QSqlRecord> +#include <QVariant> #include <string.h> QString format_parser(QString format, QVector< Widget *> widgets) @@ -98,3 +100,80 @@ QString format_parser(QString format, QVector< Widget *> widgets) return resume; } + + +QString format_parser(QString format, QSqlQuery &query) +{ + QString resume; + QString var; + + QChar *p = format.data(); + QChar *theend = p + format.size(); + while(p < theend) { + switch((*p).toLatin1()) { + case '$': + p++; + switch((*p).toLatin1()) { + case '$': + resume.append(*p); + break; + + case '{': + p++; + var = ""; + // Parser + while(p < theend && *p != '}') { + var.append(*p); + p++; + } + { + int fieldNo = query.record().indexOf(var); + resume += query.value(fieldNo).toString(); + + /* + QVector< Widget* >::iterator i = widgets.begin(); + while (i != widgets.end()) { + Widget* w = *i; + if(w->getName() == var) resume += w->getValue(); + i++; + } + */ + } + break; + + default: + resume.append(*p); + break; + } + p++; + break; + + case '\\': + p++; + switch((*p).toLatin1()) { + case 't': + resume.append('\t'); + break; + case 'n': + resume.append('\n'); + break; + case 'r': + resume.append('\r'); + break; + case '\\': + default: + resume.append(*p); + break; + } + p++; + break; + + default: + resume.append(QChar(*p)); + p++; + break; + } + } + + return resume; +} |