Esempio n. 1
0
void ORGraphicsSectionDetail::initFromXML(QDomNode & section)
{
  QDomNodeList nl = section.childNodes();
  QDomNode node;
  QString n;

  // some code to handle old style defs
  QString o_name = "unnamed";
  QString o_column = QString::null;
  bool old_head = FALSE;
  QDomNode o_head;
  bool old_foot = FALSE;
  QDomNode o_foot;

  for(int i = 0; i < nl.count(); i++) {
    node = nl.item(i);
    n = node.nodeName();
    if(n == "name") {
      o_name = node.firstChild().nodeValue();
      setTitle(o_name);
    } else if(n == "pagebreak") {
      QDomElement eThis = node.toElement();
      if(eThis.attribute("when") == "at end")
        setPageBreak(BreakAtEnd);
    } else if(n == "group") {
      ORGraphicsSectionDetailGroup * rsdg = new ORGraphicsSectionDetailGroup("unnamed", this, this);
      QDomNodeList gnl = node.childNodes();
      QDomNode gnode;
      bool show_head = FALSE;
      bool show_foot = FALSE;
      for(int gi = 0; gi < gnl.count(); gi++) {
        gnode = gnl.item(gi);
        if(gnode.nodeName() == "name") {
          rsdg->setTitle(gnode.firstChild().nodeValue());
        } else if(gnode.nodeName() == "column") {
          rsdg->setColumn(gnode.firstChild().nodeValue());
        } else if(gnode.nodeName() == "pagebreak") {
          QDomElement elemThis = gnode.toElement();
          QString n = elemThis.attribute("when");
          if("after foot" == n)
            rsdg->setPageBreak(ORGraphicsSectionDetailGroup::BreakAfterGroupFooter);
        } else if(gnode.nodeName() == "head") {
          rsdg->getGroupHead()->initFromXML(gnode);
          rsdg->showGroupHead(TRUE);
          show_head = TRUE;
        } else if(gnode.nodeName() == "foot") {
          rsdg->getGroupFoot()->initFromXML(gnode);
          rsdg->showGroupFoot(TRUE);
          show_foot = TRUE;
        } else {
          qDebug("encountered unknown element while parsing group element: %s", gnode.nodeName().toLatin1().constData());
        }
      }
      insertSection(groupSectionCount(), rsdg);
      rsdg->showGroupHead(show_head);
      rsdg->showGroupFoot(show_foot);
    } else if(n == "grouphead") {
      o_head = node;
      old_head = TRUE;
    } else if(n == "groupfoot") {
      o_foot = node;
      old_foot = TRUE;
    } else if(n == "detail") {
      // need to pull out the query key values
      QDomNode key = node.namedItem("key");
      if(key.isNull()) {
        qDebug("Did not find a key element while parsing detail section");
      } else {
        QDomNodeList knl = key.childNodes();
        QDomNode knode;
        for(int ki = 0; ki < knl.count(); ki++) {
          knode = knl.item(ki);
          if(knode.nodeName() == "query") {
            setQuery(knode.firstChild().nodeValue());
          } else if(knode.nodeName() == "column") {
            o_column = knode.firstChild().nodeValue();
          } else {
            qDebug("encountered unknown element while parsing key element: %s", knode.nodeName().toLatin1().constData());
          }
        }
      }
      _detail->initFromXML(node);
    } else {
      // unknown element
      qDebug("while parsing section encountered and unknown element: %s", n.toLatin1().constData());
    }
  }

  if(old_head || old_foot) {
    ORGraphicsSectionDetailGroup * rsdg = new ORGraphicsSectionDetailGroup(o_name, this, this);

    rsdg->setColumn(o_column);
    if(old_head)
      rsdg->getGroupHead()->initFromXML(o_head);
    if(old_foot)
      rsdg->getGroupFoot()->initFromXML(o_foot);

    // if we encountered this situation then we shouldn't have
    // any other sections but to be sure we will just tack this one
    // onto the end
    insertSection(groupSectionCount(), rsdg);

    rsdg->showGroupHead(old_head);
    rsdg->showGroupFoot(old_foot);
  }
}
Esempio n. 2
0
void ORGraphicsSectionDetail::buildXML(QDomDocument & doc, QDomElement & section)
{
  // name/title
  QDomElement name = doc.createElement("name");
  name.appendChild(doc.createTextNode(getTitle()));
  section.appendChild(name);

  if(pageBreak() != ORGraphicsSectionDetail::BreakNone)
  {
    QDomElement spagebreak = doc.createElement("pagebreak");
    if(pageBreak() == ORGraphicsSectionDetail::BreakAtEnd)
      spagebreak.setAttribute("when", "at end");
    section.appendChild(spagebreak);
  }

  for(int i = 0; i < groupList.count(); i++)
  {
    ORGraphicsSectionDetailGroup * rsdg = groupList.at(i);
    QDomNode grp = doc.createElement("group");

    QDomNode gname = doc.createElement("name");
    gname.appendChild(doc.createTextNode(rsdg->getTitle()));
    grp.appendChild(gname);

    QDomNode gcol = doc.createElement("column");
    gcol.appendChild(doc.createTextNode(rsdg->column()));
    grp.appendChild(gcol);

    if(rsdg->pageBreak() != ORGraphicsSectionDetailGroup::BreakNone)
    {
      QDomElement pagebreak = doc.createElement("pagebreak");
      if(rsdg->pageBreak() == ORGraphicsSectionDetailGroup::BreakAfterGroupFooter)
        pagebreak.setAttribute("when", "after foot");
      grp.appendChild(pagebreak);
    }

    //group head
    if(rsdg->isGroupHeadShowing())
    {
      QDomElement ghead = doc.createElement("head");
      rsdg->getGroupHead()->buildXML(doc,ghead);
      grp.appendChild(ghead);
    }
    // group foot
    if(rsdg->isGroupFootShowing())
    {
      QDomElement gfoot = doc.createElement("foot");
      rsdg->getGroupFoot()->buildXML(doc,gfoot);
      grp.appendChild(gfoot);
    }

    section.appendChild(grp);
  }

  // detail section
  QDomElement gdetail = doc.createElement("detail");
  QDomElement key = doc.createElement("key");
  QDomElement kquery = doc.createElement("query");
  kquery.appendChild(doc.createTextNode(query()));
  key.appendChild(kquery);
  gdetail.appendChild(key);
  _detail->buildXML(doc,gdetail);
  section.appendChild(gdetail);
}