KD Reports  1.5
 All Classes Namespaces Functions Enumerations Enumerator Pages
Public Member Functions | List of all members
KDReports::XmlElementHandler Class Reference

#include <KDReportsXmlElementHandler.h>

Inheritance diagram for KDReports::XmlElementHandler:
Inheritance graph
[legend]

Public Member Functions

virtual bool startReport (KDReports::Report &report, QDomElement &xmlElement)
 
virtual bool startHeader (KDReports::Header &header, QDomElement &xmlElement)
 
virtual void endHeader (KDReports::Header &header, const QDomElement &xmlElement)
 
virtual bool startFooter (KDReports::Footer &footer, QDomElement &xmlElement)
 
virtual void endFooter (KDReports::Footer &footer, const QDomElement &xmlElement)
 
virtual bool textElement (KDReports::TextElement &textElement, QDomElement &xmlElement)
 
virtual bool htmlElement (KDReports::HtmlElement &htmlElement, QDomElement &xmlElement)
 
virtual bool startTableElement (KDReports::TableElement &tableElement, QDomElement &xmlElement)
 
virtual bool endTableElement (KDReports::TableElement &tableElement, QDomElement &xmlElement)
 
virtual bool startCell (KDReports::Cell &cell, QDomElement &xmlElement)
 
virtual bool endCell (KDReports::Cell &cell, QDomElement &xmlElement)
 
virtual bool autoTableElement (KDReports::AutoTableElement &tableElement, QDomElement &xmlElement)
 
virtual bool chartElement (KDReports::ChartElement &chartElement, QDomElement &xmlElement)
 
virtual bool imageElement (KDReports::ImageElement &imageElement, QDomElement &xmlElement)
 
virtual bool pageBreak (QDomElement &xmlElement)
 
virtual void customElement (const QDomElement &xmlElement)
 
virtual void endReport (KDReports::Report &report, const QDomElement &xmlElement)
 
KDReports::ErrorDetails errorDetails ()
 
void setErrorDetails (const KDReports::ErrorDetails &details)
 

Detailed Description

This handler is called for each XML element being parsed from an XML file. It allows you to customize the XML dynamically at runtime, by deriving from the XmlElementHandler interface and reimplementing some or all of the hooks. Each hook (virtual method) is called after the XML element has been parsed into a KDReports element, and before the KDReports element is added to the report. After that, both the XML element and the KDReports element are discarded, which is why this customization has to happen during loading.

Example: bool CustomElementHandler::textElement( KDReports::TextElement& textElement, const QDomElement& xmlElement ) { const QString id = xmlElement.attribute( "id" ); if ( id == "customerName" ) textElement.setTextColor( Qt::blue ); return true; }

All virtual methods return a boolean which can be used to skip an element: if the method returns false, the KDReports element will not be added to the report.

Note that you can even insert new elements into the report from any of the handler methods. Those additional elements will be inserted before the currently parsed element.

It is possible to signal an error, during parsing, by calling setErrorDetails. This will result in parsing being terminated, and the error being reported to the user.

To set up the handler so that it is used during parsing, use handler = new CustomElementHandler; report.setXmlElementHandler( handler );

Member Function Documentation

virtual bool KDReports::XmlElementHandler::autoTableElement ( KDReports::AutoTableElement tableElement,
QDomElement &  xmlElement 
)
virtual

Called after parsing a "table" element (when a model is set) and its attributes, but before parsing the cells in the table. Changes to those attributes must be done on tableElement.

As a special case, changes to the alignment for block elements must be done using xmlElement.setAttribute().

virtual bool KDReports::XmlElementHandler::chartElement ( KDReports::ChartElement chartElement,
QDomElement &  xmlElement 
)
virtual

Called after parsing "chart" and its attributes. Changes to those attributes must be done on chartElement.

As a special case, changes to the alignment for block elements must be done using xmlElement.setAttribute().

virtual void KDReports::XmlElementHandler::customElement ( const QDomElement &  xmlElement)
virtual

Called after parsing "custom", whose only purpose is to call this method. This allows you to define special places in the XML file where this method should be called, for instance to insert dynamic content into the report.

