author | František Kučera <franta-hg@frantovo.cz> |
Fri, 23 Oct 2020 12:10:45 +0200 | |
branch | v_0 |
changeset 49 | a3777909fd44 |
parent 45 | 50461b01e30d |
permissions | -rw-r--r-- |
29
0f9f7d6564cd
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
28
diff
changeset
|
1 |
/** |
0f9f7d6564cd
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
28
diff
changeset
|
2 |
* Relational pipes |
0f9f7d6564cd
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
28
diff
changeset
|
3 |
* Copyright © 2018 František Kučera (Frantovo.cz, GlobalCode.info) |
0f9f7d6564cd
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
28
diff
changeset
|
4 |
* |
0f9f7d6564cd
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
28
diff
changeset
|
5 |
* This program is free software: you can redistribute it and/or modify |
0f9f7d6564cd
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
28
diff
changeset
|
6 |
* it under the terms of the GNU General Public License as published by |
42
707a6734f364
fix license version: GNU GPLv3
František Kučera <franta-hg@frantovo.cz>
parents:
32
diff
changeset
|
7 |
* the Free Software Foundation, version 3 of the License. |
29
0f9f7d6564cd
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
28
diff
changeset
|
8 |
* |
0f9f7d6564cd
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
28
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
0f9f7d6564cd
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
28
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
0f9f7d6564cd
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
28
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
0f9f7d6564cd
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
28
diff
changeset
|
12 |
* GNU General Public License for more details. |
0f9f7d6564cd
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
28
diff
changeset
|
13 |
* |
0f9f7d6564cd
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
28
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
0f9f7d6564cd
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
28
diff
changeset
|
15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
0f9f7d6564cd
license: GNU GPLv3+
František Kučera <franta-hg@frantovo.cz>
parents:
28
diff
changeset
|
16 |
*/ |
23
ff4a1c07a481
use our own QAbstractTableModel and a QTableView instead of the QTableWidget
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
17 |
#include <vector> |
ff4a1c07a481
use our own QAbstractTableModel and a QTableView instead of the QTableWidget
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
18 |
|
12
a45d1cac365e
splitter and component placeholders
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
19 |
#include <QPushButton> |
23
ff4a1c07a481
use our own QAbstractTableModel and a QTableView instead of the QTableWidget
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
20 |
#include <QTableView> |
45
50461b01e30d
basic keyboard shortcuts: Ctrl+PgDown, Ctrl+PgUp, Ctrl+Q
František Kučera <franta-hg@frantovo.cz>
parents:
42
diff
changeset
|
21 |
#include <QAction> |
49
a3777909fd44
fix Qt includes: #include <QHeaderView>
František Kučera <franta-hg@frantovo.cz>
parents:
45
diff
changeset
|
22 |
#include <QHeaderView> |
12
a45d1cac365e
splitter and component placeholders
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
23 |
|
4
1622c087f3ea
add main window, compile Qt .ui file
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
24 |
#include "RelpipeChartMainWindow.h" |
1622c087f3ea
add main window, compile Qt .ui file
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
25 |
|
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:
12
diff
changeset
|
26 |
using namespace relpipe::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:
12
diff
changeset
|
27 |
using namespace relpipe::reader::handlers; |
23
ff4a1c07a481
use our own QAbstractTableModel and a QTableView instead of the QTableWidget
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
28 |
|
4
1622c087f3ea
add main window, compile Qt .ui file
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
29 |
RelpipeChartMainWindow::RelpipeChartMainWindow() { |
1622c087f3ea
add main window, compile Qt .ui file
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
30 |
widget.setupUi(this); |
12
a45d1cac365e
splitter and component placeholders
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
31 |
|
15 | 32 |
int optionsIndex = tabs->addTab(new QPushButton("here will be options", tabs), "Options"); |
33 |
tabs->setTabIcon(optionsIndex, QIcon::fromTheme("configure")); |
|
19
ac70c7af6a9b
code clean-up, exit code
František Kučera <franta-hg@frantovo.cz>
parents:
18
diff
changeset
|
34 |
statusBar()->addWidget(status); |
12
a45d1cac365e
splitter and component placeholders
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
35 |
setCentralWidget(tabs); |
45
50461b01e30d
basic keyboard shortcuts: Ctrl+PgDown, Ctrl+PgUp, Ctrl+Q
František Kučera <franta-hg@frantovo.cz>
parents:
42
diff
changeset
|
36 |
setupKeyboardShortcuts(); |
4
1622c087f3ea
add main window, compile Qt .ui file
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
37 |
} |
1622c087f3ea
add main window, compile Qt .ui file
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
38 |
|
45
50461b01e30d
basic keyboard shortcuts: Ctrl+PgDown, Ctrl+PgUp, Ctrl+Q
František Kučera <franta-hg@frantovo.cz>
parents:
42
diff
changeset
|
39 |
void RelpipeChartMainWindow::setupKeyboardShortcuts() { |
50461b01e30d
basic keyboard shortcuts: Ctrl+PgDown, Ctrl+PgUp, Ctrl+Q
František Kučera <franta-hg@frantovo.cz>
parents:
42
diff
changeset
|
40 |
// TODO: less boilerplate code |
50461b01e30d
basic keyboard shortcuts: Ctrl+PgDown, Ctrl+PgUp, Ctrl+Q
František Kučera <franta-hg@frantovo.cz>
parents:
42
diff
changeset
|
41 |
QAction* nextTabAction = new QAction(this); |
50461b01e30d
basic keyboard shortcuts: Ctrl+PgDown, Ctrl+PgUp, Ctrl+Q
František Kučera <franta-hg@frantovo.cz>
parents:
42
diff
changeset
|
42 |
nextTabAction->setShortcut(Qt::Key_PageDown | Qt::CTRL); |
50461b01e30d
basic keyboard shortcuts: Ctrl+PgDown, Ctrl+PgUp, Ctrl+Q
František Kučera <franta-hg@frantovo.cz>
parents:
42
diff
changeset
|
43 |
connect(nextTabAction, &QAction::triggered, this, &RelpipeChartMainWindow::selectNextTab); |
50461b01e30d
basic keyboard shortcuts: Ctrl+PgDown, Ctrl+PgUp, Ctrl+Q
František Kučera <franta-hg@frantovo.cz>
parents:
42
diff
changeset
|
44 |
this->addAction(nextTabAction); |
50461b01e30d
basic keyboard shortcuts: Ctrl+PgDown, Ctrl+PgUp, Ctrl+Q
František Kučera <franta-hg@frantovo.cz>
parents:
42
diff
changeset
|
45 |
|
50461b01e30d
basic keyboard shortcuts: Ctrl+PgDown, Ctrl+PgUp, Ctrl+Q
František Kučera <franta-hg@frantovo.cz>
parents:
42
diff
changeset
|
46 |
QAction* previousTabAction = new QAction(this); |
50461b01e30d
basic keyboard shortcuts: Ctrl+PgDown, Ctrl+PgUp, Ctrl+Q
František Kučera <franta-hg@frantovo.cz>
parents:
42
diff
changeset
|
47 |
previousTabAction->setShortcut(Qt::Key_PageUp | Qt::CTRL); |
50461b01e30d
basic keyboard shortcuts: Ctrl+PgDown, Ctrl+PgUp, Ctrl+Q
František Kučera <franta-hg@frantovo.cz>
parents:
42
diff
changeset
|
48 |
connect(previousTabAction, &QAction::triggered, this, &RelpipeChartMainWindow::selectPreviousTab); |
50461b01e30d
basic keyboard shortcuts: Ctrl+PgDown, Ctrl+PgUp, Ctrl+Q
František Kučera <franta-hg@frantovo.cz>
parents:
42
diff
changeset
|
49 |
this->addAction(previousTabAction); |
50461b01e30d
basic keyboard shortcuts: Ctrl+PgDown, Ctrl+PgUp, Ctrl+Q
František Kučera <franta-hg@frantovo.cz>
parents:
42
diff
changeset
|
50 |
|
50461b01e30d
basic keyboard shortcuts: Ctrl+PgDown, Ctrl+PgUp, Ctrl+Q
František Kučera <franta-hg@frantovo.cz>
parents:
42
diff
changeset
|
51 |
QAction* quitAction = new QAction(this); |
50461b01e30d
basic keyboard shortcuts: Ctrl+PgDown, Ctrl+PgUp, Ctrl+Q
František Kučera <franta-hg@frantovo.cz>
parents:
42
diff
changeset
|
52 |
quitAction->setShortcut(Qt::Key_Q | Qt::CTRL); |
50461b01e30d
basic keyboard shortcuts: Ctrl+PgDown, Ctrl+PgUp, Ctrl+Q
František Kučera <franta-hg@frantovo.cz>
parents:
42
diff
changeset
|
53 |
connect(quitAction, &QAction::triggered, this, &RelpipeChartMainWindow::close); |
50461b01e30d
basic keyboard shortcuts: Ctrl+PgDown, Ctrl+PgUp, Ctrl+Q
František Kučera <franta-hg@frantovo.cz>
parents:
42
diff
changeset
|
54 |
this->addAction(quitAction); |
50461b01e30d
basic keyboard shortcuts: Ctrl+PgDown, Ctrl+PgUp, Ctrl+Q
František Kučera <franta-hg@frantovo.cz>
parents:
42
diff
changeset
|
55 |
} |
50461b01e30d
basic keyboard shortcuts: Ctrl+PgDown, Ctrl+PgUp, Ctrl+Q
František Kučera <franta-hg@frantovo.cz>
parents:
42
diff
changeset
|
56 |
|
50461b01e30d
basic keyboard shortcuts: Ctrl+PgDown, Ctrl+PgUp, Ctrl+Q
František Kučera <franta-hg@frantovo.cz>
parents:
42
diff
changeset
|
57 |
|
4
1622c087f3ea
add main window, compile Qt .ui file
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
58 |
RelpipeChartMainWindow::~RelpipeChartMainWindow() { |
1622c087f3ea
add main window, compile Qt .ui file
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
59 |
} |
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:
12
diff
changeset
|
60 |
|
45
50461b01e30d
basic keyboard shortcuts: Ctrl+PgDown, Ctrl+PgUp, Ctrl+Q
František Kučera <franta-hg@frantovo.cz>
parents:
42
diff
changeset
|
61 |
void RelpipeChartMainWindow::selectNextTab() { |
50461b01e30d
basic keyboard shortcuts: Ctrl+PgDown, Ctrl+PgUp, Ctrl+Q
František Kučera <franta-hg@frantovo.cz>
parents:
42
diff
changeset
|
62 |
tabs->setCurrentIndex((tabs->currentIndex() + 1) % tabs->count()); |
50461b01e30d
basic keyboard shortcuts: Ctrl+PgDown, Ctrl+PgUp, Ctrl+Q
František Kučera <franta-hg@frantovo.cz>
parents:
42
diff
changeset
|
63 |
} |
50461b01e30d
basic keyboard shortcuts: Ctrl+PgDown, Ctrl+PgUp, Ctrl+Q
František Kučera <franta-hg@frantovo.cz>
parents:
42
diff
changeset
|
64 |
|
50461b01e30d
basic keyboard shortcuts: Ctrl+PgDown, Ctrl+PgUp, Ctrl+Q
František Kučera <franta-hg@frantovo.cz>
parents:
42
diff
changeset
|
65 |
void RelpipeChartMainWindow::selectPreviousTab() { |
50461b01e30d
basic keyboard shortcuts: Ctrl+PgDown, Ctrl+PgUp, Ctrl+Q
František Kučera <franta-hg@frantovo.cz>
parents:
42
diff
changeset
|
66 |
tabs->setCurrentIndex((tabs->count() + tabs->currentIndex() - 1) % tabs->count()); |
50461b01e30d
basic keyboard shortcuts: Ctrl+PgDown, Ctrl+PgUp, Ctrl+Q
František Kučera <franta-hg@frantovo.cz>
parents:
42
diff
changeset
|
67 |
} |
50461b01e30d
basic keyboard shortcuts: Ctrl+PgDown, Ctrl+PgUp, Ctrl+Q
František Kučera <franta-hg@frantovo.cz>
parents:
42
diff
changeset
|
68 |
|
20
b13e7ed9eea3
better use of signal/slot mechanism, threads, Qt::ConnectionType::QueuedConnection
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
69 |
void RelpipeChartMainWindow::startRelation(const string_t name, std::vector<AttributeMetadata> attributes) { |
19
ac70c7af6a9b
code clean-up, exit code
František Kučera <franta-hg@frantovo.cz>
parents:
18
diff
changeset
|
70 |
setStatusMessage(L"Reading relation: " + name); |
18
16784291982f
add QTableWidget with rows and collumns filled with attribute values
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
71 |
|
23
ff4a1c07a481
use our own QAbstractTableModel and a QTableView instead of the QTableWidget
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
72 |
currentModel = new RelpipeTableModel(attributes, this); |
ff4a1c07a481
use our own QAbstractTableModel and a QTableView instead of the QTableWidget
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
73 |
QTableView* tableView = new QTableView(this); |
ff4a1c07a481
use our own QAbstractTableModel and a QTableView instead of the QTableWidget
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
74 |
tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeMode::ResizeToContents); |
ff4a1c07a481
use our own QAbstractTableModel and a QTableView instead of the QTableWidget
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
75 |
tableView->setModel(currentModel); |
28
04f1ac8a931b
Qt Charts: first working version
František Kučera <franta-hg@frantovo.cz>
parents:
23
diff
changeset
|
76 |
|
04f1ac8a931b
Qt Charts: first working version
František Kučera <franta-hg@frantovo.cz>
parents:
23
diff
changeset
|
77 |
if (currentChartWidget) currentChartWidget->endOfRelation(); |
32
23018a2ed2a0
fix: multiple relations
František Kučera <franta-hg@frantovo.cz>
parents:
29
diff
changeset
|
78 |
splitter = new QSplitter(Qt::Orientation::Vertical, tabs); |
28
04f1ac8a931b
Qt Charts: first working version
František Kučera <franta-hg@frantovo.cz>
parents:
23
diff
changeset
|
79 |
currentChartWidget = new RelpipeChartWidget(currentModel, splitter); |
04f1ac8a931b
Qt Charts: first working version
František Kučera <franta-hg@frantovo.cz>
parents:
23
diff
changeset
|
80 |
splitter->addWidget(currentChartWidget); |
23
ff4a1c07a481
use our own QAbstractTableModel and a QTableView instead of the QTableWidget
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
81 |
splitter->addWidget(tableView); |
28
04f1ac8a931b
Qt Charts: first working version
František Kučera <franta-hg@frantovo.cz>
parents:
23
diff
changeset
|
82 |
splitter->setSizes({currentChartWidget->hasChartData() ? 1 : 0, 1}); |
04f1ac8a931b
Qt Charts: first working version
František Kučera <franta-hg@frantovo.cz>
parents:
23
diff
changeset
|
83 |
// splitter->setStretchFactor(currentChartWidget->hasChartData() ? 1 : 0, 1); // FIXME: 50:50 if chart is present |
15 | 84 |
int index = tabs->addTab(splitter, QString::fromWCharArray(name.c_str())); |
85 |
if (tabs->count() == 2) tabs->setCurrentIndex(index); // switch to the first relation (first tab is Options tab) |
|
86 |
tabs->setTabIcon(index, QIcon::fromTheme("application-vnd.oasis.opendocument.spreadsheet")); |
|
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:
12
diff
changeset
|
87 |
} |
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:
12
diff
changeset
|
88 |
|
20
b13e7ed9eea3
better use of signal/slot mechanism, threads, Qt::ConnectionType::QueuedConnection
František Kučera <franta-hg@frantovo.cz>
parents:
19
diff
changeset
|
89 |
void RelpipeChartMainWindow::attribute(const string_t value) { |
23
ff4a1c07a481
use our own QAbstractTableModel and a QTableView instead of the QTableWidget
František Kučera <franta-hg@frantovo.cz>
parents:
22
diff
changeset
|
90 |
currentModel->addAttribute(value); |
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:
12
diff
changeset
|
91 |
} |
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:
12
diff
changeset
|
92 |
|
19
ac70c7af6a9b
code clean-up, exit code
František Kučera <franta-hg@frantovo.cz>
parents:
18
diff
changeset
|
93 |
void RelpipeChartMainWindow::setStatusMessage(string_t message) { |
ac70c7af6a9b
code clean-up, exit code
František Kučera <franta-hg@frantovo.cz>
parents:
18
diff
changeset
|
94 |
status->setText(QString::fromWCharArray(message.c_str())); |
ac70c7af6a9b
code clean-up, exit code
František Kučera <franta-hg@frantovo.cz>
parents:
18
diff
changeset
|
95 |
} |
ac70c7af6a9b
code clean-up, exit code
František Kučera <franta-hg@frantovo.cz>
parents:
18
diff
changeset
|
96 |
|
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:
12
diff
changeset
|
97 |
void RelpipeChartMainWindow::endOfPipe() { |
28
04f1ac8a931b
Qt Charts: first working version
František Kučera <franta-hg@frantovo.cz>
parents:
23
diff
changeset
|
98 |
if (currentChartWidget) currentChartWidget->endOfRelation(); |
19
ac70c7af6a9b
code clean-up, exit code
František Kučera <franta-hg@frantovo.cz>
parents:
18
diff
changeset
|
99 |
setStatusMessage(L"Reading successfully finished."); |
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:
12
diff
changeset
|
100 |
} |