35 CSVFile(
const QString &fileName) { mHasCaptions =
true; mFlat =
false; mFixedWidth=
false;
loadFile(fileName);}
37 bool openFile(
const QString &fileName);
43 bool flat()
const {
return mFlat; }
47 QStringList
captions()
const {
return mCaptions; }
48 QStringList
column(
const int col)
const;
52 void setFixedWidth(
const bool hasFixedWidth) { mFixedWidth = hasFixedWidth; }
53 void setFlat(
const bool isflat) { mFlat = isflat; }
56 bool loadFile(
const QString &fileName);
58 QString
columnName(
const int col) {
if (col<mColCount)
return mCaptions[col];
return QString(); }
64 QVariant
value(
const int row,
const int col)
const;
65 QVariant
row(
const int row);
66 QJSValue
jsValue(
const int row,
const int col)
const;
70 void saveFile(
const QString &fileName);
79 QStringList mCaptions;
Provides access to table data stored in text files (CSV style).
Definition: csvfile.h:27
void setFixedWidth(const bool hasFixedWidth)
Definition: csvfile.h:52
void saveFile(const QString &fileName)
save the current content to a file
Definition: csvfile.cpp:336
CSVFile(QObject *parent=0)
Definition: csvfile.cpp:56
QStringList captions() const
returns true when no valid file has been loaded (returns false when a file with 0 rows is loaded)
Definition: csvfile.h:47
int colCount
Definition: csvfile.h:31
int columnIndex(const QString &columnName) const
index of column or -1 if not available
Definition: csvfile.h:59
bool next()
advance to next record (i.e. line). return false if end of file is reached.
QStringList column(const int col) const
retrieve a string list of a given row
Definition: csvfile.cpp:285
bool captions
if true, the first line are considered to be headers
Definition: csvfile.h:29
QJSValue jsValue(const int row, const QString column_name) const
Definition: csvfile.h:67
bool flat
if true, there is only one column (a flat file)
Definition: csvfile.h:30
bool streamingMode() const
return true, if in "streaming mode" (for large files)
Definition: csvfile.h:41
bool hasCaptions() const
true, if first line contains headers
Definition: csvfile.h:42
bool isEmpty() const
Definition: csvfile.h:46
QString columnName(const int col)
get caption of ith column.
Definition: csvfile.h:58
QVariant row(const int row)
retrieve content of the full row row as a QJSValue
Definition: csvfile.cpp:253
void setFlat(const bool isflat)
Definition: csvfile.h:53
bool flat() const
simple list, not multiple columns
Definition: csvfile.h:43
CSVFile(const QString &fileName)
ctor, load fileName.
Definition: csvfile.h:35
void setHasCaptions(const bool hasCaps)
Definition: csvfile.h:51
bool openFile(const QString &fileName)
open file in streaming mode.
Definition: csvfile.cpp:278
static void addToScriptEngine(QJSEngine &engine)
Definition: csvfile.cpp:44
int rowCount() const
number or rows (excl. captions), or -1.
Definition: csvfile.h:44
void setValue(const int row, const int col, QVariant value)
set the value of the column
Definition: csvfile.cpp:293
QVariant colValue(const int col)
get value of column with index col. Use in streaming mode.
QVariantList values(const int row) const
get a list of the values in row "row"
Definition: csvfile.cpp:149
bool loadFile(const QString &fileName)
load fileName. load the complete file at once.
Definition: csvfile.cpp:139
int colCount() const
number of columns, or -1
Definition: csvfile.h:45
QJSValue jsValue(const int row, const int col) const
Definition: csvfile.cpp:267
QVariant value(const int row, const QString column_name) const
Definition: csvfile.h:61
bool loadFromString(const QString &content)
load content from a given string.
Definition: csvfile.cpp:74
int rowCount
Definition: csvfile.h:32