-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph.cpp
More file actions
165 lines (137 loc) · 3.93 KB
/
graph.cpp
File metadata and controls
165 lines (137 loc) · 3.93 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QGraphicsView>
#include <QGraphicsEllipseItem>
#include <QTimer>
#include <QDebug>
#include <QScrollBar>
#include <QPen>
#include <QGraphicsLineItem>
#include <QtConcurrent>
#include <QPainterPath>
#include <QtSerialPort/QSerialPort>
int calc_moyenne(int *marray, int nb_val)
{
int i;
i = nb_val;
int moy = 0;;
while(i--)
{
moy = moy + marray[i];
}
return moy;
}
void MainWindow::draw_background(int posx)
{
//Affichage axe x
QPen pen;
pen.setWidth(1);
pen.setColor(Qt::gray);
if (g_axis_x)
delete g_axis_x;
if (posx > ui->gridLayout->geometry().width())
g_axis_x = new QGraphicsLineItem(ui->gridLayout->geometry().x(), ui->gridLayout->geometry().height()/2, posx, ui->gridLayout->geometry().height()/2);
else
g_axis_x = new QGraphicsLineItem(ui->gridLayout->geometry().x(), ui->gridLayout->geometry().height()/2, ui->gridLayout->geometry().width(), ui->gridLayout->geometry().height()/2);
g_axis_x->setPen(pen);
scene->addItem(g_axis_x);
}
void MainWindow::drawfirststep(int posx, int posy)
{
//Affichage courbe température
QPen pen;
pen.setWidth(2);
pen.setColor(Qt::darkMagenta);
if (!m_datapath)
{
m_datapath = new QPainterPath();
m_datapath->moveTo(posx, posy);
}
m_datapath->lineTo(posx, posy );
if (g_datagraph)
delete g_datagraph;
g_datagraph = new QGraphicsPathItem();
g_datagraph->setPath(*m_datapath);
g_datagraph->setPen(pen);
scene->addItem(g_datagraph);
//Affichage axe y
// if (!yline)
// {
// yline = new QPainterPath();
// yline->moveTo(ui->gridLayout->geometry().width()/2,0);
// }
// yline->lineTo(ui->gridLayout->geometry().width()/2, ui->gridLayout->geometry().height() );
// if (ypath)
// delete ypath;
// ypath = new QGraphicsPathItem();
// ypath->setPath(*yline);
// g_axis_x->setPen(pen);
// scene->addItem(ypath);
// // Quadrillage y
// // y=m_dep_x*(1000/m_timereset)
// QPen yqpen;
// yqpen.setColor(Qt::gray);
// yqpen.setWidth(1);
// if (!yqline)
// {
// yqline = new QPainterPath();
// yqline->moveTo(m_dep_x*(1000/m_timereset),0);
// }
// yqline->lineTo(m_dep_x*(1000/m_timereset), ui->gridLayout->geometry().height() );
// if (yqpath)
// delete yqpath;
// yqpath = new QGraphicsPathItem();
// yqpath->setPath(*yqline);
// yqpath->setPen(yqpen);
// scene->addItem(yqpath);
}
void MainWindow::moyenne_update(const int posx, const int posy, long long *count)
{
moytab[*count%m_nbvalmoy] = posy;
*count = *count + 1;
m_olx = posx;
m_oldy = posy;
/* calc moyenne */
if (future.isFinished() || future.isPaused())
{
if (future.isFinished() && *count > 1 )
moyenne = future.result();
future = QtConcurrent::run(calc_moyenne,moytab, m_nbvalmoy);
}
}
void MainWindow::setmoyenne(int moyenne)
{
ui->lcdN_Moyenne->display(moyenne);
if (g_moyennepath)
delete g_moyennepath;
QPen moypen;
moypen.setWidth(2);
moypen.setColor(Qt::red);
g_moyennepath = new QGraphicsPathItem();
g_moyennepath->setPath(*m_moyennepath);
g_moyennepath->setPen(moypen);
if (ui->radioButton->isChecked())
scene->addItem(g_moyennepath);
}
void MainWindow::endpos_update(int *posx)
{
if (ui->cBscroll->isChecked() && *posx > ui->gridLayout->geometry().width())
{
view->horizontalScrollBar()->setValue(view->horizontalScrollBar()->maximum());
}
else
{
if (*posx > ui->gridLayout->geometry().width() )
{
scene->clear();
g_datagraph = NULL;
m_datapath = NULL;
if (m_moyennepath)
delete m_moyennepath;
m_moyennepath = NULL;
g_moyennepath = NULL;
g_axis_x = NULL;
*posx = 0;
}
}
}