#include <iostream>
Go to the source code of this file.
std::shared_ptr<WStandardItemModel> csvToModel |
( |
const std::string & |
csvFile, |
|
|
bool |
firstLineIsHeader = true |
|
) |
| |
Definition at line 40 of file CsvUtil.C.
43 std::ifstream f(csvFile.c_str());
46 std::shared_ptr<WStandardItemModel> result = std::make_shared<WStandardItemModel>(0, 0);
47 result->setItemPrototype(cpp14::make_unique<NumericItem>());
void readFromCsv(std::istream &f, std::shared_ptr< WAbstractItemModel > model, int numRows, bool firstLineIsHeaders)
void readFromCsv |
( |
std::istream & |
f, |
|
|
std::shared_ptr< WAbstractItemModel > |
model, |
|
|
int |
numRows = -1 , |
|
|
bool |
firstLineIsHeaders = true |
|
) |
| |
Definition at line 54 of file CsvUtil.C.
64 typedef boost::tokenizer<boost::escaped_list_separator<char> >
66 CsvTokenizer tok(line);
69 for (CsvTokenizer::iterator i = tok.begin();
70 i != tok.end(); ++i, ++col) {
72 if (col >= model->columnCount())
73 model->insertColumns(model->columnCount(),
74 col + 1 - model->columnCount());
76 if (firstLineIsHeaders && csvRow == 0)
77 model->setHeaderData(col, cpp17::any{
WString{*i}});
79 int dataRow = firstLineIsHeaders ? csvRow - 1 : csvRow;
81 if (numRows != -1 && dataRow >= numRows)
84 if (dataRow >= model->rowCount())
85 model->insertRows(model->rowCount(),
86 dataRow + 1 - model->rowCount());
89 model->setData(dataRow, col, data);