qse  0.5.4
Public Member Functions | Private Attributes | List of all members
QseScan Class Reference

#include <qsescan.h>

Inheritance diagram for QseScan:
Inheritance graph

Public Member Functions

 QseScan (const char *name)
 
 ~QseScan ()
 
QString name () const
 
void setName (QString name)
 
int columnCount () const
 
void setColumnCount (int n)
 
int maxRowCount () const
 
void setRowCount (int n)
 
void clear ()
 
QseColumncolumn (int n) const
 
QseColumncolumn (const QString &nm) const
 
void setColumnNames (const char *nms)
 
void appendHeader (const QString &h)
 
void appendData (const char *l)
 
QseColumnappendColumn (const QString &name, const QseColumn *proto=NULL)
 
QString scanCommand () const
 
void setScanCommand (const QString &cmd)
 
void writeScan (const QString &name)
 
QStringList header () const
 
void mergeHeaders (const QStringList &hdr)
 
QDateTime scanDateTime () const
 
void setScanDateTime (const QDateTime &datetime)
 
QString scanDateLine () const
 
QString scanColumnCountLine () const
 
QString scanColumnNamesLine () const
 
int scanNumber () const
 
void setScanNumber (int n)
 

Private Attributes

QStringList m_Header
 
QList< QseColumn * > m_Columns
 
QString m_Name
 
QString m_Command
 
QMutex m_Mutex
 
QDateTime m_ScanDateTime
 
int m_ScanNumber
 
QHash< QString, QseColumn * > m_ColumnsDictionary
 

Detailed Description

Definition at line 15 of file qsescan.h.

Constructor & Destructor Documentation

QseScan::QseScan ( const char *  name)

Definition at line 9 of file qsescan.cpp.

10  : QObject(NULL),
11 // m_Role(UnspecifiedRole),
12  m_Name(name),
13  m_Command(name),
14  m_Mutex(QMutex::Recursive),
15  m_ScanDateTime(QDateTime::currentDateTime()),
16  m_ScanNumber(-1)
17 {
18 }
int m_ScanNumber
Definition: qsescan.h:72
QString m_Name
Definition: qsescan.h:68
QMutex m_Mutex
Definition: qsescan.h:70
QString m_Command
Definition: qsescan.h:69
QDateTime m_ScanDateTime
Definition: qsescan.h:71
QString name() const
Definition: qsescan.cpp:31
QseScan::~QseScan ( )

Definition at line 20 of file qsescan.cpp.

References column(), m_Columns, and m_Mutex.

21 {
22  QMutexLocker lock(&m_Mutex);
23 
25 
26  foreach (column, m_Columns) {
27  delete column;
28  }
29 }
QMutex m_Mutex
Definition: qsescan.h:70
QseColumn * column(int n) const
Definition: qsescan.cpp:104
QList< QseColumn * > m_Columns
Definition: qsescan.h:67

Member Function Documentation

QseColumn * QseScan::appendColumn ( const QString &  name,
const QseColumn proto = NULL 
)

Definition at line 240 of file qsescan.cpp.

References column(), columnCount(), m_Columns, m_ColumnsDictionary, m_Mutex, name(), and setRowCount().

Referenced by appendData(), QseNormalizer::normalizeScan(), and setColumnNames().

241 {
242  QseColumn *res=NULL;
243 
244  {
245  QMutexLocker lock(&m_Mutex);
246 
247  res = new QseColumn(name);
248  m_Columns.append(res);
250  }
251 
252  if (proto) {
253  res -> setRowCount(proto -> rowCount());
254  res -> assignment(proto);
255  } else if (columnCount() > 0) {
256  res -> setRowCount(column(0)->rowCount());
257  res -> assignment(0.0);
258  }
259 
260  return res;
261 }
void setRowCount(int n)
Definition: qsescan.cpp:94
QMutex m_Mutex
Definition: qsescan.h:70
int columnCount() const
Definition: qsescan.cpp:45
QHash< QString, QseColumn * > m_ColumnsDictionary
Definition: qsescan.h:73
QseColumn * column(int n) const
Definition: qsescan.cpp:104
QList< QseColumn * > m_Columns
Definition: qsescan.h:67
QString name() const
Definition: qsescan.cpp:31
void QseScan::appendData ( const char *  l)

