Fix progress dialog for imports of very large CSV files

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.
This commit is contained in:
Martin Kleusberg
2017-11-02 22:56:39 +01:00
parent fae7235548
commit 60ce9c869b

View File

@@ -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);
}
@@ -139,7 +140,7 @@ public:
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();
@@ -152,6 +153,8 @@ public:
private:
QProgressDialog* m_pProgressDlg;
unsigned long long totalFileSize;
};
void ImportCsvDialog::accept()