summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakub Wieczorek <faw217@gmail.com>2010-05-26 09:50:57 (GMT)
committerOlivier Goffart <olivier.goffart@nokia.com>2010-05-26 10:00:47 (GMT)
commite0dc3b88abc9c4bcd6c3710c458c4948e5b8a912 (patch)
tree0bb9c59a9629decd81bf69652c9bd4497ba50e51
parent058fa44c7aba859c3383f912da4f976c896f921d (diff)
downloadQt-e0dc3b88abc9c4bcd6c3710c458c4948e5b8a912.zip
Qt-e0dc3b88abc9c4bcd6c3710c458c4948e5b8a912.tar.gz
Qt-e0dc3b88abc9c4bcd6c3710c458c4948e5b8a912.tar.bz2
QXmlStreamWriter: Auto-formatting does not behave properly with processing instructions.
When writing a processing instruction with auto-formatting enabled, it should put it in a new line for readability and apply the indentation properly. Merge-request: 620 Reviewed-by: Olivier Goffart <olivier.goffart@nokia.com>
-rw-r--r--src/corelib/xml/qxmlstream.cpp3
-rw-r--r--tests/auto/qxmlstream/tst_qxmlstream.cpp17
2 files changed, 19 insertions, 1 deletions
diff --git a/src/corelib/xml/qxmlstream.cpp b/src/corelib/xml/qxmlstream.cpp
index 1bf00b8..ae12007 100644
--- a/src/corelib/xml/qxmlstream.cpp
+++ b/src/corelib/xml/qxmlstream.cpp
@@ -3716,7 +3716,8 @@ void QXmlStreamWriter::writeProcessingInstruction(const QString &target, const Q
{
Q_D(QXmlStreamWriter);
Q_ASSERT(!data.contains(QLatin1String("?>")));
- d->finishStartElement();
+ if (!d->finishStartElement(false) && d->autoFormatting)
+ d->indent(d->tagStack.size());
d->write("<?");
d->write(target);
if (!data.isNull()) {
diff --git a/tests/auto/qxmlstream/tst_qxmlstream.cpp b/tests/auto/qxmlstream/tst_qxmlstream.cpp
index 3c5358c..f93d4fc 100644
--- a/tests/auto/qxmlstream/tst_qxmlstream.cpp
+++ b/tests/auto/qxmlstream/tst_qxmlstream.cpp
@@ -546,6 +546,7 @@ private slots:
void writerHangs() const;
void writerAutoFormattingWithComments() const;
void writerAutoFormattingWithTabs() const;
+ void writerAutoFormattingWithProcessingInstructions() const;
void writerAutoEmptyTags() const;
void writeAttributesWithSpace() const;
void addExtraNamespaceDeclarations();
@@ -1030,6 +1031,22 @@ void tst_QXmlStream::writerAutoFormattingWithTabs() const
QCOMPARE(buffer.buffer().data(), str);
}
+void tst_QXmlStream::writerAutoFormattingWithProcessingInstructions() const
+{
+ QBuffer buffer;
+ buffer.open(QIODevice::WriteOnly);
+
+ QXmlStreamWriter writer(&buffer);
+ writer.setAutoFormatting(true);
+ writer.writeStartDocument();
+ writer.writeProcessingInstruction("B", "C");
+ writer.writeStartElement("A");
+ writer.writeEndElement();
+ writer.writeEndDocument();
+ const char *str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<?B C?>\n<A/>\n";
+ QCOMPARE(buffer.buffer().data(), str);
+}
+
/*!
Task 204822
*/