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

#include <vector>

#include <QPushButton>
#include <QTableView>

#include "RelpipeChartMainWindow.h"

using namespace relpipe::reader;
using namespace relpipe::reader::handlers;

RelpipeChartMainWindow::RelpipeChartMainWindow() {
	widget.setupUi(this);

	int optionsIndex = tabs->addTab(new QPushButton("here will be options", tabs), "Options");
	tabs->setTabIcon(optionsIndex, QIcon::fromTheme("configure"));
	statusBar()->addWidget(status);
	setCentralWidget(tabs);
}

RelpipeChartMainWindow::~RelpipeChartMainWindow() {
}

void RelpipeChartMainWindow::startRelation(const string_t name, std::vector<AttributeMetadata> attributes) {
	setStatusMessage(L"Reading relation: " + name);

	currentModel = new RelpipeTableModel(attributes, this);
	QTableView* tableView = new QTableView(this);
	tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeMode::ResizeToContents);
	tableView->setModel(currentModel);

	if (currentChartWidget) currentChartWidget->endOfRelation();
	currentChartWidget = new RelpipeChartWidget(currentModel, splitter);
	splitter->addWidget(currentChartWidget);
	splitter->addWidget(tableView);
	splitter->setSizes({currentChartWidget->hasChartData() ? 1 : 0, 1});
	// splitter->setStretchFactor(currentChartWidget->hasChartData() ? 1 : 0, 1); // FIXME: 50:50 if chart is present
	int index = tabs->addTab(splitter, QString::fromWCharArray(name.c_str()));
	if (tabs->count() == 2) tabs->setCurrentIndex(index); // switch to the first relation (first tab is Options tab)
	tabs->setTabIcon(index, QIcon::fromTheme("application-vnd.oasis.opendocument.spreadsheet"));
}

void RelpipeChartMainWindow::attribute(const string_t value) {
	currentModel->addAttribute(value);
}

void RelpipeChartMainWindow::setStatusMessage(string_t message) {
	status->setText(QString::fromWCharArray(message.c_str()));
}

void RelpipeChartMainWindow::endOfPipe() {
	if (currentChartWidget) currentChartWidget->endOfRelation();
	setStatusMessage(L"Reading successfully finished.");
}