Definition at line 190 of file qsescan.cpp.

References appendColumn(), column(), columnCount(), and setRowCount().

191 {
192  int nc = columnCount();
193  const char *ptr = l;
194  char *next;
195 
196  for (int col = 0; ptr; col++) {
197  double val;
198  val = strtod(ptr, &next);
199 
200  if (ptr == next) {
201  return ;
202  }
203 
204  QseColumn *c=NULL;
205 
206  if (col >= nc) {
207  c = appendColumn(QString("col%1").arg(col));
208 
209  if (nc > 0) {
210  c -> setRowCount(column(0)->rowCount() - 1);
211  }
212 
213  nc++;
214  } else {
215  c = column(col);
216  }
217 
218  c -> appendData(val);
219 
220  ptr = next;
221  }
222 
223  printf("\n");
224 }
QseColumn * appendColumn(const QString &name, const QseColumn *proto=NULL)
Definition: qsescan.cpp:240
void setRowCount(int n)
Definition: qsescan.cpp:94
int columnCount() const
Definition: qsescan.cpp:45
void appendData(const char *l)
Definition: qsescan.cpp:190
QseColumn * column(int n) const
Definition: qsescan.cpp:104
void QseScan::appendHeader ( const QString &  h)

Definition at line 161 of file qsescan.cpp.

References m_Header, and m_Mutex.

Referenced by mergeHeaders().

162 {
163  QMutexLocker lock(&m_Mutex);
164  m_Header.push_back(h);
165 }
QMutex m_Mutex
Definition: qsescan.h:70
QStringList m_Header
Definition: qsescan.h:66
void QseScan::clear ( )

Definition at line 65 of file qsescan.cpp.

References m_Header, m_Mutex, and setColumnCount().

66 {
67  setColumnCount(0);
68 
69  QMutexLocker lock(&m_Mutex);
70 
71  m_Header.clear();
72 }
void setColumnCount(int n)
Definition: qsescan.cpp:52
QMutex m_Mutex
Definition: qsescan.h:70
QStringList m_Header
Definition: qsescan.h:66
QseColumn * QseScan::column ( int  n) const
QseColumn * QseScan::column ( const QString &  nm) const

Definition at line 113 of file qsescan.cpp.

References column(), m_Columns, m_Mutex, and QseColumn::name().

114 {
115  QMutexLocker lock(&m_Mutex);
116  QseColumn *column;
117 
118  foreach (column, m_Columns) {
119  if (column && (column->name()==nm)) {
120  return column;
121  }
122  }
123 
124  return NULL;
125 }
QMutex m_Mutex
Definition: qsescan.h:70
QString name() const
Definition: qsecolumn.cpp:26
QseColumn * column(int n) const
Definition: qsescan.cpp:104
QList< QseColumn * > m_Columns
Definition: qsescan.h:67
int QseScan::columnCount ( ) const
QStringList QseScan::header ( ) const

Definition at line 167 of file qsescan.cpp.

References m_Header, and m_Mutex.

Referenced by QseScanAverager::addScanToAverage(), QseNormalizer::normalizeScan(), and QseDataExport::updatePreview().

168 {
169  QMutexLocker lock(&m_Mutex);
170  return m_Header;
171 }
QMutex m_Mutex
Definition: qsescan.h:70
QStringList m_Header
Definition: qsescan.h:66
int QseScan::maxRowCount ( ) const

Definition at line 74 of file qsescan.cpp.

References column(), columnCount(), and QseColumn::rowCount().

