From 99c4c9176ee1b9383f461e51a9bd5c8ccacd265b 2012-01-05 10:38:29 From: Tero Ahola Date: 2012-01-05 10:38:29 Subject: [PATCH] New features like chart type to the test app --- diff --git a/test/chartwidgettest/chartwidgettest.pro b/test/chartwidgettest/chartwidgettest.pro index 7e87b0d..97cd4e8 100644 --- a/test/chartwidgettest/chartwidgettest.pro +++ b/test/chartwidgettest/chartwidgettest.pro @@ -1,16 +1,22 @@ -TARGET = chartwidgettest -TEMPLATE = app - -QT += core gui -contains(QT_MAJOR_VERSION, 5) { - QT += widgets -} - -CONFIG += charts -CHARTS += widget - -OBJECTS_DIR = tmp -MOC_DIR = tmp - -SOURCES += main.cpp - +TARGET = chartwidgettest +TEMPLATE = app + +QT += core gui +contains(QT_MAJOR_VERSION, 5) { + QT += widgets +} + +CONFIG += charts +CHARTS += widget + +OBJECTS_DIR = tmp +MOC_DIR = tmp + +SOURCES += main.cpp \ + mainwidget.cpp + +HEADERS += \ + mainwidget.h + + + diff --git a/test/chartwidgettest/main.cpp b/test/chartwidgettest/main.cpp index 8c9e9a8..cc1e7c1 100644 --- a/test/chartwidgettest/main.cpp +++ b/test/chartwidgettest/main.cpp @@ -4,16 +4,14 @@ #else #include #endif -#include +#include "mainwidget.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); - ChartWidget w; - w.resize(QSize(200,200)); - w.setColor(Qt::red); + MainWidget w; w.show(); - + return a.exec(); } diff --git a/test/chartwidgettest/mainwidget.cpp b/test/chartwidgettest/mainwidget.cpp new file mode 100644 index 0000000..69c50d6 --- /dev/null +++ b/test/chartwidgettest/mainwidget.cpp @@ -0,0 +1,138 @@ +#include "mainwidget.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +MainWidget::MainWidget(QWidget *parent) : + QWidget(parent) +{ + m_chartWidget = new ChartWidget(this); + m_chartWidget->resize(QSize(200,200)); + m_chartWidget->setColor(Qt::red); + + // Chart type + 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 + QComboBox *dataCombo = new QComboBox(this); + dataCombo->addItem("todo: add test data"); + connect(dataCombo, SIGNAL(currentIndexChanged(QString)), + this, SLOT(dataChanged(QString))); + + // Chart background + QComboBox *backgroundCombo = new QComboBox(this); + backgroundCombo->addItem("todo: add background types"); + connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), + this, SLOT(backgroundChanged(int))); + + // Axis + // 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))); + + QGridLayout *grid = new QGridLayout(); + QHBoxLayout *hbox = new QHBoxLayout(); + grid->addWidget(new QLabel("Chart type:"), 0, 0); + grid->addWidget(chartTypeCombo, 0, 1); + grid->addWidget(new QLabel("Data:"), 1, 0); + 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); + // add row with empty label to make all the other rows static + grid->addWidget(new QLabel(""), 7, 0); + grid->setRowStretch(7, 1); + + hbox->addLayout(grid); + hbox->addWidget(m_chartWidget); + hbox->setStretch(1, 1); + + setLayout(hbox); +} + +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; + } +} + +void MainWidget::dataChanged(QString itemText) +{ + qDebug() << "dataChanged: " << itemText; +} + +void MainWidget::backgroundChanged(int itemIndex) +{ + qDebug() << "backgroundChanged: " << itemIndex; +} + +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; +} diff --git a/test/chartwidgettest/mainwidget.h b/test/chartwidgettest/mainwidget.h new file mode 100644 index 0000000..77d2119 --- /dev/null +++ b/test/chartwidgettest/mainwidget.h @@ -0,0 +1,29 @@ +#ifndef MAINWIDGET_H +#define MAINWIDGET_H + +#include + +class ChartWidget; + +class MainWidget : public QWidget +{ + Q_OBJECT +public: + explicit MainWidget(QWidget *parent = 0); + +signals: + +private slots: + void chartTypeChanged(int itemIndex); + void dataChanged(QString itemText); + void backgroundChanged(int itemIndex); + void xMinChanged(int value); + void xMaxChanged(int value); + void yMinChanged(int value); + void yMaxChanged(int value); + +private: + ChartWidget *m_chartWidget; +}; + +#endif // MAINWIDGET_H diff --git a/test/qmlcharttest/charttest.qml b/test/qmlcharttest/charttest.qml index c4a9672..85a871a 100644 --- a/test/qmlcharttest/charttest.qml +++ b/test/qmlcharttest/charttest.qml @@ -1,5 +1,5 @@ -//import QtQuick 1.1 -import QtQuick 2.0 +import QtQuick 1.1 +//import QtQuick 2.0 import com.digia.charts 1.0 Chart {