#include "pieCharts_test.h" #include "../../../src/charts/PieChart.h" #include #include const QStringList PieChartsTest::Labels = {"Studied", "Scheduled for today", "New"}; PieChartsTest::PieChartsTest() { srand(time(NULL)); createUi(); changeDataSet(); } void PieChartsTest::changeDataSet() { yValuesStr = "Values: "; dataSet.clear(); for (int i = 0; i < 3; i++) addDataPoint(i); chart->setDataSet(dataSet); valuesLabel->setText(yValuesStr); } void PieChartsTest::addDataPoint(int index) { int yValue = rand() % 200; dataSet << DataPoint(Labels[index], yValue, ""); yValuesStr += QString::number(yValue) + ", "; } void PieChartsTest::createUi() { QPushButton* newBtn = new QPushButton(tr("New chart")); connect(newBtn, SIGNAL(clicked()), SLOT(changeDataSet())); valuesLabel = new QLabel; chart = new PieChart; chart->setColors({"#39c900", "#ece900", "#ff0000"}); 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); }