src/RelpipeChartMainWindow.cpp
author František Kučera <franta-hg@frantovo.cz>
Fri, 31 Jan 2020 23:34:52 +0100
branchv_0
changeset 44 334a114407cd
parent 42 707a6734f364
child 45 50461b01e30d
permissions -rw-r--r--
Added tag v0.15 for changeset f3867ada29b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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>
12
a45d1cac365e splitter and component placeholders
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    21
4
1622c087f3ea add main window, compile Qt .ui file
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
#include "RelpipeChartMainWindow.h"
1622c087f3ea add main window, compile Qt .ui file
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
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
    24
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
    25
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
    26
4
1622c087f3ea add main window, compile Qt .ui file
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
RelpipeChartMainWindow::RelpipeChartMainWindow() {
1622c087f3ea add main window, compile Qt .ui file
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
	widget.setupUi(this);
12
a45d1cac365e splitter and component placeholders
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    29
15
547a7c5681a5 tab icons
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    30
	int optionsIndex = tabs->addTab(new QPushButton("here will be options", tabs), "Options");
547a7c5681a5 tab icons
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    31
	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
    32
	statusBar()->addWidget(status);
12
a45d1cac365e splitter and component placeholders
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    33
	setCentralWidget(tabs);
4
1622c087f3ea add main window, compile Qt .ui file
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
}
1622c087f3ea add main window, compile Qt .ui file
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
1622c087f3ea add main window, compile Qt .ui file
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
RelpipeChartMainWindow::~RelpipeChartMainWindow() {
1622c087f3ea add main window, compile Qt .ui file
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
}
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
    38
20
b13e7ed9eea3 better use of signal/slot mechanism, threads, Qt::ConnectionType::QueuedConnection
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
    39
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
    40
	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
    41
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
    42
	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
    43
	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
    44
	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
    45
	tableView->setModel(currentModel);
28
04f1ac8a931b Qt Charts: first working version
František Kučera <franta-hg@frantovo.cz>
parents: 23
diff changeset
    46
04f1ac8a931b Qt Charts: first working version
František Kučera <franta-hg@frantovo.cz>
parents: 23
diff changeset
    47
	if (currentChartWidget) currentChartWidget->endOfRelation();
32
23018a2ed2a0 fix: multiple relations
František Kučera <franta-hg@frantovo.cz>
parents: 29
diff changeset
    48
	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
    49
	currentChartWidget = new RelpipeChartWidget(currentModel, splitter);
04f1ac8a931b Qt Charts: first working version
František Kučera <franta-hg@frantovo.cz>
parents: 23
diff changeset
    50
	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
    51
	splitter->addWidget(tableView);
28
04f1ac8a931b Qt Charts: first working version
František Kučera <franta-hg@frantovo.cz>
parents: 23
diff changeset
    52
	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
    53
	// splitter->setStretchFactor(currentChartWidget->hasChartData() ? 1 : 0, 1); // FIXME: 50:50 if chart is present
15
547a7c5681a5 tab icons
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    54
	int index = tabs->addTab(splitter, QString::fromWCharArray(name.c_str()));
547a7c5681a5 tab icons
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    55
	if (tabs->count() == 2) tabs->setCurrentIndex(index); // switch to the first relation (first tab is Options tab)
547a7c5681a5 tab icons
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    56
	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
    57
}
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
    58
20
b13e7ed9eea3 better use of signal/slot mechanism, threads, Qt::ConnectionType::QueuedConnection
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
    59
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
    60
	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
    61
}
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
    62
19
ac70c7af6a9b code clean-up, exit code
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
    63
void RelpipeChartMainWindow::setStatusMessage(string_t message) {
ac70c7af6a9b code clean-up, exit code
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
    64
	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
    65
}
ac70c7af6a9b code clean-up, exit code
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
    66
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
    67
void RelpipeChartMainWindow::endOfPipe() {
28
04f1ac8a931b Qt Charts: first working version
František Kučera <franta-hg@frantovo.cz>
parents: 23
diff changeset
    68
	if (currentChartWidget) currentChartWidget->endOfRelation();
19
ac70c7af6a9b code clean-up, exit code
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
    69
	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
    70
}