#include "charts_test.h" #include "../../../src/charts/Chart.h" #include #include ChartsTest::ChartsTest() { srand(time(NULL)); createUi(); changeDataSet(); } void ChartsTest::changeDataSet() { const int daysNum = 7; yValuesStr = "Values: "; dataSet.clear(); for (int i = 0; i < daysNum; i++) addDataPoint(i); chart->setDataSet(dataSet); valuesLabel->setText(yValuesStr); } void ChartsTest::addDataPoint(int index) { const int firstDay = 15; QString xLabel = QString::number(firstDay + index) + ".11"; int yValue = rand() % 70; dataSet << DataPoint(xLabel, yValue, xLabel); yValuesStr += QString::number(yValue) + ", "; } void ChartsTest::createUi() { QPushButton* newBtn = new QPushButton(tr("New chart")); connect(newBtn, SIGNAL(clicked()), SLOT(changeDataSet())); valuesLabel = new QLabel; chart = new Chart; chart->setLabels("Date", "Value"); QHBoxLayout* controlLt = new QHBoxLayout; controlLt->addWidget(valuesLabel); controlLt->addWidget(newBtn); QVBoxLayout* mainLt = new QVBoxLayout; mainLt->addLayout(controlLt); mainLt->addWidget(chart); setLayout(mainLt); resize(800, 500); }