本文整理汇总了C++中QTextFragment::charFormatIndex方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextFragment::charFormatIndex方法的具体用法?C++ QTextFragment::charFormatIndex怎么用?C++ QTextFragment::charFormatIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextFragment
的用法示例。
在下文中一共展示了QTextFragment::charFormatIndex方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: writeBody
void OdtWriter::writeBody(const QTextDocument* document)
{
m_xml.writeStartElement(QString::fromLatin1("office:body"));
m_xml.writeStartElement(QString::fromLatin1("office:text"));
for (QTextBlock block = document->begin(); block.isValid(); block = block.next()) {
int heading = block.blockFormat().property(QTextFormat::UserProperty).toInt();
if (!heading) {
m_xml.writeStartElement(QString::fromLatin1("text:p"));
} else {
m_xml.writeStartElement(QString::fromLatin1("text:h"));
m_xml.writeAttribute(QString::fromLatin1("text:outline-level"), QString::number(heading));
}
m_xml.writeAttribute(QString::fromLatin1("text:style-name"), m_styles.value(block.blockFormatIndex()));
m_xml.setAutoFormatting(false);
for (QTextBlock::iterator iter = block.begin(); !(iter.atEnd()); ++iter) {
QTextFragment fragment = iter.fragment();
QString style = m_styles.value(fragment.charFormatIndex());
if (!style.isEmpty()) {
m_xml.writeStartElement(QString::fromLatin1("text:span"));
m_xml.writeAttribute(QString::fromLatin1("text:style-name"), style);
}
QString text = fragment.text();
int start = 0;
int spaces = -1;
for (int i = 0; i < text.length(); ++i) {
QChar c = text.at(i);
if (c.unicode() == 0x0009) {
m_xml.writeCharacters(text.mid(start, i - start));
m_xml.writeEmptyElement(QString::fromLatin1("text:tab"));
start = i + 1;
} else if (c.unicode() == 0x2028) {
m_xml.writeCharacters(text.mid(start, i - start));
m_xml.writeEmptyElement(QString::fromLatin1("text:line-break"));
start = i + 1;
} else if (c.unicode() == 0x0020) {
++spaces;
} else if (spaces > 0) {
m_xml.writeCharacters(text.mid(start, i - spaces - start));
m_xml.writeEmptyElement(QString::fromLatin1("text:s"));
m_xml.writeAttribute(QString::fromLatin1("text:c"), QString::number(spaces));
spaces = -1;
start = i;
} else {
spaces = -1;
}
}
if (spaces > 0) {
m_xml.writeCharacters(text.mid(start, text.length() - spaces - start));
m_xml.writeEmptyElement(QString::fromLatin1("text:s"));
m_xml.writeAttribute(QString::fromLatin1("text:c"), QString::number(spaces));
} else {
m_xml.writeCharacters(text.mid(start));
}
if (!style.isEmpty()) {
m_xml.writeEndElement();
}
}
m_xml.writeEndElement();
m_xml.setAutoFormatting(true);
}
m_xml.writeEndElement();
m_xml.writeEndElement();
}