src/RelpipeChartMainWindow.cpp
author František Kučera <franta-hg@frantovo.cz>
Sun, 18 Nov 2018 00:38:49 +0100
branchv_0
changeset 28 04f1ac8a931b
parent 23 ff4a1c07a481
child 29 0f9f7d6564cd
permissions -rw-r--r--
Qt Charts: first working version
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
     1
#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
     2
12
a45d1cac365e splitter and component placeholders
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
     3
#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
     4
#include <QTableView>
12
a45d1cac365e splitter and component placeholders
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
     5
4
1622c087f3ea add main window, compile Qt .ui file
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
#include "RelpipeChartMainWindow.h"
1622c087f3ea add main window, compile Qt .ui file
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
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
     8
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
     9
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
    10
4
1622c087f3ea add main window, compile Qt .ui file
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
RelpipeChartMainWindow::RelpipeChartMainWindow() {
1622c087f3ea add main window, compile Qt .ui file
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
	widget.setupUi(this);
12
a45d1cac365e splitter and component placeholders
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    13
15
547a7c5681a5 tab icons
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    14
	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
    15
	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
    16
	statusBar()->addWidget(status);
12
a45d1cac365e splitter and component placeholders
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    17
	setCentralWidget(tabs);
4
1622c087f3ea add main window, compile Qt .ui file
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
}
1622c087f3ea add main window, compile Qt .ui file
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
1622c087f3ea add main window, compile Qt .ui file
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
RelpipeChartMainWindow::~RelpipeChartMainWindow() {
1622c087f3ea add main window, compile Qt .ui file
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
}
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
    22
20
b13e7ed9eea3 better use of signal/slot mechanism, threads, Qt::ConnectionType::QueuedConnection
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
    23
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
    24
	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
    25
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
	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
    27
	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
    28
	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
    29
	tableView->setModel(currentModel);
28
04f1ac8a931b Qt Charts: first working version
František Kučera <franta-hg@frantovo.cz>
parents: 23
diff changeset
    30
04f1ac8a931b Qt Charts: first working version
František Kučera <franta-hg@frantovo.cz>
parents: 23
diff changeset
    31
	if (currentChartWidget) currentChartWidget->endOfRelation();
04f1ac8a931b Qt Charts: first working version
František Kučera <franta-hg@frantovo.cz>
parents: 23
diff changeset
    32
	currentChartWidget = new RelpipeChartWidget(currentModel, splitter);
04f1ac8a931b Qt Charts: first working version
František Kučera <franta-hg@frantovo.cz>
parents: 23
diff changeset
    33
	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
    34
	splitter->addWidget(tableView);
28
04f1ac8a931b Qt Charts: first working version
František Kučera <franta-hg@frantovo.cz>
parents: 23
diff changeset
    35
	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
    36
	// 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
    37
	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
    38
	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
    39
	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
    40
}
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
    41
20
b13e7ed9eea3 better use of signal/slot mechanism, threads, Qt::ConnectionType::QueuedConnection
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
    42
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
    43
	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
    44
}
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
    45
19
ac70c7af6a9b code clean-up, exit code
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
    46
void RelpipeChartMainWindow::setStatusMessage(string_t message) {
ac70c7af6a9b code clean-up, exit code
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
    47
	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
    48
}
ac70c7af6a9b code clean-up, exit code
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
    49
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
    50
void RelpipeChartMainWindow::endOfPipe() {
28
04f1ac8a931b Qt Charts: first working version
František Kučera <franta-hg@frantovo.cz>
parents: 23
diff changeset
    51
	if (currentChartWidget) currentChartWidget->endOfRelation();
19
ac70c7af6a9b code clean-up, exit code
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
    52
	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
    53
}