qse  0.5.0
qsefilereader.cpp
Go to the documentation of this file.
1 #include <QStringList>
2 #include <QTimer>
3 
4 #include "qsescan.h"
5 #include "qseinputfile.h"
6 #include "qsefilereader.h"
7 #include "qsecontroller.h"
8 
9 #include <stdio.h>
10 
11 QseFileReader::QseFileReader(const QString& name, QObject *parent)
12  : inherited(parent),
13  m_Timer(NULL),
14  m_Name(name),
15  m_Data(NULL),
16  m_Abort(false),
17  m_Restart(false),
18  m_Changed(false)
19 {
20  m_Data = new QseInputFile(m_Name);
21 
22  m_Timer = new QTimer(this);
23 
24  connect(m_Timer, SIGNAL(timeout()), this, SLOT(timerRoutine()));
25 
26  m_Timer -> start(500);
27 }
28 
30 {
31 }
32 
33 void QseFileReader::openFile(QString fileName)
34 {
35  m_FileNames.clear();
36  m_FileNames.append(fileName);
37  m_Restart = true;
38 }
39 
40 void QseFileReader::appendFile(QString fileName)
41 {
42  m_FileNames.append(fileName);
43 }
44 
46 {
47  forever {
48  int atend = m_Data -> atEnd();
49  int nfiles = m_FileNames.size();
50 
51  if (m_Abort) return;
52 
53  if (m_Restart || atend) {
54  if (m_Restart) {
55  m_Data -> clear();
56  m_Restart = false;
57  m_Changed = true;
58  }
59 
60  if (nfiles) {
61  QString nextFile = m_FileNames.takeFirst();
62 // printf("next data file\n");
63 
64  m_Data -> nextDataFile(nextFile);
65  m_Changed = true;
66  } else {
67  if (m_Changed) {
69  m_Changed = false;
70  }
71  return;
72  }
73  } else if (!atend) {
74  m_Data -> nextInputLine();
75  m_Changed = true;
76  }
77  }
78 }
79 
81 {
82  return m_Data;
83 }
84