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.
This commit is contained in:
Martin Kleusberg
2013-01-05 14:37:58 +01:00
parent a836837b57
commit 9e2beb6c81
2 changed files with 5 additions and 6 deletions

View File

@@ -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)

View File

@@ -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;