# HG changeset patch # User František Kučera # Date 1543702961 -3600 # Node ID 23354fc917f47191128fff2e35e8c374847b1c43 # Parent 0f9f7d6564cd7012ae94419d575c03016380105c fix names diff -r 0f9f7d6564cd -r 23354fc917f4 nbproject/configurations.xml --- a/nbproject/configurations.xml Thu Nov 29 22:30:12 2018 +0100 +++ b/nbproject/configurations.xml Sat Dec 01 23:22:41 2018 +0100 @@ -47,40 +47,31 @@ /usr/share/cmake-3.10/Modules/CMakeCXXCompilerABI.cpp /usr/share/cmake-3.10/Modules/CMakeCompilerABI.h - - - build/Debug/src/relpipe-out-chart_autogen/EWIEGA46WW/moc_QtRelationalReaderStringHadler.cpp - build/Debug/src/relpipe-out-chart_autogen/EWIEGA46WW/moc_RelpipeChartMainWindow.cpp - build/Debug/src/relpipe-out-chart_autogen/EWIEGA46WW/moc_RelpipeChartWidget.cpp - build/Debug/src/relpipe-out-chart_autogen/EWIEGA46WW/moc_RelpipeTableModel.cpp - - - build/Debug/src/relpipe-out-chart_autogen/include/ui_RelpipeChartMainWindow.h - - build/Debug/src/relpipe-out-chart_autogen/mocs_compilation.cpp - - - - - - mocs_compilation.cpp - - - - RelpipeChartMainWindow.cpp RelpipeChartMainWindow.h RelpipeChartMainWindow.ui RelpipeChartWidget.h RelpipeTableModel.h - relpipe-out-chart.cpp + relpipe-out-gui.cpp + + + build/Debug/src/relpipe-out-gui_autogen/EWIEGA46WW/moc_QtRelationalReaderStringHadler.cpp + build/Debug/src/relpipe-out-gui_autogen/EWIEGA46WW/moc_RelpipeChartMainWindow.cpp + build/Debug/src/relpipe-out-gui_autogen/EWIEGA46WW/moc_RelpipeChartWidget.cpp + build/Debug/src/relpipe-out-gui_autogen/EWIEGA46WW/moc_RelpipeTableModel.cpp + + + build/Debug/src/relpipe-out-gui_autogen/include/ui_RelpipeChartMainWindow.h + + build/Debug/src/relpipe-out-gui_autogen/mocs_compilation.cpp + - @@ -115,6 +104,27 @@ ${MAKE} -f Makefile ${MAKE} -f Makefile clean build/Debug/src/relpipe-out-gui + + + build/Debug/src + src + build/Debug/src/relpipe-out-gui_autogen/include + ../relpipe-lib-reader.cpp/include + ../relpipe-lib-cli.cpp/include + /usr/include/x86_64-linux-gnu/qt5 + /usr/include/x86_64-linux-gnu/qt5/QtWidgets + /usr/include/x86_64-linux-gnu/qt5/QtGui + /usr/include/x86_64-linux-gnu/qt5/QtCore + /usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++ + /usr/include/x86_64-linux-gnu/qt5/QtCharts + + + QT_CHARTS_LIB + QT_CORE_LIB + QT_GUI_LIB + QT_WIDGETS_LIB + + build/Debug @@ -127,33 +137,26 @@ tool="1" flavor2="11"> - - - - - - - - - - - - build/Debug/src - src - build/Debug/src/relpipe-out-gui_autogen/include - ../relpipe-lib-reader.cpp/include - ../relpipe-lib-cli.cpp/include - /usr/include/x86_64-linux-gnu/qt5 - /usr/include/x86_64-linux-gnu/qt5/QtWidgets - /usr/include/x86_64-linux-gnu/qt5/QtGui - /usr/include/x86_64-linux-gnu/qt5/QtCore - /usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++ - /usr/include/x86_64-linux-gnu/qt5/QtCharts - - - QT_CHARTS_LIB - QT_CORE_LIB - QT_GUI_LIB - QT_WIDGETS_LIB - - - - build/Debug/src - src - build/Debug/src/relpipe-out-gui_autogen/include - ../relpipe-lib-reader.cpp/include - ../relpipe-lib-cli.cpp/include - /usr/include/x86_64-linux-gnu/qt5 - /usr/include/x86_64-linux-gnu/qt5/QtWidgets - /usr/include/x86_64-linux-gnu/qt5/QtGui - /usr/include/x86_64-linux-gnu/qt5/QtCore - /usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++ - /usr/include/x86_64-linux-gnu/qt5/QtCharts /usr/include - - QT_CHARTS_LIB - QT_CORE_LIB - QT_GUI_LIB - QT_WIDGETS_LIB - - - - - - - /usr/include/x86_64-linux-gnu/qt5/QtCore - ../relpipe-lib-reader.cpp/include/relpipe/reader/handlers - src - build/Debug/src/relpipe-out-chart_autogen/EWIEGA46WW - ../relpipe-lib-reader.cpp/include/relpipe/reader - /usr/include/x86_64-linux-gnu/qt5/QtGui - /usr/include/x86_64-linux-gnu/qt5/QtWidgets - build/Debug/src/relpipe-out-chart_autogen/include - /usr/include/x86_64-linux-gnu/qt5/QtCharts - build/Debug/src/relpipe-out-chart_autogen - /usr/include/x86_64-linux-gnu/qt5 - ../relpipe-lib-reader.cpp/include - build/Debug/src - - + @@ -275,7 +219,7 @@ - + diff -r 0f9f7d6564cd -r 23354fc917f4 nbproject/project.xml --- a/nbproject/project.xml Thu Nov 29 22:30:12 2018 +0100 +++ b/nbproject/project.xml Sat Dec 01 23:22:41 2018 +0100 @@ -42,7 +42,7 @@ org.netbeans.modules.cnd.makeproject - relpipe-out-chart.qt.cpp + relpipe-out-gui.qt.cpp cpp h diff -r 0f9f7d6564cd -r 23354fc917f4 src/CMakeLists.txt --- a/src/CMakeLists.txt Thu Nov 29 22:30:12 2018 +0100 +++ b/src/CMakeLists.txt Sat Dec 01 23:22:41 2018 +0100 @@ -42,7 +42,7 @@ RelpipeTableModel.h RelpipeChartMainWindow.ui RelpipeChartMainWindow.cpp - relpipe-out-chart.cpp + relpipe-out-gui.cpp ) # Link libraries: diff -r 0f9f7d6564cd -r 23354fc917f4 src/relpipe-out-chart.cpp --- a/src/relpipe-out-chart.cpp Thu Nov 29 22:30:12 2018 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,111 +0,0 @@ -/** - * Relational pipes - * Copyright © 2018 František Kučera (Frantovo.cz, GlobalCode.info) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#include -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include - -#include "RelpipeChartMainWindow.h" -#include "QtRelationalReaderStringHadler.h" - -using namespace relpipe::cli; -using namespace relpipe::reader; - -// signal/slot parameters must be declared here and registered with qRegisterMetaType() - -Q_DECLARE_METATYPE(string_t) -Q_DECLARE_METATYPE(std::vector) - -class RelationalReaderThread : public QThread { -private: - std::shared_ptr reader; -public: - - // TODO: better background thread; lambda? - - RelationalReaderThread(std::shared_ptr reader) : - reader(reader) { - setTerminationEnabled(true); - } - - void run() { - try { - reader->process(); - } catch (RelpipeReaderException& e) { - // TODO: handle exception, show error dialog - std::wcerr << L"RelpipeReaderException: " << e.getMessge() << std::endl; - } - } -}; - -int main(int argc, char**argv) { - CLI cli(argc, argv); - // TODO: argument name collisions? Filter arguments? Use prefix for Qt? Qt: -title, -style, -geometry - QApplication app(argc, argv); - - std::shared_ptr reader(Factory::create(std::cin)); - int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR; - - RelpipeChartMainWindow window; - window.show(); - - RelationalReaderThread t(reader); - - // Proxy that passes calls from the background thread to the GUI thread using signal-slot mechanism: - QtRelationalReaderStringHadler handler(&t); // &t instead of handler.moveToThread(&t); // QObject::moveToThread: Cannot move objects with a parent - - // see Q_DECLARE_METATYPE above - qRegisterMetaType(); - qRegisterMetaType> (); - - QObject::connect(&handler, &QtRelationalReaderStringHadler::startRelationReceived, &window, &RelpipeChartMainWindow::startRelation, Qt::ConnectionType::QueuedConnection); - QObject::connect(&handler, &QtRelationalReaderStringHadler::attributeReceived, &window, &RelpipeChartMainWindow::attribute, Qt::ConnectionType::QueuedConnection); - QObject::connect(&handler, &QtRelationalReaderStringHadler::endOfPipeReceived, &window, &RelpipeChartMainWindow::endOfPipe, Qt::ConnectionType::QueuedConnection); - - reader->addHandler(&handler); - - // Start background thread - t.start(); - - int qtResultCode = app.exec(); - - if (qtResultCode == 0) { - resultCode = CLI::EXIT_CODE_SUCCESS; - } else { - // TODO: report and log Qt errors if any - } - - if (t.isRunning()) { - std::wcerr << L"Background RelationalReader thread is still running → terminate()" << std::endl; - t.terminate(); - std::wcerr << L"Background RelationalReader thread was terminated → wait()" << std::endl; - t.wait(); - std::wcerr << L"Background RelationalReader thread wait() finished" << std::endl; - } - - return resultCode; -} diff -r 0f9f7d6564cd -r 23354fc917f4 src/relpipe-out-gui.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/relpipe-out-gui.cpp Sat Dec 01 23:22:41 2018 +0100 @@ -0,0 +1,111 @@ +/** + * Relational pipes + * Copyright © 2018 František Kučera (Frantovo.cz, GlobalCode.info) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +#include "RelpipeChartMainWindow.h" +#include "QtRelationalReaderStringHadler.h" + +using namespace relpipe::cli; +using namespace relpipe::reader; + +// signal/slot parameters must be declared here and registered with qRegisterMetaType() + +Q_DECLARE_METATYPE(string_t) +Q_DECLARE_METATYPE(std::vector) + +class RelationalReaderThread : public QThread { +private: + std::shared_ptr reader; +public: + + // TODO: better background thread; lambda? + + RelationalReaderThread(std::shared_ptr reader) : + reader(reader) { + setTerminationEnabled(true); + } + + void run() { + try { + reader->process(); + } catch (RelpipeReaderException& e) { + // TODO: handle exception, show error dialog + std::wcerr << L"RelpipeReaderException: " << e.getMessge() << std::endl; + } + } +}; + +int main(int argc, char**argv) { + CLI cli(argc, argv); + // TODO: argument name collisions? Filter arguments? Use prefix for Qt? Qt: -title, -style, -geometry + QApplication app(argc, argv); + + std::shared_ptr reader(Factory::create(std::cin)); + int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR; + + RelpipeChartMainWindow window; + window.show(); + + RelationalReaderThread t(reader); + + // Proxy that passes calls from the background thread to the GUI thread using signal-slot mechanism: + QtRelationalReaderStringHadler handler(&t); // &t instead of handler.moveToThread(&t); // QObject::moveToThread: Cannot move objects with a parent + + // see Q_DECLARE_METATYPE above + qRegisterMetaType(); + qRegisterMetaType> (); + + QObject::connect(&handler, &QtRelationalReaderStringHadler::startRelationReceived, &window, &RelpipeChartMainWindow::startRelation, Qt::ConnectionType::QueuedConnection); + QObject::connect(&handler, &QtRelationalReaderStringHadler::attributeReceived, &window, &RelpipeChartMainWindow::attribute, Qt::ConnectionType::QueuedConnection); + QObject::connect(&handler, &QtRelationalReaderStringHadler::endOfPipeReceived, &window, &RelpipeChartMainWindow::endOfPipe, Qt::ConnectionType::QueuedConnection); + + reader->addHandler(&handler); + + // Start background thread + t.start(); + + int qtResultCode = app.exec(); + + if (qtResultCode == 0) { + resultCode = CLI::EXIT_CODE_SUCCESS; + } else { + // TODO: report and log Qt errors if any + } + + if (t.isRunning()) { + std::wcerr << L"Background RelationalReader thread is still running → terminate()" << std::endl; + t.terminate(); + std::wcerr << L"Background RelationalReader thread was terminated → wait()" << std::endl; + t.wait(); + std::wcerr << L"Background RelationalReader thread wait() finished" << std::endl; + } + + return resultCode; +}