qse  0.5.4
qsedataset.cpp
Go to the documentation of this file.
1 #include <QDir>
2 #include <QFileInfo>
3 
4 #include "qsedataset.h"
5 #include "qsedataexport.h"
6 
7 #include <stdio.h>
8 
9 QseDataSet::QseDataSet(const QString &name, QObject *parent)
10  : QObject(parent),
11  m_Mutex(QMutex::Recursive)
12 {
13  setObjectName(name);
14 }
15 
17 {
18  QMutexLocker lock(&m_Mutex);
19 
20  QseScan *scan;
21 
22  foreach (scan, m_Scans) {
23  delete scan;
24  }
25 
26  foreach (scan, m_SpareScans) {
27  delete scan;
28  }
29 }
30 
32 {
33  QMutexLocker lock(&m_Mutex);
34 
35  return m_Scans.size();
36 }
37 
39 {
40 // printf("QseDataSet::emitOperationCompleted()\n");
41 
42  emit operationCompleted();
43 }
44 
46 {
47  printf("QseDataSet::emitDataChanged()\n");
48 
49  emit dataChanged();
50 }
51 
53 {
54  int sz = scanCount();
55 
56  {
57  QMutexLocker lock(&m_Mutex);
58 
59  for (int i = sz-1; i>=0; i--) {
60  m_SpareScans.append(m_Scans.takeLast());
61  }
62 
63  m_Header.clear();
64  }
65 
66  emit dataCleared();
67  emit dataChanged();
68 }
69 
71 {
72  int ns = scanCount();
73 
74  if (n >= 0 && n < ns) {
75  QMutexLocker lock(&m_Mutex);
76  return m_Scans.at(n);
77  } else {
78  return NULL;
79  }
80 }
81 
83 {
84  QMutexLocker lock(&m_Mutex);
85 
86  int max=0;
87  QseScan* scan;
88 
89  foreach (scan, m_Scans) {
90  if (scan) {
91  if (scan->columnCount()>max) {
92  max = scan->columnCount();
93  }
94  }
95  }
96 
97  return max;
98 }
99 
101 {
102  QseScan *scan = NULL;
103 
104  {
105  QMutexLocker lock(&m_Mutex);
106 
107  if (m_SpareScans.size()) {
108  scan = m_SpareScans.takeLast();
109  scan -> clear();
110  } else {
111  scan = new QseScan("");
112  }
113 
114  m_Scans.append(scan);
115  }
116 
117 // printf("%s: Append scan %d\n", qPrintable(objectName()), scanCount()-1);
118 
119  emit scanAdded(scanCount()-1);
120  emit dataChanged();
121 
122  return scan;
123 }
124 
125 QStringList QseDataSet::header() const
126 {
127  QMutexLocker lock(&m_Mutex);
128 
129  return m_Header;
130 }
131 
132 void QseDataSet::setHeader(const QStringList& hdr)
133 {
134  m_Header = hdr;
135 }
136 
137 void QseDataSet::appendHeader(const QString &l)
138 {
139  QMutexLocker lock(&m_Mutex);
140 
141  m_Header.push_back(l);
142 }
143 
144 void QseDataSet::writeScans(const QString &name)
145 {
146  for (int i=0; i<scanCount(); i++) {
147  writeScan(i, name);
148  }
149 }
150 
151 void QseDataSet::writeScan(int i, const QString &name)
152 {
153  QFileInfo fileInfo(name);
154 
155  QDir dir = fileInfo.dir();
156  QString base = fileInfo.completeBaseName();
157  QString extn = fileInfo.suffix();
158 
159  QFileInfo ofile(dir, base+"-"+QString().setNum(i)+"."+extn);
160 
161  QseScan *s = scan(i);
162 
163  if (s) {
164  s -> writeScan(ofile.filePath());
165 
166  emit message (QString("Scan %1 saved as %2").arg(i).arg(ofile.filePath()));
167  }
168 }
169 
171 {
172  if (i >= 0 && i < scanCount()) {
173  {
174  QMutexLocker lock(&m_Mutex);
175  QseScan *s = m_Scans.takeAt(i);
176 
177  if (s) {
178  m_SpareScans.append(s);
179  }
180  }
181 
182  emit dataChanged();
183  }
184 }
185 
186 QString QseDataSet::fileName() const
187 {
188  return m_FileName;
189 }
190 
191 void QseDataSet::setFileName(const QString &nam)
192 {
193  m_FileName = nam;
194 }
int scanCount() const
Definition: qsedataset.cpp:31
QseScan * scan(int n) const
Definition: qsedataset.cpp:70
void dataChanged()
void message(const QString &msg)
void clear()
Definition: qsedataset.cpp:52
QMutex m_Mutex
Definition: qsedataset.h:62
void operationCompleted()
void scanAdded(int n)
void setHeader(const QStringList &hdr)
Definition: qsedataset.cpp:132
QString m_FileName
Definition: qsedataset.h:59
void setFileName(const QString &name)
Definition: qsedataset.cpp:191
QString fileName() const
Definition: qsedataset.cpp:186
QseDataSet(const QString &name, QObject *parent=0)
Definition: qsedataset.cpp:9
void removeScan(int i)
Definition: qsedataset.cpp:170
void emitOperationCompleted()
Definition: qsedataset.cpp:38
int columnCount() const
Definition: qsescan.cpp:45
void appendHeader(const QString &hline)
Definition: qsedataset.cpp:137
void writeScans(const QString &name)
Definition: qsedataset.cpp:144
QStringList m_Header
Definition: qsedataset.h:55
int maxColumnCount() const
Definition: qsedataset.cpp:82
QList< QseScan * > m_SpareScans
Definition: qsedataset.h:57
QList< QseScan * > m_Scans
Definition: qsedataset.h:56
QseScan * appendScan()
Definition: qsedataset.cpp:100
void dataCleared()
QStringList header() const
Definition: qsedataset.cpp:125
void emitDataChanged()
Definition: qsedataset.cpp:45
void writeScan(int i, const QString &name)
Definition: qsedataset.cpp:151