src/RelpipeChartMainWindow.cpp
author František Kučera <franta-hg@frantovo.cz>
Tue, 09 Oct 2018 23:02:11 +0200
branchv_0
changeset 23 ff4a1c07a481
parent 22 0f0344e1ba61
child 28 04f1ac8a931b
permissions -rw-r--r--
use our own QAbstractTableModel and a QTableView instead of the QTableWidget

#include <vector>

#include <QPushButton>
#include <QSplitter>
#include <QTableView>

#include <QChart>
#include <QChartView>
#include <QStackedBarSeries>
#include <QBarCategoryAxis>
#include <QVBarModelMapper>

#include "RelpipeChartMainWindow.h"

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

QT_CHARTS_USE_NAMESPACE

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);
	QSplitter* splitter = new QSplitter(Qt::Orientation::Vertical, tabs);

	currentModel = new RelpipeTableModel(attributes, this);
	QTableView* tableView = new QTableView(this);
	tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeMode::ResizeToContents);
	tableView->setModel(currentModel);
	
	// TODO: chart
	splitter->addWidget(new QPushButton("here will be the chart", splitter));
	splitter->addWidget(tableView);
	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() {
	setStatusMessage(L"Reading successfully finished.");
}