src/RelpipeChartMainWindow.cpp
branchv_0
changeset 28 04f1ac8a931b
parent 23 ff4a1c07a481
child 29 0f9f7d6564cd
equal deleted inserted replaced
27:8c5364450a46 28:04f1ac8a931b
     1 #include <vector>
     1 #include <vector>
     2 
     2 
     3 #include <QPushButton>
     3 #include <QPushButton>
     4 #include <QSplitter>
       
     5 #include <QTableView>
     4 #include <QTableView>
     6 
       
     7 #include <QChart>
       
     8 #include <QChartView>
       
     9 #include <QStackedBarSeries>
       
    10 #include <QBarCategoryAxis>
       
    11 #include <QVBarModelMapper>
       
    12 
     5 
    13 #include "RelpipeChartMainWindow.h"
     6 #include "RelpipeChartMainWindow.h"
    14 
     7 
    15 using namespace relpipe::reader;
     8 using namespace relpipe::reader;
    16 using namespace relpipe::reader::handlers;
     9 using namespace relpipe::reader::handlers;
    17 
       
    18 QT_CHARTS_USE_NAMESPACE
       
    19 
    10 
    20 RelpipeChartMainWindow::RelpipeChartMainWindow() {
    11 RelpipeChartMainWindow::RelpipeChartMainWindow() {
    21 	widget.setupUi(this);
    12 	widget.setupUi(this);
    22 
    13 
    23 	int optionsIndex = tabs->addTab(new QPushButton("here will be options", tabs), "Options");
    14 	int optionsIndex = tabs->addTab(new QPushButton("here will be options", tabs), "Options");
    29 RelpipeChartMainWindow::~RelpipeChartMainWindow() {
    20 RelpipeChartMainWindow::~RelpipeChartMainWindow() {
    30 }
    21 }
    31 
    22 
    32 void RelpipeChartMainWindow::startRelation(const string_t name, std::vector<AttributeMetadata> attributes) {
    23 void RelpipeChartMainWindow::startRelation(const string_t name, std::vector<AttributeMetadata> attributes) {
    33 	setStatusMessage(L"Reading relation: " + name);
    24 	setStatusMessage(L"Reading relation: " + name);
    34 	QSplitter* splitter = new QSplitter(Qt::Orientation::Vertical, tabs);
       
    35 
    25 
    36 	currentModel = new RelpipeTableModel(attributes, this);
    26 	currentModel = new RelpipeTableModel(attributes, this);
    37 	QTableView* tableView = new QTableView(this);
    27 	QTableView* tableView = new QTableView(this);
    38 	tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeMode::ResizeToContents);
    28 	tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeMode::ResizeToContents);
    39 	tableView->setModel(currentModel);
    29 	tableView->setModel(currentModel);
    40 	
    30 
    41 	// TODO: chart
    31 	if (currentChartWidget) currentChartWidget->endOfRelation();
    42 	splitter->addWidget(new QPushButton("here will be the chart", splitter));
    32 	currentChartWidget = new RelpipeChartWidget(currentModel, splitter);
       
    33 	splitter->addWidget(currentChartWidget);
    43 	splitter->addWidget(tableView);
    34 	splitter->addWidget(tableView);
       
    35 	splitter->setSizes({currentChartWidget->hasChartData() ? 1 : 0, 1});
       
    36 	// splitter->setStretchFactor(currentChartWidget->hasChartData() ? 1 : 0, 1); // FIXME: 50:50 if chart is present
    44 	int index = tabs->addTab(splitter, QString::fromWCharArray(name.c_str()));
    37 	int index = tabs->addTab(splitter, QString::fromWCharArray(name.c_str()));
    45 	if (tabs->count() == 2) tabs->setCurrentIndex(index); // switch to the first relation (first tab is Options tab)
    38 	if (tabs->count() == 2) tabs->setCurrentIndex(index); // switch to the first relation (first tab is Options tab)
    46 	tabs->setTabIcon(index, QIcon::fromTheme("application-vnd.oasis.opendocument.spreadsheet"));
    39 	tabs->setTabIcon(index, QIcon::fromTheme("application-vnd.oasis.opendocument.spreadsheet"));
    47 }
    40 }
    48 
    41 
    53 void RelpipeChartMainWindow::setStatusMessage(string_t message) {
    46 void RelpipeChartMainWindow::setStatusMessage(string_t message) {
    54 	status->setText(QString::fromWCharArray(message.c_str()));
    47 	status->setText(QString::fromWCharArray(message.c_str()));
    55 }
    48 }
    56 
    49 
    57 void RelpipeChartMainWindow::endOfPipe() {
    50 void RelpipeChartMainWindow::endOfPipe() {
       
    51 	if (currentChartWidget) currentChartWidget->endOfRelation();
    58 	setStatusMessage(L"Reading successfully finished.");
    52 	setStatusMessage(L"Reading successfully finished.");
    59 }
    53 }