--- a/src/RelpipeChartMainWindow.cpp Mon Oct 08 14:08:21 2018 +0200
+++ b/src/RelpipeChartMainWindow.cpp Tue Oct 09 23:02:11 2018 +0200
@@ -1,10 +1,8 @@
-#include <QTabWidget>
+#include <vector>
+
#include <QPushButton>
-#include <QLabel>
-#include <QStatusBar>
#include <QSplitter>
-#include <QScrollArea>
-#include <QTableWidget>
+#include <QTableView>
#include <QChart>
#include <QChartView>
@@ -16,6 +14,7 @@
using namespace relpipe::reader;
using namespace relpipe::reader::handlers;
+
QT_CHARTS_USE_NAMESPACE
RelpipeChartMainWindow::RelpipeChartMainWindow() {
@@ -32,32 +31,23 @@
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);
-
+ 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(currentTable);
+ 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) {
- // TODO: draw chart
- integer_t column = attributeCounter % currentTable->columnCount();
- integer_t row = attributeCounter / currentTable->columnCount();
- if (row >= currentTable->rowCount()) currentTable->insertRow(currentTable->rowCount());
- QString name = QString::fromWCharArray(value.c_str());
- currentTable->setItem(row, column, new QTableWidgetItem(name));
- attributeCounter++;
+ currentModel->addAttribute(value);
}
void RelpipeChartMainWindow::setStatusMessage(string_t message) {