diff options
author | Jedidiah Barber <contact@jedbarber.id.au> | 2021-07-14 11:49:10 +1200 |
---|---|---|
committer | Jedidiah Barber <contact@jedbarber.id.au> | 2021-07-14 11:49:10 +1200 |
commit | d24f813f3f2a05c112e803e4256b53535895fc98 (patch) | |
tree | 601e6ae9a1cd44bcfdcf91739a5ca36aedd827c9 /tests/fute/charts/charts_test.cpp |
Diffstat (limited to 'tests/fute/charts/charts_test.cpp')
-rw-r--r-- | tests/fute/charts/charts_test.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/fute/charts/charts_test.cpp b/tests/fute/charts/charts_test.cpp new file mode 100644 index 0000000..0870027 --- /dev/null +++ b/tests/fute/charts/charts_test.cpp @@ -0,0 +1,52 @@ +#include "charts_test.h" +#include "../../../src/charts/Chart.h" + +#include <cstdlib> +#include <time.h> + +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); +} |