@@ -35,29 +35,29 @@ class QTextStream;
35
35
* for parsing each record. The following options are supported:
36
36
* - Basic whitespace parsing. Each line in the file is treated as a record.
37
37
* Extracts all contiguous sequences of non-whitespace
38
- * characters. Leading and trailing whitespace are ignored.
39
- * - Regular expression parsing. Each line in the file is treated as a record.
40
- * The string is split into fields based on a regular expression.
41
- * - Character delimited, based on a delimiter character set, a quote character, and
38
+ * characters. Leading and trailing whitespace are ignored.
39
+ * - Regular expression parsing. Each line in the file is treated as a record.
40
+ * The string is split into fields based on a regular expression.
41
+ * - Character delimited, based on a delimiter character set, a quote character, and
42
42
* an escape character. The escape treats the next character as a part of a field.
43
- * Fields may start and end with quote characters, in which case any non-escaped
43
+ * Fields may start and end with quote characters, in which case any non-escaped
44
44
* character within the field is treated literally, including end of line characters.
45
45
* The escape character within a string causes the next character to be read literally
46
- * (this includes new line characters). If the escape and quote characters are the
47
- * same, then only quote characters will be escaped (ie to include a quote in a
46
+ * (this includes new line characters). If the escape and quote characters are the
47
+ * same, then only quote characters will be escaped (ie to include a quote in a
48
48
* quoted field it is entered as two quotes. All other characters in quoted fields
49
49
* are treated literally, including newlines.
50
50
* - CSV format files - these are a special case of character delimited, in which the
51
51
* delimiter is a comma, and the quote and escape characters are double quotes (")
52
52
*
53
- * The delimiters can be encode in and decoded from a QUrl as query items. The
53
+ * The delimiters can be encode in and decoded from a QUrl as query items. The
54
54
* items used are:
55
- * - delimiterType, one of plain (delimiter is any of a set of characters),
55
+ * - delimiterType, one of plain (delimiter is any of a set of characters),
56
56
* regexp, csv, whitespace
57
57
* - delimiter, interpreted according to the type. For plain characters this is
58
58
* a sequence of characters. The string \t in the sequence is replaced by a tab.
59
- * For regexp type delimiters this specifies the reqular expression.
60
- * The field is ignored for csv and whitespace
59
+ * For regexp type delimiters this specifies the reqular expression.
60
+ * The field is ignored for csv and whitespace
61
61
* - quoteChar, optional, a single character used for quoting plain fields
62
62
* - escapeChar, optional, a single characer used for escaping (may be the same as quoteChar)
63
63
*/
@@ -66,10 +66,10 @@ class QTextStream;
66
66
// on an abstract base class in order to facilitate changing the type of the parser easily
67
67
// eg in the provider dialog
68
68
69
- class QgsDelimitedTextFile
69
+ class QgsDelimitedTextFile
70
70
{
71
71
72
- public:
72
+ public:
73
73
74
74
enum Status
75
75
{
@@ -91,14 +91,16 @@ class QgsDelimitedTextFile
91
91
92
92
virtual ~QgsDelimitedTextFile ();
93
93
94
- /* * Set the filename
94
+ /* * Set the filename
95
95
* @param filename the name of the file
96
96
*/
97
97
void setFileName ( QString filename );
98
- /* * Return the filename
98
+ /* * Return the filename
99
99
* @return filename the name of the file
100
100
*/
101
- QString fileName (){ return mFileName ; }
101
+ QString fileName () {
102
+ return mFileName ;
103
+ }
102
104
103
105
/* * Decode the parser settings from a url as a string
104
106
* @param url The url from which the delimiter and delimiterType items are read
@@ -125,7 +127,7 @@ class QgsDelimitedTextFile
125
127
/* * Set the parser to use a character type delimiter.
126
128
* @param delim The field delimiter character set
127
129
* @param quote The quote character, used to define quoted fields
128
- * @param escape The escape character used to escape quote or delim
130
+ * @param escape The escape character used to escape quote or delim
129
131
* characters.
130
132
*/
131
133
void setTypeCSV ( QString delim=QString(" ," ), QString quote=QString(" \" " ), QString escape=QString(" \" " ) );
@@ -136,11 +138,15 @@ class QgsDelimitedTextFile
136
138
* return an unlimited number of fields
137
139
* @param maxFields The maximum number of fields into which a record will be split
138
140
*/
139
- void setMaxFields ( int maxFields ){ mMaxFields = maxFields; }
141
+ void setMaxFields ( int maxFields ) {
142
+ mMaxFields = maxFields;
143
+ }
140
144
/* Return the maximum number of fields to return
141
- * @return maxFields The maximum number of fields to return
145
+ * @return maxFields The maximum number of fields to return
142
146
*/
143
- int maxFields (){ return mMaxFields ; }
147
+ int maxFields () {
148
+ return mMaxFields ;
149
+ }
144
150
145
151
/* Set the number of header lines to skip
146
152
* @param skiplines The maximum lines to skip
@@ -149,7 +155,9 @@ class QgsDelimitedTextFile
149
155
/* Return the number of header lines to skip
150
156
* @return skiplines The maximum lines to skip
151
157
*/
152
- int skipLines (){ return mSkipLines ; }
158
+ int skipLines () {
159
+ return mSkipLines ;
160
+ }
153
161
154
162
/* Set reading column names from the first record
155
163
* @param useheaders Column names will be read if true
@@ -158,15 +166,17 @@ class QgsDelimitedTextFile
158
166
/* Return the option for reading column names from the first record
159
167
* @return useheaders Column names will be read if true
160
168
*/
161
- bool useHeader (){ return mUseHeader ; }
169
+ bool useHeader () {
170
+ return mUseHeader ;
171
+ }
162
172
163
173
/* * Return the column names read from the header, or default names
164
174
* Col## if none defined. Will open and read the head of the file
165
175
* if required, then reset..
166
176
*/
167
177
QStringList &columnNames ();
168
178
169
- /* * Reads the next record from the stream splits into string fields.
179
+ /* * Reads the next record from the stream splits into string fields.
170
180
* @param fields The string list to populate with the fields
171
181
* @return status The result of trying to parse a record. RecordOk
172
182
* if read successfully, RecordEOF if reached the end of the
@@ -178,7 +188,9 @@ class QgsDelimitedTextFile
178
188
/* * Return the line number of the start of the last record read
179
189
* @return linenumber The line number of the start of the record
180
190
*/
181
- int recordLineNumber (){ return mRecordLineNumber ; }
191
+ int recordLineNumber () {
192
+ return mRecordLineNumber ;
193
+ }
182
194
183
195
/* * Reset the file to reread from the beginning
184
196
*/
@@ -192,15 +204,21 @@ class QgsDelimitedTextFile
192
204
* or a string)
193
205
* @return def The delimiter definition string
194
206
*/
195
- QString delimiterDefinitionString (){ return mDelimDefinition ; }
207
+ QString delimiterDefinitionString () {
208
+ return mDelimDefinition ;
209
+ }
196
210
/* * Return the quote character
197
211
* @return quote The quoet character
198
212
*/
199
- QString quoteChar (){ return mQuoteChar ; }
213
+ QString quoteChar () {
214
+ return mQuoteChar ;
215
+ }
200
216
/* * Return the escape character
201
217
* @return escape The escape character
202
218
*/
203
- QString escapeChar (){ return mEscapeChar ; }
219
+ QString escapeChar () {
220
+ return mEscapeChar ;
221
+ }
204
222
205
223
/* * Check that provider is valid (filename and definition valid)
206
224
*
@@ -209,7 +227,7 @@ class QgsDelimitedTextFile
209
227
bool isValid ();
210
228
211
229
212
- private:
230
+ private:
213
231
214
232
/* * Open the file
215
233
*
@@ -243,7 +261,7 @@ class QgsDelimitedTextFile
243
261
QString mFileName ;
244
262
QFile *mFile ;
245
263
QTextStream *mStream ;
246
-
264
+
247
265
// Parameters common to parsers
248
266
bool mDefinitionValid ;
249
267
DelimiterType mType ;
@@ -260,6 +278,6 @@ class QgsDelimitedTextFile
260
278
261
279
// Information extracted from file
262
280
QStringList mColumnNames ;
263
- int mRecordLineNumber ;
264
281
int mLineNumber ;
282
+ int mRecordLineNumber ;
265
283
};
0 commit comments