From 9e2beb6c814457355ed3d2f4462b864c8dd3037c Mon Sep 17 00:00:00 2001 From: Martin Kleusberg Date: Sat, 5 Jan 2013 14:37:58 +0100 Subject: [PATCH] Fix a few bugs in the CSV import Start numbering the rows in the preview table view of the ImportCSVForm with #1 instead of 0. Don't create too many columns when filling the preview table view. Keep the UI responsive when reading a CSV file. This way the progress dialog can be seen, too. Don't crash when reading files without an empty line at their end. --- src/ImportCSVForm.cpp | 6 ++---- src/sqlitedb.cpp | 5 +++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/ImportCSVForm.cpp b/src/ImportCSVForm.cpp index 4bb5fad1..0087a99d 100644 --- a/src/ImportCSVForm.cpp +++ b/src/ImportCSVForm.cpp @@ -185,10 +185,8 @@ void importCSVForm::preview() int maxrecs = 20; curList = pdb->decodeCSV(csvfilename, sep, quote, maxrecs, &numfields); - //qDebug("count = %d, numfields = %d", curList .count(), numfields); - previewTable->clear(); - previewTable->setColumnCount(curList.size()); + previewTable->setColumnCount(numfields); //can not operate on an empty result if (numfields==0) return; @@ -206,7 +204,7 @@ void importCSVForm::preview() int rowNum = 0; int colNum = 0; for ( QStringList::Iterator ct = curList .begin(); ct != curList .end(); ++ct ) { - if (colNum==0) previewTable->setVerticalHeaderItem( rowNum, new QTableWidgetItem( QString::number(rowNum) ) ); + if (colNum==0) previewTable->setVerticalHeaderItem( rowNum, new QTableWidgetItem( QString::number(rowNum+1) ) ); previewTable->setItem(rowNum, colNum, new QTableWidgetItem( *ct ) ); colNum++; if (colNum==numfields) diff --git a/src/sqlitedb.cpp b/src/sqlitedb.cpp index 1c7d3ef2..3317722d 100644 --- a/src/sqlitedb.cpp +++ b/src/sqlitedb.cpp @@ -733,8 +733,8 @@ QStringList DBBrowserDB::decodeCSV(const QString & csvfilename, char sep, char q QProgressDialog progress("Decoding CSV file...", "Cancel", 0, file.size()); progress.setWindowModality(Qt::ApplicationModal); char c=0; - while ( c!=-1) { - file.getChar(&c); + while(file.getChar(&c)) + { if (c==quote){ if (inquotemode){ if (inescapemode){ @@ -778,6 +778,7 @@ QStringList DBBrowserDB::decodeCSV(const QString & csvfilename, char sep, char q } recs++; progress.setValue(file.pos()); + qApp->processEvents(); if (progress.wasCanceled()) break; if ((recs>maxrecords)&&(maxrecords!=-1)) { break;