virtual bool KDReports::XmlElementHandler::endCell ( KDReports::Cell cell,
QDomElement &  xmlElement 
)
virtual

Called after parsing each "cell" element inside a table and its contents. Returning false makes the cell empty.

virtual void KDReports::XmlElementHandler::endFooter ( KDReports::Footer footer,
const QDomElement &  xmlElement 
)
virtual

Called after parsing "footer" and its contents.

virtual void KDReports::XmlElementHandler::endHeader ( KDReports::Header header,
const QDomElement &  xmlElement 
)
virtual

Called after parsing "header" and its contents.

virtual void KDReports::XmlElementHandler::endReport ( KDReports::Report report,
const QDomElement &  xmlElement 
)
virtual

Called at the end of the parsing of the whole report. The "report" element is passed again here.

virtual bool KDReports::XmlElementHandler::endTableElement ( KDReports::TableElement tableElement,
QDomElement &  xmlElement 
)
virtual

Called after parsing a "table" (without a model) and its cells. Returning false skips the whole table.

KDReports::ErrorDetails KDReports::XmlElementHandler::errorDetails ( )
Returns
an ErrorDetails instance.
virtual bool KDReports::XmlElementHandler::htmlElement ( KDReports::HtmlElement htmlElement,
QDomElement &  xmlElement 
)
virtual

Called after parsing "html", its attributes and the html content. Changes to those attributes must be done on htmlElement.

As a special case, changes to the alignment and paragraph-background for block elements must done using xmlElement.setAttribute(), since they are not properties of KDReports::HtmlElement.

virtual bool KDReports::XmlElementHandler::imageElement ( KDReports::ImageElement imageElement,
QDomElement &  xmlElement 
)
virtual

Called after parsing "image" and its attributes. Changes to those attributes must be done on imageElement.

As a special case, changes to the alignment for block elements must be done using xmlElement.setAttribute().

virtual bool KDReports::XmlElementHandler::pageBreak ( QDomElement &  xmlElement)
virtual

Called after parsing "page-break". Can be used to skip the page break depending on some condition.

void KDReports::XmlElementHandler::setErrorDetails ( const KDReports::ErrorDetails details)

When parsing the XML code, errors may be reported by setting an ErrorDetail using this method. Parsing will be stopped, and the error reported back to the user.

virtual bool KDReports::XmlElementHandler::startCell ( KDReports::Cell cell,
QDomElement &  xmlElement 
)
virtual

Called after parsing a "cell" element inside a table, but before parsing the cell contents. Returning false makes the cell empty.

virtual bool KDReports::XmlElementHandler::startFooter ( KDReports::Footer footer,
QDomElement &  xmlElement 
)
virtual

Called after parsing "footer" and its attributes, but before parsing its contents. Returning false skips this footer.

virtual bool KDReports::XmlElementHandler::startHeader ( KDReports::Header header,
QDomElement &  xmlElement 
)
virtual

Called after parsing "header" and its attributes, but before parsing its contents. Returning false skips this header.

virtual bool KDReports::XmlElementHandler::startReport ( KDReports::Report report,
QDomElement &  xmlElement 
)
virtual

Called after parsing "report" and its attributes. Returning false aborts the loading of the report.

virtual bool KDReports::XmlElementHandler::startTableElement ( KDReports::TableElement tableElement,
QDomElement &  xmlElement 
)
virtual

Called after parsing "table" (without a model) and its attributes, but before parsing the cells in the table. Changes to those attributes must be done on tableElement.

As a special case, changes to the alignment for block elements must be done using xmlElement.setAttribute(). Returning false skips the whole table.

virtual bool KDReports::XmlElementHandler::textElement ( KDReports::TextElement textElement,
QDomElement &  xmlElement 
)
virtual

Called after parsing "text", its attributes and the text content. Changes to those attributes must be done on textElement.

As a special case, changes to the alignment and paragraph-background for block elements must done using xmlElement.setAttribute(), since they are not properties of KDReports::TextElement.


The documentation for this class was generated from the following file:

Klarälvdalens Datakonsult AB (KDAB)
Qt-related services and products
http://www.kdab.com/
http://www.kdab.com/products/kd-reports/