1 #include <iostream> |
1 #include <iostream> |
2 |
2 |
3 #include <QApplication> |
3 #include <QApplication> |
|
4 #include <QThread> |
4 |
5 |
5 #include <relpipe/cli/CLI.h> |
6 #include <relpipe/cli/CLI.h> |
6 #include <relpipe/cli/RelpipeCLIException.h> |
7 #include <relpipe/cli/RelpipeCLIException.h> |
7 #include <relpipe/reader/Factory.h> |
8 #include <relpipe/reader/Factory.h> |
8 #include <relpipe/reader/RelationalReader.h> |
9 #include <relpipe/reader/RelationalReader.h> |
9 #include <relpipe/reader/RelpipeReaderException.h> |
10 #include <relpipe/reader/RelpipeReaderException.h> |
10 |
11 |
11 #include "RelpipeChartMainWindow.h" |
12 #include "RelpipeChartMainWindow.h" |
|
13 #include "QtRelationalReaderStringHadler.h" |
12 |
14 |
13 using namespace relpipe::cli; |
15 using namespace relpipe::cli; |
14 using namespace relpipe::reader; |
16 using namespace relpipe::reader; |
|
17 |
|
18 class WorkerThread : public QThread { |
|
19 private: |
|
20 std::shared_ptr<RelationalReader> reader; |
|
21 public: |
|
22 |
|
23 // TODO: better background thread; lambda? |
|
24 |
|
25 WorkerThread(std::shared_ptr<RelationalReader> reader) : |
|
26 reader(reader) { |
|
27 } |
|
28 |
|
29 void run() { |
|
30 try { |
|
31 reader->process(); |
|
32 } catch (RelpipeReaderException& e) { |
|
33 // TODO: handle exception, show error dialog |
|
34 } |
|
35 } |
|
36 }; |
15 |
37 |
16 int main(int argc, char**argv) { |
38 int main(int argc, char**argv) { |
17 CLI cli(argc, argv); |
39 CLI cli(argc, argv); |
18 // TODO: argument name collisions? Filter arguments? Use prefix for Qt? Qt: -title, -style, -geometry |
40 // TODO: argument name collisions? Filter arguments? Use prefix for Qt? Qt: -title, -style, -geometry |
19 QApplication app(argc, argv); |
41 QApplication app(argc, argv); |
20 |
42 |
21 std::cout << "TODO: relpipe-out-chart..." << std::endl; |
43 std::cout << "TODO: relpipe-out-chart..." << std::endl; |
22 |
44 |
23 std::shared_ptr<RelationalReader> reader(Factory::create(std::cin)); |
45 std::shared_ptr<RelationalReader> reader(Factory::create(std::cin)); |
24 |
46 |
|
47 |
25 int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR; |
48 int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR; |
26 |
49 |
27 RelpipeChartMainWindow window; |
50 RelpipeChartMainWindow window; |
|
51 |
|
52 // TODO: remove; just demo |
|
53 QObject::connect(&window, &RelpipeChartMainWindow::signal123, &window, &RelpipeChartMainWindow::slot123); |
|
54 |
28 window.show(); |
55 window.show(); |
29 |
56 |
|
57 QtRelationalReaderStringHadler handler(&app, &window); |
|
58 reader->addHandler(&handler); |
|
59 |
|
60 // Start background thread |
|
61 WorkerThread t(reader); |
|
62 t.start(); |
|
63 // --- |
|
64 |
|
65 // window.signal123(); |
|
66 |
30 app.exec(); |
67 app.exec(); |
31 //return app.exec(); |
68 //return app.exec(); |
32 |
69 |
33 return resultCode; |
70 return resultCode; |
34 } |
71 } |