summaryrefslogtreecommitdiff
path: root/tests/fute/pieCharts/pieCharts_test.cpp
blob: d88981a6a364df77812a6d7c8f26546a5d8356a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "pieCharts_test.h"
#include "../../../src/charts/PieChart.h"

#include <cstdlib>
#include <time.h>

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);
}