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 <QtCore/QQueue>
#include <QtCore/QUrl>
#include <QtGui/QTextCursor>
#include <QtGui/QTextDocument>
@ -376,21 +377,32 @@ bool Converter::convertList( const QDomElement &element )
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 )
{
/**
* Find out dimension of the table
*/
QDomElement rowElement = element.firstChildElement();
int rowCounter = 0;
int columnCounter = 0;
while ( !rowElement.isNull() ) {
if ( rowElement.tagName() == QLatin1String( "table-row" ) ) {
QQueue<QDomNode> nodeQueue;
enqueueNodeList( nodeQueue, element.childNodes() );
while ( !nodeQueue.isEmpty() ) {
QDomElement el = nodeQueue.dequeue().toElement();
if ( el.isNull() )
continue;
if ( el.tagName() == QLatin1String( "table-row" ) ) {
rowCounter++;
int counter = 0;
QDomElement columnElement = rowElement.firstChildElement();
QDomElement columnElement = el.firstChildElement();
while ( !columnElement.isNull() ) {
if ( columnElement.tagName() == QLatin1String( "table-cell" ) ) {
counter++;
@ -399,9 +411,9 @@ bool Converter::convertTable( const QDomElement &element )
}
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
*/
rowElement = element.firstChildElement();
nodeQueue.clear();
enqueueNodeList( nodeQueue, element.childNodes() );
QTextTableFormat tableFormat;
rowCounter = 0;
while ( !rowElement.isNull() ) {
if ( rowElement.tagName() == QLatin1String( "table-row" ) ) {
while ( !nodeQueue.isEmpty() ) {
QDomElement el = nodeQueue.dequeue().toElement();
if ( el.isNull() )
continue;
if ( el.tagName() == QLatin1String( "table-row" ) ) {
int columnCounter = 0;
QDomElement columnElement = rowElement.firstChildElement();
QDomElement columnElement = el.firstChildElement();
while ( !columnElement.isNull() ) {
if ( columnElement.tagName() == QLatin1String( "table-cell" ) ) {
const StyleFormatProperty property = mStyleInformation->styleProperty( columnElement.attribute( "style-name" ) );
@ -448,14 +465,10 @@ bool Converter::convertTable( const QDomElement &element )
}
rowCounter++;
}
if ( rowElement.tagName() == QLatin1String( "table-column" ) ) {
const StyleFormatProperty property = mStyleInformation->styleProperty( rowElement.attribute( "style-name" ) );
} else if ( el.tagName() == QLatin1String( "table-column" ) ) {
const StyleFormatProperty property = mStyleInformation->styleProperty( el.attribute( "style-name" ) );
property.applyTableColumn( &tableFormat );
}
rowElement = rowElement.nextSiblingElement();
}
table->setFormat( tableFormat );

Loading…
Cancel
Save