diff options
Diffstat (limited to 'client/mainwindow.cc')
-rw-r--r-- | client/mainwindow.cc | 72 |
1 files changed, 63 insertions, 9 deletions
diff --git a/client/mainwindow.cc b/client/mainwindow.cc index dfe112f..6bf0543 100644 --- a/client/mainwindow.cc +++ b/client/mainwindow.cc @@ -48,6 +48,7 @@ #include "macro.h" #include "header.h" +#include "template.h" #include "debug.h" @@ -65,8 +66,8 @@ public: MainWindow *gmainwindow = NULL; -MainWindow::MainWindow(QString patientid, QString templ, QString host, - quint16 port, QString user) +MainWindow::MainWindow(QString patientid, QString course, QString templ, + QString host, quint16 port, QString user) : QMainWindow(0), // Qt::WindowContextHelpButtonHint netcom(host, port) { @@ -94,6 +95,7 @@ MainWindow::MainWindow(QString patientid, QString templ, QString host, this->patientid = patientid; this->user = user; + this->course = course; this->templ = templ; setWindowTitle("Pracro - " + patientid); @@ -238,6 +240,7 @@ void MainWindow::init() netcom.patientid = patientid; netcom.templ = templ; + netcom.course = course; netcom.user = user; netcom.initConnection(); @@ -285,7 +288,7 @@ void MainWindow::updateMacros(QDomNodeList &nodes) if(entities.find(j) == entities.end()) { Entity *e = NULL; if(elem.tagName() == "macro") { - e = new Macro(entities, netcom, templ, scrollarea); + e = new Macro(entities, netcom, course, templ, scrollarea); } if(elem.tagName() == "header") { e = new Header(); @@ -306,6 +309,49 @@ void MainWindow::updateMacros(QDomNodeList &nodes) } } +void MainWindow::updateTemplates(QDomNodeList &nodes) +{ + for(int j = 0; j < nodes.count(); j++) { + QDomNode node = nodes.at(j); + QDomElement elem = node.toElement(); + + if(elem.tagName() == "template") { + QString name = elem.attribute("name"); + + if(entities.find(j) == entities.end()) { + Template *e = new Template(netcom); + connect(e, SIGNAL(setTemplate(QString)), + this, SLOT(setTemplate(QString))); + entities[j] = e; + entities[j]->update(node); + w->layout()->addWidget(e->widget()); + } else { + entities[j]->update(node); + } + continue; + } + + showError("XML Error", "Expected template tag. Got '" + + elem.tagName() + "' tag."); + continue; + + } +} + +void MainWindow::setTemplate(QString name) +{ + templ = name; + + Entities::iterator i = entities.begin(); + while(i != entities.end()) { + delete i.value()->widget(); + // delete i.value(); + i++; + } + + entities.clear(); +} + void MainWindow::handle(QDomDocument &doc) { if(closing) close(); @@ -323,12 +369,12 @@ void MainWindow::handle(QDomDocument &doc) continue; } - if(element.tagName() != "template") { - showError("XML error", "Outer tag not a template."); + if(element.tagName() != "template" && element.tagName() != "course") { + showError("XML error", "Outer tag not a template or course."); continue; } - if(element.attribute("name") != templ) { + if(element.tagName() == "template" && element.attribute("name") != templ) { showError("XML error", "Got template name that didn't match current session."); continue; @@ -337,9 +383,17 @@ void MainWindow::handle(QDomDocument &doc) // Set headers. titles, etc... updateTemplateHeaders(node); - // Update macros, header and resumes. - QDomNodeList macronodes = node.childNodes(); - updateMacros(macronodes); + if(element.tagName() == "course") { + // Update macros, header and resumes. + QDomNodeList templatenodes = node.childNodes(); + updateTemplates(templatenodes); + } + + if(element.tagName() == "template") { + // Update macros, header and resumes. + QDomNodeList macronodes = node.childNodes(); + updateMacros(macronodes); + } } } |