Qt 4.8
Public Functions | Public Variables | Properties | List of all members
QTextOdfWriter Class Reference

#include <qtextodfwriter_p.h>

Public Functions

bool createArchive () const
 
 QTextOdfWriter (const QTextDocument &document, QIODevice *device)
 
void setCodec (QTextCodec *codec)
 
void setCreateArchive (bool on)
 
bool writeAll ()
 
void writeBlock (QXmlStreamWriter &writer, const QTextBlock &block)
 
void writeBlockFormat (QXmlStreamWriter &writer, QTextBlockFormat format, int formatIndex) const
 
void writeCharacterFormat (QXmlStreamWriter &writer, QTextCharFormat format, int formatIndex) const
 
void writeFormats (QXmlStreamWriter &writer, QSet< int > formatIds) const
 
void writeFrame (QXmlStreamWriter &writer, const QTextFrame *frame)
 
void writeFrameFormat (QXmlStreamWriter &writer, QTextFrameFormat format, int formatIndex) const
 
void writeInlineCharacter (QXmlStreamWriter &writer, const QTextFragment &fragment) const
 
void writeListFormat (QXmlStreamWriter &writer, QTextListFormat format, int formatIndex) const
 
void writeTableCellFormat (QXmlStreamWriter &writer, QTextTableCellFormat format, int formatIndex) const
 

Public Variables

const QString drawNS
 
const QString foNS
 
const QString officeNS
 
const QString styleNS
 
const QString svgNS
 
const QString tableNS
 
const QString textNS
 
const QString xlinkNS
 

Properties

QTextCodecm_codec
 
bool m_createArchive
 
QIODevicem_device
 
const QTextDocumentm_document
 
QStack< QTextList * > m_listStack
 
QOutputStrategym_strategy
 

Detailed Description

Definition at line 81 of file qtextodfwriter_p.h.

Constructors and Destructors

◆ QTextOdfWriter()

QTextOdfWriter::QTextOdfWriter ( const QTextDocument document,
QIODevice device 
)

Definition at line 744 of file qtextodfwriter.cpp.

745  : officeNS (QLatin1String("urn:oasis:names:tc:opendocument:xmlns:office:1.0")),
746  textNS (QLatin1String("urn:oasis:names:tc:opendocument:xmlns:text:1.0")),
747  styleNS (QLatin1String("urn:oasis:names:tc:opendocument:xmlns:style:1.0")),
748  foNS (QLatin1String("urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0")),
749  tableNS (QLatin1String("urn:oasis:names:tc:opendocument:xmlns:table:1.0")),
750  drawNS (QLatin1String("urn:oasis:names:tc:opendocument:xmlns:drawing:1.0")),
751  xlinkNS (QLatin1String("http://www.w3.org/1999/xlink")),
752  svgNS (QLatin1String("urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0")),
753  m_document(&document),
754  m_device(device),
755  m_strategy(0),
756  m_codec(0),
757  m_createArchive(true)
758 {
759 }
QIODevice * m_device
const QString xlinkNS
const QString svgNS
const QString officeNS
const QTextDocument * m_document
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QTextCodec * m_codec
const QString foNS
const QString textNS
const QString tableNS
const QString drawNS
QOutputStrategy * m_strategy
const QString styleNS

Functions

◆ createArchive()

bool QTextOdfWriter::createArchive ( ) const
inline

Definition at line 88 of file qtextodfwriter_p.h.

88 { return m_createArchive; }

◆ setCodec()

void QTextOdfWriter::setCodec ( QTextCodec codec)
inline

Definition at line 86 of file qtextodfwriter_p.h.

Referenced by QTextDocumentWriter::write().

86 { m_codec = codec; }
QTextCodec * m_codec
static QTextCodec * codec(MYSQL *mysql)
Definition: qsql_mysql.cpp:220

◆ setCreateArchive()

void QTextOdfWriter::setCreateArchive ( bool  on)
inline

Definition at line 87 of file qtextodfwriter_p.h.

87 { m_createArchive = on; }

◆ writeAll()

bool QTextOdfWriter::writeAll ( )

Definition at line 761 of file qtextodfwriter.cpp.

Referenced by QTextDocumentWriter::write().

762 {
763  if (m_createArchive)
765  else
767 
769  qWarning() << "QTextOdfWriter::writeAll: the device can not be opened for writing";
770  return false;
771  }
773 #ifndef QT_NO_TEXTCODEC
774  if (m_codec)
775  writer.setCodec(m_codec);
776 #endif
777  // prettyfy
778  writer.setAutoFormatting(true);
779  writer.setAutoFormattingIndent(2);
780 
781  writer.writeNamespace(officeNS, QString::fromLatin1("office"));
782  writer.writeNamespace(textNS, QString::fromLatin1("text"));
783  writer.writeNamespace(styleNS, QString::fromLatin1("style"));
784  writer.writeNamespace(foNS, QString::fromLatin1("fo"));
785  writer.writeNamespace(tableNS, QString::fromLatin1("table"));
786  writer.writeNamespace(drawNS, QString::fromLatin1("draw"));
787  writer.writeNamespace(xlinkNS, QString::fromLatin1("xlink"));
788  writer.writeNamespace(svgNS, QString::fromLatin1("svg"));
789  writer.writeStartDocument();
790  writer.writeStartElement(officeNS, QString::fromLatin1("document-content"));
791  writer.writeAttribute(officeNS, QString::fromLatin1("version"), QString::fromLatin1("1.2"));
792 
793  // add fragments. (for character formats)
795  QSet<int> formats;
796  while (fragIt != m_document->docHandle()->end()) {
797  const QTextFragmentData * const frag = fragIt.value();
798  formats << frag->format;
799  ++fragIt;
800  }
801 
802  // add blocks (for blockFormats)
805  while (blockIt != blocks.end()) {
806  const QTextBlockData * const block = blockIt.value();
807  formats << block->format;
808  ++blockIt;
809  }
810 
811  // add objects for lists, frames and tables
813  QList<int> copy = formats.toList();
814  for (QList<int>::Iterator iter = copy.begin(); iter != copy.end(); ++iter) {
815  QTextObject *object = m_document->objectForFormat(allFormats[*iter]);
816  if (object)
817  formats << object->formatIndex();
818  }
819 
820  writeFormats(writer, formats);
821 
822  writer.writeStartElement(officeNS, QString::fromLatin1("body"));
823  writer.writeStartElement(officeNS, QString::fromLatin1("text"));
824  QTextFrame *rootFrame = m_document->rootFrame();
825  writeFrame(writer, rootFrame);
826  writer.writeEndElement(); // text
827  writer.writeEndElement(); // body
828  writer.writeEndElement(); // document-content
829  writer.writeEndDocument();
830  delete m_strategy;
831  m_strategy = 0;
832 
833  return true;
834 }
The QXmlStreamWriter class provides an XML writer with a simple streaming API.
Definition: qxmlstream.h:416
QIODevice * m_device
const QString xlinkNS
QIODevice * contentStream
const QString svgNS
FragmentIterator end() const
bool isWritable() const
Returns true if data can be written to the device; otherwise returns false.
Definition: qiodevice.cpp:558
The QTextFrame class represents a frame in a QTextDocument.
Definition: qtextobject.h:122
Iterator begin()
const QString officeNS
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
const QTextDocument * m_document
QTextObject * objectForFormat(const QTextFormat &) const
Returns the text object associated with the format f.
FragmentMap::ConstIterator FragmentIterator
QTextFrame * rootFrame() const
Returns the document&#39;s root frame.
QTextCodec * m_codec
QList< T > toList() const
Definition: qset.h:296
QTextDocumentPrivate * docHandle() const
So that not all classes have to be friends of each other.
Iterator end()
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
const QString foNS
const QString textNS
Q_CORE_EXPORT void qWarning(const char *,...)
const BlockMap & blockMap() const
const QString tableNS
QVector< QTextFormat > allFormats() const
Returns a vector of text formats for all the formats used in the document.
const QString drawNS
void writeFormats(QXmlStreamWriter &writer, QSet< int > formatIds) const
void writeFrame(QXmlStreamWriter &writer, const QTextFrame *frame)
FragmentIterator begin() const
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
virtual bool open(OpenMode mode)
Opens the device and sets its OpenMode to mode.
Definition: qiodevice.cpp:570
QOutputStrategy * m_strategy
const QString styleNS
The QTextObject class is a base class for different kinds of objects that can group parts of a QTextD...
Definition: qtextobject.h:64

