when reading a table, do not assume there are only <table-row> elements as children of <table>; in case, read inside <table-header-rows>

svn path=/trunk/KDE/kdegraphics/okular/; revision=824835
remotes/origin/KDE/4.1
Pino Toscano 18 years ago
parent 5fc4a2cf2f
commit 3f2f754dab
  1. 47
      generators/ooo/converter.cpp

@ -9,6 +9,7 @@
#include "converter.h" #include "converter.h"
#include <QtCore/QQueue>
#include <QtCore/QUrl> #include <QtCore/QUrl>
#include <QtGui/QTextCursor> #include <QtGui/QTextCursor>
#include <QtGui/QTextDocument> #include <QtGui/QTextDocument>
@ -376,21 +377,32 @@ bool Converter::convertList( const QDomElement &element )
return true; return true;
} }
static void enqueueNodeList( QQueue<QDomNode> &queue, const QDomNodeList &list )
{
for ( int i = 0; i < list.count(); ++i ) {
queue.enqueue( list.at( i ) );
}
}
bool Converter::convertTable( const QDomElement &element ) bool Converter::convertTable( const QDomElement &element )
{ {
/** /**
* Find out dimension of the table * Find out dimension of the table
*/ */
QDomElement rowElement = element.firstChildElement();
int rowCounter = 0; int rowCounter = 0;
int columnCounter = 0; int columnCounter = 0;
while ( !rowElement.isNull() ) { QQueue<QDomNode> nodeQueue;
if ( rowElement.tagName() == QLatin1String( "table-row" ) ) { enqueueNodeList( nodeQueue, element.childNodes() );
while ( !nodeQueue.isEmpty() ) {
QDomElement el = nodeQueue.dequeue().toElement();
if ( el.isNull() )
continue;
if ( el.tagName() == QLatin1String( "table-row" ) ) {
rowCounter++; rowCounter++;
int counter = 0; int counter = 0;
QDomElement columnElement = rowElement.firstChildElement(); QDomElement columnElement = el.firstChildElement();
while ( !columnElement.isNull() ) { while ( !columnElement.isNull() ) {
if ( columnElement.tagName() == QLatin1String( "table-cell" ) ) { if ( columnElement.tagName() == QLatin1String( "table-cell" ) ) {
counter++; counter++;
@ -399,9 +411,9 @@ bool Converter::convertTable( const QDomElement &element )
} }
columnCounter = qMax( columnCounter, counter ); columnCounter = qMax( columnCounter, counter );
} else if ( el.tagName() == QLatin1String( "table-header-rows" ) ) {
enqueueNodeList( nodeQueue, el.childNodes() );
} }
rowElement = rowElement.nextSiblingElement();
} }
/** /**
@ -412,16 +424,21 @@ bool Converter::convertTable( const QDomElement &element )
/** /**
* Fill table * Fill table
*/ */
rowElement = element.firstChildElement(); nodeQueue.clear();
enqueueNodeList( nodeQueue, element.childNodes() );
QTextTableFormat tableFormat; QTextTableFormat tableFormat;
rowCounter = 0; rowCounter = 0;
while ( !rowElement.isNull() ) { while ( !nodeQueue.isEmpty() ) {
if ( rowElement.tagName() == QLatin1String( "table-row" ) ) { QDomElement el = nodeQueue.dequeue().toElement();
if ( el.isNull() )
continue;
if ( el.tagName() == QLatin1String( "table-row" ) ) {
int columnCounter = 0; int columnCounter = 0;
QDomElement columnElement = rowElement.firstChildElement(); QDomElement columnElement = el.firstChildElement();
while ( !columnElement.isNull() ) { while ( !columnElement.isNull() ) {
if ( columnElement.tagName() == QLatin1String( "table-cell" ) ) { if ( columnElement.tagName() == QLatin1String( "table-cell" ) ) {
const StyleFormatProperty property = mStyleInformation->styleProperty( columnElement.attribute( "style-name" ) ); const StyleFormatProperty property = mStyleInformation->styleProperty( columnElement.attribute( "style-name" ) );
@ -448,14 +465,10 @@ bool Converter::convertTable( const QDomElement &element )
} }
rowCounter++; rowCounter++;
} } else if ( el.tagName() == QLatin1String( "table-column" ) ) {
const StyleFormatProperty property = mStyleInformation->styleProperty( el.attribute( "style-name" ) );
if ( rowElement.tagName() == QLatin1String( "table-column" ) ) {
const StyleFormatProperty property = mStyleInformation->styleProperty( rowElement.attribute( "style-name" ) );
property.applyTableColumn( &tableFormat ); property.applyTableColumn( &tableFormat );
} }
rowElement = rowElement.nextSiblingElement();
} }
table->setFormat( tableFormat ); table->setFormat( tableFormat );

Loading…
Cancel
Save