Wt examples  3.7.1
Classes | Functions
Charts example

Classes

class  ChartConfig
 A class that allows configuration of a cartesian chart. More...
 
class  TimeSeriesExample
 A widget that demonstrates a times series chart. More...
 
class  CategoryExample
 A Widget that demonstrates a category chart. More...
 
class  ScatterPlotExample
 A Widget that demonstrates a scatter plot. More...
 
class  PieExample
 A Widget that demonstrates a Pie chart. More...
 
class  ChartsExample
 A widget that demonstrates various aspects of the charting lib. More...
 

Functions

void readFromCsv (std::istream &f, Wt::WAbstractItemModel *model, int numRows=-1, bool firstLineIsHeaders=true)
 Utility function that reads a model from a CSV file. More...
 

Detailed Description

Function Documentation

◆ readFromCsv()

void readFromCsv ( std::istream &  f,
Wt::WAbstractItemModel model,
int  numRows = -1,
bool  firstLineIsHeaders = true 
)

Utility function that reads a model from a CSV file.

Definition at line 56 of file CsvUtil.C.

58 {
59  int csvRow = 0;
60 
61  while (f) {
62  std::string line;
63  getline(f, line);
64 
65  if (f) {
66  typedef boost::tokenizer<boost::escaped_list_separator<char> >
67  CsvTokenizer;
68  CsvTokenizer tok(line);
69 
70  int col = 0;
71  for (CsvTokenizer::iterator i = tok.begin();
72  i != tok.end(); ++i, ++col) {
73 
74  if (col >= model->columnCount())
75  model->insertColumns(model->columnCount(),
76  col + 1 - model->columnCount());
77 
78  if (firstLineIsHeaders && csvRow == 0)
79  model->setHeaderData(col, boost::any(Wt::WString::fromUTF8(*i)));
80  else {
81  int dataRow = firstLineIsHeaders ? csvRow - 1 : csvRow;
82 
83  if (numRows != -1 && dataRow >= numRows)
84  return;
85 
86  if (dataRow >= model->rowCount())
87  model->insertRows(model->rowCount(),
88  dataRow + 1 - model->rowCount());
89 
90  boost::any data(Wt::WString::fromUTF8(*i));
91  model->setData(dataRow, col, data);
92  }
93  }
94  }
95 
96  ++csvRow;
97  }
98 }
virtual bool insertColumns(int column, int count, const WModelIndex &parent=WModelIndex())
static WString fromUTF8(const std::string &value, bool checkValid=false)
virtual bool insertRows(int row, int count, const WModelIndex &parent=WModelIndex())
virtual bool setData(const WModelIndex &index, const cpp17::any &value, ItemDataRole role=ItemDataRole::Edit)
virtual int rowCount(const WModelIndex &parent=WModelIndex()) const=0
virtual int columnCount(const WModelIndex &parent=WModelIndex()) const=0
virtual bool setHeaderData(int section, Orientation orientation, const cpp17::any &value, ItemDataRole role=ItemDataRole::Edit)

Generated on Tue Dec 15 2020 for the C++ Web Toolkit (Wt) by doxygen 1.8.13