src/RelpipeChartMainWindow.cpp
author František Kučera <franta-hg@frantovo.cz>
Sun, 30 Sep 2018 18:34:34 +0200
branchv_0
changeset 19 ac70c7af6a9b
parent 18 16784291982f
child 20 b13e7ed9eea3
permissions -rw-r--r--
code clean-up, exit code
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12
a45d1cac365e splitter and component placeholders
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
     1
#include <QTabWidget>
a45d1cac365e splitter and component placeholders
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
     2
#include <QPushButton>
a45d1cac365e splitter and component placeholders
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
     3
#include <QLabel>
a45d1cac365e splitter and component placeholders
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
     4
#include <QStatusBar>
a45d1cac365e splitter and component placeholders
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
     5
#include <QSplitter>
18
16784291982f add QTableWidget with rows and collumns filled with attribute values
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
     6
#include <QScrollArea>
16784291982f add QTableWidget with rows and collumns filled with attribute values
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
     7
#include <QTableWidget>
12
a45d1cac365e splitter and component placeholders
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
     8
4
1622c087f3ea add main window, compile Qt .ui file
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
#include "RelpipeChartMainWindow.h"
1622c087f3ea add main window, compile Qt .ui file
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
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
    11
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
    12
using namespace relpipe::reader::handlers;
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
    13
4
1622c087f3ea add main window, compile Qt .ui file
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
RelpipeChartMainWindow::RelpipeChartMainWindow() {
1622c087f3ea add main window, compile Qt .ui file
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
	widget.setupUi(this);
12
a45d1cac365e splitter and component placeholders
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    16
15
547a7c5681a5 tab icons
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    17
	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
    18
	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
    19
	statusBar()->addWidget(status);
12
a45d1cac365e splitter and component placeholders
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    20
	setCentralWidget(tabs);
4
1622c087f3ea add main window, compile Qt .ui file
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
}
1622c087f3ea add main window, compile Qt .ui file
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
1622c087f3ea add main window, compile Qt .ui file
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
RelpipeChartMainWindow::~RelpipeChartMainWindow() {
1622c087f3ea add main window, compile Qt .ui file
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
}
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
    25
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
void RelpipeChartMainWindow::startRelation(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
    27
	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
    28
	attributeCounter = 0;
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
    29
	QSplitter* splitter = new QSplitter(Qt::Orientation::Vertical, tabs);
18
16784291982f add QTableWidget with rows and collumns filled with attribute values
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    30
16784291982f add QTableWidget with rows and collumns filled with attribute values
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    31
	currentTable = new QTableWidget(0, attributes.size(), splitter);
16784291982f add QTableWidget with rows and collumns filled with attribute values
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    32
	QStringList headers;
16784291982f add QTableWidget with rows and collumns filled with attribute values
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    33
	for (AttributeMetadata a : attributes) headers << QString::fromWCharArray(a.getAttributeName().c_str());
19
ac70c7af6a9b code clean-up, exit code
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
    34
	// for (AttributeMetadata a : attributes) headers << (QString::fromWCharArray(a.getAttributeName().c_str()) + " (" + QString::fromWCharArray(a.getTypeName().c_str()) + ")" );
18
16784291982f add QTableWidget with rows and collumns filled with attribute values
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    35
	currentTable->setHorizontalHeaderLabels(headers);
16784291982f add QTableWidget with rows and collumns filled with attribute values
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    36
	currentTable->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeMode::ResizeToContents);
16784291982f add QTableWidget with rows and collumns filled with attribute values
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    37
16784291982f add QTableWidget with rows and collumns filled with attribute values
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    38
	// TODO: chart
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
    39
	splitter->addWidget(new QPushButton("here will be the chart", splitter));
18
16784291982f add QTableWidget with rows and collumns filled with attribute values
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    40
	splitter->addWidget(currentTable);
15
547a7c5681a5 tab icons
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
    41
	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
    42
	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
    43
	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
    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
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
    46
void RelpipeChartMainWindow::attribute(const string_t& value) {
18
16784291982f add QTableWidget with rows and collumns filled with attribute values
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    47
	// TODO: draw chart
16784291982f add QTableWidget with rows and collumns filled with attribute values
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    48
	integer_t column = attributeCounter % currentTable->columnCount();
16784291982f add QTableWidget with rows and collumns filled with attribute values
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    49
	integer_t row = attributeCounter / currentTable->columnCount();
16784291982f add QTableWidget with rows and collumns filled with attribute values
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    50
	if (row >= currentTable->rowCount()) currentTable->insertRow(currentTable->rowCount());
16784291982f add QTableWidget with rows and collumns filled with attribute values
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    51
	currentTable->setItem(row, column, new QTableWidgetItem(QString::fromWCharArray(value.c_str())));
16784291982f add QTableWidget with rows and collumns filled with attribute values
František Kučera <franta-hg@frantovo.cz>
parents: 15
diff changeset
    52
	attributeCounter++;
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
}
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
    54
19
ac70c7af6a9b code clean-up, exit code
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
    55
void RelpipeChartMainWindow::setStatusMessage(string_t message) {
ac70c7af6a9b code clean-up, exit code
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
    56
	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
    57
}
ac70c7af6a9b code clean-up, exit code
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
    58
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
    59
void RelpipeChartMainWindow::endOfPipe() {
19
ac70c7af6a9b code clean-up, exit code
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
    60
	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
    61
}