QTextOdfWriter: Added support for hyperlinks.

Hyperlink added in QTextDocument becomes "<span>" tag after exporting
the document to ODF with QTextDocumentWriter. Fixed by adding "<a>" tag
around it with attribute "href" pointing to hyperlink location.

Task-number: QTBUG-48853
Change-Id: I2bd689a88c9d0a5b14369777718b9cb36e4cfa19
Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
This commit is contained in:
Ilija Ristevski 2015-10-28 18:24:55 +01:00 committed by Konstantin Ritt
parent aab21bce86
commit 6302fb07e7

View File

@ -279,6 +279,12 @@ void QTextOdfWriter::writeBlock(QXmlStreamWriter &writer, const QTextBlock &bloc
writer.writeAttribute(textNS, QString::fromLatin1("style-name"), QString::fromLatin1("p%1")
.arg(block.blockFormatIndex()));
for (QTextBlock::Iterator frag = block.begin(); !frag.atEnd(); ++frag) {
bool isHyperlink = frag.fragment().charFormat().hasProperty(QTextFormat::AnchorHref);
if (isHyperlink) {
QString value = frag.fragment().charFormat().property(QTextFormat::AnchorHref).toString();
writer.writeStartElement(textNS, QString::fromLatin1("a"));
writer.writeAttribute(xlinkNS, QString::fromLatin1("href"), value);
}
writer.writeCharacters(QString()); // Trick to make sure that the span gets no linefeed in front of it.
writer.writeStartElement(textNS, QString::fromLatin1("span"));
@ -335,6 +341,9 @@ void QTextOdfWriter::writeBlock(QXmlStreamWriter &writer, const QTextBlock &bloc
writer.writeCharacters(fragmentText.mid(exportedIndex));
writer.writeEndElement(); // span
writer.writeCharacters(QString()); // Trick to make sure that the span gets no linefeed behind it.
if (isHyperlink)
writer.writeEndElement(); // a
}
writer.writeCharacters(QString()); // Trick to make sure that the span gets no linefeed behind it.
writer.writeEndElement(); // p