Referenced by QseNormalizer::matchesScan(), QseNormalizer::matchesScanPattern(), and writeScan().

75 {
76  int maxcount = 0;
77  int nc = columnCount();
78 
79  for (int i=0; i<nc; i++) {
80  QseColumn *c = column(i);
81 
82  if (c) {
83  int nr = c->rowCount();
84 
85  if (nr > maxcount) {
86  maxcount = nr;
87  }
88  }
89  }
90 
91  return maxcount;
92 }
int rowCount() const
Definition: qsecolumn.cpp:48
int columnCount() const
Definition: qsescan.cpp:45
QseColumn * column(int n) const
Definition: qsescan.cpp:104
void QseScan::mergeHeaders ( const QStringList &  hdr)

Definition at line 173 of file qsescan.cpp.

References appendHeader(), m_Header, and m_Mutex.

174 {
175  QString hdrline;
176 
177  foreach (hdrline, hdr) {
178  bool nocont;
179  {
180  QMutexLocker lock(&m_Mutex);
181  nocont = !m_Header.contains(hdrline);
182  }
183 
184  if (nocont) {
185  appendHeader(hdrline);
186  }
187  }
188 }
QMutex m_Mutex
Definition: qsescan.h:70
void appendHeader(const QString &h)
Definition: qsescan.cpp:161
QStringList m_Header
Definition: qsescan.h:66
QString QseScan::name ( ) const

Definition at line 31 of file qsescan.cpp.

References m_Mutex, and m_Name.

Referenced by QseScanAverager::addScanToAverage(), appendColumn(), QseNormalizer::normalizeScan(), QseDataExport::QseDataExport(), scanColumnNamesLine(), and setName().

32 {
33  QMutexLocker lock(&m_Mutex);
34 
35  return m_Name;
36 }
QString m_Name
Definition: qsescan.h:68
QMutex m_Mutex
Definition: qsescan.h:70
QString QseScan::scanColumnCountLine ( ) const

Definition at line 328 of file qsescan.cpp.

References columnCount(), and m_Mutex.

Referenced by QseGraphScansModel::data(), and QseDataExport::updatePreview().

329 {
330  QMutexLocker lock(&m_Mutex);
331 
332  return QString("#N %1").arg(columnCount());
333 }
QMutex m_Mutex
Definition: qsescan.h:70
int columnCount() const
Definition: qsescan.cpp:45
QString QseScan::scanColumnNamesLine ( ) const

Definition at line 335 of file qsescan.cpp.

References column(), columnCount(), m_Mutex, and name().

Referenced by QseGraphScansModel::data(), and QseDataExport::updatePreview().

336 {
337  QMutexLocker lock(&m_Mutex);
338 
339  QString res = "#L ";
340  int ncols = columnCount();
341 
342  for (int i=0; i<ncols; i++) {
343  if (i != 0) {
344  res += " ";
345  }
346 
347  res += column(i) -> name();
348  }
349 
350  return res;
351 }
QMutex m_Mutex
Definition: qsescan.h:70
int columnCount() const
Definition: qsescan.cpp:45
QseColumn * column(int n) const
Definition: qsescan.cpp:104
QString name() const
Definition: qsescan.cpp:31
QString QseScan::scanCommand ( ) const
QString QseScan::scanDateLine ( ) const

Definition at line 321 of file qsescan.cpp.

References m_Mutex, and m_ScanDateTime.

Referenced by QseGraphScansModel::data(), and QseDataExport::updatePreview().

322 {
323  QMutexLocker lock(&m_Mutex);
324 
325  return "#D " + m_ScanDateTime.toString(Qt::TextDate);
326 }
QMutex m_Mutex
Definition: qsescan.h:70
QDateTime m_ScanDateTime
Definition: qsescan.h:71
QDateTime QseScan::scanDateTime ( ) const

Definition at line 307 of file qsescan.cpp.

