diff --git a/include/eible/ImportOds.h b/include/eible/ImportOds.h index 7346cae..2070a82 100644 --- a/include/eible/ImportOds.h +++ b/include/eible/ImportOds.h @@ -38,6 +38,8 @@ class EIBLE_EXPORT ImportOds : public ImportSpreadsheet unsigned int rowLimit) override; private: + std::pair getSheetNamesFromZipFile(); + std::pair getCount( const QString& sheetName, const QHash& countMap) override; diff --git a/src/ImportOds.cpp b/src/ImportOds.cpp index 74d9b15..d689967 100644 --- a/src/ImportOds.cpp +++ b/src/ImportOds.cpp @@ -18,46 +18,9 @@ std::pair ImportOds::getSheetNames() if (sheetNames_) return {true, *sheetNames_}; - QuaZipFile zipFile; - if (!initZipFile(zipFile, QStringLiteral("settings.xml"))) - return {false, {}}; - - QDomDocument xmlDocument; - if (!xmlDocument.setContent(zipFile.readAll())) - { - setError(QStringLiteral("Xml file is damaged.")); + const auto [success, sheetNames]{getSheetNamesFromZipFile()}; + if (!success) return {false, {}}; - } - - const QString configMapNamed{ - QStringLiteral("config:config-item-map-named")}; - const QString configName{QStringLiteral("config:name")}; - const QString configMapEntry{ - QStringLiteral("config:config-item-map-entry")}; - const QString tables{QStringLiteral("Tables")}; - - const QDomElement root{xmlDocument.documentElement()}; - const int elementsCount{root.elementsByTagName(configMapNamed).size()}; - QStringList sheetNames{}; - for (int i{0}; i < elementsCount; ++i) - { - const QDomElement currentElement{ - root.elementsByTagName(configMapNamed).at(i).toElement()}; - if (currentElement.hasAttribute(configName) && - (currentElement.attribute(configName) == tables)) - { - const int innerElementsCount{ - currentElement.elementsByTagName(configMapEntry).size()}; - for (int j{0}; j < innerElementsCount; ++j) - { - const QDomElement element{ - currentElement.elementsByTagName(configMapEntry) - .at(j) - .toElement()}; - sheetNames.push_back(element.attribute(configName)); - } - } - } sheetNames_ = std::move(sheetNames); return {true, *sheetNames_}; @@ -188,6 +151,52 @@ std::pair>> ImportOds::getLimitedData( return {true, dataContainer}; } +std::pair ImportOds::getSheetNamesFromZipFile() +{ + QuaZipFile zipFile; + if (!initZipFile(zipFile, QStringLiteral("settings.xml"))) + return {false, {}}; + + QDomDocument xmlDocument; + if (!xmlDocument.setContent(zipFile.readAll())) + { + setError(QStringLiteral("Xml file is damaged.")); + return {false, {}}; + } + + const QString configMapNamed{ + QStringLiteral("config:config-item-map-named")}; + const QString configName{QStringLiteral("config:name")}; + const QString configMapEntry{ + QStringLiteral("config:config-item-map-entry")}; + const QString tables{QStringLiteral("Tables")}; + + const QDomElement root{xmlDocument.documentElement()}; + const int elementsCount{root.elementsByTagName(configMapNamed).size()}; + QStringList sheetNames{}; + for (int i{0}; i < elementsCount; ++i) + { + const QDomElement currentElement{ + root.elementsByTagName(configMapNamed).at(i).toElement()}; + if (currentElement.hasAttribute(configName) && + (currentElement.attribute(configName) == tables)) + { + const int innerElementsCount{ + currentElement.elementsByTagName(configMapEntry).size()}; + for (int j{0}; j < innerElementsCount; ++j) + { + const QDomElement element{ + currentElement.elementsByTagName(configMapEntry) + .at(j) + .toElement()}; + sheetNames.push_back(element.attribute(configName)); + } + } + } + + return {true, sheetNames}; +} + std::pair ImportOds::getCount( const QString& sheetName, const QHash& countMap) {