[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: koffice/libs/kotext
From: Thomas Zander <zander () kde ! org>
Date: 2010-09-10 20:57:38
Message-ID: 20100910210204.A0574AC892 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1173916 by zander:
Make it possible to output debug to anywhere
Instead of using QDebug use QTextStream to dump the KoTextDebug to.
This allows the user to determine where his output goes.
M +46 -33 KoTextDebug.cpp
M +7 -6 KoTextDebug.h
M +7 -4 opendocument/tests/TestLoading.cpp
--- trunk/koffice/libs/kotext/KoTextDebug.cpp #1173915:1173916
@@ -27,7 +27,7 @@
#include <QTextTable>
#include <QTextFragment>
#include <QTextList>
-#include <QDebug>
+#include <QTextStream>
#include "styles/KoParagraphStyle.h"
#include "styles/KoCharacterStyle.h"
@@ -48,6 +48,9 @@
const int KoTextDebug::INDENT = 2;
const QTextDocument *KoTextDebug::document = 0;
+#define dumpIndent(T) { for (int i=0; i<T; ++i) out << ' '; }
+#define dumpList(T) { foreach (const QString &x, T) out << x << ' '; }
+
Q_DECLARE_METATYPE(QList<KoText::Tab>)
static QString fontProperties(const QTextCharFormat &textFormat)
@@ -98,13 +101,13 @@
return fontProps.join(",");
}
-void KoTextDebug::dumpDocument(const QTextDocument *doc)
+void KoTextDebug::dumpDocument(const QTextDocument *doc, QTextStream &out)
{
Q_ASSERT(doc);
document = doc;
- qDebug() << qPrintable(QString("<document defaultfont=\"%1\">").arg(doc->defaultFont().toString()));
- dumpFrame(document->rootFrame());
- qDebug() << "</document>";
+ out << QString("<document defaultfont=\"%1\">").arg(doc->defaultFont().toString());
+ dumpFrame(document->rootFrame(), out);
+ out << "</document>";
document = 0;
}
@@ -1139,13 +1142,12 @@
return attrs;
}
-void KoTextDebug::dumpFrame(const QTextFrame *frame)
+void KoTextDebug::dumpFrame(const QTextFrame *frame, QTextStream &out)
{
depth += INDENT;
- QString attrs;
- attrs.append(frameAttributes(frame->frameFormat()));
- qDebug("%*s<frame%s>", depth, " ", qPrintable(attrs));
+ dumpIndent(depth);
+ out << "<frame" << frameAttributes(frame->frameFormat()) << '>' << endl;
QTextFrame::iterator iterator = frame->begin();
@@ -1156,20 +1158,21 @@
if (childFrame) {
QTextTable *table = qobject_cast<QTextTable *>(childFrame);
if (table) {
- dumpTable(table);
+ dumpTable(table, out);
} else {
- dumpFrame(frame);
+ dumpFrame(frame, out);
}
} else if (textBlock.isValid()) {
- dumpBlock(textBlock);
+ dumpBlock(textBlock, out);
}
}
- qDebug("%*s%s", depth, " ", "</frame>");
+ dumpIndent(depth);
+ out << "</frame>" << endl;
depth -= INDENT;
}
-void KoTextDebug::dumpBlock(const QTextBlock &block)
+void KoTextDebug::dumpBlock(const QTextBlock &block, QTextStream &out)
{
depth += INDENT;
@@ -1186,43 +1189,47 @@
attrs.append(listAttributes(list->format()));
}
- qDebug("%*s<block%s>", depth, " ", qPrintable(attrs));
+ dumpIndent(depth);
+ out << "<block" << attrs << '>' << endl;
QTextBlock::Iterator iterator = block.begin();
for (; !iterator.atEnd() && !iterator.atEnd(); ++iterator) {
QTextFragment fragment = iterator.fragment();
if (fragment.isValid()) {
- dumpFragment(fragment);
+ dumpFragment(fragment, out);
}
}
- qDebug("%*s%s", depth, " ", "</block>");
+ dumpIndent(depth);
+ out << "</block>" << endl;
depth -= INDENT;
if (block.next().isValid())
- qDebug(" ");
+ out << ' ';
}
-void KoTextDebug::dumpTable(const QTextTable *table)
+void KoTextDebug::dumpTable(const QTextTable *table, QTextStream &out)
{
depth += INDENT;
QString attrs;
attrs.append(tableAttributes(table->format()));
- attrs.append(frameAttributes(table->frameFormat())); // include frame attribues too.
+ attrs.append(frameAttributes(table->frameFormat())); // include frame attributes too.
- qDebug("%*s<table%s>", depth, " ", qPrintable(attrs));
+ dumpIndent(depth);
+ out << "<table" << attrs << '>' << endl;
// loop through all the cells in the table and dump the cells.
for (int row = 0; row < table->rows(); ++row) {
for (int column = 0; column < table->columns(); ++column) {
- dumpTableCell(table->cellAt(row, column));
+ dumpTableCell(table->cellAt(row, column), out);
}
}
- qDebug("%*s%s", depth, " ", "</table>");
+ dumpIndent(depth);
+ out << "</table>" << endl;
depth -= INDENT;
}
-void KoTextDebug::dumpTableCell(const QTextTableCell &cell)
+void KoTextDebug::dumpTableCell(const QTextTableCell &cell, QTextStream &out)
{
depth += INDENT;
@@ -1230,27 +1237,29 @@
attrs.append(textAttributes(cell.format()));
attrs.append(tableCellAttributes(cell.format().toTableCellFormat()));
- qDebug("%*s<cell%s>", depth, " ", qPrintable(attrs));
+ dumpIndent(depth);
+ out << "<cell" << attrs << '>' << endl;
// iterate through the cell content.
QTextFrame::iterator cellIter = cell.begin();
while (!cellIter.atEnd()) {
if (cellIter.currentFrame() != 0) {
// content is a frame or table.
- dumpFrame(cellIter.currentFrame());
+ dumpFrame(cellIter.currentFrame(), out);
} else {
// content is a block.
- dumpBlock(cellIter.currentBlock());
+ dumpBlock(cellIter.currentBlock(), out);
}
++cellIter;
}
- qDebug("%*s%s", depth, " ", "</cell>");
+ dumpIndent(depth);
+ out << "</cell>\n";
depth -= INDENT;
}
-void KoTextDebug::dumpFragment(const QTextFragment &fragment)
+void KoTextDebug::dumpFragment(const QTextFragment &fragment, QTextStream &out)
{
depth += INDENT;
@@ -1260,13 +1269,17 @@
if (inlineObject) {
QString cf = inlineObjectAttributes(charFormat);
- qDebug("%*s<fragment%s/>", depth, " ", qPrintable(cf));
+ dumpIndent(depth);
+ out << "<fragment" << cf << ">\n";
} else {
QString cf = textAttributes(charFormat);
- qDebug("%*s<fragment%s>", depth, " ", qPrintable(cf));
- qDebug("%*s|%s|", depth + INDENT, " ", qPrintable(fragment.text()));
- qDebug("%*s%s", depth, " ", "</fragment>");
+ dumpIndent(depth);
+ out << "<fragment" << cf << ">\n";
+ dumpIndent(depth + INDENT);
+ out << '|' << fragment.text() << "|\n";
+ dumpIndent(depth);
+ out << "</fragment>\n";
}
depth -= INDENT;
--- trunk/koffice/libs/kotext/KoTextDebug.h #1173915:1173916
@@ -35,6 +35,7 @@
class QTextTableCellFormat;
class QTextFrameFormat;
class QTextBlockFormat;
+class QTextStream;
class KoParagraphStyle;
class KoCharacterStyle;
class KoTableStyle;
@@ -95,7 +96,7 @@
*
* @param document a pointer to the document that should be dumped.
*/
- static void dumpDocument(const QTextDocument *document);
+ static void dumpDocument(const QTextDocument *document, QTextStream &out);
/**
* Dump the structure of the specified frame.
@@ -104,14 +105,14 @@
*
* @param frame a pointer to the frame that should be dumped.
*/
- static void dumpFrame(const QTextFrame *frame);
+ static void dumpFrame(const QTextFrame *frame, QTextStream &out);
/**
* Dump the structure of the specified block.
*
* @param block the block that should be dumped.
*/
- static void dumpBlock(const QTextBlock &block);
+ static void dumpBlock(const QTextBlock &block, QTextStream &out);
/**
* Dump the structure of the specified table.
@@ -120,7 +121,7 @@
*
* @param a pointer to the table that should be dumped.
*/
- static void dumpTable(const QTextTable *table);
+ static void dumpTable(const QTextTable *table, QTextStream &out);
/**
* Dump the structure of the specified table cell.
@@ -129,7 +130,7 @@
*
* @param cell the cell that should be dumped.
*/
- static void dumpTableCell(const QTextTableCell &cell);
+ static void dumpTableCell(const QTextTableCell &cell, QTextStream &out);
/**
* Dump the contents of the specified text fragment.
@@ -138,7 +139,7 @@
*
* @param fragment the fragment which's content should be dumped.
*/
- static void dumpFragment(const QTextFragment &fragment);
+ static void dumpFragment(const QTextFragment &fragment, QTextStream &out);
/**
* Get the properties of the given text character format.
--- trunk/koffice/libs/kotext/opendocument/tests/TestLoading.cpp #1173915:1173916
@@ -22,6 +22,7 @@
#include <QtGui>
#include <KDebug>
+#include <QTextStream>
#include <QtScript>
#include <QtTest>
@@ -1150,10 +1151,11 @@
// showDocument(actualDocument);
// showDocument(expectedDocument);
if (!documentsEqual) {
+ QTextStream out(stdout);
qDebug() << "actual document: ======================";
- KoTextDebug::dumpDocument(actualDocument);
+ KoTextDebug::dumpDocument(actualDocument, out);
qDebug() << "expected document: ======================";
- KoTextDebug::dumpDocument(expectedDocument);
+ KoTextDebug::dumpDocument(expectedDocument, out);
}
delete actualDocument;
delete expectedDocument;
@@ -1184,8 +1186,9 @@
bool documentsEqual = compareDocuments(savedDocument, expectedDocument);
if (!documentsEqual) {
- KoTextDebug::dumpDocument(savedDocument);
- KoTextDebug::dumpDocument(expectedDocument);
+ QTextStream out(stdout);
+ KoTextDebug::dumpDocument(savedDocument, out);
+ KoTextDebug::dumpDocument(expectedDocument, out);
}
delete actualDocument;
delete expectedDocument;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic