File indexing completed on 2025-01-19 10:49:28
0001 /* This file is part of the KDE project 0002 0003 SPDX-FileCopyrightText: 2012-2014 Inge Wallin <inge@lysator.liu.se> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 0009 // Own 0010 #include "OdsReader.h" 0011 0012 // Qt 0013 #include <QStringList> 0014 #include <QBuffer> 0015 0016 // KF5 0017 #include <klocalizedstring.h> 0018 0019 // Calligra 0020 #include <KoStore.h> 0021 #include <KoXmlStreamReader.h> 0022 #include <KoXmlNS.h> 0023 #include <KoXmlWriter.h> // For copyXmlElement 0024 #include <KoOdfReadStore.h> 0025 0026 // Reader library 0027 #include "OdsReaderBackend.h" 0028 #include "OdfReaderContext.h" 0029 #include "OdfTextReader.h" 0030 #include "OdfReaderDebug.h" 0031 0032 0033 #if 0 0034 static int debugIndent = 0; 0035 #define DEBUGSTART() \ 0036 ++debugIndent; \ 0037 DEBUG_READING("entering") 0038 #define DEBUGEND() \ 0039 DEBUG_READING("exiting"); \ 0040 --debugIndent 0041 #define DEBUG_READING(param) \ 0042 debugOdfReader << QString("%1").arg(" ", debugIndent * 2) << param << ": " \ 0043 << (reader.isStartElement() ? "start": (reader.isEndElement() ? "end" : "other")) \ 0044 << reader.qualifiedName().toString() 0045 #else 0046 #define DEBUGSTART() \ 0047 // NOTHING 0048 #define DEBUGEND() \ 0049 // NOTHING 0050 #define DEBUG_READING(param) \ 0051 // NOTHING 0052 #endif 0053 0054 0055 OdsReader::OdsReader() 0056 : OdfReader() 0057 { 0058 } 0059 0060 OdsReader::~OdsReader() 0061 { 0062 } 0063 0064 0065 #if 0 0066 // This is a template function for the reader library. 0067 // Copy this one and change the name and fill in the code. 0068 void OdsReader::readElementNamespaceTagname(KoXmlStreamReader &reader) 0069 { 0070 DEBUGSTART(); 0071 0072 // <namespace:tagname> has the following children in ODF 1.2: 0073 // FILL IN THE CHILDREN LIKE THIS EXAMPLE (taken from office:document-content): 0074 // <office:automatic-styles> 3.15.3 0075 // <office:body> 3.3 0076 // <office:font-face-decls> 3.14 0077 // <office:scripts> 3.12. 0078 while (reader.readNextStartElement()) { 0079 QString tagName = reader.qualifiedName().toString(); 0080 0081 if (tagName == "office:automatic-styles") { 0082 // FIXME: NYI 0083 } 0084 else if (tagName == "office:body") { 0085 readElementOfficeBody(reader); 0086 } 0087 ... MORE else if () HERE 0088 else { 0089 reader.skipCurrentElement(); 0090 } 0091 } 0092 0093 m_backend->elementNamespaceTagname(reader, m_context); 0094 DEBUGEND(); 0095 } 0096 #endif 0097 0098 0099 // Reimplemented from OdfReader 0100 void OdsReader::readElementOfficeSpreadsheet(KoXmlStreamReader &reader) 0101 { 0102 DEBUGSTART(); 0103 OdsReaderBackend *backend = dynamic_cast<OdsReaderBackend *>(m_backend); 0104 backend->elementOfficeSpreadsheet(reader, m_context); 0105 0106 // <office:spreadsheet> has the following children in ODF 1.2: 0107 // 0108 // <table:calculation-settings> 9.4.1 0109 // <table:consolidation> 9.7 0110 // <table:content-validations> 9.4.4 0111 // <table:database-ranges> 9.4.14 0112 // <table:data-pilot-tables> 9.6.2 0113 // <table:dde-links> 9.8 0114 // <table:label-ranges> 9.4.10 0115 // <table:named-expressions> 9.4.11 0116 // [done] <table:table> 9.1.2 0117 // <table:tracked-changes> 9.9.2 0118 // <text:alphabetical-index-auto-mark-file> 8.8.3 0119 // <text:dde-connection-decls> 14.6.2 0120 // <text:sequence-decls> 7.4.11 0121 // <text:user-field-decls> 7.4.7 0122 // <text:variable-decls> 7.4.2 0123 0124 // 0125 // FIXME: For now, only very few of these are handled. 0126 while (reader.readNextStartElement()) { 0127 DEBUG_READING("loop-start"); 0128 0129 QString tagName = reader.qualifiedName().toString(); 0130 if (tagName == "table:table") { 0131 if (m_textReader) { 0132 // <table:table> is handled in the text reader even in spreadsheets. 0133 m_textReader->readElementTableTable(reader); 0134 } 0135 else { 0136 reader.skipCurrentElement(); 0137 } 0138 } 0139 else if (tagName == "table:calculation-settings") { 0140 // FIXME: NYI 0141 reader.skipCurrentElement(); 0142 } 0143 else if (tagName == "table:consolidation") { 0144 reader.skipCurrentElement(); 0145 } 0146 else if (tagName == "table:content-validation") { 0147 reader.skipCurrentElement(); 0148 } 0149 else if (tagName == "table:database-ranges") { 0150 reader.skipCurrentElement(); 0151 } 0152 else if (tagName == "table:data-pilot-tables") { 0153 reader.skipCurrentElement(); 0154 } 0155 else if (tagName == "table:dde-links") { 0156 reader.skipCurrentElement(); 0157 } 0158 else if (tagName == "table:label-ranges") { 0159 reader.skipCurrentElement(); 0160 } 0161 else if (tagName == "table:named-expressions") { 0162 reader.skipCurrentElement(); 0163 } 0164 else if (tagName == "table:tracked-changes") { 0165 reader.skipCurrentElement(); 0166 } 0167 else if (tagName == "text:alphabetical-index-auto-mark-file") { 0168 reader.skipCurrentElement(); 0169 } 0170 else if (tagName == "text:dde-connection-decls") { 0171 reader.skipCurrentElement(); 0172 } 0173 else if (tagName == "text:sequence-decls") { 0174 reader.skipCurrentElement(); 0175 } 0176 else if (tagName == "text:user-field-decls") { 0177 reader.skipCurrentElement(); 0178 } 0179 else if (tagName == "text:variable-decls") { 0180 reader.skipCurrentElement(); 0181 } 0182 else { 0183 reader.skipCurrentElement(); 0184 } 0185 DEBUG_READING("loop-end"); 0186 } 0187 0188 backend->elementOfficeSpreadsheet(reader, m_context); 0189 DEBUGEND(); 0190 } 0191 0192 0193 // ---------------------------------------------------------------- 0194 // Other functions