◆ writeBlock()

void QTextOdfWriter::writeBlock ( QXmlStreamWriter writer,
const QTextBlock block 
)

Definition at line 241 of file qtextodfwriter.cpp.

242 {
243  if (block.textList()) { // its a list-item
244  const int listLevel = block.textList()->format().indent();
245  if (m_listStack.isEmpty() || m_listStack.top() != block.textList()) {
246  // not the same list we were in.
247  while (m_listStack.count() >= listLevel && !m_listStack.isEmpty() && m_listStack.top() != block.textList() ) { // we need to close tags
248  m_listStack.pop();
249  writer.writeEndElement(); // list
250  if (m_listStack.count())
251  writer.writeEndElement(); // list-item
252  }
253  while (m_listStack.count() < listLevel) {
254  if (m_listStack.count())
255  writer.writeStartElement(textNS, QString::fromLatin1("list-item"));
257  if (m_listStack.count() == listLevel - 1) {
258  m_listStack.push(block.textList());
259  writer.writeAttribute(textNS, QString::fromLatin1("style-name"), QString::fromLatin1("L%1")
260  .arg(block.textList()->formatIndex()));
261  }
262  else {
263  m_listStack.push(0);
264  }
265  }
266  }
267  writer.writeStartElement(textNS, QString::fromLatin1("list-item"));
268  }
269  else {
270  while (! m_listStack.isEmpty()) {
271  m_listStack.pop();
272  writer.writeEndElement(); // list
273  if (m_listStack.count())
274  writer.writeEndElement(); // list-item
275  }
276  }
277 
278  if (block.length() == 1) { // only a linefeed
280  writer.writeAttribute(textNS, QString::fromLatin1("style-name"), QString::fromLatin1("p%1")
281  .arg(block.blockFormatIndex()));
282  if (block.textList())
283  writer.writeEndElement(); // numbered-paragraph
284  return;
285  }
287  writer.writeAttribute(textNS, QString::fromLatin1("style-name"), QString::fromLatin1("p%1")
288  .arg(block.blockFormatIndex()));
289  for (QTextBlock::Iterator frag= block.begin(); !frag.atEnd(); frag++) {
290  writer.writeCharacters(QString()); // Trick to make sure that the span gets no linefeed in front of it.
292 
293  QString fragmentText = frag.fragment().text();
294  if (fragmentText.length() == 1 && fragmentText[0] == 0xFFFC) { // its an inline character.
295  writeInlineCharacter(writer, frag.fragment());
296  writer.writeEndElement(); // span
297  continue;
298  }
299 
300  writer.writeAttribute(textNS, QString::fromLatin1("style-name"), QString::fromLatin1("c%1")
301  .arg(frag.fragment().charFormatIndex()));
302  bool escapeNextSpace = true;
303  int precedingSpaces = 0;
304  int exportedIndex = 0;
305  for (int i=0; i <= fragmentText.count(); ++i) {
306  bool isSpace = false;
307  QChar character = fragmentText[i];
308  isSpace = character.unicode() == ' ';
309 
310  // find more than one space. -> <text:s text:c="2" />
311  if (!isSpace && escapeNextSpace && precedingSpaces > 1) {
312  const bool startParag = exportedIndex == 0 && i == precedingSpaces;
313  if (!startParag)
314  writer.writeCharacters(fragmentText.mid(exportedIndex, i - precedingSpaces + 1 - exportedIndex));
316  const int count = precedingSpaces - (startParag?0:1);
317  if (count > 1)
319  precedingSpaces = 0;
320  exportedIndex = i;
321  }
322 
323  if (i < fragmentText.count()) {
324  if (character.unicode() == 0x2028) { // soft-return
325  //if (exportedIndex < i)
326  writer.writeCharacters(fragmentText.mid(exportedIndex, i - exportedIndex));
327  writer.writeEmptyElement(textNS, QString::fromLatin1("line-break"));
328  exportedIndex = i+1;
329  continue;
330  } else if (character.unicode() == '\t') { // Tab
331  //if (exportedIndex < i)
332  writer.writeCharacters(fragmentText.mid(exportedIndex, i - exportedIndex));
334  exportedIndex = i+1;
335  precedingSpaces = 0;
336  } else if (isSpace) {
337  ++precedingSpaces;
338  escapeNextSpace = true;
339  } else if (!isSpace) {
340  precedingSpaces = 0;
341  }
342  }
343  }
344 
345  writer.writeCharacters(fragmentText.mid(exportedIndex));
346  writer.writeEndElement(); // span
347  }
348  writer.writeCharacters(QString()); // Trick to make sure that the span gets no linefeed behind it.
349  writer.writeEndElement(); // p
350  if (block.textList())
351  writer.writeEndElement(); // list-item
352 }
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
int formatIndex() const
Returns the index of the object&#39;s format in the document&#39;s internal list of formats.
int blockFormatIndex() const
Returns an index into the document&#39;s internal list of block formats for the text block&#39;s format...
QTextList * textList() const
If the block represents a list item, returns the list that the item belongs to; otherwise returns 0...
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
bool atEnd() const
Returns true if the current item is the last item in the text block.
Definition: qtextobject.h:264
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
iterator begin() const
Returns a text block iterator pointing to the beginning of the text block.
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
T pop()
Removes the top item from the stack and returns it.
Definition: qstack.h:67
void writeAttribute(const QString &qualifiedName, const QString &value)
Writes an attribute with qualifiedName and value.
const QString textNS
int length() const
Returns the length of the block in characters.
void push(const T &t)
Adds element t to the top of the stack.
Definition: qstack.h:60
void writeCharacters(const QString &text)
Writes text.
int count() const
Definition: qstring.h:103
The QTextBlock::iterator class provides an iterator for reading the contents of a QTextBlock...
Definition: qtextobject.h:251
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
void writeEndElement()
Closes the previous start element.
QStack< QTextList * > m_listStack
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
void writeEmptyElement(const QString &qualifiedName)
Writes an empty element with qualified name qualifiedName.
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
void writeInlineCharacter(QXmlStreamWriter &writer, const QTextFragment &fragment) const
int indent() const
Returns the list format&#39;s indentation.
Definition: qtextformat.h:666
void writeStartElement(const QString &qualifiedName)
This is an overloaded member function, provided for convenience. It differs from the above function o...
T & top()
Returns a reference to the stack&#39;s top item.
Definition: qstack.h:72
QTextListFormat format() const
Returns the list&#39;s format.
Definition: qtextlist.h:80

