mainwidget.cpp
157 lines
| 4.9 KiB
| text/x-c
|
CppLexer
Tero Ahola
|
r5 | #include "mainwidget.h" | ||
Tero Ahola
|
r8 | #include "qchartwidget.h" | ||
//#include <chartwidget.h> | ||||
Tero Ahola
|
r5 | #include <QPushButton> | ||
#include <QComboBox> | ||||
#include <QSpinBox> | ||||
Tero Ahola
|
r6 | #include <QCheckBox> | ||
Tero Ahola
|
r5 | #include <QGridLayout> | ||
#include <QHBoxLayout> | ||||
#include <QLabel> | ||||
#include <QSpacerItem> | ||||
#include <QMessageBox> | ||||
#include <QDebug> | ||||
MainWidget::MainWidget(QWidget *parent) : | ||||
QWidget(parent) | ||||
{ | ||||
Tero Ahola
|
r8 | m_chartWidget = new QChartWidget(this); | ||
// m_chartWidget->resize(QSize(200,200)); | ||||
// m_chartWidget->setColor(Qt::red); | ||||
Tero Ahola
|
r5 | // Chart type | ||
Tero Ahola
|
r7 | // TODO: How about multiple types? | ||
// Should the type be a property of a graph instead of the chart? | ||||
Tero Ahola
|
r5 | QComboBox *chartTypeCombo = new QComboBox(this); | ||
chartTypeCombo->addItem("Line"); | ||||
chartTypeCombo->addItem("Area"); | ||||
chartTypeCombo->addItem("Bar"); | ||||
chartTypeCombo->addItem("Pie"); | ||||
chartTypeCombo->addItem("Scatter"); | ||||
chartTypeCombo->addItem("Spline"); | ||||
connect(chartTypeCombo, SIGNAL(currentIndexChanged(int)), | ||||
this, SLOT(chartTypeChanged(int))); | ||||
// Test data selector | ||||
Tero Ahola
|
r8 | QPushButton *fileButton = new QPushButton("From file"); | ||
QPushButton *urlButton = new QPushButton("From URL"); | ||||
Tero Ahola
|
r5 | |||
// Chart background | ||||
QComboBox *backgroundCombo = new QComboBox(this); | ||||
backgroundCombo->addItem("todo: add background types"); | ||||
connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), | ||||
this, SLOT(backgroundChanged(int))); | ||||
// Axis | ||||
Tero Ahola
|
r7 | // TODO: multiple axes? | ||
Tero Ahola
|
r8 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); | ||
connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); | ||||
Tero Ahola
|
r5 | // Allow setting also non-sense values (like -2147483648 and 2147483647) | ||
Tero Ahola
|
r6 | m_xMinSpin = new QSpinBox(); | ||
m_xMinSpin->setMinimum(INT_MIN); | ||||
m_xMinSpin->setMaximum(INT_MAX); | ||||
m_xMinSpin->setValue(0); | ||||
connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); | ||||
m_xMaxSpin = new QSpinBox(); | ||||
m_xMaxSpin->setMinimum(INT_MIN); | ||||
m_xMaxSpin->setMaximum(INT_MAX); | ||||
m_xMaxSpin->setValue(10); | ||||
connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); | ||||
m_yMinSpin = new QSpinBox(); | ||||
m_yMinSpin->setMinimum(INT_MIN); | ||||
m_yMinSpin->setMaximum(INT_MAX); | ||||
m_yMinSpin->setValue(0); | ||||
connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); | ||||
m_yMaxSpin = new QSpinBox(); | ||||
m_yMaxSpin->setMinimum(INT_MIN); | ||||
m_yMaxSpin->setMaximum(INT_MAX); | ||||
m_yMaxSpin->setValue(10); | ||||
connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); | ||||
Tero Ahola
|
r5 | |||
QGridLayout *grid = new QGridLayout(); | ||||
QHBoxLayout *hbox = new QHBoxLayout(); | ||||
grid->addWidget(new QLabel("Chart type:"), 0, 0); | ||||
Tero Ahola
|
r8 | grid->addWidget(chartTypeCombo, 0, 1, 1, 2); | ||
Tero Ahola
|
r5 | grid->addWidget(new QLabel("Data:"), 1, 0); | ||
Tero Ahola
|
r8 | grid->addWidget(fileButton, 1, 1); | ||
grid->addWidget(urlButton, 1, 2); | ||||
Tero Ahola
|
r5 | grid->addWidget(new QLabel("Background:"), 2, 0); | ||
Tero Ahola
|
r8 | grid->addWidget(backgroundCombo, 2, 1, 1, 2); | ||
grid->addWidget(m_autoScaleCheck, 3, 0); | ||||
Tero Ahola
|
r6 | grid->addWidget(new QLabel("x min:"), 4, 0); | ||
Tero Ahola
|
r8 | grid->addWidget(m_xMinSpin, 4, 1, 1, 2); | ||
Tero Ahola
|
r6 | grid->addWidget(new QLabel("x max:"), 5, 0); | ||
Tero Ahola
|
r8 | grid->addWidget(m_xMaxSpin, 5, 1, 1, 2); | ||
Tero Ahola
|
r6 | grid->addWidget(new QLabel("y min:"), 6, 0); | ||
Tero Ahola
|
r8 | grid->addWidget(m_yMinSpin, 6, 1, 1, 2); | ||
Tero Ahola
|
r6 | grid->addWidget(new QLabel("y max:"), 7, 0); | ||
Tero Ahola
|
r8 | grid->addWidget(m_yMaxSpin, 7, 1, 1, 2); | ||
Tero Ahola
|
r5 | // add row with empty label to make all the other rows static | ||
Tero Ahola
|
r6 | grid->addWidget(new QLabel(""), 8, 0); | ||
grid->setRowStretch(8, 1); | ||||
Tero Ahola
|
r5 | |||
hbox->addLayout(grid); | ||||
hbox->addWidget(m_chartWidget); | ||||
hbox->setStretch(1, 1); | ||||
setLayout(hbox); | ||||
Tero Ahola
|
r6 | |||
Tero Ahola
|
r8 | m_autoScaleCheck->setChecked(true); | ||
Tero Ahola
|
r5 | } | ||
void MainWidget::chartTypeChanged(int itemIndex) | ||||
{ | ||||
Tero Ahola
|
r8 | // TODO: change chart type | ||
switch (itemIndex) { | ||||
case 4: { | ||||
m_chartWidget->setType(4); | ||||
break; | ||||
} | ||||
default: | ||||
m_chartWidget->setType(0); | ||||
break; | ||||
} | ||||
Tero Ahola
|
r5 | } | ||
void MainWidget::dataChanged(QString itemText) | ||||
{ | ||||
qDebug() << "dataChanged: " << itemText; | ||||
} | ||||
void MainWidget::backgroundChanged(int itemIndex) | ||||
{ | ||||
qDebug() << "backgroundChanged: " << itemIndex; | ||||
} | ||||
Tero Ahola
|
r6 | void MainWidget::autoScaleChanged(int value) | ||
{ | ||||
Tero Ahola
|
r8 | if (value) { | ||
// TODO: enable auto scaling | ||||
} else { | ||||
// TODO: set scaling manually (and disable auto scaling) | ||||
Tero Ahola
|
r6 | } | ||
Tero Ahola
|
r8 | m_xMinSpin->setEnabled(!value); | ||
m_xMaxSpin->setEnabled(!value); | ||||
m_yMinSpin->setEnabled(!value); | ||||
m_yMaxSpin->setEnabled(!value); | ||||
Tero Ahola
|
r6 | } | ||
Tero Ahola
|
r5 | void MainWidget::xMinChanged(int value) | ||
{ | ||||
qDebug() << "xMinChanged: " << value; | ||||
} | ||||
void MainWidget::xMaxChanged(int value) | ||||
{ | ||||
qDebug() << "xMaxChanged: " << value; | ||||
} | ||||
void MainWidget::yMinChanged(int value) | ||||
{ | ||||
qDebug() << "yMinChanged: " << value; | ||||
} | ||||
void MainWidget::yMaxChanged(int value) | ||||
{ | ||||
qDebug() << "yMaxChanged: " << value; | ||||
} | ||||