src/RelpipeChartMainWindow.cpp
author František Kučera <franta-hg@frantovo.cz>
Sun, 26 May 2019 22:22:59 +0200
branchv_0
changeset 40 338f27352aaa
parent 32 23018a2ed2a0
child 42 707a6734f364
permissions -rw-r--r--
Added tag v0.12 for changeset 4ad44f170a58

/**
 * Relational pipes
 * Copyright © 2018 František Kučera (Frantovo.cz, GlobalCode.info)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
#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();
	splitter = new QSplitter(Qt::Orientation::Vertical, tabs);
	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.");
}