xlsxabstractooxmlfile.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /****************************************************************************
  2. ** Copyright (c) 2013-2014 Debao Zhang <hello@debao.me>
  3. ** All right reserved.
  4. **
  5. ** Permission is hereby granted, free of charge, to any person obtaining
  6. ** a copy of this software and associated documentation files (the
  7. ** "Software"), to deal in the Software without restriction, including
  8. ** without limitation the rights to use, copy, modify, merge, publish,
  9. ** distribute, sublicense, and/or sell copies of the Software, and to
  10. ** permit persons to whom the Software is furnished to do so, subject to
  11. ** the following conditions:
  12. **
  13. ** The above copyright notice and this permission notice shall be
  14. ** included in all copies or substantial portions of the Software.
  15. **
  16. ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. ** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  20. ** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  21. ** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  22. ** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. **
  24. ****************************************************************************/
  25. #include "xlsxabstractooxmlfile.h"
  26. #include "xlsxabstractooxmlfile_p.h"
  27. #include <QBuffer>
  28. #include <QByteArray>
  29. QT_BEGIN_NAMESPACE_XLSX
  30. AbstractOOXmlFilePrivate::AbstractOOXmlFilePrivate(AbstractOOXmlFile *q, AbstractOOXmlFile::CreateFlag flag=AbstractOOXmlFile::F_NewFromScratch)
  31. :relationships(new Relationships), flag(flag), q_ptr(q)
  32. {
  33. }
  34. AbstractOOXmlFilePrivate::~AbstractOOXmlFilePrivate()
  35. {
  36. }
  37. /*!
  38. * \internal
  39. *
  40. * \class AbstractOOXmlFile
  41. *
  42. * Base class of all the ooxml part file.
  43. */
  44. AbstractOOXmlFile::AbstractOOXmlFile(CreateFlag flag)
  45. :d_ptr(new AbstractOOXmlFilePrivate(this, flag))
  46. {
  47. }
  48. AbstractOOXmlFile::AbstractOOXmlFile(AbstractOOXmlFilePrivate *d)
  49. :d_ptr(d)
  50. {
  51. }
  52. AbstractOOXmlFile::~AbstractOOXmlFile()
  53. {
  54. if (d_ptr->relationships)
  55. delete d_ptr->relationships;
  56. delete d_ptr;
  57. }
  58. QByteArray AbstractOOXmlFile::saveToXmlData() const
  59. {
  60. QByteArray data;
  61. QBuffer buffer(&data);
  62. buffer.open(QIODevice::WriteOnly);
  63. saveToXmlFile(&buffer);
  64. return data;
  65. }
  66. bool AbstractOOXmlFile::loadFromXmlData(const QByteArray &data)
  67. {
  68. QBuffer buffer;
  69. buffer.setData(data);
  70. buffer.open(QIODevice::ReadOnly);
  71. return loadFromXmlFile(&buffer);
  72. }
  73. /*!
  74. * \internal
  75. */
  76. void AbstractOOXmlFile::setFilePath(const QString path)
  77. {
  78. Q_D(AbstractOOXmlFile);
  79. d->filePathInPackage = path;
  80. }
  81. /*!
  82. * \internal
  83. */
  84. QString AbstractOOXmlFile::filePath() const
  85. {
  86. Q_D(const AbstractOOXmlFile);
  87. return d->filePathInPackage;
  88. }
  89. /*!
  90. * \internal
  91. */
  92. Relationships *AbstractOOXmlFile::relationships() const
  93. {
  94. Q_D(const AbstractOOXmlFile);
  95. return d->relationships;
  96. }
  97. QT_END_NAMESPACE_XLSX