summaryrefslogtreecommitdiff
path: root/tests/fute/charts/charts_test.cpp
blob: 0870027da2daa38b62aea151b092520c84b5c803 (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 "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);
}