References m_Mutex, and m_ScanDateTime.

308 {
309  QMutexLocker lock(&m_Mutex);
310 
311  return m_ScanDateTime;
312 }
QMutex m_Mutex
Definition: qsescan.h:70
QDateTime m_ScanDateTime
Definition: qsescan.h:71
int QseScan::scanNumber ( ) const

Definition at line 353 of file qsescan.cpp.

References m_Mutex, and m_ScanNumber.

Referenced by QseNormalizer::normalizeScan(), and QseGraphController::updateGraph().

354 {
355  QMutexLocker lock(&m_Mutex);
356 
357  return m_ScanNumber;
358 }
int m_ScanNumber
Definition: qsescan.h:72
QMutex m_Mutex
Definition: qsescan.h:70
void QseScan::setColumnCount ( int  n)

Definition at line 52 of file qsescan.cpp.

References columnCount(), m_Columns, and m_Mutex.

Referenced by clear().

53 {
54  int sz = columnCount();
55 
56  for (int i = sz-1; i>=n; i--) {
57  QMutexLocker lock(&m_Mutex);
58 
59  if (m_Columns[i]) {
60  delete m_Columns.takeAt(i);
61  }
62  }
63 }
QMutex m_Mutex
Definition: qsescan.h:70
int columnCount() const
Definition: qsescan.cpp:45
QList< QseColumn * > m_Columns
Definition: qsescan.h:67
void QseScan::setColumnNames ( const char *  nms)

Definition at line 127 of file qsescan.cpp.

References appendColumn(), and columnCount().

128 {
129  const char *ptr = nms + 3;
130  const char *found, *next;
131  int nc = columnCount();
132  int col;
133  char nam[256];
134 
135  for (col = 0; ptr; col++) {
136  while ((*ptr)=='\t' || (*ptr)==' ') {
137  ptr++;
138  }
139 
140  found = strstr(ptr, " ");
141  if (found) {
142  next = found + 2;
143  } else {
144  next = NULL;
145  }
146 
147  QseColumn* c= NULL;
148 
149  if (next) {
150  qstrncpy(nam, ptr, found-ptr+1);
151  c = appendColumn(nam);
152  } else {
153  c = appendColumn(ptr);
154  }
155 
156  nc++;
157  ptr = next;
158  }
159 }
QseColumn * appendColumn(const QString &name, const QseColumn *proto=NULL)
Definition: qsescan.cpp:240
int columnCount() const
Definition: qsescan.cpp:45
void QseScan::setName ( QString  name)

Definition at line 38 of file qsescan.cpp.

References m_Mutex, m_Name, and name().

39 {
40  QMutexLocker lock(&m_Mutex);
41 
42  m_Name = name;
43 }
QString m_Name
Definition: qsescan.h:68
QMutex m_Mutex
Definition: qsescan.h:70
QString name() const
Definition: qsescan.cpp:31
void QseScan::setRowCount ( int  n)

Definition at line 94 of file qsescan.cpp.

References column(), m_Columns, and m_Mutex.

Referenced by appendColumn(), and appendData().

95 {
96  QMutexLocker lock(&m_Mutex);
98 
99  foreach (column, m_Columns) {
100  column -> setRowCount(n);
101  }
102 }
void setRowCount(int n)
Definition: qsescan.cpp:94
QMutex m_Mutex
Definition: qsescan.h:70
QseColumn * column(int n) const
Definition: qsescan.cpp:104
QList< QseColumn * > m_Columns
Definition: qsescan.h:67
void QseScan::setScanCommand ( const QString &  cmd)

Definition at line 233 of file qsescan.cpp.

References m_Command, and m_Mutex.

234 {
235  QMutexLocker lock(&m_Mutex);
236 
237  m_Command = cmd;
238 }
QMutex m_Mutex
Definition: qsescan.h:70
QString m_Command
Definition: qsescan.h:69
void QseScan::setScanDateTime ( const QDateTime &  datetime)

