Skip to content

Commit

Permalink
Fix progress dialog for imports of very large CSV files
Browse files Browse the repository at this point in the history
QProgressDialog only takes an int as the maximum value and the current
value. So using the number of bytes parsed so far isn't going to work
for very large files when an int will overflow. This commit changes this
by precalculating a progress indicator and handing that over to the
QProgressDialog object.

See issue #1212.
  • Loading branch information
MKleusberg committed Nov 2, 2017
1 parent fae7235 commit 60ce9c8
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/ImportCsvDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,14 @@ void rollback(
class CSVImportProgress : public CSVProgress
{
public:
explicit CSVImportProgress(qint64 filesize)
explicit CSVImportProgress(unsigned long long filesize)
: totalFileSize(filesize)
{
m_pProgressDlg = new QProgressDialog(
QObject::tr("Importing CSV file..."),
QObject::tr("Cancel"),
0,
filesize);
10000);
m_pProgressDlg->setWindowModality(Qt::ApplicationModal);
}

Expand All @@ -139,7 +140,7 @@ class CSVImportProgress : public CSVProgress

bool update(unsigned long long pos)
{
m_pProgressDlg->setValue(pos);
m_pProgressDlg->setValue(static_cast<int>((static_cast<float>(pos) / static_cast<float>(totalFileSize)) * 10000.0f));
qApp->processEvents();

return !m_pProgressDlg->wasCanceled();
Expand All @@ -152,6 +153,8 @@ class CSVImportProgress : public CSVProgress

private:
QProgressDialog* m_pProgressDlg;

unsigned long long totalFileSize;
};

void ImportCsvDialog::accept()
Expand Down

0 comments on commit 60ce9c8

Please sign in to comment.