@@ -82,6 +82,11 @@ void QgsDelimitedTextFile::close()
82
82
delete mWatcher ;
83
83
mWatcher = 0 ;
84
84
}
85
+ mLineNumber = -1 ;
86
+ mRecordLineNumber = -1 ;
87
+ mRecordNumber = -1 ;
88
+ mMaxRecordNumber = -1 ;
89
+ mHoldCurrentRecord = false ;
85
90
}
86
91
87
92
bool QgsDelimitedTextFile::open ()
@@ -95,25 +100,24 @@ bool QgsDelimitedTextFile::open()
95
100
QgsDebugMsg ( " Data file " + mFileName + " could not be opened" );
96
101
delete mFile ;
97
102
mFile = 0 ;
98
- return false ;
99
- }
100
- mStream = new QTextStream ( mFile );
101
- if ( ! mEncoding .isEmpty () )
102
- {
103
- QTextCodec *codec = QTextCodec::codecForName ( mEncoding .toAscii () );
104
- mStream ->setCodec ( codec );
105
103
}
106
- mMaxRecordNumber = -1 ;
107
- mHoldCurrentRecord = false ;
108
- if ( mWatcher ) delete mWatcher ;
109
- if ( mUseWatcher )
104
+ if ( mFile )
110
105
{
111
- mWatcher = new QFileSystemWatcher ( this );
112
- mWatcher ->addPath ( mFileName );
113
- connect ( mWatcher , SIGNAL ( fileChanged ( QString ) ), this , SLOT ( updateFile () ) );
106
+ mStream = new QTextStream ( mFile );
107
+ if ( ! mEncoding .isEmpty () )
108
+ {
109
+ QTextCodec *codec = QTextCodec::codecForName ( mEncoding .toAscii () );
110
+ mStream ->setCodec ( codec );
111
+ }
112
+ if ( mUseWatcher )
113
+ {
114
+ mWatcher = new QFileSystemWatcher ( this );
115
+ mWatcher ->addPath ( mFileName );
116
+ connect ( mWatcher , SIGNAL ( fileChanged ( QString ) ), this , SLOT ( updateFile () ) );
117
+ }
114
118
}
115
119
}
116
- return true ;
120
+ return mFile != 0 ;
117
121
}
118
122
119
123
void QgsDelimitedTextFile::updateFile ()
@@ -501,6 +505,7 @@ int QgsDelimitedTextFile::fieldIndex( QString name )
501
505
502
506
bool QgsDelimitedTextFile::setNextRecordId ( long nextRecordId )
503
507
{
508
+ if ( ! mFile ) return false ;
504
509
mHoldCurrentRecord = nextRecordId == mRecordLineNumber ;
505
510
if ( mHoldCurrentRecord ) return true ;
506
511
return setNextLineNumber ( nextRecordId );
@@ -524,7 +529,7 @@ QgsDelimitedTextFile::Status QgsDelimitedTextFile::nextRecord( QStringList &reco
524
529
// Find the first non-blank line to read
525
530
QString buffer;
526
531
status = nextLine ( buffer, true );
527
- if ( status != RecordOk ) return status ;
532
+ if ( status != RecordOk ) return RecordEOF ;
528
533
529
534
mCurrentRecord .clear ();
530
535
mRecordLineNumber = mLineNumber ;
0 commit comments