forked from AdunanzA/Tsunami
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatisticswindow.cpp.bak
114 lines (96 loc) · 3.87 KB
/
statisticswindow.cpp.bak
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include "statisticswindow.h"
#include "ui_statisticswindow.h"
#include <QTableView>
statisticswindow::statisticswindow(QWidget *parent) :
QWidget(parent),
// chart(new ChartXY),
ui(new Ui::statisticswindow)
{
ui->setupUi(this);
chart = new ChartXY(this);
setupModel();
setupChart();
}
statisticswindow::~statisticswindow()
{
delete ui;
}
void statisticswindow::updateStats(const QPair<int, int> &values)
{
//qDebug() << QString("updateState x:%1 d:%2, u:%3").arg(values.first).arg(values.second).arg(QDateTime::currentDateTime().time().toString());
QList<QStandardItem *> newRow;
// newRow.append(new QStandardItem(QDateTime::currentDateTime().time().toString()));
// newRow.append(new QStandardItem(QString("%1").arg(values.first)));
// newRow.append(new QStandardItem(QString("%1").arg(values.second)));
newRow.append(new QStandardItem());
newRow.append(new QStandardItem());
newRow.append(new QStandardItem());
model->appendRow(newRow);
int lastRowIndex = model->rowCount()-1;
model->setData(model->index(lastRowIndex,0),QVariant(QDateTime::currentDateTime()));
if (values.first > 0 ) {
model->setData(model->index(lastRowIndex,1),values.first);
} else {
model->setData(model->index(lastRowIndex,1), 1);
}
model->setData(model->index(lastRowIndex,1),QColor(255,0,0),Qt::DecorationRole);
if (values.second > 0 ) {
model->setData(model->index(lastRowIndex,2),values.second);
} else {
model->setData(model->index(lastRowIndex,2), 1);
}
model->setData(model->index(lastRowIndex,2),QColor(0,255,0),Qt::DecorationRole);
if (model->rowCount() > 100) { model->removeRow(0); }
chart->updateChart();
}
void statisticswindow::setupModel()
{
// int i;
// QDateTime date_time=QDateTime::currentDateTime();
model=new QStandardItemModel(1,3,this);
model->setHeaderData(0,Qt::Horizontal,tr("X"));
model->setHeaderData(1,Qt::Horizontal,tr("Y"));
model->setHeaderData(2,Qt::Horizontal,tr("K"));
model->setData(model->index(0,0),QVariant(QDateTime::currentDateTime()));
model->setData(model->index(0,1),QColor(255,0,0),Qt::DecorationRole);
model->setData(model->index(0,1), 1);
model->setData(model->index(0,2),QColor(0,255,0),Qt::DecorationRole);
model->setData(model->index(0,2), 1);
// for(i=0;i<model->rowCount();i++)
// {
// model->setData(model->index(i,0,QModelIndex()),QVariant(date_time));
// date_time=date_time.addSecs(60);
// model->setData(model->index(i,1,QModelIndex()),i*2+qrand()%7);
// model->setData(model->index(i,1,QModelIndex()),QColor(255,0,0),Qt::DecorationRole);
// model->setData(model->index(i,2,QModelIndex()),i+qrand()%14);
// model->setData(model->index(i,2,QModelIndex()),QColor(0,255,0),Qt::DecorationRole);
// }
// ui->table->setModel(model);
}
void statisticswindow::setupChart()
{
// QTableView *qtv = new QTableView();
// qtv->setModel(model);
// ui->horizontalLayout->addWidget(qtv);
ui->horizontalLayout->addWidget(chart);
chart->setModel(model);
chart->setting().border().setRight(64);
//chart->setting().border().setBackgroundColor(QColor(255,255,255,1));
chart->setting().grid().horizzontalTick().setTickMajor(4);
chart->setting().grid().horizzontalTick().setTickMinor(5);
chart->setting().grid().verticalTick().setTickMajor(8);
chart->setting().grid().verticalTick().setTickMinor(5);
chart->setting().grid().setBackgroundColor(QColor(192,192,192,1));
chart->setting().grid().setForegroundColor(QColor(210,210,210));
chart->setting().grid().setBorder(0);
chart->setting().scale().setAutoCurrentLimit(true);
chart->setting().scale().setNominalAutoLimit(true);
chart->updateChart();
}
void statisticswindow::changeEvent(QEvent *e)
{
if(e->type() == QEvent::LanguageChange)
{
ui->retranslateUi(this);
}
}