Skip to content

Commit

Permalink
some cleanup and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
shun2wang committed Sep 9, 2024
1 parent 334410c commit 031fc6b
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 24 deletions.
2 changes: 0 additions & 2 deletions Desktop/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ target_include_directories(
$<$<BOOL:${FLATPAK_USED}>:/app/include/QtCore5Compat>
$<$<BOOL:${FLATPAK_USED}>:/app/include/QtWebEngineQuick>
$<$<BOOL:${FLATPAK_USED}>:/app/include/QtWebEngineCore>
# FreeXL
$<$<PLATFORM_ID:Windows>:${RTOOLS_LIBFREEXL_H}>
${LIBFREEXL_INCLUDE_DIRS}
)

Expand Down
18 changes: 8 additions & 10 deletions Desktop/data/importers/excel/excel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@

#include "excel.h"
#include "utilities/qutils.h"
#include "utils.h"

#include <QFileInfo>
#include <QDebug>

using namespace std;

Excel::Excel(const string &locator)
Excel::Excel(const std::string &locator)
{
_path = locator;
}
Expand All @@ -35,11 +32,12 @@ void Excel::open()
_fileSize = fi.size();

if (_fileSize < 0)
throw runtime_error("Could not access file");
throw std::runtime_error("Could not access file");

if (_fileSize == 0)
throw runtime_error("File is empty");
throw std::runtime_error("File is empty");
}

void Excel::openWorkbook()
{
QString xlsFilePath = tq(_path);
Expand All @@ -52,24 +50,24 @@ void Excel::openWorkbook()
else if (extension == "xlsx")
ret = freexl_open_xlsx(utf8Path, &_handle);
else
throw runtime_error("Unsupported file format: " + fq(extension));
throw std::runtime_error("Unsupported file format: " + fq(extension));

if(ret != FREEXL_OK)
throw runtime_error("Unexpected error while loading excel file, error code: " + std::to_string(ret));
throw std::runtime_error("Unexpected error while loading excel file, error code: " + std::to_string(ret));
}

void Excel::selectActiveWorksheet()
{
int ret = freexl_select_active_worksheet(_handle, 0); // import the first worksheet(index=0) by default.
if (ret != FREEXL_OK)
throw runtime_error("Could not select active worksheet,\n error code: " + std::to_string(ret));
throw std::runtime_error("Could not select active worksheet,\n error code: " + std::to_string(ret));
}

void Excel::getWorksheetDimensions(uint32_t &rows, uint16_t &cols) {
int ret = freexl_worksheet_dimensions(_handle, &rows, &cols);

if (ret != FREEXL_OK)
throw runtime_error("Could not read worksheet dimensions, error code: " + std::to_string(ret));
throw std::runtime_error("Could not read worksheet dimensions, error code: " + std::to_string(ret));

_numCols = cols; //get cols count while read sheet
}
Expand Down
1 change: 0 additions & 1 deletion Desktop/data/importers/excel/excel.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#ifndef EXCEL_H
#define EXCEL_H

#include <vector>
#include <string>
#include <stdint.h>

Expand Down
8 changes: 3 additions & 5 deletions Desktop/data/importers/excelimporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ ImportDataSet* ExcelImporter::loadFile(const std::string &locator, std::function
std::string colName = colNames[i];
if (colName.empty())
colName = "V" + std::to_string(i + 1);
else if(ColumnUtils::isIntValue(colName))
else if(ColumnUtils::isIntValue(colName) || ColumnUtils::isDoubleValue(colName))
colName = "V" + colName;
//What is the purpose of the `find` here? Maybe explain in a comment here
if (std::find(colNames.begin(), colNames.begin() + i, colName) != colNames.begin() + i)
// distinguish duplicate column names
if(std::find(colNames.begin(), colNames.begin() + i, colName) != colNames.begin() + i)
colName += "_" + std::to_string(i + 1);

colNames[i] = colName;
Expand All @@ -95,9 +95,7 @@ ImportDataSet* ExcelImporter::loadFile(const std::string &locator, std::function
}

for (ExcelImportColumn* col : importColumns)
{
data->addColumn(col);
}

data->buildDictionary();
excel.close();
Expand Down
2 changes: 1 addition & 1 deletion Desktop/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1737,7 +1737,7 @@ bool MainWindow::startDataEditorHandler()
else
{
QString caption = "Find Data File";
QString filter = "Data File (*.csv *.txt *.tsv *.sav *.ods *.xls *.xlsx)";
QString filter = "Data File (*.csv *.txt *.tsv *.sav *.ods *.xls *.xlsx)";

dataFilePath = MessageForwarder::browseOpenFile(caption, "", filter);
if (dataFilePath == "")
Expand Down
2 changes: 0 additions & 2 deletions Engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ if(WINDOWS)
${CMAKE_BINARY_DIR}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${RTOOLS_LIBREADSTAT_DLL}
${CMAKE_BINARY_DIR}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${RTOOLS_LIBFREEXL_DLL}
${CMAKE_BINARY_DIR}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${RTOOLS_ZLIB_DLL}
${CMAKE_BINARY_DIR}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${RTOOLS_LIBICONV_DLL}
Expand Down
1 change: 0 additions & 1 deletion Tools/CMake/Install.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,6 @@ if(WIN32)
${RTOOLS_LIBWINPTHREAD_DLL}
#${RTOOLS_LIBJSONCPP_DLL}
${RTOOLS_LIBREADSTAT_DLL}
${RTOOLS_LIBFREEXL_DLL}
${RTOOLS_ZLIB_DLL}
${RTOOLS_LIBICONV_DLL}
${_LIB_R_INTERFACE_DLL}
Expand Down
4 changes: 2 additions & 2 deletions Tools/CMake/Libraries.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ endif()
find_package(ZLIB 1.2 REQUIRED)
find_package(Iconv 1.16 REQUIRED)
find_package(SQLite3 3.37.0 REQUIRED)
find_package(freexl 2.0.0 REQUIRED)

#if(USE_CONAN)
# find_package(jsoncpp 1.9 REQUIRED)
Expand Down Expand Up @@ -215,7 +216,7 @@ if(LINUX)
message(CHECK_FAIL "not found")
message(
FATAL_ERROR
"FreeXl is required for building on Linux, please follow the build instruction before you continue."
"FreeXL is required for building on Linux, please follow the build instruction before you continue."
)
endif()

Expand All @@ -229,7 +230,6 @@ if(APPLE)
message(CHECK_START "Looking for 'libbrotlicommon'")

find_package(Brotli 1.0.9 REQUIRED)
find_package(Freexl 2.0.0 REQUIRED)

endif()

Expand Down

0 comments on commit 031fc6b

Please sign in to comment.