xlsxdrawing.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // xlsxdrawing.cpp
  2. #include <QtGlobal>
  3. #include <QXmlStreamWriter>
  4. #include <QXmlStreamReader>
  5. #include <QBuffer>
  6. #include "xlsxdrawing_p.h"
  7. #include "xlsxdrawinganchor_p.h"
  8. #include "xlsxabstractsheet.h"
  9. QT_BEGIN_NAMESPACE_XLSX
  10. Drawing::Drawing(AbstractSheet *sheet, CreateFlag flag)
  11. :AbstractOOXmlFile(flag), sheet(sheet)
  12. {
  13. workbook = sheet->workbook();
  14. }
  15. Drawing::~Drawing()
  16. {
  17. qDeleteAll(anchors);
  18. }
  19. void Drawing::saveToXmlFile(QIODevice *device) const
  20. {
  21. relationships()->clear();
  22. QXmlStreamWriter writer(device);
  23. writer.writeStartDocument(QStringLiteral("1.0"), true);
  24. writer.writeStartElement(QStringLiteral("xdr:wsDr"));
  25. writer.writeAttribute(QStringLiteral("xmlns:xdr"), QStringLiteral("http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing"));
  26. writer.writeAttribute(QStringLiteral("xmlns:a"), QStringLiteral("http://schemas.openxmlformats.org/drawingml/2006/main"));
  27. for (DrawingAnchor *anchor : anchors)
  28. anchor->saveToXml(writer);
  29. writer.writeEndElement();//xdr:wsDr
  30. writer.writeEndDocument();
  31. }
  32. // check point
  33. bool Drawing::loadFromXmlFile(QIODevice *device)
  34. {
  35. /*
  36. <xsd:group name="EG_Anchor">
  37. <xsd:choice>
  38. <xsd:element name="twoCellAnchor" type="CT_TwoCellAnchor"/>
  39. <xsd:element name="oneCellAnchor" type="CT_OneCellAnchor"/>
  40. <xsd:element name="absoluteAnchor" type="CT_AbsoluteAnchor"/>
  41. </xsd:choice>
  42. </xsd:group>
  43. */
  44. QXmlStreamReader reader(device);
  45. while (!reader.atEnd())
  46. {
  47. reader.readNextStartElement();
  48. if (reader.tokenType() == QXmlStreamReader::StartElement)
  49. {
  50. if (reader.name() == QLatin1String("absoluteAnchor")) // CT_AbsoluteAnchor
  51. {
  52. DrawingAbsoluteAnchor * anchor = new DrawingAbsoluteAnchor(this);
  53. anchor->loadFromXml(reader);
  54. }
  55. else if (reader.name() == QLatin1String("oneCellAnchor")) // CT_OneCellAnchor
  56. {
  57. DrawingOneCellAnchor * anchor = new DrawingOneCellAnchor(this);
  58. anchor->loadFromXml(reader);
  59. }
  60. else if (reader.name() == QLatin1String("twoCellAnchor")) // CT_TwoCellAnchor
  61. {
  62. DrawingTwoCellAnchor * anchor = new DrawingTwoCellAnchor(this);
  63. anchor->loadFromXml(reader);
  64. }
  65. }
  66. }
  67. return true;
  68. }
  69. QT_END_NAMESPACE_XLSX