From d24f813f3f2a05c112e803e4256b53535895fc98 Mon Sep 17 00:00:00 2001 From: Jedidiah Barber Date: Wed, 14 Jul 2021 11:49:10 +1200 Subject: Initial mirror commit --- tests/fute/charts/charts_test.cpp | 52 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 tests/fute/charts/charts_test.cpp (limited to 'tests/fute/charts/charts_test.cpp') 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 +#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); +} -- cgit