◆ writeBlockFormat()

void QTextOdfWriter::writeBlockFormat ( QXmlStreamWriter writer,
QTextBlockFormat  format,
int  formatIndex 
) const

Definition at line 443 of file qtextodfwriter.cpp.

444 {
446  writer.writeAttribute(styleNS, QString::fromLatin1("name"), QString::fromLatin1("p%1").arg(formatIndex));
447  writer.writeAttribute(styleNS, QString::fromLatin1("family"), QString::fromLatin1("paragraph"));
448  writer.writeStartElement(styleNS, QString::fromLatin1("paragraph-properties"));
449 
451  const Qt::Alignment alignment = format.alignment() & Qt::AlignHorizontal_Mask;
452  QString value;
453  if (alignment == Qt::AlignLeading)
454  value = QString::fromLatin1("start");
455  else if (alignment == Qt::AlignTrailing)
456  value = QString::fromLatin1("end");
457  else if (alignment == (Qt::AlignLeft | Qt::AlignAbsolute))
458  value = QString::fromLatin1("left");
459  else if (alignment == (Qt::AlignRight | Qt::AlignAbsolute))
460  value = QString::fromLatin1("right");
461  else if (alignment == Qt::AlignHCenter)
462  value = QString::fromLatin1("center");
463  else if (alignment == Qt::AlignJustify)
464  value = QString::fromLatin1("justify");
465  else
466  qWarning() << "QTextOdfWriter: unsupported paragraph alignment; " << format.alignment();
467  if (! value.isNull())
468  writer.writeAttribute(foNS, QString::fromLatin1("text-align"), value);
469  }
470 
472  writer.writeAttribute(foNS, QString::fromLatin1("margin-top"), pixelToPoint(qMax(qreal(0.), format.topMargin())) );
474  writer.writeAttribute(foNS, QString::fromLatin1("margin-bottom"), pixelToPoint(qMax(qreal(0.), format.bottomMargin())) );
476  writer.writeAttribute(foNS, QString::fromLatin1("margin-left"), pixelToPoint(qMax(qreal(0.),
477  format.leftMargin() + format.indent())));
479  writer.writeAttribute(foNS, QString::fromLatin1("margin-right"), pixelToPoint(qMax(qreal(0.), format.rightMargin())) );
481  writer.writeAttribute(foNS, QString::fromLatin1("text-indent"), pixelToPoint(format.textIndent()));
484  writer.writeAttribute(foNS, QString::fromLatin1("break-before"), QString::fromLatin1("page"));
486  writer.writeAttribute(foNS, QString::fromLatin1("break-after"), QString::fromLatin1("page"));
487  }
489  QBrush brush = format.background();
490  writer.writeAttribute(foNS, QString::fromLatin1("background-color"), brush.color().name());
491  }
493  writer.writeAttribute(foNS, QString::fromLatin1("keep-together"),
494  format.nonBreakableLines() ? QString::fromLatin1("true") : QString::fromLatin1("false"));
496  QList<QTextOption::Tab> tabs = format.tabPositions();
497  writer.writeStartElement(styleNS, QString::fromLatin1("tab-stops"));
498  QList<QTextOption::Tab>::Iterator iterator = tabs.begin();
499  while(iterator != tabs.end()) {
500  writer.writeEmptyElement(styleNS, QString::fromLatin1("tab-stop"));
501  writer.writeAttribute(styleNS, QString::fromLatin1("position"), pixelToPoint(iterator->position) );
502  QString type;
503  switch(iterator->type) {
504  case QTextOption::DelimiterTab: type = QString::fromLatin1("char"); break;
505  case QTextOption::LeftTab: type = QString::fromLatin1("left"); break;
506  case QTextOption::RightTab: type = QString::fromLatin1("right"); break;
507  case QTextOption::CenterTab: type = QString::fromLatin1("center"); break;
508  }
509  writer.writeAttribute(styleNS, QString::fromLatin1("type"), type);
510  if (iterator->delimiter != 0)
511  writer.writeAttribute(styleNS, QString::fromLatin1("char"), iterator->delimiter);
512  ++iterator;
513  }
514 
515  writer.writeEndElement(); // tab-stops
516  }
517 
518  writer.writeEndElement(); // paragraph-properties
519  writer.writeEndElement(); // style
520 }
int type
Definition: qmetatype.cpp:239
double qreal
Definition: qglobal.h:1193
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
PageBreakFlags pageBreakPolicy() const
Returns the currently set page break policy for the paragraph.
Definition: qtextformat.h:608
static QString pixelToPoint(qreal pixels)
Convert pixels to postscript point units.
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
The QString class provides a Unicode character string.
Definition: qstring.h:83
qreal topMargin() const
Returns the paragraph&#39;s top margin.
Definition: qtextformat.h:566
int indent() const
Returns the paragraph&#39;s indent.
Definition: qtextformat.h:590
qreal rightMargin() const
Returns the paragraph&#39;s right margin.
Definition: qtextformat.h:581
Qt::Alignment alignment() const
Returns the paragraph&#39;s alignment.
Definition: qtextformat.h:561
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
bool hasProperty(int propertyId) const
Returns true if the text format has a property with the given propertyId; otherwise returns false...
void writeAttribute(const QString &qualifiedName, const QString &value)
Writes an attribute with qualifiedName and value.
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
const QString foNS
QList< QTextOption::Tab > tabPositions() const
Returns a list of tab positions defined for the text block.
Q_CORE_EXPORT void qWarning(const char *,...)
QBrush background() const
Returns the brush used to paint the document&#39;s background.
Definition: qtextformat.h:345
qreal textIndent() const
Returns the paragraph&#39;s text indent.
Definition: qtextformat.h:586
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
bool nonBreakableLines() const
Returns true if the lines in the paragraph are non-breakable; otherwise returns false.
Definition: qtextformat.h:603
void writeEndElement()
Closes the previous start element.
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
qreal bottomMargin() const
Returns the paragraph&#39;s bottom margin.
Definition: qtextformat.h:571
void writeEmptyElement(const QString &qualifiedName)
Writes an empty element with qualified name qualifiedName.
const QString styleNS
qreal leftMargin() const
Returns the paragraph&#39;s left margin.
Definition: qtextformat.h:576
QString name() const
Returns the name of the color in the format "#RRGGBB"; i.e.
Definition: qcolor.cpp:529
void writeStartElement(const QString &qualifiedName)
This is an overloaded member function, provided for convenience. It differs from the above function o...

