DISPLACE  1.0
A spatial model of fisheries to help sustainable fishing and maritime spatial planning
datamerger.h
Go to the documentation of this file.
1 #ifndef DATAMERGER_H
2 #define DATAMERGER_H
3 
4 #include <QObject>
5 #include <QException>
6 #include <QFuture>
7 #include <QFutureWatcher>
8 #include <waitdialog.h>
9 
11 #include <displacemodel.h>
12 
13 namespace displace {
14 namespace workers {
15 
16 class DataMerger : public QObject
17 {
18  Q_OBJECT
19 public:
20  class Strategy {
21  public:
22  virtual ~Strategy() {}
23  virtual void attach(DataMerger *merger) = 0;
24  virtual bool processHeaderField(QString field, int i) = 0;
25  virtual bool postHeaderProcessed() = 0;
29  virtual void processLine (int linenum, QString line) = 0;
30  virtual bool saveOutput(QString out) = 0;
31  };
32 
33  explicit DataMerger(Strategy *strategy, DisplaceModel *model);
34  ~DataMerger();
35 
36  void setWaitDialog (WaitDialog *dlg) {
37  mWaitDialog = dlg;
38  }
39  void setDistance (double km) {
40  mDist = km;
41  }
42  double distance() const { return mDist; }
43 
44  void start(QString in, QString out);
45  bool checkResult();
46 
47  void setSeparator(QChar sep) { mSeparator = sep; }
48  QChar separator() const { return mSeparator; }
49 
50  bool mustExit() const { return mExit; }
51 
52  QList<std::shared_ptr<NodeData>> getAllNodesWithin(QPointF pt, double dist) const;
53 
54  static const char FieldSeparator;
55 
56 signals:
57  void completed (DataMerger *merger);
58 
59 private slots:
60  void workCompleted();
61  void aborted();
62 
63 public:
64 
65 private:
66  DisplaceModel *mModel;
67  double mDist;
68  QChar mSeparator;
69  bool mExit;
70 
71  QFuture<bool> mWork;
72  QFutureWatcher<bool> *mWatcher;
73  QFutureWatcher<void> *mInternalWatcher;
74  WaitDialog *mWaitDialog;
75 
76  Strategy *mStrategy;
77 
78  bool doWork(QString in, QString out);
79 };
80 
81 } // ns workers
82 } // ns displace
83 
84 #endif // DATAMERGER_H
static const char FieldSeparator
Definition: datamerger.h:54
Definition: datamerger.h:16
void setWaitDialog(WaitDialog *dlg)
Definition: datamerger.h:36
double dist(double x1, double y1, double x2, double y2)
Definition: myRutils.h:109
Definition: decisiontreemanager.h:13
virtual void processLine(int linenum, QString line)=0
process a single line of the file
void setSeparator(QChar sep)
Definition: datamerger.h:47
void completed(DataMerger *merger)
Definition: moc_datamerger.cpp:150
bool mustExit() const
Definition: datamerger.h:50
void setDistance(double km)
Definition: datamerger.h:39
virtual bool processHeaderField(QString field, int i)=0
Definition: displacemodel.h:71
QList< std::shared_ptr< NodeData > > getAllNodesWithin(QPointF pt, double dist) const
Definition: datamerger.cpp:68
bool checkResult()
this function returns true. The purpose of this function is simply calling QFuture::result() to check...
Definition: datamerger.cpp:58
QChar separator() const
Definition: datamerger.h:48
Definition: waitdialog.h:56
Definition: datamerger.h:20
virtual ~Strategy()
Definition: datamerger.h:22
void start(QString in, QString out)
Definition: datamerger.cpp:34
virtual bool saveOutput(QString out)=0
~DataMerger()
Definition: datamerger.cpp:28
virtual void attach(DataMerger *merger)=0
double distance() const
Definition: datamerger.h:42
DataMerger(Strategy *strategy, DisplaceModel *model)
Definition: datamerger.cpp:16