src/RelpipeChartMainWindow.cpp
branchv_0
changeset 23 ff4a1c07a481
parent 22 0f0344e1ba61
child 28 04f1ac8a931b
equal deleted inserted replaced
22:0f0344e1ba61 23:ff4a1c07a481
     1 #include <QTabWidget>
     1 #include <vector>
       
     2 
     2 #include <QPushButton>
     3 #include <QPushButton>
     3 #include <QLabel>
       
     4 #include <QStatusBar>
       
     5 #include <QSplitter>
     4 #include <QSplitter>
     6 #include <QScrollArea>
     5 #include <QTableView>
     7 #include <QTableWidget>
       
     8 
     6 
     9 #include <QChart>
     7 #include <QChart>
    10 #include <QChartView>
     8 #include <QChartView>
    11 #include <QStackedBarSeries>
     9 #include <QStackedBarSeries>
    12 #include <QBarCategoryAxis>
    10 #include <QBarCategoryAxis>
    14 
    12 
    15 #include "RelpipeChartMainWindow.h"
    13 #include "RelpipeChartMainWindow.h"
    16 
    14 
    17 using namespace relpipe::reader;
    15 using namespace relpipe::reader;
    18 using namespace relpipe::reader::handlers;
    16 using namespace relpipe::reader::handlers;
       
    17 
    19 QT_CHARTS_USE_NAMESPACE
    18 QT_CHARTS_USE_NAMESPACE
    20 
    19 
    21 RelpipeChartMainWindow::RelpipeChartMainWindow() {
    20 RelpipeChartMainWindow::RelpipeChartMainWindow() {
    22 	widget.setupUi(this);
    21 	widget.setupUi(this);
    23 
    22 
    30 RelpipeChartMainWindow::~RelpipeChartMainWindow() {
    29 RelpipeChartMainWindow::~RelpipeChartMainWindow() {
    31 }
    30 }
    32 
    31 
    33 void RelpipeChartMainWindow::startRelation(const string_t name, std::vector<AttributeMetadata> attributes) {
    32 void RelpipeChartMainWindow::startRelation(const string_t name, std::vector<AttributeMetadata> attributes) {
    34 	setStatusMessage(L"Reading relation: " + name);
    33 	setStatusMessage(L"Reading relation: " + name);
    35 	attributeCounter = 0;
       
    36 	QSplitter* splitter = new QSplitter(Qt::Orientation::Vertical, tabs);
    34 	QSplitter* splitter = new QSplitter(Qt::Orientation::Vertical, tabs);
    37 
    35 
    38 	currentTable = new QTableWidget(0, attributes.size(), splitter);
    36 	currentModel = new RelpipeTableModel(attributes, this);
    39 	QStringList headers;
    37 	QTableView* tableView = new QTableView(this);
    40 	for (AttributeMetadata a : attributes) headers << QString::fromWCharArray(a.getAttributeName().c_str());
    38 	tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeMode::ResizeToContents);
    41 	// for (AttributeMetadata a : attributes) headers << (QString::fromWCharArray(a.getAttributeName().c_str()) + " (" + QString::fromWCharArray(a.getTypeName().c_str()) + ")" );
    39 	tableView->setModel(currentModel);
    42 	currentTable->setHorizontalHeaderLabels(headers);
    40 	
    43 	currentTable->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeMode::ResizeToContents);
       
    44 
       
    45 	// TODO: chart
    41 	// TODO: chart
    46 	splitter->addWidget(new QPushButton("here will be the chart", splitter));
    42 	splitter->addWidget(new QPushButton("here will be the chart", splitter));
    47 	splitter->addWidget(currentTable);
    43 	splitter->addWidget(tableView);
    48 	int index = tabs->addTab(splitter, QString::fromWCharArray(name.c_str()));
    44 	int index = tabs->addTab(splitter, QString::fromWCharArray(name.c_str()));
    49 	if (tabs->count() == 2) tabs->setCurrentIndex(index); // switch to the first relation (first tab is Options tab)
    45 	if (tabs->count() == 2) tabs->setCurrentIndex(index); // switch to the first relation (first tab is Options tab)
    50 	tabs->setTabIcon(index, QIcon::fromTheme("application-vnd.oasis.opendocument.spreadsheet"));
    46 	tabs->setTabIcon(index, QIcon::fromTheme("application-vnd.oasis.opendocument.spreadsheet"));
    51 }
    47 }
    52 
    48 
    53 void RelpipeChartMainWindow::attribute(const string_t value) {
    49 void RelpipeChartMainWindow::attribute(const string_t value) {
    54 	// TODO: draw chart
    50 	currentModel->addAttribute(value);
    55 	integer_t column = attributeCounter % currentTable->columnCount();
       
    56 	integer_t row = attributeCounter / currentTable->columnCount();
       
    57 	if (row >= currentTable->rowCount()) currentTable->insertRow(currentTable->rowCount());
       
    58 	QString name = QString::fromWCharArray(value.c_str());
       
    59 	currentTable->setItem(row, column, new QTableWidgetItem(name));
       
    60 	attributeCounter++;
       
    61 }
    51 }
    62 
    52 
    63 void RelpipeChartMainWindow::setStatusMessage(string_t message) {
    53 void RelpipeChartMainWindow::setStatusMessage(string_t message) {
    64 	status->setText(QString::fromWCharArray(message.c_str()));
    54 	status->setText(QString::fromWCharArray(message.c_str()));
    65 }
    55 }