◆ writeCharacterFormat()

void QTextOdfWriter::writeCharacterFormat ( QXmlStreamWriter writer,
QTextCharFormat  format,
int  formatIndex 
) const

Definition at line 522 of file qtextodfwriter.cpp.

523 {
525  writer.writeAttribute(styleNS, QString::fromLatin1("name"), QString::fromLatin1("c%1").arg(formatIndex));
527  writer.writeEmptyElement(styleNS, QString::fromLatin1("text-properties"));
528  if (format.fontItalic())
529  writer.writeAttribute(foNS, QString::fromLatin1("font-style"), QString::fromLatin1("italic"));
530  if (format.hasProperty(QTextFormat::FontWeight) && format.fontWeight() != QFont::Normal) {
531  QString value;
532  if (format.fontWeight() == QFont::Bold)
533  value = QString::fromLatin1("bold");
534  else
535  value = QString::number(format.fontWeight() * 10);
536  writer.writeAttribute(foNS, QString::fromLatin1("font-weight"), value);
537  }
539  writer.writeAttribute(foNS, QString::fromLatin1("font-family"), format.fontFamily());
540  else
541  writer.writeAttribute(foNS, QString::fromLatin1("font-family"), QString::fromLatin1("Sans")); // Qt default
543  writer.writeAttribute(foNS, QString::fromLatin1("font-size"), QString::fromLatin1("%1pt").arg(format.fontPointSize()));
545  switch(format.fontCapitalization()) {
546  case QFont::MixedCase:
547  writer.writeAttribute(foNS, QString::fromLatin1("text-transform"), QString::fromLatin1("none")); break;
548  case QFont::AllUppercase:
549  writer.writeAttribute(foNS, QString::fromLatin1("text-transform"), QString::fromLatin1("uppercase")); break;
550  case QFont::AllLowercase:
551  writer.writeAttribute(foNS, QString::fromLatin1("text-transform"), QString::fromLatin1("lowercase")); break;
552  case QFont::Capitalize:
553  writer.writeAttribute(foNS, QString::fromLatin1("text-transform"), QString::fromLatin1("capitalize")); break;
554  case QFont::SmallCaps:
555  writer.writeAttribute(foNS, QString::fromLatin1("font-variant"), QString::fromLatin1("small-caps")); break;
556  }
557  }
559  writer.writeAttribute(foNS, QString::fromLatin1("letter-spacing"), pixelToPoint(format.fontLetterSpacing()));
560  if (format.hasProperty(QTextFormat::FontWordSpacing) && format.fontWordSpacing() != 0)
561  writer.writeAttribute(foNS, QString::fromLatin1("word-spacing"), pixelToPoint(format.fontWordSpacing()));
563  writer.writeAttribute(styleNS, QString::fromLatin1("text-underline-type"),
564  format.fontUnderline() ? QString::fromLatin1("single") : QString::fromLatin1("none"));
566  // bool fontOverline () const TODO
567  }
569  writer.writeAttribute(styleNS,QString::fromLatin1( "text-line-through-type"),
570  format.fontStrikeOut() ? QString::fromLatin1("single") : QString::fromLatin1("none"));
572  writer.writeAttribute(styleNS, QString::fromLatin1("text-underline-color"), format.underlineColor().name());
574  // bool fontFixedPitch () const TODO
575  }
577  QString value;
578  switch (format.underlineStyle()) {
579  case QTextCharFormat::NoUnderline: value = QString::fromLatin1("none"); break;
580  case QTextCharFormat::SingleUnderline: value = QString::fromLatin1("solid"); break;
581  case QTextCharFormat::DashUnderline: value = QString::fromLatin1("dash"); break;
582  case QTextCharFormat::DotLine: value = QString::fromLatin1("dotted"); break;
583  case QTextCharFormat::DashDotLine: value = QString::fromLatin1("dash-dot"); break;
584  case QTextCharFormat::DashDotDotLine: value = QString::fromLatin1("dot-dot-dash"); break;
585  case QTextCharFormat::WaveUnderline: value = QString::fromLatin1("wave"); break;
586  case QTextCharFormat::SpellCheckUnderline: value = QString::fromLatin1("none"); break;
587  }
588  writer.writeAttribute(styleNS, QString::fromLatin1("text-underline-style"), value);
589  }
591  QString value;
592  switch (format.verticalAlignment()) {
595  case QTextCharFormat::AlignNormal: value = QString::fromLatin1("0%"); break;
596  case QTextCharFormat::AlignSuperScript: value = QString::fromLatin1("super"); break;
597  case QTextCharFormat::AlignSubScript: value = QString::fromLatin1("sub"); break;
598  case QTextCharFormat::AlignTop: value = QString::fromLatin1("100%"); break;
599  case QTextCharFormat::AlignBottom : value = QString::fromLatin1("-100%"); break;
600  }
601  writer.writeAttribute(styleNS, QString::fromLatin1("text-position"), value);
602  }
604  writer.writeAttribute(styleNS, QString::fromLatin1("text-outline"), QString::fromLatin1("true"));
606  // QString toolTip () const TODO
607  }
608  if (format.hasProperty(QTextFormat::IsAnchor)) {
609  // bool isAnchor () const TODO
610  }
611  if (format.hasProperty(QTextFormat::AnchorHref)) {
612  // QString anchorHref () const TODO
613  }
614  if (format.hasProperty(QTextFormat::AnchorName)) {
615  // QString anchorName () const TODO
616  }
618  QBrush brush = format.foreground();
619  writer.writeAttribute(foNS, QString::fromLatin1("color"), brush.color().name());
620  }
622  QBrush brush = format.background();
623  writer.writeAttribute(foNS, QString::fromLatin1("background-color"), brush.color().name());
624  }
625 
626  writer.writeEndElement(); // style
627 }
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
bool fontStrikeOut() const
Returns true if the text format&#39;s font is struck out (has a horizontal line drawn through it); otherw...
Definition: qtextformat.h:443
QColor underlineColor() const
Returns the color used to underline the characters with this format.
Definition: qtextformat.h:448
static QString pixelToPoint(qreal pixels)
Convert pixels to postscript point units.
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool hasProperty(int propertyId) const
Returns true if the text format has a property with the given propertyId; otherwise returns false...
UnderlineStyle underlineStyle() const
Returns the style of underlining the text.
Definition: qtextformat.h:481
void writeAttribute(const QString &qualifiedName, const QString &value)
Writes an attribute with qualifiedName and value.
const QString foNS
int fontWeight() const
Returns the text format&#39;s font weight.
Definition: qtextformat.h:413
QBrush background() const
Returns the brush used to paint the document&#39;s background.
Definition: qtextformat.h:345
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
VerticalAlignment verticalAlignment() const
Returns the vertical alignment used for characters with this format.
Definition: qtextformat.h:486
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
void writeEndElement()
Closes the previous start element.
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
qreal fontWordSpacing() const
Returns the current word spacing value.
Definition: qtextformat.h:429
QBrush foreground() const
Returns the brush used to render foreground details, such as text, frame outlines, and table borders.
Definition: qtextformat.h:352
void writeEmptyElement(const QString &qualifiedName)
Writes an empty element with qualified name qualifiedName.
const QString styleNS
qreal fontPointSize() const
Returns the font size used to display text in this format.
Definition: qtextformat.h:408
qreal fontLetterSpacing() const
Returns the current letter spacing percentage.
Definition: qtextformat.h:425
bool fontItalic() const
Returns true if the text format&#39;s font is italic; otherwise returns false.
Definition: qtextformat.h:417
QString fontFamily() const
Returns the text format&#39;s font family.
Definition: qtextformat.h:403
QString name() const
Returns the name of the color in the format "#RRGGBB"; i.e.
Definition: qcolor.cpp:529
QFont::Capitalization fontCapitalization() const
Returns the current capitalization type of the font.
Definition: qtextformat.h:421
bool fontUnderline() const
Returns true if the text format&#39;s font is underlined; otherwise returns false.
void writeStartElement(const QString &qualifiedName)
This is an overloaded member function, provided for convenience. It differs from the above function o...

