34 #include <QDomDocument>
35 #include <QDomElement>
36 #include <QModelIndex>
55 m_cell.addElement(element, horizontalAlignment);
61 qWarning(
"Unexpected vspace inside cell!");
72 if (testForErrorAndFillErrorDetails())
75 const QString name = element.tagName();
77 const int row = element.attribute(QStringLiteral(
"row")).toInt();
78 const int column = element.attribute(QStringLiteral(
"column")).toInt();
79 const int rowSpan = element.attribute(QStringLiteral(
"rowspan"), QStringLiteral(
"1")).toInt();
80 const int colSpan = element.attribute(QStringLiteral(
"colspan"), QStringLiteral(
"1")).toInt();
88 cellReportBuilder.copyStateFrom(builder);
90 if (m_xmlElementHandler && !m_xmlElementHandler->
startCell(cell, element))
93 if (!processNode(element, &cellReportBuilder, inHeader, inFooter))
96 if (m_xmlElementHandler && !m_xmlElementHandler->
endCell(cell, element))
101 if (testForErrorAndFillErrorDetails())
128 if (element.
hasAttribute(QStringLiteral(
"pointsize"))) {
129 const int pointSize = element.
attribute(QStringLiteral(
"pointsize")).
toInt();
152 error(
QObject::tr(
"Expected \"<report>\" as the topmost element, but found \"<%1>\"").arg(docElement.
tagName()));
157 if (docElement.
hasAttribute(QStringLiteral(
"orientation"))) {
158 const QString orientation = docElement.
attribute(QStringLiteral(
"orientation"));
166 double marginTop = 20.0;
167 if (docElement.
hasAttribute(QStringLiteral(
"margin-top")))
169 double marginLeft = 20.0;
170 if (docElement.
hasAttribute(QStringLiteral(
"margin-left")))
172 double marginBottom = 20.0;
173 if (docElement.
hasAttribute(QStringLiteral(
"margin-bottom")))
175 double marginRight = 20.0;
176 if (docElement.
hasAttribute(QStringLiteral(
"margin-right")))
178 m_report->setMargins(marginTop, marginLeft, marginBottom, marginRight);
180 if (docElement.
hasAttribute(QStringLiteral(
"header-body-spacing")))
181 m_report->setHeaderBodySpacing(docElement.
attribute(QStringLiteral(
"header-body-spacing")).toDouble());
182 if (docElement.
hasAttribute(QStringLiteral(
"footer-body-spacing")))
183 m_report->setFooterBodySpacing(docElement.
attribute(QStringLiteral(
"footer-body-spacing")).toDouble());
188 m_report->setDefaultFont(font);
191 if (m_xmlElementHandler && !m_xmlElementHandler->startReport(*m_report, docElement)) {
193 *m_errorDetails = m_xmlElementHandler->errorDetails();
198 if (!processNode(docElement, builder,
false,
false))
201 if (m_xmlElementHandler)
202 m_xmlElementHandler->endReport(*m_report, docElement);
204 if (testForErrorAndFillErrorDetails())
213 error(
QObject::tr(
"<%1> is only supported in WordProcessing mode").arg(element.
tagName()));
231 if (testForErrorAndFillErrorDetails())
239 const QString text = extractText(element, &
id, m_report->d->m_currentModel, m_report->d->m_currentRow);
241 textElement.
setId(
id);
245 if (element.
hasAttribute(QStringLiteral(
"pointsize"))) {
246 const int pointSize = element.
attribute(QStringLiteral(
"pointsize")).
toInt();
269 if (element.
hasAttribute(QStringLiteral(
"strikeout"))) {
270 bool strikeOut =
false;
275 if (element.
hasAttribute(QStringLiteral(
"underline"))) {
276 bool underline =
false;
284 if (m_xmlElementHandler && !m_xmlElementHandler->textElement(textElement, element))
287 if (textElement.
id() != oldId) {
290 if (it != m_textValues.constEnd()) {
296 error(
QObject::tr(
"<text> is only supported in WordProcessing mode"));
313 const QString text = extractText(element, &
id);
315 htmlElement.
setId(
id);
322 if (m_xmlElementHandler && !m_xmlElementHandler->htmlElement(htmlElement, element))
325 if (htmlElement.
id() != oldId) {
328 if (it != m_textValues.constEnd()) {
333 addElement(htmlElement, builder, element);
338 error(
QObject::tr(
"<tabs> is only supported in WordProcessing mode"));
340 parseTabs(builder, element);
346 error(
QObject::tr(
"<paragraph-margins> is only supported in WordProcessing mode"));
348 parseParagraphMargins(builder, element);
354 htmlElement.
setHtml(QStringLiteral(
"<hr>"));
355 if (m_xmlElementHandler && !m_xmlElementHandler->htmlElement(htmlElement, element))
358 addElement(htmlElement, builder, element);
366 error(
QObject::tr(
"<vspace> is only supported in WordProcessing mode"));
368 if (builder != m_report->d->builder()) {
369 error(
QObject::tr(
"<vspace> not allowed in headers, footers, or table cells"));
373 if (m_xmlElementHandler && !m_xmlElementHandler->vspace(size, element))
375 m_report->addVerticalSpacing(size);
381 error(
QObject::tr(
"<table> without a model is only supported in WordProcessing mode"));
385 const int headerRowCount = element.
attribute(QStringLiteral(
"headerRowCount")).
toInt();
387 if (element.
hasAttribute(QStringLiteral(
"cellpadding")))
389 parseCommonTableAttributes(tableElement, element);
391 if (m_xmlElementHandler && !m_xmlElementHandler->startTableElement(tableElement, element))
394 if (!parseTableContents(tableElement, element, *builder, inHeader, inFooter))
397 if (m_xmlElementHandler && !m_xmlElementHandler->endTableElement(tableElement, element))
400 addElement(tableElement, builder, element);
405 tableElement.setVerticalHeaderVisible(
false);
407 tableElement.setHorizontalHeaderVisible(
false);
410 tableElement.setHeaderBackground(headerBgColor);
411 parseCommonTableAttributes(tableElement, element);
412 if (m_xmlElementHandler && !m_xmlElementHandler->autoTableElement(tableElement, element))
416 m_report->mainTable()->setAutoTableElement(tableElement);
418 addElement(tableElement, builder, element);
427 chartElement.setBackground(bgColor);
445 height = str.
toInt();
447 chartElement.setSize(width, height, unit);
449 if (m_xmlElementHandler && !m_xmlElementHandler->chartElement(chartElement, element))
452 addElement(chartElement, builder, element);
458 QImage image = extractImage(element, &
id);
460 imageElement.setId(
id);
467 imageElement.setWidth(widthStr.
toInt());
469 }
else if (element.
hasAttribute(QStringLiteral(
"height"))) {
475 imageElement.setHeight(heightStr.
toInt());
477 }
else if (element.
hasAttribute(QStringLiteral(
"fitToPage"))) {
478 imageElement.setFitToPage();
481 if (m_xmlElementHandler && !m_xmlElementHandler->imageElement(imageElement, element))
484 addElement(imageElement, builder, element);
490 if (m_xmlElementHandler && !m_xmlElementHandler->startHeader(header, element))
492 if (!processNode(element, &header.d->m_builder,
true,
false))
494 if (m_xmlElementHandler)
495 m_xmlElementHandler->endHeader(header, element);
500 if (m_xmlElementHandler && !m_xmlElementHandler->startFooter(footer, element))
502 if (!processNode(element, &footer.d->m_builder,
false,
true))
504 if (m_xmlElementHandler)
505 m_xmlElementHandler->endFooter(footer, element);
507 if (!inHeader && !inFooter) {
508 error(
QObject::tr(
"<variable> tags only allowed in headers and footers"));
512 error(
QObject::tr(
"<variable> tags must have a 'type' attribute"));
519 if (m_xmlElementHandler && !m_xmlElementHandler->variable(vt, element))
524 if (m_xmlElementHandler && !m_xmlElementHandler->pageBreak(element))
526 m_report->addPageBreak();
530 const bool skip = m_textValues.value(
id).
isEmpty();
532 if (!processNode(element, builder, inHeader, inFooter))
537 if (m_xmlElementHandler)
538 m_xmlElementHandler->customElement(element);
542 if (element.
hasAttribute(QStringLiteral(
"thickness"))) {
543 const double thickness = element.
attribute(QStringLiteral(
"thickness")).
toDouble();
553 const int margin = element.
attribute(QStringLiteral(
"margin")).
toInt();
557 if (m_xmlElementHandler && !m_xmlElementHandler->hLineElement(hLineElement, element))
560 addElement(hLineElement, builder, element);
562 error(
QObject::tr(
"KDReports::Report::loadFromXML(): Unknown element %1").arg(name));
566 if (testForErrorAndFillErrorDetails())
592 tab.delimiter = delimiter.
at(0);
605 if (!m_xmlElementHandler || m_xmlElementHandler->tabs(tabs, tabsElement))
615 if (!m_xmlElementHandler || m_xmlElementHandler->paragraphMargin(left, top, right, bottom, element))
625 if (it != m_imageValues.end()) {
633 if (!image.
load(fileName)) {
634 qWarning(
"Image not found or invalid: %s", qPrintable(fileName));
646 if (it != m_textValues.end()) {
649 }
else if (element.
hasAttribute(QStringLiteral(
"model"))) {
654 if (model == currentModel && currentRow > -1) {
659 const int column = element.
attribute(QStringLiteral(
"column")).
toInt();
665 return element.
text();
668 bool KDReports::XmlParser::testForErrorAndFillErrorDetails()
670 if (m_xmlElementHandler && m_xmlElementHandler->errorDetails().hasError()) {
672 *m_errorDetails = m_xmlElementHandler->errorDetails();
678 void KDReports::XmlParser::error(
const QString &errorString)
681 m_errorDetails->setDriverMessage(errorString);
683 qWarning(
"%s", qPrintable(errorString));