#include <QTabWidget>
#include <QPushButton>
#include <QLabel>
#include <QStatusBar>
#include <QSplitter>
#include <QScrollArea>
#include <QTableWidget>
#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(new QLabel("Loading relations...", widget.statusbar));
// TODO: remove; just demo
QPushButton* emitButton = new QPushButton("emit", widget.statusbar);
statusBar()->addWidget(emitButton);
QObject::connect(
emitButton, &QPushButton::pressed,
this, &RelpipeChartMainWindow::slot123
);
// ---
setCentralWidget(tabs);
}
RelpipeChartMainWindow::~RelpipeChartMainWindow() {
}
void RelpipeChartMainWindow::slot123() {
// TODO: remove; just demo
statusBar()->addWidget(new QPushButton("slot123", widget.statusbar));
}
void RelpipeChartMainWindow::startRelation(string_t name, std::vector<AttributeMetadata> attributes) {
attributeCounter = 0;
QSplitter* splitter = new QSplitter(Qt::Orientation::Vertical, tabs);
currentTable = new QTableWidget(0, attributes.size(), splitter);
QStringList headers;
for (AttributeMetadata a : attributes) headers << QString::fromWCharArray(a.getAttributeName().c_str());
currentTable->setHorizontalHeaderLabels(headers);
currentTable->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeMode::ResizeToContents);
// TODO: chart
splitter->addWidget(new QPushButton("here will be the chart", splitter));
splitter->addWidget(currentTable);
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) {
// TODO: draw chart
integer_t column = attributeCounter % currentTable->columnCount();
integer_t row = attributeCounter / currentTable->columnCount();
if (row >= currentTable->rowCount()) currentTable->insertRow(currentTable->rowCount());
currentTable->setItem(row, column, new QTableWidgetItem(QString::fromWCharArray(value.c_str())));
attributeCounter++;
}
void RelpipeChartMainWindow::endOfPipe() {
// TODO: just display a message
statusBar()->addWidget(new QPushButton("endOfPipe", widget.statusbar));
}