◆ writeFormats()

void QTextOdfWriter::writeFormats ( QXmlStreamWriter writer,
QSet< int >  formatIds 
) const

Definition at line 411 of file qtextodfwriter.cpp.

Referenced by writeAll().

412 {
413  writer.writeStartElement(officeNS, QString::fromLatin1("automatic-styles"));
415  QSetIterator<int> formatId(formats);
416  while(formatId.hasNext()) {
417  int formatIndex = formatId.next();
418  QTextFormat textFormat = allStyles.at(formatIndex);
419  switch (textFormat.type()) {
421  if (textFormat.isTableCellFormat())
422  writeTableCellFormat(writer, textFormat.toTableCellFormat(), formatIndex);
423  else
424  writeCharacterFormat(writer, textFormat.toCharFormat(), formatIndex);
425  break;
427  writeBlockFormat(writer, textFormat.toBlockFormat(), formatIndex);
428  break;
430  writeListFormat(writer, textFormat.toListFormat(), formatIndex);
431  break;
433  writeFrameFormat(writer, textFormat.toFrameFormat(), formatIndex);
434  break;
436  ;break;
437  }
438  }
439 
440  writer.writeEndElement(); // automatic-styles
441 }
void writeCharacterFormat(QXmlStreamWriter &writer, QTextCharFormat format, int formatIndex) const
QTextTableCellFormat toTableCellFormat() const
Returns this format as a table cell format.
const QString officeNS
const QTextDocument * m_document
void writeFrameFormat(QXmlStreamWriter &writer, QTextFrameFormat format, int formatIndex) const
void writeTableCellFormat(QXmlStreamWriter &writer, QTextTableCellFormat format, int formatIndex) const
QTextFrameFormat toFrameFormat() const
Returns this format as a frame format.
int type() const
Returns the type of this format.
The QTextFormat class provides formatting information for a QTextDocument.
Definition: qtextformat.h:129
void writeBlockFormat(QXmlStreamWriter &writer, QTextBlockFormat format, int formatIndex) const
QTextBlockFormat toBlockFormat() const
Returns this format as a block format.
QTextListFormat toListFormat() const
Returns this format as a list format.
void writeListFormat(QXmlStreamWriter &writer, QTextListFormat format, int formatIndex) const
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QVector< QTextFormat > allFormats() const
Returns a vector of text formats for all the formats used in the document.
void writeEndElement()
Closes the previous start element.
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
QTextCharFormat toCharFormat() const
Returns this format as a character format.
bool isTableCellFormat() const
Returns true if this text format is a TableCellFormat; otherwise returns false.
Definition: qtextformat.h:324
void writeStartElement(const QString &qualifiedName)
This is an overloaded member function, provided for convenience. It differs from the above function o...

◆ writeFrame()

void QTextOdfWriter::writeFrame ( QXmlStreamWriter writer,
const QTextFrame frame 
)

Definition at line 188 of file qtextodfwriter.cpp.

Referenced by writeAll().

