summaryrefslogtreecommitdiff
path: root/tests/fute/timeCharts/timeCharts_test.cpp
blob: 53f09215d1ead513fcc1d9f17f167f6afff4635f (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
53
54
55
56
57
58
#include "../../../src/charts/TimeChart.h"

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

TimeChartsTest::TimeChartsTest()
{
    srand(time(NULL));
    createUi();
    changeDataSet();
}

void TimeChartsTest::changeDataSet()
{
    int daysNum = periodBox->value();
    yValuesStr = "Values: ";
    dates.clear();
    for (int i = 0; i < daysNum; i++)
        addDataPoint(i);
    chart->setDates(dates, daysNum, 1);
    valuesLabel->setText(yValuesStr);
}

void TimeChartsTest::addDataPoint(int index)
{
    QDateTime date = QDateTime::currentDateTime().addDays(index);
    int dayCardsNum = rand() % 50;
    for(int i = 0; i < dayCardsNum; i++)
        dates << date;
    yValuesStr += QString::number(dayCardsNum) + ", ";
}

void TimeChartsTest::createUi()
{
    QPushButton* newBtn = new QPushButton(tr("New chart"));
    connect(newBtn, SIGNAL(clicked()), SLOT(changeDataSet()));

    valuesLabel = new QLabel;
    valuesLabel->setMaximumWidth(750);

    periodBox = new QSpinBox;
    periodBox->setRange(7, 5000);

    chart = new TimeChart;
    chart->setLabels(tr("Date"), tr("Cards"));

    QHBoxLayout* controlLt = new QHBoxLayout;
    controlLt->addWidget(periodBox);
    controlLt->addWidget(newBtn);

    QVBoxLayout* mainLt = new QVBoxLayout;
    mainLt->addLayout(controlLt);
    mainLt->addWidget(valuesLabel);
    mainLt->addWidget(chart);
    setLayout(mainLt);
    resize(800, 500);
}