OpenCurves  0.9
plotfile.h
1 //
2 // author Kazys Stepanas
3 //
4 // Copyright (c) CSIRO 2015
5 //
6 #ifndef PLOTFILE_H
7 #define PLOTFILE_H
8 
9 #include "ocurvesconfig.h"
10 
11 #include "stringitems.h"
12 
13 #include <QTextStream>
14 
15 #include <vector>
16 
17 #include <QFile>
18 #include <QString>
19 #include <QStringList>
20 
51 class PlotFile
52 {
53 public:
56  {
60  OptUseLocale = (1 << 0)
61  };
62 
66  PlotFile(const QString &fileName, unsigned options = 0);
67 
69  ~PlotFile();
70 
73  bool isOpen() const;
74 
77  qint64 fileSize() const;
78 
86  qint64 filePos() const;
87 
94  qint64 streamPos() const;
95 
99  void streamSeek(qint64 pos);
100 
104  bool readLine();
105 
125  bool generateHeadings(QStringList &headings);
126 
129  const QString &currentLine() const;
130 
140  void dataLine(std::vector<double> &data);
141 
154  static void dataLine(QString &line, std::vector<double> &data, bool useSystemLocale);
155 
156 protected:
157  QFile _file;
158  QTextStream _stream;
159  QString _line;
160  unsigned _options;
161 };
162 
163 #endif // PLOTFILE_H
QString _line
Last read line (readLine()).
Definition: plotfile.h:159
void dataLine(std::vector< double > &data)
Converts the currently cached line into double precision data values.
~PlotFile()
Destructor.
bool generateHeadings(QStringList &headings)
Generates headings for the plot file.
qint64 fileSize() const
Returns the overall file size in bytes.
QFile _file
The file object.
Definition: plotfile.h:157
qint64 filePos() const
Returns the current buffered byte position in the file.
const QString & currentLine() const
Returns the last line read from the file (after readLine()).
Use the current QLocale for parsing rather than the C locale.
Definition: plotfile.h:60
QTextStream _stream
Stream wrapping the file object.
Definition: plotfile.h:158
OptionFlag
Enumeration of option flags used to control file loading.
Definition: plotfile.h:55
void streamSeek(qint64 pos)
Sets the stream position to pos.
The PlotFile supports loading of data series from a CSV style text file.
Definition: plotfile.h:51
unsigned _options
Option flags.
Definition: plotfile.h:160
bool isOpen() const
Returns true if a file is currently open.
qint64 streamPos() const
Returns the current byte position in the stream.
PlotFile(const QString &fileName, unsigned options=0)
Create a plot file opening fileName.
bool readLine()
Reads the next line from the file, caching it.