189 {
190  Q_ASSERT(frame);
191  const QTextTable *table = qobject_cast<const QTextTable*> (frame);
192 
193  if (table) { // Start a table.
195  writer.writeEmptyElement(tableNS, QString::fromLatin1("table-column"));
196  writer.writeAttribute(tableNS, QString::fromLatin1("number-columns-repeated"), QString::number(table->columns()));
197  } else if (frame->document() && frame->document()->rootFrame() != frame) { // start a section
198  writer.writeStartElement(textNS, QString::fromLatin1("section"));
199  }
200 
201  QTextFrame::iterator iterator = frame->begin();
202  QTextFrame *child = 0;
203 
204  int tableRow = -1;
205  while (! iterator.atEnd()) {
206  if (iterator.currentFrame() && child != iterator.currentFrame())
207  writeFrame(writer, iterator.currentFrame());
208  else { // no frame, its a block
209  QTextBlock block = iterator.currentBlock();
210  if (table) {
211  QTextTableCell cell = table->cellAt(block.position());
212  if (tableRow < cell.row()) {
213  if (tableRow >= 0)
214  writer.writeEndElement(); // close table row
215  tableRow = cell.row();
216  writer.writeStartElement(tableNS, QString::fromLatin1("table-row"));
217  }
218  writer.writeStartElement(tableNS, QString::fromLatin1("table-cell"));
219  if (cell.columnSpan() > 1)
220  writer.writeAttribute(tableNS, QString::fromLatin1("number-columns-spanned"), QString::number(cell.columnSpan()));
221  if (cell.rowSpan() > 1)
222  writer.writeAttribute(tableNS, QString::fromLatin1("number-rows-spanned"), QString::number(cell.rowSpan()));
223  if (cell.format().isTableCellFormat()) {
224  writer.writeAttribute(tableNS, QString::fromLatin1("style-name"), QString::fromLatin1("T%1").arg(cell.tableCellFormatIndex()));
225  }
226  }
227  writeBlock(writer, block);
228  if (table)
229  writer.writeEndElement(); // table-cell
230  }
231  child = iterator.currentFrame();
232  ++iterator;
233  }
234  if (tableRow >= 0)
235  writer.writeEndElement(); // close table-row
236 
237  if (table || (frame->document() && frame->document()->rootFrame() != frame))
238  writer.writeEndElement(); // close table or section element
239 }
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
T qobject_cast(QObject *object)
Definition: qobject.h:375
int columns() const
Returns the number of columns in the table.
The QTextFrame class represents a frame in a QTextDocument.
Definition: qtextobject.h:122
QTextFrame * currentFrame() const
Returns the current frame pointed to by the iterator, or 0 if the iterator currently points to a bloc...
QTextDocument * document() const
Returns the document this object belongs to.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
int rowSpan() const
Returns the number of rows this cell spans.
Definition: qtexttable.cpp:218
QTextFrame * rootFrame() const
Returns the document&#39;s root frame.
int position() const
Returns the index of the block&#39;s first character within the document.
void writeBlock(QXmlStreamWriter &writer, const QTextBlock &block)
QTextTableCell cellAt(int row, int col) const
Returns the table cell at the given row and column in the table.
Definition: qtexttable.cpp:630
void writeAttribute(const QString &qualifiedName, const QString &value)
Writes an attribute with qualifiedName and value.
QTextCharFormat format() const
Returns the cell&#39;s character format.
Definition: qtexttable.cpp:153
const QString textNS
The QTextBlock class provides a container for text fragments in a QTextDocument.
Definition: qtextobject.h:199
int row() const
Returns the number of the row in the table that contains this cell.
Definition: qtexttable.cpp:184
The QTextTable class represents a table in a QTextDocument.
Definition: qtexttable.h:103
const QString tableNS
The iterator class provides an iterator for reading the contents of a QTextFrame. ...
Definition: qtextobject.h:144
void writeEndElement()
Closes the previous start element.
void writeFrame(QXmlStreamWriter &writer, const QTextFrame *frame)
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
The QTextTableCell class represents the properties of a cell in a QTextTable.
Definition: qtexttable.h:59
void writeEmptyElement(const QString &qualifiedName)
Writes an empty element with qualified name qualifiedName.
int tableCellFormatIndex() const
Returns the index of the tableCell&#39;s format in the document&#39;s internal list of formats.
Definition: qtexttable.cpp:173
bool atEnd() const
Returns true if the current item is the last item in the text frame.
Definition: qtextobject.h:165
int columnSpan() const
Returns the number of columns this cell spans.
Definition: qtexttable.cpp:228
bool isTableCellFormat() const
Returns true if this text format is a TableCellFormat; otherwise returns false.
Definition: qtextformat.h:324
QTextBlock currentBlock() const
Returns the current block the iterator points to.
void writeStartElement(const QString &qualifiedName)
This is an overloaded member function, provided for convenience. It differs from the above function o...
iterator begin() const
Returns an iterator pointing to the first document element inside the frame.

◆ writeFrameFormat()

void QTextOdfWriter::writeFrameFormat ( QXmlStreamWriter writer,
QTextFrameFormat  format,
int  formatIndex 
) const

Definition at line 666 of file qtextodfwriter.cpp.

667 {
669  writer.writeAttribute(styleNS, QString::fromLatin1("name"), QString::fromLatin1("s%1").arg(formatIndex));
670  writer.writeAttribute(styleNS, QString::fromLatin1("family"), QString::fromLatin1("section"));
671  writer.writeEmptyElement(styleNS, QString::fromLatin1("section-properties"));
673  writer.writeAttribute(foNS, QString::fromLatin1("margin-top"), pixelToPoint(qMax(qreal(0.), format.topMargin())) );
675  writer.writeAttribute(foNS, QString::fromLatin1("margin-bottom"), pixelToPoint(qMax(qreal(0.), format.bottomMargin())) );
677  writer.writeAttribute(foNS, QString::fromLatin1("margin-left"), pixelToPoint(qMax(qreal(0.), format.leftMargin())) );
679  writer.writeAttribute(foNS, QString::fromLatin1("margin-right"), pixelToPoint(qMax(qreal(0.), format.rightMargin())) );
680 
681  writer.writeEndElement(); // style
682 
683 // TODO consider putting the following properties in a qt-namespace.
684 // Position position () const
685 // qreal border () const
686 // QBrush borderBrush () const
687 // BorderStyle borderStyle () const
688 // qreal padding () const
689 // QTextLength width () const
690 // QTextLength height () const
691 // PageBreakFlags pageBreakPolicy () const
692 }
double qreal
Definition: qglobal.h:1193
static QString pixelToPoint(qreal pixels)
Convert pixels to postscript point units.
qreal leftMargin() const
Returns the width of the frame&#39;s left margin in pixels.
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
bool hasProperty(int propertyId) const
Returns true if the text format has a property with the given propertyId; otherwise returns false...
void writeAttribute(const QString &qualifiedName, const QString &value)
Writes an attribute with qualifiedName and value.
qreal topMargin() const
Returns the width of the frame&#39;s top margin in pixels.
qreal bottomMargin() const
Returns the width of the frame&#39;s bottom margin in pixels.
const QString foNS
void writeEndElement()
Closes the previous start element.
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
qreal rightMargin() const
Returns the width of the frame&#39;s right margin in pixels.
void writeEmptyElement(const QString &qualifiedName)
Writes an empty element with qualified name qualifiedName.
const QString styleNS
void writeStartElement(const QString &qualifiedName)
This is an overloaded member function, provided for convenience. It differs from the above function o...

◆ writeInlineCharacter()

void QTextOdfWriter::writeInlineCharacter ( QXmlStreamWriter writer,
const QTextFragment fragment 
) const

Definition at line 354 of file qtextodfwriter.cpp.

