Visual optimisation for the CSV import process

When importing multiple CSV files at once, remove each entry from the
list of CSV files as its import completes. This way people can see the
list shrink visibly onscreen.

Also don't close the window if there are still files left to be
imported. This allows the user to import unchecked files, too, probably
using different settings.

See issue #1072.
This commit is contained in:
Martin Kleusberg
2017-09-19 21:43:30 +02:00
parent 969d3e470a
commit 8f82f26d4f
2 changed files with 26 additions and 8 deletions

View File

@@ -171,18 +171,37 @@ void ImportCsvDialog::accept()
// Get all the selected files and start the import
if (ui->filePickerBlock->isVisible())
{
bool filesLeft = false;
// Loop through all the rows in the file picker list
for (int i = 0; i < ui->filePicker->count(); i++) {
auto item = ui->filePicker->item(i);
if (item->checkState() == Qt::Checked) {
int row = ui->filePicker->row(item);
// Check for files that aren't hidden (=imported) yet but that are checked and thus marked for import
if (item->checkState() == Qt::Checked && !ui->filePicker->isRowHidden(row)) {
importCsv(item->data(Qt::DisplayRole).toString(), item->data(Qt::UserRole).toString());
// Hide each row after it's done
ui->filePicker->setRowHidden(row, true);
} else if(!ui->filePicker->isRowHidden(row)) {
// Check for files that aren't hidden yet but that aren't checked either. These are files that are still left
// to be imported
filesLeft = true;
}
}
}
else
{
// Don't close the window if there are still files left to be imported
if(filesLeft)
{
QApplication::restoreOverrideCursor(); // restore original cursor
return;
}
} else {
importCsv(csvFilenames.first());
}
QMessageBox::information(this, QApplication::applicationName(), tr("Import completed"));
QApplication::restoreOverrideCursor(); // restore original cursor
QDialog::accept();
}

View File

@@ -1174,12 +1174,11 @@ void MainWindow::importTableFromCSV()
validFiles.append(file);
}
if (!validFiles.isEmpty()) {
if (!validFiles.isEmpty())
{
ImportCsvDialog dialog(validFiles, &db, this);
if (dialog.exec()) {
if (dialog.exec())
populateTable();
QMessageBox::information(this, QApplication::applicationName(), tr("Import completed"));
}
}
}