src/relpipe-out-chart.cpp
author František Kučera <franta-hg@frantovo.cz>
Sat, 29 Sep 2018 00:43:16 +0200
branchv_0
changeset 13 c84042d014c9
parent 11 0f42346c8fc7
child 16 b6f790137bb8
permissions -rw-r--r--
background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
ba16fce7ef20 create cmake+netbeans project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
#include <iostream>
ba16fce7ef20 create cmake+netbeans project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
3
0d857519a4c9 add Qt libraries using cmake
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
     3
#include <QApplication>
13
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
     4
#include <QThread>
3
0d857519a4c9 add Qt libraries using cmake
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
     5
2
7ba3ae8cf1fc add relpipe pkg-config libraries using cmake
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
     6
#include <relpipe/cli/CLI.h>
7ba3ae8cf1fc add relpipe pkg-config libraries using cmake
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
     7
#include <relpipe/cli/RelpipeCLIException.h>
7ba3ae8cf1fc add relpipe pkg-config libraries using cmake
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
     8
#include <relpipe/reader/Factory.h>
7ba3ae8cf1fc add relpipe pkg-config libraries using cmake
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
     9
#include <relpipe/reader/RelationalReader.h>
7ba3ae8cf1fc add relpipe pkg-config libraries using cmake
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    10
#include <relpipe/reader/RelpipeReaderException.h>
7ba3ae8cf1fc add relpipe pkg-config libraries using cmake
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    11
4
1622c087f3ea add main window, compile Qt .ui file
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    12
#include "RelpipeChartMainWindow.h"
13
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    13
#include "QtRelationalReaderStringHadler.h"
2
7ba3ae8cf1fc add relpipe pkg-config libraries using cmake
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    14
7ba3ae8cf1fc add relpipe pkg-config libraries using cmake
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    15
using namespace relpipe::cli;
7ba3ae8cf1fc add relpipe pkg-config libraries using cmake
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    16
using namespace relpipe::reader;
7ba3ae8cf1fc add relpipe pkg-config libraries using cmake
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    17
13
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    18
class WorkerThread : public QThread {
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    19
private:
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    20
	std::shared_ptr<RelationalReader> reader;
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    21
public:
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    22
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    23
	// TODO: better background thread; lambda?
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    24
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    25
	WorkerThread(std::shared_ptr<RelationalReader> reader) :
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    26
	reader(reader) {
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    27
	}
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    28
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    29
	void run() {
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    30
		try {
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    31
			reader->process();
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    32
		} catch (RelpipeReaderException& e) {
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    33
			// TODO: handle exception, show error dialog
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    34
		}
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    35
	}
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    36
};
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    37
0
ba16fce7ef20 create cmake+netbeans project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
int main(int argc, char**argv) {
2
7ba3ae8cf1fc add relpipe pkg-config libraries using cmake
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    39
	CLI cli(argc, argv);
9
d88df75dc2eb comment on possible CLI argument collision
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    40
	// TODO: argument name collisions? Filter arguments? Use prefix for Qt? Qt: -title, -style, -geometry
3
0d857519a4c9 add Qt libraries using cmake
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
    41
	QApplication app(argc, argv);
13
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    42
0
ba16fce7ef20 create cmake+netbeans project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
	std::cout << "TODO: relpipe-out-chart..." << std::endl;
13
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    44
2
7ba3ae8cf1fc add relpipe pkg-config libraries using cmake
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    45
	std::shared_ptr<RelationalReader> reader(Factory::create(std::cin));
7ba3ae8cf1fc add relpipe pkg-config libraries using cmake
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    46
13
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    47
2
7ba3ae8cf1fc add relpipe pkg-config libraries using cmake
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    48
	int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR;
13
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    49
4
1622c087f3ea add main window, compile Qt .ui file
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    50
	RelpipeChartMainWindow window;
13
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    51
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    52
	// TODO: remove; just demo
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    53
	QObject::connect(&window, &RelpipeChartMainWindow::signal123, &window, &RelpipeChartMainWindow::slot123);
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    54
4
1622c087f3ea add main window, compile Qt .ui file
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    55
	window.show();
13
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    56
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    57
	QtRelationalReaderStringHadler handler(&app, &window);
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    58
	reader->addHandler(&handler);
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    59
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    60
	// Start background thread
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    61
	WorkerThread t(reader);
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    62
	t.start();
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    63
	// ---
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    64
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    65
	// window.signal123();
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    66
4
1622c087f3ea add main window, compile Qt .ui file
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    67
	app.exec();
1622c087f3ea add main window, compile Qt .ui file
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    68
	//return app.exec();
2
7ba3ae8cf1fc add relpipe pkg-config libraries using cmake
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    69
7ba3ae8cf1fc add relpipe pkg-config libraries using cmake
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    70
	return resultCode;
0
ba16fce7ef20 create cmake+netbeans project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    71
}