12 #include "RelpipeChartMainWindow.h" |
12 #include "RelpipeChartMainWindow.h" |
13 #include "QtRelationalReaderStringHadler.h" |
13 #include "QtRelationalReaderStringHadler.h" |
14 |
14 |
15 using namespace relpipe::cli; |
15 using namespace relpipe::cli; |
16 using namespace relpipe::reader; |
16 using namespace relpipe::reader; |
|
17 |
|
18 // signal/slot parameters must be declared here and registered with qRegisterMetaType() |
|
19 |
|
20 Q_DECLARE_METATYPE(string_t) |
|
21 Q_DECLARE_METATYPE(std::vector<AttributeMetadata>) |
17 |
22 |
18 class RelationalReaderThread : public QThread { |
23 class RelationalReaderThread : public QThread { |
19 private: |
24 private: |
20 std::shared_ptr<RelationalReader> reader; |
25 std::shared_ptr<RelationalReader> reader; |
21 public: |
26 public: |
46 int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR; |
51 int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR; |
47 |
52 |
48 RelpipeChartMainWindow window; |
53 RelpipeChartMainWindow window; |
49 window.show(); |
54 window.show(); |
50 |
55 |
51 QtRelationalReaderStringHadler handler(&app, &window); |
56 RelationalReaderThread t(reader); |
|
57 |
|
58 // Proxy that passes calls from the background thread to the GUI thread using signal-slot mechanism: |
|
59 QtRelationalReaderStringHadler handler(&t); // &t instead of handler.moveToThread(&t); // QObject::moveToThread: Cannot move objects with a parent |
|
60 |
|
61 // see Q_DECLARE_METATYPE above |
|
62 qRegisterMetaType<string_t>(); |
|
63 qRegisterMetaType<std::vector < AttributeMetadata >> (); |
|
64 |
|
65 QObject::connect(&handler, &QtRelationalReaderStringHadler::startRelationReceived, &window, &RelpipeChartMainWindow::startRelation, Qt::ConnectionType::QueuedConnection); |
|
66 QObject::connect(&handler, &QtRelationalReaderStringHadler::attributeReceived, &window, &RelpipeChartMainWindow::attribute, Qt::ConnectionType::QueuedConnection); |
|
67 QObject::connect(&handler, &QtRelationalReaderStringHadler::endOfPipeReceived, &window, &RelpipeChartMainWindow::endOfPipe, Qt::ConnectionType::QueuedConnection); |
|
68 |
52 reader->addHandler(&handler); |
69 reader->addHandler(&handler); |
53 |
70 |
54 // Start background thread |
71 // Start background thread |
55 RelationalReaderThread t(reader); |
|
56 t.start(); |
72 t.start(); |
57 // --- |
|
58 |
73 |
59 int qtResultCode = app.exec(); |
74 int qtResultCode = app.exec(); |
60 |
75 |
61 if (qtResultCode == 0) { |
76 if (qtResultCode == 0) { |
62 resultCode = CLI::EXIT_CODE_SUCCESS; |
77 resultCode = CLI::EXIT_CODE_SUCCESS; |