Added support of optional header names when importing CSV file.
This commit is contained in:
@ -52,6 +52,11 @@ bool CsvParser::isCsvCompatible(const rapidcsv::Document& doc) {
|
||||
qInfo() << "Checking CSV document for compatiblity...";
|
||||
const std::vector<std::string> columnNames = doc.GetColumnNames();
|
||||
for (const QString& headerName : GET_HEADER_NAMES()) {
|
||||
if (OPTIONAL_CSV_HEADERS.contains(headerName)) {
|
||||
/// no need to have a column for the optional values
|
||||
continue;
|
||||
}
|
||||
/// these column must be found in CSV document
|
||||
bool isHeaderNameFound = false;
|
||||
if (std::find(columnNames.begin(), columnNames.end(), headerName) != columnNames.end()) {
|
||||
qDebug() << QString("Header found in column names: %1").arg(headerName);
|
||||
@ -86,14 +91,13 @@ QHash<QString, std::vector<std::string>> CsvParser::extractColumnValues(
|
||||
const rapidcsv::Document& doc) {
|
||||
QHash<QString, std::vector<std::string>> columnValueMap;
|
||||
for (const QString& columnName : headerNames) {
|
||||
// TODO add support for optional columns
|
||||
// if (optionalCsvHeaderNames.contains(columnName)) {
|
||||
// const std::vector<std::string> columnNames = doc.GetColumnNames();
|
||||
// int columnIdx = doc.GetColumnIdx(columnName.toStdString());
|
||||
// if (columnIdx == -1) {
|
||||
// continue;
|
||||
// }
|
||||
// }
|
||||
if (OPTIONAL_CSV_HEADERS.contains(columnName)) {
|
||||
const std::vector<std::string> columnNames = doc.GetColumnNames();
|
||||
int columnIdx = doc.GetColumnIdx(columnName.toStdString());
|
||||
if (columnIdx == -1) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
const std::vector<std::string> columnValues =
|
||||
doc.GetColumn<std::string>(columnName.toStdString());
|
||||
columnValueMap.insert(columnName, columnValues);
|
||||
|
||||
Reference in New Issue
Block a user