Definition at line 314 of file qsescan.cpp.

References m_Mutex, and m_ScanDateTime.

315 {
316  QMutexLocker lock(&m_Mutex);
317 
318  m_ScanDateTime = datetime;
319 }
QMutex m_Mutex
Definition: qsescan.h:70
QDateTime m_ScanDateTime
Definition: qsescan.h:71
void QseScan::setScanNumber ( int  n)

Definition at line 360 of file qsescan.cpp.

References m_Mutex, and m_ScanNumber.

361 {
362  QMutexLocker lock(&m_Mutex);
363 
364  m_ScanNumber = n;
365 }
int m_ScanNumber
Definition: qsescan.h:72
QMutex m_Mutex
Definition: qsescan.h:70
void QseScan::writeScan ( const QString &  name)

Definition at line 263 of file qsescan.cpp.

References column(), columnCount(), QseColumn::data(), m_Header, m_Mutex, maxRowCount(), and QseColumn::name().

264 {
265  FILE *f = fopen(qPrintable(name),"w");
266  int nr = maxRowCount();
267  int nc = columnCount();
268  int hsz;
269 
270  {
271  QMutexLocker lock(&m_Mutex);
272  hsz = m_Header.size();
273  }
274 
275  for (int i = 0; i < hsz; i++) {
276  QMutexLocker lock(&m_Mutex);
277  fputs(qPrintable(m_Header[i]+"\n"), f);
278  }
279 
280  fprintf(f,"#N");
281 
282  for (int i = 0; i < nc; i++) {
283  QseColumn *c = column(i);
284  if (c) {
285  fprintf(f,"\t%s", qPrintable(c->name()));
286  }
287  }
288 
289  fprintf(f,"\n");
290 
291  for (int r = 0; r<nr; r++) {
292  fprintf(f, "%d", r);
293 
294  for (int i = 0; i < nc; i++) {
295  QseColumn *c = column(i);
296  if (c) {
297  fprintf(f,"\t%0.12g", c->data(r));
298  }
299  }
300 
301  fprintf(f,"\n");
302  }
303 
304  fclose(f);
305 }
const double * data() const
Definition: qsecolumn.cpp:62
QMutex m_Mutex
Definition: qsescan.h:70
int columnCount() const
Definition: qsescan.cpp:45
QString name() const
Definition: qsecolumn.cpp:26
QseColumn * column(int n) const
Definition: qsescan.cpp:104
QStringList m_Header
Definition: qsescan.h:66
int maxRowCount() const
Definition: qsescan.cpp:74
QString name() const
Definition: qsescan.cpp:31

Member Data Documentation

QList<QseColumn*> QseScan::m_Columns
private

Definition at line 67 of file qsescan.h.

Referenced by appendColumn(), column(), columnCount(), setColumnCount(), setRowCount(), and ~QseScan().

QHash<QString, QseColumn*> QseScan::m_ColumnsDictionary
private

Definition at line 73 of file qsescan.h.

Referenced by appendColumn().

QString QseScan::m_Command
private

Definition at line 69 of file qsescan.h.

Referenced by scanCommand(), and setScanCommand().

QStringList QseScan::m_Header
private

Definition at line 66 of file qsescan.h.

Referenced by appendHeader(), clear(), header(), mergeHeaders(), and writeScan().

QMutex QseScan::m_Mutex
mutableprivate
QString QseScan::m_Name
private

Definition at line 68 of file qsescan.h.

Referenced by name(), and setName().

QDateTime QseScan::m_ScanDateTime
private

Definition at line 71 of file qsescan.h.

Referenced by scanDateLine(), scanDateTime(), and setScanDateTime().

int QseScan::m_ScanNumber
private

Definition at line 72 of file qsescan.h.

Referenced by scanNumber(), and setScanNumber().


The documentation for this class was generated from the following files: