diff --git a/test/chartwidgettest/mainwidget.cpp b/test/chartwidgettest/mainwidget.cpp index 69c50d6..7711389 100644 --- a/test/chartwidgettest/mainwidget.cpp +++ b/test/chartwidgettest/mainwidget.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -41,27 +42,29 @@ MainWidget::MainWidget(QWidget *parent) : this, SLOT(backgroundChanged(int))); // Axis + QCheckBox *autoScaleCheck = new QCheckBox("Automatic scaling"); + connect(autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); // Allow setting also non-sense values (like -2147483648 and 2147483647) - QSpinBox *xMinSpin = new QSpinBox(); - xMinSpin->setMinimum(INT_MIN); - xMinSpin->setMaximum(INT_MAX); - xMinSpin->setValue(0); - connect(xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); - QSpinBox *xMaxSpin = new QSpinBox(); - xMaxSpin->setMinimum(INT_MIN); - xMaxSpin->setMaximum(INT_MAX); - xMaxSpin->setValue(10); - connect(xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); - QSpinBox *yMinSpin = new QSpinBox(); - yMinSpin->setMinimum(INT_MIN); - yMinSpin->setMaximum(INT_MAX); - yMinSpin->setValue(0); - connect(yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); - QSpinBox *yMaxSpin = new QSpinBox(); - yMaxSpin->setMinimum(INT_MIN); - yMaxSpin->setMaximum(INT_MAX); - yMaxSpin->setValue(10); - connect(yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); + 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))); QGridLayout *grid = new QGridLayout(); QHBoxLayout *hbox = new QHBoxLayout(); @@ -71,40 +74,36 @@ MainWidget::MainWidget(QWidget *parent) : grid->addWidget(dataCombo, 1, 1); grid->addWidget(new QLabel("Background:"), 2, 0); grid->addWidget(backgroundCombo, 2, 1); - grid->addWidget(new QLabel("x min:"), 3, 0); - grid->addWidget(xMinSpin, 3, 1); - grid->addWidget(new QLabel("x max:"), 4, 0); - grid->addWidget(xMaxSpin, 4, 1); - grid->addWidget(new QLabel("y min:"), 5, 0); - grid->addWidget(yMinSpin, 5, 1); - grid->addWidget(new QLabel("y max:"), 6, 0); - grid->addWidget(yMaxSpin, 6, 1); + grid->addWidget(autoScaleCheck, 3, 0); + grid->addWidget(new QLabel("x min:"), 4, 0); + grid->addWidget(m_xMinSpin, 4, 1); + grid->addWidget(new QLabel("x max:"), 5, 0); + grid->addWidget(m_xMaxSpin, 5, 1); + grid->addWidget(new QLabel("y min:"), 6, 0); + grid->addWidget(m_yMinSpin, 6, 1); + grid->addWidget(new QLabel("y max:"), 7, 0); + grid->addWidget(m_yMaxSpin, 7, 1); // add row with empty label to make all the other rows static - grid->addWidget(new QLabel(""), 7, 0); - grid->setRowStretch(7, 1); + grid->addWidget(new QLabel(""), 8, 0); + grid->setRowStretch(8, 1); hbox->addLayout(grid); hbox->addWidget(m_chartWidget); hbox->setStretch(1, 1); setLayout(hbox); + + // Setting auto scale affects min/max value spin boxes, so it needs to be done after they have + // been constructed + autoScaleCheck->setChecked(true); } void MainWidget::chartTypeChanged(int itemIndex) { qDebug() << "chartTypeChanged: " << itemIndex; - - switch (itemIndex) { -// case 0: -// m_chartWidget->setType(ChartWidget::TypeLine); -// break; - default: - // TODO: api for setting chart type? - QMessageBox msg; - msg.setText("TODO: API for setting chart type"); - msg.exec(); - break; - } + QMessageBox msg; + msg.setText("TODO: API for setting chart type"); + msg.exec(); } void MainWidget::dataChanged(QString itemText) @@ -117,6 +116,21 @@ void MainWidget::backgroundChanged(int itemIndex) qDebug() << "backgroundChanged: " << itemIndex; } +void MainWidget::autoScaleChanged(int value) +{ + if (this->isVisible()) { + QMessageBox msg; + msg.setText("TODO: APIs for using either auto scaling or explicit values"); + msg.exec(); + } + + // TODO: get initial spin box axis values from charts widget + m_xMinSpin->setEnabled(value == Qt::Unchecked); + m_xMaxSpin->setEnabled(value == Qt::Unchecked); + m_yMinSpin->setEnabled(value == Qt::Unchecked); + m_yMaxSpin->setEnabled(value == Qt::Unchecked); +} + void MainWidget::xMinChanged(int value) { qDebug() << "xMinChanged: " << value; diff --git a/test/chartwidgettest/mainwidget.h b/test/chartwidgettest/mainwidget.h index 77d2119..8b703a6 100644 --- a/test/chartwidgettest/mainwidget.h +++ b/test/chartwidgettest/mainwidget.h @@ -4,6 +4,7 @@ #include class ChartWidget; +class QSpinBox; class MainWidget : public QWidget { @@ -17,6 +18,7 @@ private slots: void chartTypeChanged(int itemIndex); void dataChanged(QString itemText); void backgroundChanged(int itemIndex); + void autoScaleChanged(int value); void xMinChanged(int value); void xMaxChanged(int value); void yMinChanged(int value); @@ -24,6 +26,10 @@ private slots: private: ChartWidget *m_chartWidget; + QSpinBox *m_xMinSpin; + QSpinBox *m_xMaxSpin; + QSpinBox *m_yMinSpin; + QSpinBox *m_yMaxSpin; }; #endif // MAINWIDGET_H