Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Let users know if no data displayed because all records are badly for…
…matted
  • Loading branch information
ccrook committed Apr 26, 2013
1 parent 56f4a5e commit f7dc548
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/providers/delimitedtext/qgsdelimitedtextsourceselect.cpp
Expand Up @@ -36,6 +36,7 @@ QgsDelimitedTextSourceSelect::QgsDelimitedTextSourceSelect( QWidget * parent, Qt
QDialog( parent, fl ),
mFile( new QgsDelimitedTextFile() ),
mExampleRowCount( 20 ),
mBadRowCount( 0 ),
mPluginKey( "/Plugin-DelimitedText" ),
mLastFileType( "" )
{
Expand Down Expand Up @@ -394,14 +395,15 @@ void QgsDelimitedTextSourceSelect::updateFieldLists()
QList<bool> isValidWkt;
QList<bool> isEmpty;
int counter = 0;
mBadRowCount = 0;
QStringList values;
QRegExp wktre( "^\\s*(?:MULTI)?(?:POINT|LINESTRING|POLYGON)\\s*Z?\\s*M?\\(", Qt::CaseInsensitive );

while ( counter < mExampleRowCount )
{
QgsDelimitedTextFile::Status status = mFile->nextRecord( values );
if ( status == QgsDelimitedTextFile::RecordEOF ) break;
if ( status != QgsDelimitedTextFile::RecordOk ) continue;
if ( status != QgsDelimitedTextFile::RecordOk ) { mBadRowCount++; continue; }
counter++;

// Look at count of non-blank fields
Expand Down Expand Up @@ -692,6 +694,10 @@ bool QgsDelimitedTextSourceSelect::validate()
else if ( tblSample->rowCount() == 0 )
{
message = tr( "No data found in file" );
if( mBadRowCount > 0 )
{
message = message + " (" + tr("%1 badly formatted records discarded").arg(mBadRowCount)+")";
}
}
else if ( geomTypeXY->isChecked() && ( cmbXField->currentText().isEmpty() || cmbYField->currentText().isEmpty() ) )
{
Expand All @@ -708,6 +714,11 @@ bool QgsDelimitedTextSourceSelect::validate()
else
{
enabled = true;
if( mBadRowCount > 0 )
{
message = tr("%1 badly formatted records discarded from sample data").arg(mBadRowCount);
}

}
lblStatus->setText( message );
return enabled;
Expand Down
1 change: 1 addition & 0 deletions src/providers/delimitedtext/qgsdelimitedtextsourceselect.h
Expand Up @@ -50,6 +50,7 @@ class QgsDelimitedTextSourceSelect : public QDialog, private Ui::QgsDelimitedTex
private:
QgsDelimitedTextFile *mFile;
int mExampleRowCount;
int mBadRowCount;
QString mPluginKey;
QString mLastFileType;

Expand Down

0 comments on commit f7dc548

Please sign in to comment.