From 1d8f8b316dca8c026ff8637ccd2d3a44364c1662 2012-02-22 14:16:50 From: Tero Ahola Date: 2012-02-22 14:16:50 Subject: [PATCH] Refactored chartwidgettest test data impl --- diff --git a/example/scatter/main.cpp b/example/scatter/main.cpp index 0a5c1b7..3a2d258 100644 --- a/example/scatter/main.cpp +++ b/example/scatter/main.cpp @@ -13,6 +13,7 @@ int main(int argc, char *argv[]) // Create chart widget QChartView *chartView = new QChartView(); + //! [1] // Add scatter series with simple test data QScatterSeries *scatter = new QScatterSeries(); *scatter << QPointF(0.5, 5.0) @@ -24,6 +25,7 @@ int main(int argc, char *argv[]) << QPointF(2.5, 5.0); // Chart takes ownership chartView->addSeries(scatter); + //! [1] // Add another scatter series // - more data with random component diff --git a/src/charttheme.cpp b/src/charttheme.cpp index 1ba027c..1ea3d29 100644 --- a/src/charttheme.cpp +++ b/src/charttheme.cpp @@ -167,12 +167,12 @@ void ChartTheme::decorate(ScatterPresenter* presenter, QScatterSeries* series, i QColor color = m_seriesColor.at(count % m_seriesColor.size()); // TODO: define alpha in the theme? or in the series? - color.setAlpha(120); + //color.setAlpha(120); QBrush brush(color, Qt::SolidPattern); presenter->m_markerBrush = brush; - QPen pen(brush, 1); + QPen pen(brush, 3); pen.setColor(color); presenter->m_markerPen = pen; } diff --git a/src/piechart/qpieseries.cpp b/src/piechart/qpieseries.cpp index 37e9c1e..0a94f51 100644 --- a/src/piechart/qpieseries.cpp +++ b/src/piechart/qpieseries.cpp @@ -66,7 +66,7 @@ bool QPieSeries::setData(QList data) { // TODO: remove this function QList slices; - foreach (int value, data) + foreach (qreal value, data) slices << new QPieSlice(value, QString::number(value)); set(slices); return true; diff --git a/src/scatterseries/qscatterseries.cpp b/src/scatterseries/qscatterseries.cpp index da8c86d..701f699 100644 --- a/src/scatterseries/qscatterseries.cpp +++ b/src/scatterseries/qscatterseries.cpp @@ -33,6 +33,7 @@ QScatterSeriesPrivate::QScatterSeriesPrivate() : \class QScatterSeries \brief QtCommercial Chart series API for showing scatter series. + \snippet ../../example/scatter/main.cpp 1 Example on how to create a chart with scatter series: \code #include diff --git a/src/scatterseries/scatterpresenter.cpp b/src/scatterseries/scatterpresenter.cpp index d886f03..cda4d02 100644 --- a/src/scatterseries/scatterpresenter.cpp +++ b/src/scatterseries/scatterpresenter.cpp @@ -4,6 +4,7 @@ #include #include #include +#include QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -45,21 +46,61 @@ void ScatterPresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem * { // TODO: Optimization: avoid setting on every paint method call? // The custom settings in series override those defined by the theme - if (m_series->markerPen().color().isValid()) - painter->setPen(m_series->markerPen()); - else - painter->setPen(m_markerPen); + int shape = m_series->markerShape(); + + painter->save(); + painter->setClipRect(m_boundingRect); + + // Paint dropshadow + QPen dropShadowPen(QColor(0, 0, 0, 70)); + dropShadowPen.setWidth(3); + painter->setPen(dropShadowPen); + painter->setBrush(Qt::NoBrush); + painter->setRenderHint(QPainter::Antialiasing); + for (int i(0); i < m_scenex.count() && i < m_sceney.count(); i++) { + if (scene()->width() > m_scenex.at(i) && scene()->height() > m_sceney.at(i)) + switch (shape) { + case QScatterSeries::MarkerShapeDefault: + // Fallthrough, defaults to circle + case QScatterSeries::MarkerShapeCircle: + painter->drawChord(m_scenex.at(i) + 2, m_sceney.at(i) + 2, 9, 9, 0, 5760); + break; + case QScatterSeries::MarkerShapePoint: + //painter->drawPoint(m_scenex.at(i), m_sceney.at(i)); + break; + case QScatterSeries::MarkerShapeRectangle: + painter->drawRect(m_scenex.at(i) + 2, m_sceney.at(i) + 2, 8, 8); + break; + case QScatterSeries::MarkerShapeTiltedRectangle: { + // TODO: + static const QPointF points[4] = { + QPointF(-1.0 + m_scenex.at(i), 0.0 + m_sceney.at(i)), + QPointF(0.0 + m_scenex.at(i), 1.0 + m_sceney.at(i)), + QPointF(1.0 + m_scenex.at(i), 0.0 + m_sceney.at(i)), + QPointF(0.0 + m_scenex.at(i), -1.0 + m_sceney.at(i)) + }; + painter->drawPolygon(points, 4); + break; + } + default: + // TODO: implement the rest of the shapes + Q_ASSERT(false); + break; + } + } + // Paint the shape + QPen pen = m_markerPen; + if (m_series->markerPen().color().isValid()) + pen = m_series->markerPen(); if (m_series->markerBrush().color().isValid()) painter->setBrush(m_series->markerBrush()); else painter->setBrush(m_markerBrush); - - int shape = m_series->markerShape(); - + painter->setPen(pen); + painter->setRenderHint(QPainter::Antialiasing, false); for (int i(0); i < m_scenex.count() && i < m_sceney.count(); i++) { if (scene()->width() > m_scenex.at(i) && scene()->height() > m_sceney.at(i)) - // Paint a shape switch (shape) { case QScatterSeries::MarkerShapeDefault: // Fallthrough, defaults to circle @@ -72,7 +113,7 @@ void ScatterPresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem * case QScatterSeries::MarkerShapeRectangle: painter->drawRect(m_scenex.at(i), m_sceney.at(i), 9, 9); break; - case QScatterSeries::MarkerShapeTiltedRectangle: + case QScatterSeries::MarkerShapeTiltedRectangle: { // TODO: static const QPointF points[4] = { QPointF(-1.0 + m_scenex.at(i), 0.0 + m_sceney.at(i)), @@ -82,12 +123,15 @@ void ScatterPresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem * }; painter->drawPolygon(points, 4); break; + } default: // TODO: implement the rest of the shapes Q_ASSERT(false); break; } } + + painter->restore(); } void ScatterPresenter::changeGeometry() diff --git a/test/chartwidgettest/dataseriedialog.cpp b/test/chartwidgettest/dataseriedialog.cpp index 6c64d4a..acfb32c 100644 --- a/test/chartwidgettest/dataseriedialog.cpp +++ b/test/chartwidgettest/dataseriedialog.cpp @@ -1,42 +1,16 @@ #include "dataseriedialog.h" #include #include -#include +#include #include +#include +#include #include #include DataSerieDialog::DataSerieDialog(QString defaultType, QWidget *parent) : QDialog(parent) { - // Combo box for selecting the series type - m_seriesTypeCombo = new QComboBox(this); - m_seriesTypeCombo->addItem("Line"); - m_seriesTypeCombo->addItem("Area"); - m_seriesTypeCombo->addItem("Bar"); - m_seriesTypeCombo->addItem("StackedBar"); - m_seriesTypeCombo->addItem("PercentBar"); - m_seriesTypeCombo->addItem("Pie"); - m_seriesTypeCombo->addItem("Scatter"); - m_seriesTypeCombo->addItem("Spline"); - - // Allow pre-selection of a series type - if (defaultType != "") { - int index = m_seriesTypeCombo->findText(defaultType); - if (index > 0) - m_seriesTypeCombo->setCurrentIndex(index); - } - - // Combo box for selecting data for the new series - m_testDataCombo = new QComboBox(this); - m_testDataCombo->addItem("linear"); - m_testDataCombo->addItem("linear, 1M"); - m_testDataCombo->addItem("SIN"); - m_testDataCombo->addItem("SIN + random"); - m_testDataCombo->addItem("Table, 5 series"); - m_testDataCombo->addItem("TODO From file..."); - m_testDataCombo->addItem("TODO From URL..."); - QDialogButtonBox *addSeriesBox = new QDialogButtonBox(Qt::Horizontal); QPushButton *b = addSeriesBox->addButton(QDialogButtonBox::Ok); connect(b, SIGNAL(clicked()), this, SLOT(accept())); @@ -44,22 +18,132 @@ DataSerieDialog::DataSerieDialog(QString defaultType, QWidget *parent) : connect(b, SIGNAL(clicked()), this, SLOT(reject())); QGridLayout *grid = new QGridLayout(); - grid->addWidget(new QLabel("Series type:"), 0, 0); - grid->addWidget(m_seriesTypeCombo, 0, 1); - grid->addWidget(new QLabel("Data:"), 1, 0); - grid->addWidget(m_testDataCombo, 1, 1); - grid->addWidget(addSeriesBox, 2, 1); + + m_seriesTypeSelector = seriesTypeSelector(); + m_columnCountSelector = columnCountSelector(); + m_rowCountSelector = rowCountSelector(); + m_dataCharacteristicsSelector = dataCharacteristicsSelector(); + + grid->addWidget(m_seriesTypeSelector, 0, 0); + grid->addWidget(m_columnCountSelector, 0, 1); + grid->addWidget(m_rowCountSelector, 1, 1); + grid->addWidget(m_dataCharacteristicsSelector, 1, 0); + m_labelsSelector = new QCheckBox("Labels defined"); + m_labelsSelector->setChecked(true); + grid->addWidget(m_labelsSelector, 2, 0); + grid->addWidget(addSeriesBox, 3, 1); setLayout(grid); } +QGroupBox *DataSerieDialog::seriesTypeSelector() +{ + QVBoxLayout *layout = new QVBoxLayout(); + + QRadioButton *line = new QRadioButton("&Line"); + QRadioButton *area = new QRadioButton("&Area"); + QRadioButton *pie = new QRadioButton("&Pie"); + QRadioButton *bar = new QRadioButton("&Bar"); + QRadioButton *scatter = new QRadioButton("&Scatter"); + QRadioButton *spline = new QRadioButton("Spl&ine"); + line->setChecked(true); + + layout->addWidget(line); + layout->addWidget(area); + layout->addWidget(pie); + layout->addWidget(bar); + layout->addWidget(scatter); + layout->addWidget(spline); + + QGroupBox *groupBox = new QGroupBox("Series type"); + groupBox->setLayout(layout); + + return groupBox; +} + +QGroupBox *DataSerieDialog::columnCountSelector() +{ + QVBoxLayout *layout = new QVBoxLayout(); + + QRadioButton *radio = new QRadioButton("1"); + radio->setChecked(true); + layout->addWidget(radio); + layout->addWidget(new QRadioButton("2")); + layout->addWidget(new QRadioButton("3")); + layout->addWidget(new QRadioButton("5")); + layout->addWidget(new QRadioButton("10")); + layout->addWidget(new QRadioButton("100")); + + QGroupBox *groupBox = new QGroupBox("Column count"); + groupBox->setLayout(layout); + + return groupBox; +} + +QGroupBox *DataSerieDialog::rowCountSelector() +{ + QVBoxLayout *layout = new QVBoxLayout(); + + layout->addWidget(new QRadioButton("1")); + QRadioButton *radio = new QRadioButton("10"); + radio->setChecked(true); + layout->addWidget(radio); + layout->addWidget(new QRadioButton("50")); + layout->addWidget(new QRadioButton("100")); + layout->addWidget(new QRadioButton("10000")); + layout->addWidget(new QRadioButton("1000000")); + + QGroupBox *groupBox = new QGroupBox("Row count"); + groupBox->setLayout(layout); + + return groupBox; +} + +QGroupBox *DataSerieDialog::dataCharacteristicsSelector() +{ + QVBoxLayout *layout = new QVBoxLayout(); + + QRadioButton *radio1 = new QRadioButton("Linear"); + radio1->setChecked(true); + layout->addWidget(radio1); + layout->addWidget(new QRadioButton("Constant")); + layout->addWidget(new QRadioButton("Random")); + layout->addWidget(new QRadioButton("Sin")); + layout->addWidget(new QRadioButton("Sin + random")); + + QGroupBox *groupBox = new QGroupBox("Data Characteristics"); + groupBox->setLayout(layout); + + return groupBox; +} + void DataSerieDialog::accept() { - accepted(m_seriesTypeCombo->currentText(), m_testDataCombo->currentText()); + accepted(radioSelection(m_seriesTypeSelector), + radioSelection(m_columnCountSelector).toInt(), + radioSelection(m_rowCountSelector).toInt(), + radioSelection(m_dataCharacteristicsSelector), + m_labelsSelector->isChecked()); QDialog::accept(); } -//void DataSerieDialog::addSeries(QAbstractButton *button) -//{ -// addSeries(button->text().toAscii()); -// accept(); -//} + +QString DataSerieDialog::radioSelection(QGroupBox *groupBox) +{ + QString selection; + QVBoxLayout *layout = qobject_cast(groupBox->layout()); + Q_ASSERT(layout); + + for (int i(0); i < layout->count(); i++) { + QLayoutItem *item = layout->itemAt(i); + Q_ASSERT(item); + QRadioButton *radio = qobject_cast(item->widget()); + Q_ASSERT(radio); + if (radio->isChecked()) { + selection = radio->text(); + break; + } + } + + qDebug() << "radioSelection: " << selection; + return selection; +} diff --git a/test/chartwidgettest/dataseriedialog.h b/test/chartwidgettest/dataseriedialog.h index 37ec17b..9ba83c6 100644 --- a/test/chartwidgettest/dataseriedialog.h +++ b/test/chartwidgettest/dataseriedialog.h @@ -3,7 +3,8 @@ #include -class QComboBox; +class QGroupBox; +class QCheckBox; class DataSerieDialog : public QDialog { @@ -12,14 +13,22 @@ public: explicit DataSerieDialog(QString defaultType, QWidget *parent = 0); signals: - void accepted(QString series, QString data); + void accepted(QString series, int columnCount, int rowCount, QString dataCharacteristics, bool labelsDefined); public slots: void accept(); private: - QComboBox *m_seriesTypeCombo; - QComboBox *m_testDataCombo; + QGroupBox *seriesTypeSelector(); + QGroupBox *columnCountSelector(); + QGroupBox *rowCountSelector(); + QGroupBox *dataCharacteristicsSelector(); + QString radioSelection(QGroupBox *groupBox); + QGroupBox *m_seriesTypeSelector; + QGroupBox *m_columnCountSelector; + QGroupBox *m_rowCountSelector; + QCheckBox *m_labelsSelector; + QGroupBox *m_dataCharacteristicsSelector; }; #endif // DATASERIEDIALOG_H diff --git a/test/chartwidgettest/mainwidget.cpp b/test/chartwidgettest/mainwidget.cpp index 28e2d73..8728a84 100644 --- a/test/chartwidgettest/mainwidget.cpp +++ b/test/chartwidgettest/mainwidget.cpp @@ -63,9 +63,6 @@ MainWidget::MainWidget(QWidget *parent) : // Add layouts and the chart widget to the main layout mainLayout->addWidget(m_chartWidget, 0, 1, 3, 1); setLayout(mainLayout); - - // force an update to test data - testDataChanged(0); } // Combo box for selecting the chart's background @@ -168,140 +165,91 @@ void MainWidget::initPieControls() void MainWidget::addSeries() { DataSerieDialog dialog(m_defaultSeriesName, this); - connect(&dialog, SIGNAL(accepted(QString, QString)), this, SLOT(addSeries(QString, QString))); + connect(&dialog, SIGNAL(accepted(QString, int, int, QString, bool)), + this, SLOT(addSeries(QString, int, int, QString, bool))); dialog.exec(); } -void MainWidget::addSeries(QString series, QString data) +QList MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics) { - qDebug() << "addSeries: " << series << " data: " << data; - m_defaultSeriesName = series; - - // TODO: a dedicated data class for storing x and y values - QList x; - QList y; - - QBarSet *set0 = new QBarSet; - QBarSet *set1 = new QBarSet; - QBarSet *set2 = new QBarSet; - QBarSet *set3 = new QBarSet; - QBarSet *set4 = new QBarSet; - - if (data == "linear") { - for (int i = 0; i < 20; i++) { - x.append(i); - y.append(i); + // TODO: dataCharacteristics + QList testData; + for (int j(0); j < columnCount; j++) { + QList newColumn; + for (int i(0); i < rowCount; i++) { + if (dataCharacteristics == "Sin") { + newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100)); + } else if (dataCharacteristics == "Sin + random") { + newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); + } else if (dataCharacteristics == "Random") { + newColumn.append(rand() % 5); + } else if (dataCharacteristics == "Linear") { + //newColumn.append(i * (j + 1.0)); + // TODO: temporary hack to make pie work; prevent zero values: + newColumn.append(i * (j + 1.0) + 0.1); + } else { // "constant" + newColumn.append((j + 1.0)); + } } - } else if (data == "linear, 1M") { - // 1 million data points from 0.0001 to 100 - // TODO: What is the requirement? Should we be able to show this kind of data with - // reasonable performance, or can we expect the application developer to do "data mining" - // for us, so that the count of data points given to QtCommercial Chart is always - // reasonable? - for (qreal i = 0; i < 100; i += 0.0001) { - x.append(i); - y.append(20); + testData.append(newColumn); + } + return testData; +} + +QStringList MainWidget::generateLabels(int count) +{ + QStringList result; + for (int i(0); i < count; i++) + result.append("label" + QString::number(i)); + return result; +} + +void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled) +{ + qDebug() << "addSeries: " << seriesName + << " columnCount: " << columnCount + << " rowCount: " << rowCount + << " dataCharacteristics: " << dataCharacteristics + << " labels enabled: " << labelsEnabled; + m_defaultSeriesName = seriesName; + + QList data = generateTestData(columnCount, rowCount, dataCharacteristics); + + // Line series and scatter series use similar data + if (seriesName.contains("line", Qt::CaseInsensitive)) { + for (int j(0); j < data.count(); j ++) { + QList column = data.at(j); + QLineChartSeries *series = new QLineChartSeries(); + for (int i(0); i < column.count(); i++) { + series->add(i, column.at(i)); + } + m_chartWidget->addSeries(series); + setCurrentSeries(series); } - } else if (data == "SIN") { - for (int i = 0; i < 100; i++) { - x.append(i); - y.append(abs(sin(3.14159265358979 / 50 * i) * 100)); + } else if (seriesName.contains("scatter", Qt::CaseInsensitive)) { + for (int j(0); j < data.count(); j++) { + QList column = data.at(j); + QScatterSeries *series = new QScatterSeries(); + for (int i(0); i < column.count(); i++) { + (*series) << QPointF(i, column.at(i)); + } + m_chartWidget->addSeries(series); + setCurrentSeries(series); } - } else if (data == "SIN + random") { - for (qreal i = 0; i < 100; i += 0.1) { - x.append(i + (rand() % 5)); - y.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); + } else if (seriesName.contains("pie", Qt::CaseInsensitive)) { + QStringList labels = generateLabels(rowCount); + for (int j(0); j < data.count(); j++) { + QPieSeries *series = new QPieSeries(); + QList column = data.at(j); + for (int i(0); i < column.count(); i++) { + series->add(column.at(i), labels.at(i)); + } + m_chartWidget->addSeries(series); + setCurrentSeries(series); } - } else if (data == "Table, 5 series"){ - // Create some test data to chart - *set0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12; - *set1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0 << 4 << 2; - *set2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1 << 3 << 5; - *set3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5 << 2 << 7; - *set4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10 << 1 << 6; - } else { - // TODO: check if data has a valid file name - Q_ASSERT(false); - } - - // TODO: color of the series - QChartSeries *newSeries = 0; - if (series == "Scatter") { - QScatterSeries *scatter = new QScatterSeries(); - for (int i(0); i < x.count() && i < y.count(); i++) - (*scatter) << QPointF(x.at(i), y.at(i)); - m_chartWidget->addSeries(scatter); - } else if (series == "Pie") { - newSeries = new QPieSeries(); - m_chartWidget->addSeries(newSeries); - Q_ASSERT(newSeries->setData(y)); - } else if (series == "Line") { - // TODO: adding data to an existing line series does not give any visuals for some reason -// newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypeLine); -// QXYChartSeries *lineSeries = static_cast(newSeries); -// lineSeries->setColor(Qt::blue); -// for (int i(0); i < x.count() && i < y.count(); i++) { -// lineSeries->add(x.at(i), y.at(i)); -// } - //Q_ASSERT(newSeries->setData(x, y)); - QLineChartSeries* series0 = new QLineChartSeries(); - for (int i(0); i < x.count() && i < y.count(); i++) - series0->add(x.at(i), y.at(i)); - m_chartWidget->addSeries(series0); - newSeries = series0; - } else if (series == "Bar") { - qDebug() << "Bar chart series"; - - QBarCategory *category = new QBarCategory; - *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; - - QBarChartSeries* series0 = new QBarChartSeries(category, this); - - series0->addBarSet(set0); - series0->addBarSet(set1); - series0->addBarSet(set2); - series0->addBarSet(set3); - series0->addBarSet(set4); - - m_chartWidget->addSeries(series0); - newSeries = series0; - } else if (series == "StackedBar") { - qDebug() << "Stacked bar chart series"; - - QBarCategory *category = new QBarCategory; - *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; - - QStackedBarChartSeries* series0 = new QStackedBarChartSeries(category, this); - - series0->addBarSet(set0); - series0->addBarSet(set1); - series0->addBarSet(set2); - series0->addBarSet(set3); - series0->addBarSet(set4); - - m_chartWidget->addSeries(series0); - newSeries = series0; - } else if (series == "PercentBar") { - qDebug() << "Percent bar chart series"; - - QBarCategory *category = new QBarCategory; - *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; - - QPercentBarChartSeries* series0 = new QPercentBarChartSeries(category, this); - - series0->addBarSet(set0); - series0->addBarSet(set1); - series0->addBarSet(set2); - series0->addBarSet(set3); - series0->addBarSet(set4); - - m_chartWidget->addSeries(series0); - newSeries = series0; - } else { - qDebug() << "Something weird going on in MainWidget::addSeries"; } - setCurrentSeries(newSeries); + // TODO: bar and other... } void MainWidget::setCurrentSeries(QChartSeries *series) @@ -331,42 +279,6 @@ void MainWidget::setCurrentSeries(QChartSeries *series) } } -void MainWidget::testDataChanged(int itemIndex) -{ - qDebug() << "testDataChanged: " << itemIndex; - -// switch (itemIndex) { -// case 0: { -// QList data; -// for (int x = 0; x < 20; x++) { -// data.append(QChartDataPoint() << x << x / 2); -// } -// m_chartWidget->setData(data); -// break; -// } -// case 1: { -// QList data; -// for (int x = 0; x < 100; x++) { -// data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100)); -// } -// m_chartWidget->setData(data); -// break; -// } -// case 2: { -// QList data; -// for (int x = 0; x < 1000; x++) { -// data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); -// data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); -// data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); -// } -// m_chartWidget->setData(data); -// break; -// } -// default: -// break; -// } -} - void MainWidget::backgroundChanged(int itemIndex) { qDebug() << "backgroundChanged: " << itemIndex; diff --git a/test/chartwidgettest/mainwidget.h b/test/chartwidgettest/mainwidget.h index 4567400..21fe2fc 100644 --- a/test/chartwidgettest/mainwidget.h +++ b/test/chartwidgettest/mainwidget.h @@ -11,6 +11,8 @@ class QGridLayout; QTCOMMERCIALCHART_USE_NAMESPACE +#define RealList QList + class MainWidget : public QWidget { Q_OBJECT @@ -27,8 +29,7 @@ private: private slots: void addSeries(); - void addSeries(QString series, QString data); - void testDataChanged(int itemIndex); + void addSeries(QString series, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled); void backgroundChanged(int itemIndex); void autoScaleChanged(int value); void xMinChanged(int value); @@ -39,6 +40,8 @@ private slots: void changeChartTheme(int themeIndex); void setPieSizeFactor(double margin); void setPiePosition(int position); + QList generateTestData(int columnCount, int rowCount, QString dataCharacteristics); + QStringList generateLabels(int count); private: QChartView *m_chartWidget;