Skip to content

Commit

Permalink
[CORRECTIVE] Fix csv import in table editors.
Browse files Browse the repository at this point in the history
  • Loading branch information
hagantsa committed Jul 1, 2024
1 parent fc14c8a commit 02d83b1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 25 deletions.
42 changes: 25 additions & 17 deletions common/views/EditableTableView/editabletableview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -769,35 +769,43 @@ void EditableTableView::onCSVImport(const QString& filePath)
Q_ASSERT(targetModel);

int columnCount = targetModel->columnCount(QModelIndex());
QList<QStringList> rowsToBeAdded;

while (!stream.atEnd())
// Validate csv first
while (!stream.atEnd())
{
QString line = stream.readLine();
while (line.count(QLatin1Char(';')) < columnCount && !stream.atEnd())
QString line = stream.readLine();
QStringList items = line.split(";");

if (items.size() != columnCount)
{
line.append(QStringLiteral("\n"));
line.append(stream.readLine());
QMessageBox::critical(this, tr("Error importing file"), tr("Could not import '%1': invalid formatting").arg(target));
file.close();
QApplication::restoreOverrideCursor();
return;
}

QStringList items = line.split(";");

// add a new empty row
// data is always added to the last row
emit addItem(QModelIndex());
int rowCount = targetModel->rowCount(QModelIndex());
rowsToBeAdded.append(items);
}

// Add data if csv was valid
for (auto const& row : rowsToBeAdded)
{
emit addItem(QModelIndex());
int rowCount = targetModel->rowCount(QModelIndex());

for (int column = 0; column < columnCount && column < items.size(); ++column)
for (int column = 0; column < columnCount; ++column)
{
QString item = items.at(column);
QString item = row.at(column);
if (item.startsWith(QLatin1Char('"')) && item.endsWith(QLatin1Char('"')))
{
item = item.mid(1, item.length() - 2);
}

QModelIndex index = targetModel->index(rowCount - 1, column, QModelIndex());
targetModel->setData(index, item, Qt::EditRole);
}
}
QModelIndex index = targetModel->index(rowCount - 1, column, QModelIndex());
targetModel->setData(index, item, Qt::EditRole);
}
}

file.close();

Expand Down
16 changes: 8 additions & 8 deletions version.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@
#ifndef VERSIONNO__H
#define VERSIONNO__H

#define VERSION_FULL 3.13.427.0
#define VERSION_FULL 3.13.435.0

#define VERSION_BASEYEAR 0
#define VERSION_DATE "2024-06-28"
#define VERSION_TIME "13:52:57"
#define VERSION_DATE "2024-07-01"
#define VERSION_TIME "13:29:28"

#define VERSION_MAJOR 3
#define VERSION_MINOR 13
#define VERSION_BUILDNO 427
#define VERSION_BUILDNO 435
#define VERSION_EXTEND 0

#define VERSION_FILE 3,13,427,0
#define VERSION_PRODUCT 3,13,427,0
#define VERSION_FILESTR "3,13,427,0"
#define VERSION_PRODUCTSTR "3,13,427,0"
#define VERSION_FILE 3,13,435,0
#define VERSION_PRODUCT 3,13,435,0
#define VERSION_FILESTR "3,13,435,0"
#define VERSION_PRODUCTSTR "3,13,435,0"

#endif

0 comments on commit 02d83b1

Please sign in to comment.