Skip to content

Commit

Permalink
Rename zipFile variables to not colide with global one.
Browse files Browse the repository at this point in the history
  • Loading branch information
przemek83 committed Jan 1, 2025
1 parent ed40002 commit 8d69b65
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 53 deletions.
2 changes: 1 addition & 1 deletion include/eible/ImportOds.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class EIBLE_EXPORT ImportOds : public ImportSpreadsheet
std::tuple<bool, unsigned int, QVector<ColumnType>>
retrieveRowCountAndColumnTypes(const QString& sheetName) override;

bool moveToSecondRow(const QString& sheetName, QuaZipFile& zipFile,
bool moveToSecondRow(const QString& sheetName, QuaZipFile& quaZipFile,
QXmlStreamReader& reader) const;

void skipToSheet(QXmlStreamReader& reader, const QString& sheetName) const;
Expand Down
4 changes: 2 additions & 2 deletions include/eible/ImportSpreadsheet.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ class EIBLE_EXPORT ImportSpreadsheet : public QObject

bool setCurrentZipFile(const QString& zipFileName);

bool openZipFile(QuaZipFile& zipFile);
bool openZipFile(QuaZipFile& quaZipFile);

bool initZipFile(QuaZipFile& zipFile, const QString& zipFileName);
bool initZipFile(QuaZipFile& quaZipFile, const QString& zipFileName);

static QVector<QVariant> createTemplateDataRow(
const QVector<unsigned int>& excludedColumns,
Expand Down
5 changes: 3 additions & 2 deletions include/eible/ImportXlsx.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ class EIBLE_EXPORT ImportXlsx : public ImportSpreadsheet

std::pair<bool, QString> getSheetPath(const QString& sheetName);

bool moveToSecondRow(QuaZipFile& zipFile, QXmlStreamReader& reader) const;
bool moveToSecondRow(QuaZipFile& quaZipFile,
QXmlStreamReader& reader) const;

std::pair<bool, unsigned int> getCount(
const QString& sheetName,
Expand All @@ -75,7 +76,7 @@ class EIBLE_EXPORT ImportXlsx : public ImportSpreadsheet
const QMap<QString, QString>& sheetIdToUserFriendlyNameMap);

std::pair<bool, QDomNodeList> getSheetNodes(
QuaZipFile& zipFile,
QuaZipFile& quaZipFile,
const std::function<QDomNodeList(const QDomElement&)>& nodesRetriever);

bool isRowStart(const QXmlStreamReader& reader) const;
Expand Down
36 changes: 19 additions & 17 deletions src/ImportOds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ std::pair<bool, QVector<ColumnType>> ImportOds::getColumnTypes(
if (sheetNames_.has_value() && (!isSheetNameValid(*sheetNames_, sheetName)))
return {false, {}};

QuaZipFile zipFile;
if (!initZipFile(zipFile, QStringLiteral("content.xml")))
QuaZipFile quaZipFile;
if (!initZipFile(quaZipFile, QStringLiteral("content.xml")))
return {false, {}};

if (QXmlStreamReader reader; !moveToSecondRow(sheetName, zipFile, reader))
if (QXmlStreamReader reader;
!moveToSecondRow(sheetName, quaZipFile, reader))
return {false, {}};

if (!analyzeSheet(sheetName))
Expand Down Expand Up @@ -79,12 +80,12 @@ std::pair<bool, QVector<QVector<QVariant>>> ImportOds::getLimitedData(
if (!columnsToExcludeAreValid(excludedColumns, columnCount))
return {false, {}};

QuaZipFile zipFile;
if (!initZipFile(zipFile, QStringLiteral("content.xml")))
QuaZipFile quaZipFile;
if (!initZipFile(quaZipFile, QStringLiteral("content.xml")))
return {false, {}};

QXmlStreamReader reader;
if (!moveToSecondRow(sheetName, zipFile, reader))
if (!moveToSecondRow(sheetName, quaZipFile, reader))
return {false, {}};

const QVector<QVariant> templateDataRow(
Expand Down Expand Up @@ -153,12 +154,12 @@ std::pair<bool, QVector<QVector<QVariant>>> ImportOds::getLimitedData(

std::pair<bool, QStringList> ImportOds::getSheetNamesFromZipFile()
{
QuaZipFile zipFile;
if (!initZipFile(zipFile, QStringLiteral("settings.xml")))
QuaZipFile quaZipFile;
if (!initZipFile(quaZipFile, QStringLiteral("settings.xml")))
return {false, {}};

QDomDocument xmlDocument;
if (!xmlDocument.setContent(zipFile.readAll()))
if (!xmlDocument.setContent(quaZipFile.readAll()))
{
setError(QStringLiteral("Xml file is damaged."));
return {false, {}};
Expand Down Expand Up @@ -218,12 +219,12 @@ std::pair<bool, unsigned int> ImportOds::getCount(
std::pair<bool, QStringList> ImportOds::retrieveColumnNames(
const QString& sheetName)
{
QuaZipFile zipFile;
if (!initZipFile(zipFile, QStringLiteral("content.xml")))
QuaZipFile quaZipFile;
if (!initZipFile(quaZipFile, QStringLiteral("content.xml")))
return {false, {}};

QXmlStreamReader reader;
reader.setDevice(&zipFile);
reader.setDevice(&quaZipFile);
skipToSheet(reader, sheetName);

while ((!reader.atEnd()) && (reader.name() != TABLE_ROW_TAG))
Expand Down Expand Up @@ -258,12 +259,12 @@ std::pair<bool, QStringList> ImportOds::retrieveColumnNames(
std::tuple<bool, unsigned int, QVector<ColumnType>>
ImportOds::retrieveRowCountAndColumnTypes(const QString& sheetName)
{
QuaZipFile zipFile;
if (!initZipFile(zipFile, QStringLiteral("content.xml")))
QuaZipFile quaZipFile;
if (!initZipFile(quaZipFile, QStringLiteral("content.xml")))
return {false, {}, {}};

QXmlStreamReader reader;
if (!moveToSecondRow(sheetName, zipFile, reader))
if (!moveToSecondRow(sheetName, quaZipFile, reader))
return {false, {}, {}};

QVector<ColumnType> columnTypes;
Expand Down Expand Up @@ -315,10 +316,11 @@ ImportOds::retrieveRowCountAndColumnTypes(const QString& sheetName)
return {true, rowCounter, columnTypes};
}

bool ImportOds::moveToSecondRow(const QString& sheetName, QuaZipFile& zipFile,
bool ImportOds::moveToSecondRow(const QString& sheetName,
QuaZipFile& quaZipFile,
QXmlStreamReader& reader) const
{
reader.setDevice(&zipFile);
reader.setDevice(&quaZipFile);
skipToSheet(reader, sheetName);

bool secondRow{false};
Expand Down
13 changes: 7 additions & 6 deletions src/ImportSpreadsheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,22 @@ bool ImportSpreadsheet::setCurrentZipFile(const QString& zipFileName)
return true;
}

bool ImportSpreadsheet::openZipFile(QuaZipFile& zipFile)
bool ImportSpreadsheet::openZipFile(QuaZipFile& quaZipFile)
{
zipFile.setZip(&zip_);
if (!zipFile.open(QIODevice::ReadOnly | QIODevice::Text))
quaZipFile.setZip(&zip_);
if (!quaZipFile.open(QIODevice::ReadOnly | QIODevice::Text))
{
setError("Can not open file " + zipFile.getFileName() + ".");
setError("Can not open file " + quaZipFile.getFileName() + ".");
return false;
}
return true;
}

bool ImportSpreadsheet::initZipFile(QuaZipFile& zipFile,
bool ImportSpreadsheet::initZipFile(QuaZipFile& quaZipFile,
const QString& zipFileName)
{
return openZip() && setCurrentZipFile(zipFileName) && openZipFile(zipFile);
return openZip() && setCurrentZipFile(zipFileName) &&
openZipFile(quaZipFile);
}

QMap<unsigned int, unsigned int> ImportSpreadsheet::createActiveColumnMapping(
Expand Down
50 changes: 25 additions & 25 deletions src/ImportXlsx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ QList<int> ImportXlsx::retrieveAllStyles(const QDomNodeList& sheetNodes)
std::tuple<bool, std::optional<QList<int>>, std::optional<QList<int>>>
ImportXlsx::getStyles()
{
QuaZipFile zipFile;
if (!initZipFile(zipFile, QStringLiteral("xl/styles.xml")))
QuaZipFile quaZipFile;
if (!initZipFile(quaZipFile, QStringLiteral("xl/styles.xml")))
return {false, {}, {}};

QDomDocument xmlDocument;
if (!xmlDocument.setContent(zipFile.readAll()))
if (!xmlDocument.setContent(quaZipFile.readAll()))
{
setError(QStringLiteral("Xml file is corrupted."));
return {false, std::nullopt, std::nullopt};
Expand Down Expand Up @@ -166,12 +166,12 @@ std::pair<bool, QStringList> ImportXlsx::getSharedStrings()
if (!setCurrentZipFile(QStringLiteral("xl/sharedStrings.xml")))
return {true, {}};

QuaZipFile zipFile;
if (!openZipFile(zipFile))
QuaZipFile quaZipFile;
if (!openZipFile(quaZipFile))
return {false, {}};

QXmlStreamReader reader;
reader.setDevice(&zipFile);
reader.setDevice(&quaZipFile);

QStringList sharedStrings;
while (!reader.atEnd())
Expand Down Expand Up @@ -204,10 +204,10 @@ std::pair<bool, QVector<ColumnType>> ImportXlsx::getColumnTypes(
return {true, columnTypes_.value(sheetName)};
}

bool ImportXlsx::moveToSecondRow(QuaZipFile& zipFile,
bool ImportXlsx::moveToSecondRow(QuaZipFile& quaZipFile,
QXmlStreamReader& reader) const
{
reader.setDevice(&zipFile);
reader.setDevice(&quaZipFile);
bool secondRow{false};
while (!reader.atEnd())
{
Expand Down Expand Up @@ -241,11 +241,11 @@ std::pair<bool, unsigned int> ImportXlsx::getCount(
}

std::pair<bool, QDomNodeList> ImportXlsx::getSheetNodes(
QuaZipFile& zipFile,
QuaZipFile& quaZipFile,
const std::function<QDomNodeList(const QDomElement&)>& nodesRetriever)
{
QDomDocument xmlDocument;
if (!xmlDocument.setContent(zipFile.readAll()))
if (!xmlDocument.setContent(quaZipFile.readAll()))
{
setError(QStringLiteral("File is corrupted."));
return {false, {}};
Expand Down Expand Up @@ -288,12 +288,12 @@ std::pair<bool, QStringList> ImportXlsx::retrieveColumnNames(
if (!sheetFound)
return {false, {}};

QuaZipFile zipFile;
if (!initZipFile(zipFile, sheetPath))
QuaZipFile quaZipFile;
if (!initZipFile(quaZipFile, sheetPath))
return {false, {}};

QXmlStreamReader reader;
reader.setDevice(&zipFile);
reader.setDevice(&quaZipFile);
skipToFirstRow(reader);

int columnIndex{NOT_SET_COLUMN};
Expand Down Expand Up @@ -333,12 +333,12 @@ ImportXlsx::retrieveRowCountAndColumnTypes(const QString& sheetName)
if (!sheetFound)
return {false, {}, {}};

QuaZipFile zipFile;
if (!initZipFile(zipFile, sheetPath))
QuaZipFile quaZipFile;
if (!initZipFile(quaZipFile, sheetPath))
return {false, {}, {}};

QXmlStreamReader reader;
if (!moveToSecondRow(zipFile, reader))
if (!moveToSecondRow(quaZipFile, reader))
return {false, {}, {}};

QVector<ColumnType> columnTypes;
Expand Down Expand Up @@ -442,14 +442,14 @@ ColumnType ImportXlsx::recognizeColumnType(ColumnType currentType,
std::pair<bool, QMap<QString, QString>>
ImportXlsx::getSheetIdToUserFriendlyNameMap()
{
QuaZipFile zipFile;
if (!initZipFile(zipFile, QStringLiteral("xl/workbook.xml")))
QuaZipFile quaZipFile;
if (!initZipFile(quaZipFile, QStringLiteral("xl/workbook.xml")))
return {false, {}};

auto nodesRetriever{[](const QDomElement& root) {
return root.firstChildElement(QStringLiteral("sheets")).childNodes();
}};
auto [sucess, sheetNodes]{getSheetNodes(zipFile, nodesRetriever)};
auto [sucess, sheetNodes]{getSheetNodes(quaZipFile, nodesRetriever)};
if (!sucess)
return {false, {}};

Expand All @@ -469,12 +469,12 @@ std::pair<bool, QVector<std::pair<QString, QString>>>
ImportXlsx::retrieveSheets(
const QMap<QString, QString>& sheetIdToUserFriendlyNameMap)
{
QuaZipFile zipFile;
if (!initZipFile(zipFile, QStringLiteral("xl/_rels/workbook.xml.rels")))
QuaZipFile quaZipFile;
if (!initZipFile(quaZipFile, QStringLiteral("xl/_rels/workbook.xml.rels")))
return {false, {}};

auto [sucess, sheetNodes]{getSheetNodes(
zipFile, [](const QDomElement& root) { return root.childNodes(); })};
quaZipFile, [](const QDomElement& root) { return root.childNodes(); })};
if (!sucess)
return {false, {}};

Expand Down Expand Up @@ -596,12 +596,12 @@ std::pair<bool, QVector<QVector<QVariant>>> ImportXlsx::getLimitedData(
if (!sheetFound)
return {false, {}};

QuaZipFile zipFile;
if (!initZipFile(zipFile, sheetPath))
QuaZipFile quaZipFile;
if (!initZipFile(quaZipFile, sheetPath))
return {false, {}};

QXmlStreamReader reader;
moveToSecondRow(zipFile, reader);
moveToSecondRow(quaZipFile, reader);

const QVector<QVariant> templateDataRow(
createTemplateDataRow(excludedColumns, columnTypes));
Expand Down

0 comments on commit 8d69b65

Please sign in to comment.