355 {
356  writer.writeStartElement(drawNS, QString::fromLatin1("frame"));
357  if (m_strategy == 0) {
358  // don't do anything.
359  }
360  else if (fragment.charFormat().isImageFormat()) {
361  QTextImageFormat imageFormat = fragment.charFormat().toImageFormat();
362  writer.writeAttribute(drawNS, QString::fromLatin1("name"), imageFormat.name());
363 
364  // vvv Copy pasted mostly from Qt =================
365  QImage image;
366  QString name = imageFormat.name();
367  if (name.startsWith(QLatin1String(":/"))) // auto-detect resources
368  name.prepend(QLatin1String("qrc"));
369  QUrl url = QUrl::fromEncoded(name.toUtf8());
371  if (data.type() == QVariant::Image) {
372  image = qvariant_cast<QImage>(data);
373  } else if (data.type() == QVariant::ByteArray) {
374  image.loadFromData(data.toByteArray());
375  }
376 
377  if (image.isNull()) {
378  QString context;
380  image = QTextImageHandler::externalLoader(name, context);
381 
382  if (image.isNull()) { // try direct loading
383  name = imageFormat.name(); // remove qrc:/ prefix again
384  image.load(name);
385  }
386  }
387 
388  // ^^^ Copy pasted mostly from Qt =================
389  if (! image.isNull()) {
390  QBuffer imageBytes;
391  QImageWriter imageWriter(&imageBytes, "png");
392  imageWriter.write(image);
394  m_strategy->addFile(filename, QString::fromLatin1("image/png"), imageBytes.data());
395 
396  // get the width/height from the format.
397  qreal width = (imageFormat.hasProperty(QTextFormat::ImageWidth)) ? imageFormat.width() : image.width();
398  writer.writeAttribute(svgNS, QString::fromLatin1("width"), pixelToPoint(width));
399  qreal height = (imageFormat.hasProperty(QTextFormat::ImageHeight)) ? imageFormat.height() : image.height();
400  writer.writeAttribute(svgNS, QString::fromLatin1("height"), pixelToPoint(height));
401 
402  writer.writeStartElement(drawNS, QString::fromLatin1("image"));
403  writer.writeAttribute(xlinkNS, QString::fromLatin1("href"), filename);
404  writer.writeEndElement(); // image
405  }
406  }
407 
408  writer.writeEndElement(); // frame
409 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
const QString xlinkNS
double qreal
Definition: qglobal.h:1193
const QString svgNS
const QByteArray & data() const
Returns the data contained in the buffer.
Definition: qbuffer.cpp:301
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
Definition: qstring.cpp:4074
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
QString & prepend(QChar c)
Definition: qstring.h:261
static QString pixelToPoint(qreal pixels)
Convert pixels to postscript point units.
const QTextDocument * m_document
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
static Q_GUI_EXPORT ExternalImageLoaderFunction externalLoader
The QBuffer class provides a QIODevice interface for a QByteArray.
Definition: qbuffer.h:57
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
qreal height() const
Returns the height of the rectangle occupied by the image.
Definition: qtextformat.h:710
bool load(QIODevice *device, const char *format)
This function reads a QImage from the given device.
Definition: qimage.cpp:5251
virtual void addFile(const QString &fileName, const QString &mimeType, const QByteArray &bytes)=0
bool hasProperty(int propertyId) const
Returns true if the text format has a property with the given propertyId; otherwise returns false...
QTextCharFormat charFormat() const
Returns the text fragment&#39;s character format.
The QTextImageFormat class provides formatting information for images in a QTextDocument.
Definition: qtextformat.h:694
void writeAttribute(const QString &qualifiedName, const QString &value)
Writes an attribute with qualifiedName and value.
The QImageWriter class provides a format independent interface for writing images to files or other d...
Definition: qimagewriter.h:59
const char * name
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
static const char * data(const QByteArray &arr)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
QTextImageFormat toImageFormat() const
Returns this format as an image format.
const QString drawNS
void writeEndElement()
Closes the previous start element.
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
QOutputStrategy * m_strategy
QVariant resource(int type, const QUrl &name) const
Returns data of the specified type from the resource with the given name.
bool isImageFormat() const
Returns true if this text format is an image format; otherwise returns false.
Definition: qtextformat.h:322
static QUrl fromEncoded(const QByteArray &url)
Parses input and returns the corresponding QUrl.
Definition: qurl.cpp:5964
QString name() const
Returns the name of the image.
Definition: qtextformat.h:702
void writeStartElement(const QString &qualifiedName)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool loadFromData(const uchar *buf, int len, const char *format=0)
Loads an image from the first len bytes of the given binary data.
Definition: qimage.cpp:5275
qreal width() const
Returns the width of the rectangle occupied by the image.
Definition: qtextformat.h:706
QString createUniqueImageName()

◆ writeListFormat()

void QTextOdfWriter::writeListFormat ( QXmlStreamWriter writer,
QTextListFormat  format,
int  formatIndex 
) const

Definition at line 629 of file qtextodfwriter.cpp.

630 {
631  writer.writeStartElement(textNS, QString::fromLatin1("list-style"));
632  writer.writeAttribute(styleNS, QString::fromLatin1("name"), QString::fromLatin1("L%1").arg(formatIndex));
633 
634  QTextListFormat::Style style = format.style();
638  || style == QTextListFormat::ListUpperRoman) {
639  writer.writeStartElement(textNS, QString::fromLatin1("list-level-style-number"));
640  writer.writeAttribute(styleNS, QString::fromLatin1("num-format"), bulletChar(style));
641 
643  writer.writeAttribute(styleNS, QString::fromLatin1("num-suffix"), format.numberSuffix());
644  else
645  writer.writeAttribute(styleNS, QString::fromLatin1("num-suffix"), QString::fromLatin1("."));
646 
648  writer.writeAttribute(styleNS, QString::fromLatin1("num-prefix"), format.numberPrefix());
649 
650  } else {
651  writer.writeStartElement(textNS, QString::fromLatin1("list-level-style-bullet"));
652  writer.writeAttribute(textNS, QString::fromLatin1("bullet-char"), bulletChar(style));
653  }
654 
655  writer.writeAttribute(textNS, QString::fromLatin1("level"), QString::number(format.indent()));
656  writer.writeEmptyElement(styleNS, QString::fromLatin1("list-level-properties"));
657  writer.writeAttribute(foNS, QString::fromLatin1("text-align"), QString::fromLatin1("start"));
658  QString spacing = QString::fromLatin1("%1mm").arg(format.indent() * 8);
659  writer.writeAttribute(textNS, QString::fromLatin1("space-before"), spacing);
660  //writer.writeAttribute(textNS, QString::fromLatin1("min-label-width"), spacing);
661 
662  writer.writeEndElement(); // list-level-style-*
663  writer.writeEndElement(); // list-style
664 }
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QString bulletChar(QTextListFormat::Style style)
bool hasProperty(int propertyId) const
Returns true if the text format has a property with the given propertyId; otherwise returns false...
Style style() const
Returns the list format&#39;s style.
Definition: qtextformat.h:662
void writeAttribute(const QString &qualifiedName, const QString &value)
Writes an attribute with qualifiedName and value.
QString numberSuffix() const
Returns the list format&#39;s number suffix.
Definition: qtextformat.h:674
Style
This enum describes the symbols used to decorate list items:
Definition: qtextformat.h:649
const QString foNS
const QString textNS
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
QString numberPrefix() const
Returns the list format&#39;s number prefix.
Definition: qtextformat.h:670
void writeEndElement()
Closes the previous start element.
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
void writeEmptyElement(const QString &qualifiedName)
Writes an empty element with qualified name qualifiedName.
const QString styleNS
int indent() const
Returns the list format&#39;s indentation.
Definition: qtextformat.h:666
void writeStartElement(const QString &qualifiedName)
This is an overloaded member function, provided for convenience. It differs from the above function o...

