File indexing completed on 2024-06-23 03:45:57
0001 /**************************************************************************** 0002 ** Copyright (c) 2013-2014 Debao Zhang <hello@debao.me> 0003 ** All right reserved. 0004 ** 0005 ** Permission is hereby granted, free of charge, to any person obtaining 0006 ** a copy of this software and associated documentation files (the 0007 ** "Software"), to deal in the Software without restriction, including 0008 ** without limitation the rights to use, copy, modify, merge, publish, 0009 ** distribute, sublicense, and/or sell copies of the Software, and to 0010 ** permit persons to whom the Software is furnished to do so, subject to 0011 ** the following conditions: 0012 ** 0013 ** The above copyright notice and this permission notice shall be 0014 ** included in all copies or substantial portions of the Software. 0015 ** 0016 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 0017 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 0018 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 0019 ** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 0020 ** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 0021 ** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 0022 ** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 0023 ** 0024 ****************************************************************************/ 0025 #ifndef XLSXSHAREDSTRINGS_H 0026 #define XLSXSHAREDSTRINGS_H 0027 0028 // 0029 // W A R N I N G 0030 // ------------- 0031 // 0032 // This file is not part of the Qt Xlsx API. It exists for the convenience 0033 // of the Qt Xlsx. This header file may change from 0034 // version to version without notice, or even be removed. 0035 // 0036 // We mean it. 0037 // 0038 0039 #include <QHash> 0040 #include <QStringList> 0041 #include <QIODevice> 0042 #include <QXmlStreamReader> 0043 #include <QXmlStreamWriter> 0044 0045 #include "xlsxglobal.h" 0046 #include "xlsxrichstring.h" 0047 #include "xlsxabstractooxmlfile.h" 0048 0049 QT_BEGIN_NAMESPACE_XLSX 0050 0051 class XlsxSharedStringInfo 0052 { 0053 public: 0054 XlsxSharedStringInfo(int index=0, int count = 1) : 0055 index(index), count(count) 0056 { 0057 } 0058 0059 int index; 0060 int count; 0061 }; 0062 0063 class SharedStrings : public AbstractOOXmlFile 0064 { 0065 public: 0066 SharedStrings(CreateFlag flag); 0067 int count() const; 0068 bool isEmpty() const; 0069 0070 int addSharedString(const QString &string); 0071 int addSharedString(const RichString &string); 0072 void removeSharedString(const QString &string); 0073 void removeSharedString(const RichString &string); 0074 void incRefByStringIndex(int idx); 0075 0076 int getSharedStringIndex(const QString &string) const; 0077 int getSharedStringIndex(const RichString &string) const; 0078 RichString getSharedString(int index) const; 0079 QList<RichString> getSharedStrings() const; 0080 0081 void saveToXmlFile(QIODevice *device) const override; 0082 bool loadFromXmlFile(QIODevice *device) override; 0083 0084 private: 0085 void readString(QXmlStreamReader &reader); // <si> 0086 void readRichStringPart(QXmlStreamReader &reader, RichString &rich); // <r> 0087 void readPlainStringPart(QXmlStreamReader &reader, RichString &rich); // <v> 0088 Format readRichStringPart_rPr(QXmlStreamReader &reader); 0089 void writeRichStringPart_rPr(QXmlStreamWriter &writer, const Format &format) const; 0090 0091 QHash<RichString, XlsxSharedStringInfo> m_stringTable; //for fast lookup 0092 QList<RichString> m_stringList; 0093 int m_stringCount; 0094 }; 0095 0096 QT_END_NAMESPACE_XLSX 0097 0098 #endif // XLSXSHAREDSTRINGS_H