better use of signal/slot mechanism, threads, Qt::ConnectionType::QueuedConnection
#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(status);
setCentralWidget(tabs);
}
RelpipeChartMainWindow::~RelpipeChartMainWindow() {
}
void RelpipeChartMainWindow::startRelation(const string_t name, std::vector<AttributeMetadata> attributes) {
setStatusMessage(L"Reading relation: " + name);
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());
// for (AttributeMetadata a : attributes) headers << (QString::fromWCharArray(a.getAttributeName().c_str()) + " (" + QString::fromWCharArray(a.getTypeName().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::setStatusMessage(string_t message) {
status->setText(QString::fromWCharArray(message.c_str()));
}
void RelpipeChartMainWindow::endOfPipe() {
setStatusMessage(L"Reading successfully finished.");
}