Bugfixing of output formatter

This commit is contained in:
Jakub Melka 2020-09-26 17:40:59 +02:00
parent 4c763277fc
commit 13563a7bcc
1 changed files with 24 additions and 2 deletions

View File

@ -103,6 +103,7 @@ private:
QString m_prefix; QString m_prefix;
QXmlStreamWriter m_streamWriter; QXmlStreamWriter m_streamWriter;
int m_depth; int m_depth;
std::stack<PDFOutputFormatter::Element> m_elementStack;
}; };
class PDFHtmlOutputFormatterImpl : public PDFOutputFormatterImpl class PDFHtmlOutputFormatterImpl : public PDFOutputFormatterImpl
@ -126,6 +127,7 @@ private:
PDFTextOutputFormatterImpl::PDFTextOutputFormatterImpl() : PDFTextOutputFormatterImpl::PDFTextOutputFormatterImpl() :
m_string(), m_string(),
m_streamWriter(&m_string, QIODevice::WriteOnly), m_streamWriter(&m_string, QIODevice::WriteOnly),
m_indent(0),
m_elementStack() m_elementStack()
{ {
@ -143,6 +145,7 @@ void PDFTextOutputFormatterImpl::beginElement(PDFOutputFormatter::Element type,
case PDFOutputFormatter::Element::Text: case PDFOutputFormatter::Element::Text:
case PDFOutputFormatter::Element::Root: case PDFOutputFormatter::Element::Root:
{ {
writeIndent();
m_streamWriter << description << Qt::endl; m_streamWriter << description << Qt::endl;
m_indent += INDENT_STEP; m_indent += INDENT_STEP;
break; break;
@ -221,6 +224,9 @@ void PDFTextOutputFormatterImpl::endElement()
{ {
for (size_t column = 0; column < columns; ++column) for (size_t column = 0; column < columns; ++column)
{ {
m_streamWriter.setFieldWidth(0);
writeIndent();
const TableCell& tableCell = getTableCell(row, column); const TableCell& tableCell = getTableCell(row, column);
m_streamWriter.setFieldWidth(columnSize[column]); m_streamWriter.setFieldWidth(columnSize[column]);
@ -493,6 +499,8 @@ void PDFXmlOutputFormatterImpl::beginElement(PDFOutputFormatter::Element type, Q
{ {
Q_UNUSED(alignment); Q_UNUSED(alignment);
m_elementStack.push(type);
switch (type) switch (type)
{ {
case PDFOutputFormatter::Element::Root: case PDFOutputFormatter::Element::Root:
@ -539,10 +547,24 @@ void PDFXmlOutputFormatterImpl::beginElement(PDFOutputFormatter::Element type, Q
void PDFXmlOutputFormatterImpl::endElement() void PDFXmlOutputFormatterImpl::endElement()
{ {
m_streamWriter.writeEndElement(); PDFOutputFormatter::Element type = m_elementStack.top();
m_elementStack.pop();
--m_depth;
switch (type)
{
case PDFOutputFormatter::Element::Text:
case PDFOutputFormatter::Element::TableColumn:
case PDFOutputFormatter::Element::TableHeaderColumn:
break;
default:
m_streamWriter.writeEndElement();
break;
}
// Do we finish the document? If yes, then tell stream writer to end the document // Do we finish the document? If yes, then tell stream writer to end the document
if (--m_depth == 0) if (m_depth == 0)
{ {
m_streamWriter.writeEndDocument(); m_streamWriter.writeEndDocument();
} }