Skip to content

Commit

Permalink
Divide ImportOds::getSheetNames() method.
Browse files Browse the repository at this point in the history
  • Loading branch information
przemek83 committed Jan 1, 2025
1 parent 98ee806 commit d008cf9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 39 deletions.
2 changes: 2 additions & 0 deletions include/eible/ImportOds.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class EIBLE_EXPORT ImportOds : public ImportSpreadsheet
unsigned int rowLimit) override;

private:
std::pair<bool, QStringList> getSheetNamesFromZipFile();

std::pair<bool, unsigned int> getCount(
const QString& sheetName,
const QHash<QString, unsigned int>& countMap) override;
Expand Down
87 changes: 48 additions & 39 deletions src/ImportOds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,9 @@ std::pair<bool, QStringList> 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_};
Expand Down Expand Up @@ -188,6 +151,52 @@ std::pair<bool, QVector<QVector<QVariant>>> ImportOds::getLimitedData(
return {true, dataContainer};
}

std::pair<bool, QStringList> 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<bool, unsigned int> ImportOds::getCount(
const QString& sheetName, const QHash<QString, unsigned int>& countMap)
{
Expand Down

0 comments on commit d008cf9

Please sign in to comment.