◆ writeTableCellFormat()

void QTextOdfWriter::writeTableCellFormat ( QXmlStreamWriter writer,
QTextTableCellFormat  format,
int  formatIndex 
) const

Definition at line 694 of file qtextodfwriter.cpp.

695 {
697  writer.writeAttribute(styleNS, QString::fromLatin1("name"), QString::fromLatin1("T%1").arg(formatIndex));
698  writer.writeAttribute(styleNS, QString::fromLatin1("family"), QString::fromLatin1("table"));
699  writer.writeEmptyElement(styleNS, QString::fromLatin1("table-properties"));
700 
701 
702  qreal padding = format.topPadding();
703  if (padding > 0 && padding == format.bottomPadding()
704  && padding == format.leftPadding() && padding == format.rightPadding()) {
705  writer.writeAttribute(foNS, QString::fromLatin1("padding"), pixelToPoint(padding));
706  }
707  else {
708  if (padding > 0)
709  writer.writeAttribute(foNS, QString::fromLatin1("padding-top"), pixelToPoint(padding));
710  if (format.bottomPadding() > 0)
711  writer.writeAttribute(foNS, QString::fromLatin1("padding-bottom"), pixelToPoint(format.bottomPadding()));
712  if (format.leftPadding() > 0)
713  writer.writeAttribute(foNS, QString::fromLatin1("padding-left"), pixelToPoint(format.leftPadding()));
714  if (format.rightPadding() > 0)
715  writer.writeAttribute(foNS, QString::fromLatin1("padding-right"), pixelToPoint(format.rightPadding()));
716  }
717 
719  QString pos;
720  switch (format.verticalAlignment()) {
722  pos = QString::fromLatin1("middle"); break;
724  pos = QString::fromLatin1("top"); break;
726  pos = QString::fromLatin1("bottom"); break;
727  default:
728  pos = QString::fromLatin1("automatic"); break;
729  }
730  writer.writeAttribute(styleNS, QString::fromLatin1("vertical-align"), pos);
731  }
732 
733  // TODO
734  // ODF just search for style-table-cell-properties-attlist)
735  // QTextFormat::BackgroundImageUrl
736  // format.background
737  // QTextFormat::FrameBorder
738 
739  writer.writeEndElement(); // style
740 }
qreal rightPadding() const
Gets the right padding of the table cell.
Definition: qtextformat.h:959
double qreal
Definition: qglobal.h:1193
static QString pixelToPoint(qreal pixels)
Convert pixels to postscript point units.
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool hasProperty(int propertyId) const
Returns true if the text format has a property with the given propertyId; otherwise returns false...
void writeAttribute(const QString &qualifiedName, const QString &value)
Writes an attribute with qualifiedName and value.
const QString foNS
VerticalAlignment verticalAlignment() const
Returns the vertical alignment used for characters with this format.
Definition: qtextformat.h:486
void writeEndElement()
Closes the previous start element.
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
void writeEmptyElement(const QString &qualifiedName)
Writes an empty element with qualified name qualifiedName.
const QString styleNS
qreal topPadding() const
Gets the top padding of the table cell.
Definition: qtextformat.h:929
qreal leftPadding() const
Gets the left padding of the table cell.
Definition: qtextformat.h:949
qreal bottomPadding() const
Gets the bottom padding of the table cell.
Definition: qtextformat.h:939
void writeStartElement(const QString &qualifiedName)
This is an overloaded member function, provided for convenience. It differs from the above function o...

Properties

◆ drawNS

const QString QTextOdfWriter::drawNS

Definition at line 100 of file qtextodfwriter_p.h.

Referenced by writeAll().

◆ foNS

const QString QTextOdfWriter::foNS

Definition at line 100 of file qtextodfwriter_p.h.

Referenced by writeAll().

◆ m_codec

QTextCodec* QTextOdfWriter::m_codec
private

Definition at line 106 of file qtextodfwriter_p.h.

Referenced by writeAll().

◆ m_createArchive

bool QTextOdfWriter::m_createArchive
private

Definition at line 107 of file qtextodfwriter_p.h.

Referenced by writeAll().

◆ m_device

QIODevice* QTextOdfWriter::m_device
private

Definition at line 103 of file qtextodfwriter_p.h.

Referenced by writeAll().

◆ m_document

const QTextDocument* QTextOdfWriter::m_document
private

Definition at line 102 of file qtextodfwriter_p.h.

Referenced by writeAll().

◆ m_listStack

QStack<QTextList *> QTextOdfWriter::m_listStack
private

Definition at line 109 of file qtextodfwriter_p.h.

◆ m_strategy

QOutputStrategy* QTextOdfWriter::m_strategy
private

Definition at line 105 of file qtextodfwriter_p.h.

Referenced by writeAll().

◆ officeNS

const QString QTextOdfWriter::officeNS

Definition at line 100 of file qtextodfwriter_p.h.

Referenced by writeAll().

◆ styleNS

const QString QTextOdfWriter::styleNS

Definition at line 100 of file qtextodfwriter_p.h.

Referenced by writeAll().

◆ svgNS

const QString QTextOdfWriter::svgNS

Definition at line 100 of file qtextodfwriter_p.h.

Referenced by writeAll().

◆ tableNS

const QString QTextOdfWriter::tableNS

Definition at line 100 of file qtextodfwriter_p.h.

Referenced by writeAll().

◆ textNS

const QString QTextOdfWriter::textNS

Definition at line 100 of file qtextodfwriter_p.h.

Referenced by writeAll().

◆ xlinkNS

const QString QTextOdfWriter::xlinkNS

Definition at line 100 of file qtextodfwriter_p.h.

Referenced by writeAll().


The documentation for this class was generated from the following files: