bool parseReportImage(const QDomElement & elemSource, ORImageData & imageTarget) { QDomNodeList params = elemSource.childNodes(); bool valid_rect = FALSE; bool valid_data = FALSE; bool valid_inline = FALSE; imageTarget.mode = "clip"; for(int paramCounter = 0; paramCounter < params.count(); paramCounter++) { QDomElement elemParam = params.item(paramCounter).toElement(); if(elemParam.tagName() == "rect") valid_rect = parseReportRect(elemParam, imageTarget.rect); else if(elemParam.tagName() == "data") valid_data = parseReportData(elemParam, imageTarget.data); else if(elemParam.tagName() == "mode") imageTarget.mode = elemParam.text(); else if(elemParam.tagName() == "map") { // ok we have an inline image here imageTarget.format = elemParam.attribute("format"); imageTarget.inline_data = elemParam.firstChild().nodeValue(); valid_inline = TRUE; } else qDebug("Tag not parsed at <image>:%s", (const char*)elemParam.tagName()); } if(valid_rect && ( valid_data || valid_inline ) ) return TRUE; return FALSE; }
KReportItemCheckBox::KReportItemCheckBox(const QDomNode &element) { createProperties(); QDomNodeList nl = element.childNodes(); QString n; QDomNode node; nameProperty()->setValue(element.toElement().attribute(QLatin1String("report:name"))); m_controlSource->setValue(element.toElement().attribute(QLatin1String("report:item-data-source"))); setZ(element.toElement().attribute(QLatin1String("report:z-index")).toDouble()); m_foregroundColor->setValue(QColor(element.toElement().attribute(QLatin1String("fo:foreground-color")))); m_checkStyle->setValue(element.toElement().attribute(QLatin1String("report:check-style"))); m_staticValue->setValue(QVariant(element.toElement().attribute(QLatin1String("report:value"))).toBool()); parseReportRect(element.toElement()); for (int i = 0; i < nl.count(); i++) { node = nl.item(i); n = node.nodeName(); if (n == QLatin1String("report:line-style")) { KReportLineStyle ls; if (parseReportLineStyleData(node.toElement(), &ls)) { m_lineWeight->setValue(ls.width()); m_lineColor->setValue(ls.color()); m_lineStyle->setValue(QPen(ls.penStyle())); } } else { kreportpluginWarning() << "while parsing check element encountered unknow element: " << n; } } }
bool parseReportBarcode(const QDomElement & elemSource, ORBarcodeData & barcodeTarget) { QDomNodeList params = elemSource.childNodes(); bool valid_rect = FALSE; bool valid_data = FALSE; barcodeTarget.format = "3of9"; barcodeTarget.align = 0; // left alignment [default] for(int paramCounter = 0; paramCounter < params.count(); paramCounter++) { QDomElement elemParam = params.item(paramCounter).toElement(); if(elemParam.tagName() == "rect") valid_rect = parseReportRect(elemParam, barcodeTarget.rect); else if(elemParam.tagName() == "data") valid_data = parseReportData(elemParam, barcodeTarget.data); else if(elemParam.tagName() == "maxlength") barcodeTarget.maxlength = elemParam.text().toInt(); else if(elemParam.tagName() == "format") barcodeTarget.format = elemParam.text(); else if(elemParam.tagName() == "left") barcodeTarget.align = 0; else if(elemParam.tagName() == "center") barcodeTarget.align = 1; else if(elemParam.tagName() == "right") barcodeTarget.align = 2; else qDebug("Tag not parsed at <barcode>:%s", (const char*)elemParam.tagName()); } if(valid_rect && valid_data) return TRUE; return FALSE; }
KoReportItemMaps::KoReportItemMaps(QDomNode & element) { myDebug() << "======" << this; createProperties(); QDomNodeList nl = element.childNodes(); QString n; QDomNode node; m_name->setValue(element.toElement().attribute("report:name")); m_controlSource->setValue(element.toElement().attribute("report:item-data-source")); //m_resizeMode->setValue(element.toElement().attribute("report:resize-mode", "stretch")); Z = element.toElement().attribute("report:z-index").toDouble(); parseReportRect(element.toElement(), &m_pos, &m_size); myDebug() << "====== childgren:"; for (int i = 0; i < nl.count(); i++) { node = nl.item(i); n = node.nodeName(); // if (n == "report:Maps-data") { // // setInlineImageData(node.firstChild().nodeValue().toLatin1()); // } else { kDebug() << "====== while parsing image element encountered unknow element: " << n; // } } m_mapImage = new QImage(m_size.toScene().toSize(), QImage::Format_ARGB32); m_mapImage->fill(QColor(200, 150, 5).rgb()); }
bool parseReportRect(const QDomElement & elemSource, QRect & rectTarget) { ORRectData rData; bool res = parseReportRect(elemSource, rData); if(res) { rectTarget = QRect (rData.x, rData.y, rData.width, rData.height); } return res; }
bool parseReportField(const QDomElement & elemSource, ORFieldData & fieldTarget) { QDomNodeList params = elemSource.childNodes(); bool valid_rect = FALSE; bool valid_data = FALSE; fieldTarget.align = 0; fieldTarget.trackTotal = FALSE; fieldTarget.sub_total = FALSE; fieldTarget.builtinFormat = FALSE; fieldTarget.format = QString::null; for (int paramCounter = 0; paramCounter < params.count(); paramCounter++) { QDomElement elemParam = params.item(paramCounter).toElement(); if (elemParam.tagName() == "rect") valid_rect = parseReportRect(elemParam, fieldTarget.rect); else if (elemParam.tagName() == "font") parseReportFont(elemParam, fieldTarget.font); else if (elemParam.tagName() == "left") fieldTarget.align |= Qt::AlignLeft; else if (elemParam.tagName() == "right") fieldTarget.align |= Qt::AlignRight; else if (elemParam.tagName() == "vcenter") fieldTarget.align |= Qt::AlignVCenter; else if (elemParam.tagName() == "hcenter") fieldTarget.align |= Qt::AlignHCenter; else if (elemParam.tagName() == "top") fieldTarget.align |= Qt::AlignTop; else if (elemParam.tagName() == "bottom") fieldTarget.align |= Qt::AlignBottom; else if (elemParam.tagName() == "wordwrap") fieldTarget.align |= Qt::TextWordWrap; else if (elemParam.tagName() == "data") valid_data = parseReportData(elemParam, fieldTarget.data); else if (elemParam.tagName() == "tracktotal") { fieldTarget.builtinFormat = (elemParam.attribute("builtin")=="true"?TRUE:FALSE); fieldTarget.sub_total = (elemParam.attribute("subtotal")=="true"?TRUE:FALSE); fieldTarget.format = elemParam.text(); if(fieldTarget.format.length() > 0) fieldTarget.trackTotal = TRUE; } else qDebug("Tag not Parsed at <field>:%s\n", (const char *)elemParam.tagName()); } if(valid_rect && valid_data) return TRUE; return FALSE; }
KoReportItemBarcode::KoReportItemBarcode(QDomNode & element) { createProperties(); QDomNodeList nl = element.childNodes(); QString n; QDomNode node; m_name->setValue(element.toElement().attribute("report:name")); m_controlSource->setValue(element.toElement().attribute("report:control-source")); Z = element.toElement().attribute("report:z-index").toDouble(); m_horizontalAlignment->setValue(element.toElement().attribute("report:horizontal-align")); m_maxLength->setValue(element.toElement().attribute("report:barcode-max-length")); m_format->setValue(element.toElement().attribute("report:barcode-format")); parseReportRect(element.toElement(), &m_pos, &m_size); }
KoReportItemWeb::KoReportItemWeb(QDomNode &element) { createProperties(); init(); QDomNodeList nl = element.childNodes(); QString n; QDomNode node; QDomElement e = element.toElement(); m_controlSource->setValue(element.toElement().attribute("report:item-data-source")); m_name->setValue(element.toElement().attribute("report:name")); Z = element.toElement().attribute("report:z-index").toDouble(); parseReportRect(element.toElement(), &m_pos, &m_size); for (int i = 0; i < nl.count(); i++) { node = nl.item(i); n = node.nodeName(); } }
KReportItemField::KReportItemField(const QDomNode & element) { createProperties(); QDomNodeList nl = element.childNodes(); QString n; QDomNode node; nameProperty()->setValue(element.toElement().attribute(QLatin1String("report:name"))); m_controlSource->setValue(element.toElement().attribute(QLatin1String("report:item-data-source"))); m_itemValue->setValue(element.toElement().attribute(QLatin1String("report:value"))); setZ(element.toElement().attribute(QLatin1String("report:z-index")).toDouble()); m_horizontalAlignment->setValue(element.toElement().attribute(QLatin1String("report:horizontal-align"))); m_verticalAlignment->setValue(element.toElement().attribute(QLatin1String("report:vertical-align"))); m_canGrow->setValue(element.toElement().attribute(QLatin1String("report:can-grow"))); m_wordWrap->setValue(element.toElement().attribute(QLatin1String("report:word-wrap"))); parseReportRect(element.toElement()); for (int i = 0; i < nl.count(); i++) { node = nl.item(i); n = node.nodeName(); if (n == QLatin1String("report:text-style")) { KRTextStyleData ts; if (parseReportTextStyleData(node.toElement(), &ts)) { m_backgroundColor->setValue(ts.backgroundColor); m_foregroundColor->setValue(ts.foregroundColor); m_backgroundOpacity->setValue(ts.backgroundOpacity); m_font->setValue(ts.font); } } else if (n == QLatin1String("report:line-style")) { KReportLineStyle ls; if (parseReportLineStyleData(node.toElement(), &ls)) { m_lineWeight->setValue(ls.width()); m_lineColor->setValue(ls.color()); m_lineStyle->setValue(QPen(ls.penStyle())); } } else { kreportpluginWarning() << "while parsing field element encountered unknow element: " << n; } } }
KoReportItemLabel::KoReportItemLabel(QDomNode & element) { createProperties(); QDomNodeList nl = element.childNodes(); QString n; QDomNode node; m_name->setValue(element.toElement().attribute("report:name")); m_text->setValue(element.toElement().attribute("report:caption")); Z = element.toElement().attribute("report:z-index").toDouble(); m_horizontalAlignment->setValue(element.toElement().attribute("report:horizontal-align")); m_verticalAlignment->setValue(element.toElement().attribute("report:vertical-align")); parseReportRect(element.toElement(), &m_pos, &m_size); for (int i = 0; i < nl.count(); i++) { node = nl.item(i); n = node.nodeName(); if (n == "report:text-style") { KRTextStyleData ts; if (parseReportTextStyleData(node.toElement(), ts)) { m_backgroundColor->setValue(ts.backgroundColor); m_foregroundColor->setValue(ts.foregroundColor); m_backgroundOpacity->setValue(ts.backgroundOpacity); m_font->setValue(ts.font); } } else if (n == "report:line-style") { KRLineStyleData ls; if (parseReportLineStyleData(node.toElement(), ls)) { m_lineWeight->setValue(ls.weight); m_lineColor->setValue(ls.lineColor); m_lineStyle->setValue(ls.style); } } else { kWarning() << "while parsing label element encountered unknow element: " << n; } } }
bool parseReportText(const QDomElement & elemSource, ORTextData & textTarget) { QDomNodeList params = elemSource.childNodes(); bool valid_rect = FALSE; bool valid_data = FALSE; textTarget.align = 0; textTarget.bottompad = 0; for (int paramCounter = 0; paramCounter < params.count(); paramCounter++) { QDomElement elemParam = params.item(paramCounter).toElement(); if (elemParam.tagName() == "rect") valid_rect = parseReportRect(elemParam, textTarget.rect); else if (elemParam.tagName() == "font") parseReportFont(elemParam, textTarget.font); else if (elemParam.tagName() == "left") textTarget.align |= Qt::AlignLeft; else if (elemParam.tagName() == "right") textTarget.align |= Qt::AlignRight; else if (elemParam.tagName() == "vcenter") textTarget.align |= Qt::AlignVCenter; else if (elemParam.tagName() == "hcenter") textTarget.align |= Qt::AlignHCenter; else if (elemParam.tagName() == "top") textTarget.align |= Qt::AlignTop; else if (elemParam.tagName() == "bottom") textTarget.align |= Qt::AlignBottom; else if (elemParam.tagName() == "data") valid_data = parseReportData(elemParam, textTarget.data); else if (elemParam.tagName() == "bottompad") textTarget.bottompad = elemParam.text().toInt(); else qDebug("Tag not Parsed at <text>:%s\n", (const char *)elemParam.tagName()); } if(valid_rect && valid_data) return TRUE; return FALSE; }
bool parseReportLabel(const QDomElement & elemSource, ORLabelData & labelTarget) { QDomNodeList params = elemSource.childNodes(); bool valid_rect = FALSE; bool valid_string = FALSE; labelTarget.align = 0; for (int paramCounter = 0; paramCounter < params.count(); paramCounter++) { QDomElement elemParam = params.item(paramCounter).toElement(); if (elemParam.tagName() == "rect") valid_rect = parseReportRect(elemParam, labelTarget.rect); else if (elemParam.tagName() == "font") parseReportFont(elemParam, labelTarget.font); else if (elemParam.tagName() == "string") { labelTarget.string = elemParam.text(); valid_string = TRUE; } else if (elemParam.tagName() == "left") labelTarget.align |= Qt::AlignLeft; else if (elemParam.tagName() == "right") labelTarget.align |= Qt::AlignRight; else if (elemParam.tagName() == "vcenter") labelTarget.align |= Qt::AlignVCenter; else if (elemParam.tagName() == "hcenter") labelTarget.align |= Qt::AlignHCenter; else if (elemParam.tagName() == "top") labelTarget.align |= Qt::AlignTop; else if (elemParam.tagName() == "bottom") labelTarget.align |= Qt::AlignBottom; else qDebug("Tag not Parsed at <label>:%s\n", (const char *)elemParam.tagName()); } if(valid_rect && valid_string) return TRUE; return FALSE; }
KRTextData::KRTextData(QDomNode & element) : bpad(0.0) { createProperties(); QDomNodeList nl = element.childNodes(); QString n; QDomNode node; for (int i = 0; i < nl.count(); i++) { node = nl.item(i); n = node.nodeName(); if (n == "data") { QDomNodeList dnl = node.childNodes(); for (int di = 0; di < dnl.count(); di++) { node = dnl.item(di); n = node.nodeName(); /*if ( n == "query" ) { _query->setValue ( node.firstChild().nodeValue() ); } else */if (n == "controlsource") { m_controlSource->setValue(node.firstChild().nodeValue()); } else { kDebug() << "while parsing field data encountered and unknown element: " << n; } } } else if (n == "name") { m_name->setValue(node.firstChild().nodeValue()); } else if (n == "zvalue") { Z = node.firstChild().nodeValue().toDouble(); } else if (n == "bottompad") { bpad = node.firstChild().nodeValue().toDouble() / 100.0; } else if (n == "left") { m_horizontalAlignment->setValue("Left"); } else if (n == "hcenter") { m_horizontalAlignment->setValue("Center"); } else if (n == "right") { m_horizontalAlignment->setValue("Right"); } else if (n == "top") { m_verticalAlignment->setValue("Top"); } else if (n == "vcenter") { m_verticalAlignment->setValue("Center"); } else if (n == "bottom") { m_verticalAlignment->setValue("Bottom"); } else if (n == "rect") { QRectF r; parseReportRect(node.toElement(), r); m_pos.setPointPos(r.topLeft()); m_size.setPointSize(r.size()); } else if (n == "textstyle") { ORTextStyleData ts; if (parseReportTextStyleData(node.toElement(), ts)) { m_backgroundColor->setValue(ts.bgColor); m_foregroundColor->setValue(ts.fgColor); m_backgroundOpacity->setValue(ts.bgOpacity); m_font->setValue(ts.font); } } else if (n == "linestyle") { ORLineStyleData ls; if (parseReportLineStyleData(node.toElement(), ls)) { m_lineWeight->setValue(ls.weight); m_lineColor->setValue(ls.lnColor); m_lineStyle->setValue(ls.style); } } else { kDebug() << "while parsing text element encountered unknow element: " << n; } } }
bool parseReportBackground(const QDomElement & elemSource, ORBackgroundData & bgTarget) { if(elemSource.tagName() != "background") return FALSE; bgTarget.enabled = false; bgTarget.staticImage = true; bgTarget.image = QString::null; bgTarget.data.query = QString::null; bgTarget.data.column = QString::null; bgTarget.opacity = 25; bgTarget.mode = "clip"; bgTarget.rect = QRect(); int halign = Qt::AlignLeft; int valign = Qt::AlignTop; bool valid_rect = true; QDomNodeList nlist = elemSource.childNodes(); for(int nodeCounter = 0; nodeCounter < nlist.count(); nodeCounter++) { QDomElement elemThis = nlist.item(nodeCounter).toElement(); if(elemThis.tagName() == "image") bgTarget.image = elemThis.text(); else if(elemThis.tagName() == "mode") bgTarget.mode = elemThis.text(); else if(elemThis.tagName() == "data") bgTarget.staticImage = !parseReportData(elemThis, bgTarget.data); else if(elemThis.tagName() == "left") halign = Qt::AlignLeft; else if(elemThis.tagName() == "hcenter") halign = Qt::AlignHCenter; else if(elemThis.tagName() == "right") halign = Qt::AlignRight; else if(elemThis.tagName() == "top") valign = Qt::AlignTop; else if(elemThis.tagName() == "vcenter") valign = Qt::AlignVCenter; else if(elemThis.tagName() == "bottom") valign = Qt::AlignBottom; else if(elemThis.tagName() == "rect") valid_rect = parseReportRect(elemThis, bgTarget.rect); else if(elemThis.tagName() == "opacity") { bool valid = false; int i = elemThis.text().toInt(&valid); if(valid) { if(i < 0) i = 0; if(i > 255) i = 255; bgTarget.opacity = i; } } else qDebug("While parsing background encountered an unknown element: %s",(const char*)elemThis.tagName()); } bgTarget.align = halign | valign; bgTarget.enabled = (valid_rect && ((bgTarget.staticImage && !bgTarget.image.isEmpty()) || (!bgTarget.staticImage && !bgTarget.data.query.isEmpty() && !bgTarget.data.column.isEmpty()))); return bgTarget.enabled; }
bool parseReportGraphData(const QDomElement & elemSource, ORGraphData & graphTarget) { if(elemSource.tagName() != "graph") return FALSE; bool have_data = FALSE; bool have_rect = FALSE; bool have_series = FALSE; graphTarget.title.string = QString::null; graphTarget.dataaxis.title.string = QString::null; graphTarget.dataaxis.title.font_defined = FALSE; graphTarget.dataaxis.column = QString::null; graphTarget.dataaxis.font_defined = FALSE; graphTarget.valueaxis.title.string = QString::null; graphTarget.valueaxis.min = 0; graphTarget.valueaxis.max = 100; graphTarget.valueaxis.autominmax = TRUE; graphTarget.valueaxis.font_defined = FALSE; graphTarget.series.setAutoDelete(TRUE); QDomNodeList nlist = elemSource.childNodes(); for(int nodeCounter = 0; nodeCounter < nlist.count(); nodeCounter++) { QDomElement elemThis = nlist.item(nodeCounter).toElement(); if(elemThis.tagName() == "data") have_data = parseReportData(elemThis, graphTarget.data); else if(elemThis.tagName() == "font") parseReportFont(elemThis, graphTarget.font); else if(elemThis.tagName() == "rect") have_rect = parseReportRect(elemThis, graphTarget.rect); else if(elemThis.tagName() == "title") parseReportTitleData(elemThis, graphTarget.title); else if(elemThis.tagName() == "dataaxis") { if(!parseReportDataAxisData(elemThis, graphTarget.dataaxis)) { graphTarget.dataaxis.title.string = QString::null; graphTarget.dataaxis.title.font_defined = FALSE; graphTarget.dataaxis.column = QString::null; graphTarget.dataaxis.font_defined = FALSE; } } else if(elemThis.tagName() == "valueaxis") { if(!parseReportValueAxisData(elemThis, graphTarget.valueaxis)) { graphTarget.valueaxis.title.string = QString::null; graphTarget.valueaxis.min = 0; graphTarget.valueaxis.max = 100; graphTarget.valueaxis.autominmax = TRUE; graphTarget.valueaxis.font_defined = FALSE; } } else if(elemThis.tagName() == "series") { ORSeriesData * orsd = new ORSeriesData(); if(parseReportSeriesData(elemThis, *orsd)) { graphTarget.series.append(orsd); have_series = TRUE; } else delete orsd; orsd = 0; } else qDebug("While parsing graph encountered an unknown element: %s",(const char*)elemThis.tagName()); } if(have_data && have_rect && have_series) return TRUE; return FALSE; }
bool parseReportSection(const QDomElement & elemSource, ORSectionData & sectionTarget) { sectionTarget.name = elemSource.tagName(); if(sectionTarget.name != "rpthead" && sectionTarget.name != "rptfoot" && sectionTarget.name != "pghead" && sectionTarget.name != "pgfoot" && sectionTarget.name != "grouphead" && sectionTarget.name != "groupfoot" && sectionTarget.name != "head" && sectionTarget.name != "foot" && sectionTarget.name != "detail" ) return false; sectionTarget.extra = QString::null; sectionTarget.height = -1; QDomNodeList section = elemSource.childNodes(); for(int nodeCounter = 0; nodeCounter < section.count(); nodeCounter++) { QDomElement elemThis = section.item(nodeCounter).toElement(); if(elemThis.tagName() == "height") { bool valid; int height = elemThis.text().toInt(&valid); if(valid) sectionTarget.height = height; } else if(elemThis.tagName() == "firstpage") { if(sectionTarget.name == "pghead" || sectionTarget.name == "pgfoot") sectionTarget.extra = elemThis.tagName(); } else if(elemThis.tagName() == "odd") { if(sectionTarget.name == "pghead" || sectionTarget.name == "pgfoot") sectionTarget.extra = elemThis.tagName(); } else if(elemThis.tagName() == "even") { if(sectionTarget.name == "pghead" || sectionTarget.name == "pgfoot") sectionTarget.extra = elemThis.tagName(); } else if(elemThis.tagName() == "lastpage") { if(sectionTarget.name == "pghead" || sectionTarget.name == "pgfoot") sectionTarget.extra = elemThis.tagName(); } else if(elemThis.tagName() == "label") { ORLabelData * label = new ORLabelData(); if(parseReportLabel(elemThis, *label) == TRUE) sectionTarget.objects.append(label); else delete label; } else if(elemThis.tagName() == "field") { ORFieldData * field = new ORFieldData(); if(parseReportField(elemThis, *field) == TRUE) { sectionTarget.objects.append(field); if(field->trackTotal) sectionTarget.trackTotal.append(field->data); } else delete field; } else if(elemThis.tagName() == "text") { ORTextData * text = new ORTextData(); if(parseReportText(elemThis, *text) == TRUE) sectionTarget.objects.append(text); else delete text; } else if(elemThis.tagName() == "line") { ORLineData * line = new ORLineData(); if(parseReportLine(elemThis, *line) == TRUE) sectionTarget.objects.append(line); else delete line; } else if(elemThis.tagName() == "rect") { ORRectData * rect = new ORRectData(); if(parseReportRect(elemThis, *rect) == TRUE) { sectionTarget.objects.append(rect); } else delete rect; } else if(elemThis.tagName() == "barcode") { ORBarcodeData * bc = new ORBarcodeData(); if(parseReportBarcode(elemThis, *bc) == TRUE) sectionTarget.objects.append(bc); else delete bc; } else if(elemThis.tagName() == "image") { ORImageData * img = new ORImageData(); if(parseReportImage(elemThis, *img) == TRUE) sectionTarget.objects.append(img); else delete img; } else if(elemThis.tagName() == "graph") { ORGraphData * graph = new ORGraphData(); if(parseReportGraphData(elemThis, *graph) == TRUE) sectionTarget.objects.append(graph); else delete graph; } else if(elemThis.tagName() == "key") { // we can ignore this as it will be handled elsewhere // we just catch this so we don't get an error } else qDebug("While parsing section encountered an unknown element: %s",(const char*)elemThis.tagName()); } return TRUE; }