QT编写静态动态曲线图静态动态柱状图

QT编写静态动态曲线图静态动态柱状图,可以将数据转换为静态曲线和动态曲线及柱状图显示。
标签: <无>

代码片段(6)[全屏查看所有代码]

1. [代码][C/C++]代码     

?
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
#ifndef FRMMAIN_H
#define FRMMAIN_H
 
#include <QWidget>
#include "qcustomplot.h"
 
namespace Ui
{
     class frmMain;
}
 
class frmMain : public QWidget
{
     Q_OBJECT
 
public :
     explicit frmMain(QWidget *parent = 0);
     ~frmMain();
 
private slots:
     void LoadPlot1();
     void LoadPlot2();
     void LoadPlot3();
     void LoadPlot4();
     void LoadPlot5();
     void UpdatePlot5();
     void on_btnLoad_clicked();
     void on_btnSkin_clicked();
     void on_ckText_stateChanged( int arg1);
     void on_ckBackground_stateChanged( int arg1);
     void on_ckMove_stateChanged( int arg1);
     void on_tabWidget_currentChanged( int index);
 
private :
     Ui::frmMain *ui;
 
     QTimer *plot2_timer;
     QTimer *plot5_timer;
 
     int currentIndex;
     QString currentSkin;
     QList <QCustomPlot *> plots;
 
     QVector< double > plot1_keys;
     QVector< double > plot1_values;
 
     double plot2_key;
     double plot2_value;
 
     QVector< double > plot3_keys;
     QVector< double > plot3_values1, plot3_values2, plot3_values3;
     QVector<QString> plot3_labels;
     QVector<QCPBars *> plot3_Bar;
 
     QVector< double > plot4_keys;
     QVector< double > plot4_values;
     QVector<QString> plot4_labels;
     QVector<QCPBars *> plot4_Bar;
 
     QVector< double > plot5_keys;
     QVector< double > plot5_values;
     QVector< double > plot5_currentValue;
     int maxValue;
     QVector<QString> plot5_labels;
     QVector<QCPBars *> plot5_Bar;
 
     void InitStyle();
     void InitForm();
 
     void InitPlot();
     void InitPlot1();
     void InitPlot2();
     void InitPlot3();
     void InitPlot4();
     void InitPlot5();
 
};
 
#endif // FRMMAIN_H

2. [代码][C/C++]代码     

?
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
#include "frmmain.h"
#include "ui_frmmain.h"
#include "myhelper.h"
#include "iconhelper.h"
 
#define TextColor QColor(255,255,255)
#define Plot_NoColor QColor(0,0,0,0)
 
#define Plot1_DotColor QColor(5,189,251)
#define Plot1_LineColor QColor(41,138,220)
#define Plot1_BGColor QColor(41,138,220,80)
 
#define Plot2_DotColor QColor(236,110,0)
#define Plot2_LineColor QColor(246,98,0)
#define Plot2_BGColor QColor(246,98,0,80)
 
#define Plot3_AlarmColor1 QColor(204,0,0)
#define Plot3_AlarmColor1X QColor(204,0,0,200)
#define Plot3_AlarmColor2 QColor(246,98,0)
#define Plot3_AlarmColor2X QColor(246,98,0,200)
#define Plot3_AlarmColor3 QColor(41,138,220)
#define Plot3_AlarmColor3X QColor(41,138,220,200)
 
#define Plot4_AlarmColor1 QColor(238,0,0)
#define Plot4_AlarmColor1X QColor(238,0,0,200)
#define Plot4_AlarmColor2 QColor(204,250,255)
#define Plot4_AlarmColor2X QColor(204,250,255,200)
#define Plot4_AlarmColor3 QColor(5,189,251)
#define Plot4_AlarmColor3X QColor(5,189,251,200)
#define Plot4_AlarmColor4 QColor(236,110,0)
#define Plot4_AlarmColor4X QColor(236,110,0,200)
#define Plot4_AlarmColor5 QColor(106,139,34)
#define Plot4_AlarmColor5X QColor(106,139,34,200)
#define Plot4_AlarmColor6 QColor(99,149,236)
#define Plot4_AlarmColor6X QColor(99,149,236,200)
#define Plot4_AlarmColor7 QColor(130,111,255)
#define Plot4_AlarmColor7X QColor(130,111,255,200)
#define Plot4_AlarmColor8 QColor(205,173,0)
#define Plot4_AlarmColor8X QColor(205,173,0,200)
#define Plot4_AlarmColor9 QColor(1,139,0)
#define Plot4_AlarmColor9X QColor(1,139,0,200)
 
#define TextWidth 1
#define LineWidth 2
#define DotWidth 10
 
#define Plot1_Count 20
#define Plot2_Count 5
#define Plot3_Count 7
#define Plot4_Count 9
#define Plot5_Count 9
 
#define Plot1_MaxY 50
#define Plot2_MaxY 100
#define Plot3_MaxY 500
#define Plot4_MaxY 100
 
#ifdef __arm__
#define Plot5_MaxY 20
#else
#define Plot5_MaxY 50
#endif
 
frmMain::frmMain(QWidget *parent) :
     QWidget(parent),
     ui( new Ui::frmMain)
{
     ui->setupUi( this );
 
     this ->InitStyle();
     this ->InitForm();
 
     this ->InitPlot();
     this ->InitPlot1();
     this ->InitPlot2();
     this ->InitPlot3();
     this ->InitPlot4();
     this ->InitPlot5();
 
     this ->LoadPlot1();
     this ->LoadPlot2();
     this ->LoadPlot3();
     this ->LoadPlot4();
     this ->LoadPlot5();
     plot5_timer->start(0);
}
 
frmMain::~frmMain()
{
     delete ui;
}
 
void frmMain::InitStyle()
{
     this ->setProperty( "Form" , true );
     this ->setWindowTitle(ui->lab_Title->text());
     this ->setGeometry(qApp->desktop()->availableGeometry());
     this ->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint);
     IconHelper::Instance()->SetIcon(ui->lab_Ico, QChar(0xf012));
     IconHelper::Instance()->SetIcon(ui->btnMenu_Close, QChar(0xf00d));
     connect(ui->btnMenu_Close, SIGNAL(clicked()), this , SLOT(close()));
}
 
void frmMain::InitForm()
{
     currentIndex = 0;
     currentSkin = ":/image/dev.css" ;
 
     //初始化随机数种子
     QTime time = QTime::currentTime();
     qsrand( time .msec() + time .second() * 1000);
 
     //初始化动态曲线定时器
     plot2_timer = new QTimer( this );
     connect(plot2_timer, SIGNAL(timeout()), this , SLOT(LoadPlot2()));
 
     //初始化动态柱状图定时器
     plot5_timer = new QTimer( this );
     connect(plot5_timer, SIGNAL(timeout()), this , SLOT(UpdatePlot5()));
 
     plots.append(ui->plot1);
     plots.append(ui->plot2);
     plots.append(ui->plot3);
     plots.append(ui->plot4);
     plots.append(ui->plot5);
}
 
void frmMain::InitPlot()
{
     //设置纵坐标名称
     plots[0]->yAxis->setLabel( "力度值(单位:N)" );
     plots[1]->yAxis->setLabel( "湿度值(单位:%)" );
     plots[2]->yAxis->setLabel( "一周报警总数统计图" );
     plots[3]->yAxis->setLabel( "报警数量统计图" );
     plots[4]->yAxis->setLabel( "报警数量统计图" );
 
     //设置纵坐标范围
     plots[0]->yAxis->setRange(0, Plot1_MaxY);
     plots[1]->yAxis->setRange(0, Plot2_MaxY);
     plots[2]->yAxis->setRange(0, Plot3_MaxY);
     plots[3]->yAxis->setRange(0, Plot4_MaxY);
     plots[4]->yAxis->setRange(0, Plot5_MaxY);
 
     foreach (QCustomPlot * plot, plots) {
         //设置坐标颜色/坐标名称颜色
         plot->yAxis->setLabelColor(TextColor);
         plot->xAxis->setTickLabelColor(TextColor);
         plot->yAxis->setTickLabelColor(TextColor);
         plot->xAxis->setBasePen(QPen(TextColor, TextWidth));
         plot->yAxis->setBasePen(QPen(TextColor, TextWidth));
         plot->xAxis->setTickPen(QPen(TextColor, TextWidth));
         plot->yAxis->setTickPen(QPen(TextColor, TextWidth));
         plot->xAxis->setSubTickPen(QPen(TextColor, TextWidth));
         plot->yAxis->setSubTickPen(QPen(TextColor, TextWidth));
 
         //设置画布背景色
         QLinearGradient plotGradient;
         plotGradient.setStart(0, 0);
         plotGradient.setFinalStop(0, 350);
         plotGradient.setColorAt(0, QColor(80, 80, 80));
         plotGradient.setColorAt(1, QColor(50, 50, 50));
         plot->setBackground(plotGradient);
 
         //设置坐标背景色
         QLinearGradient axisRectGradient;
         axisRectGradient.setStart(0, 0);
         axisRectGradient.setFinalStop(0, 350);
         axisRectGradient.setColorAt(0, QColor(80, 80, 80));
         axisRectGradient.setColorAt(1, QColor(30, 30, 30));
         plot->axisRect()->setBackground(axisRectGradient);
 
         //设置图例提示位置及背景色
         plot->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignTop | Qt::AlignRight);
         plot->legend->setBrush(QColor(255, 255, 255, 200));
 
         plot->replot();
     }
}
 
void frmMain::InitPlot1()
{
     plots[0]->addGraph();
     plots[0]->graph(0)->setName( "力度值(单位:N)" );
     plots[0]->graph(0)->setPen(QPen(Plot1_LineColor, LineWidth));
     plots[0]->graph(0)->setScatterStyle(
         QCPScatterStyle(QCPScatterStyle::ssCircle,
                         QPen(Plot1_DotColor, LineWidth),
                         QBrush(Plot1_DotColor), DotWidth));
 
     //设置静态曲线的横坐标范围及自适应横坐标
     plots[0]->xAxis->setRange(0, Plot1_Count, Qt::AlignLeft);
     for ( int i = 0; i < Plot1_Count; i++) {
         plot1_keys.append(i);
     }
}
 
void frmMain::InitPlot2()
{
     plots[1]->addGraph();
     plots[1]->graph(0)->setName( "湿度值(单位:%)" );
     plots[1]->graph(0)->setPen(QPen(Plot2_LineColor, LineWidth));
     plots[1]->graph(0)->setScatterStyle(
         QCPScatterStyle(QCPScatterStyle::ssCircle,
                         QPen(Plot2_DotColor, LineWidth),
                         QBrush(Plot2_DotColor), DotWidth));
 
     //设置动态曲线的横坐标格式及范围
     plots[1]->xAxis->setTickLabelType(QCPAxis::ltDateTime);
     plots[1]->xAxis->setDateTimeFormat( "HH:mm:ss" );
     plots[1]->xAxis->setAutoTickStep( false );
     plots[1]->xAxis->setTickStep(0.5);
     plots[1]->xAxis->setRange(0, Plot2_Count, Qt::AlignRight);
}
 
void frmMain::InitPlot3()
{
     //初始化横坐标名称
     plot3_labels << "星期一" << "星期二" << "星期三" ;
     plot3_labels << "星期四" << "星期五" << "星期六" << "星期日" ;
 
     //创建三个柱状图形对象
     for ( int i = 0; i < 3; i++) {
         QCPBars *bar = new QCPBars(plots[2]->xAxis, plots[2]->yAxis);
         plot3_Bar.append(bar);
         plots[2]->addPlottable(plot3_Bar[i]);
     }
 
     //设置三个柱状图形对象名称
     plot3_Bar[0]->setName( "极其重要警情" );
     plot3_Bar[1]->setName( "重要警情" );
     plot3_Bar[2]->setName( "一般警情" );
 
     //分别对三个柱状图形对象设置颜色
     QPen pen;
     pen.setWidthF(LineWidth);
     pen.setColor(Plot3_AlarmColor1);
     plot3_Bar[0]->setPen(pen);
     plot3_Bar[0]->setBrush(Plot3_AlarmColor1X);
     pen.setColor(Plot3_AlarmColor2);
     plot3_Bar[1]->setPen(pen);
     plot3_Bar[1]->setBrush(Plot3_AlarmColor2X);
     pen.setColor(Plot3_AlarmColor3);
     plot3_Bar[2]->setPen(pen);
     plot3_Bar[2]->setBrush(Plot3_AlarmColor3X);
 
     //设置柱状图形排列次序
     plot3_Bar[1]->moveAbove(plot3_Bar[2]);
     plot3_Bar[0]->moveAbove(plot3_Bar[1]);
 
     //设置横坐标
     plots[2]->xAxis->setAutoTicks( false );
     plots[2]->xAxis->setAutoTickLabels( false );
     plots[2]->xAxis->setSubTickCount(0);
     plots[2]->xAxis->setTickLength(0, 4);
     plots[2]->xAxis->grid()->setVisible( false );
     plots[2]->xAxis->setRange(0, 8);
     plots[2]->yAxis->grid()->setSubGridVisible( false );
 
     //横坐标赋值
     plot3_keys << 1 << 2 << 3 << 4 << 5 << 6 << 7;
     plots[2]->xAxis->setTickVector(plot3_keys);
     plots[2]->xAxis->setTickVectorLabels(plot3_labels);
}
 
void frmMain::InitPlot4()
{
     //初始化横坐标名称
     plot4_labels << "水量超限报警" << "缺水报警" << "无传感器" << "温度过高" << "温度过低" ;
     plot4_labels << "湿度过高" << "湿度过低" << "环境温度过低" << "温度超限停机" ;
 
     //初始化纵坐标值/柱状对象
     for ( int i = 0; i < Plot4_Count; i++) {
         plot4_values.append(0);
         plot4_keys.append(i + 1);
         QCPBars *bar = new QCPBars(plots[3]->xAxis, plots[3]->yAxis);
         bar->setName(plot4_labels[i]);
         plots[3]->addPlottable(bar);
         plot4_Bar.append(bar);
     }
 
     //设置柱状图形颜色
     QPen pen;
     pen.setWidthF(LineWidth);
     pen.setColor(Plot4_AlarmColor1);
     plot4_Bar[0]->setPen(pen);
     plot4_Bar[0]->setBrush(Plot4_AlarmColor1X);
     pen.setColor(Plot4_AlarmColor2);
     plot4_Bar[1]->setPen(pen);
     plot4_Bar[1]->setBrush(Plot4_AlarmColor2X);
     pen.setColor(Plot4_AlarmColor3);
     plot4_Bar[2]->setPen(pen);
     plot4_Bar[2]->setBrush(Plot4_AlarmColor3X);
     pen.setColor(Plot4_AlarmColor4);
     plot4_Bar[3]->setPen(pen);
     plot4_Bar[3]->setBrush(Plot4_AlarmColor4X);
     pen.setColor(Plot4_AlarmColor5);
     plot4_Bar[4]->setPen(pen);
     plot4_Bar[4]->setBrush(Plot4_AlarmColor5X);
     pen.setColor(Plot4_AlarmColor6);
     plot4_Bar[5]->setPen(pen);
     plot4_Bar[5]->setBrush(Plot4_AlarmColor6X);
     pen.setColor(Plot4_AlarmColor7);
     plot4_Bar[6]->setPen(pen);
     plot4_Bar[6]->setBrush(Plot4_AlarmColor7X);
     pen.setColor(Plot4_AlarmColor8);
     plot4_Bar[7]->setPen(pen);
     plot4_Bar[7]->setBrush(Plot4_AlarmColor8X);
     pen.setColor(Plot4_AlarmColor9);
     plot4_Bar[8]->setPen(pen);
     plot4_Bar[8]->setBrush(Plot4_AlarmColor9X);
 
     //设置横坐标
     plots[3]->xAxis->setAutoTicks( false );
     plots[3]->xAxis->setAutoTickLabels( false );
     plots[3]->xAxis->setSubTickCount(0);
     plots[3]->xAxis->grid()->setVisible( false );
     plots[3]->xAxis->setRange(0, Plot4_Count + 1);
 
     //横坐标赋值
     plots[3]->xAxis->setTickVector(plot4_keys);
     plots[3]->xAxis->setTickVectorLabels(plot4_labels);
}
 
void frmMain::InitPlot5()
{
     maxValue = 0;
     //初始化横坐标名称
     plot5_labels << "水量超限报警" << "缺水报警" << "无传感器" << "温度过高" << "温度过低" ;
     plot5_labels << "湿度过高" << "湿度过低" << "环境温度过低" << "温度超限停机" ;
 
     //初始化纵坐标值/柱状对象
     for ( int i = 0; i < Plot5_Count; i++) {
         plot5_values.append(0);
         plot5_keys.append(i + 1);
         QCPBars *bar = new QCPBars(plots[4]->xAxis, plots[4]->yAxis);
         bar->setName(plot5_labels[i]);
         plots[4]->addPlottable(bar);
         plot5_Bar.append(bar);
     }
 
     //设置柱状图形颜色
     QPen pen;
     pen.setWidthF(LineWidth);
     pen.setColor(Plot4_AlarmColor1);
     plot5_Bar[0]->setPen(pen);
     plot5_Bar[0]->setBrush(Plot4_AlarmColor1X);
     pen.setColor(Plot4_AlarmColor2);
     plot5_Bar[1]->setPen(pen);
     plot5_Bar[1]->setBrush(Plot4_AlarmColor2X);
     pen.setColor(Plot4_AlarmColor3);
     plot5_Bar[2]->setPen(pen);
     plot5_Bar[2]->setBrush(Plot4_AlarmColor3X);
     pen.setColor(Plot4_AlarmColor4);
     plot5_Bar[3]->setPen(pen);
     plot5_Bar[3]->setBrush(Plot4_AlarmColor4X);
     pen.setColor(Plot4_AlarmColor5);
     plot5_Bar[4]->setPen(pen);
     plot5_Bar[4]->setBrush(Plot4_AlarmColor5X);
     pen.setColor(Plot4_AlarmColor6);
     plot5_Bar[5]->setPen(pen);
     plot5_Bar[5]->setBrush(Plot4_AlarmColor6X);
     pen.setColor(Plot4_AlarmColor7);
     plot5_Bar[6]->setPen(pen);
     plot5_Bar[6]->setBrush(Plot4_AlarmColor7X);
     pen.setColor(Plot4_AlarmColor8);
     plot5_Bar[7]->setPen(pen);
     plot5_Bar[7]->setBrush(Plot4_AlarmColor8X);
     pen.setColor(Plot4_AlarmColor9);
     plot5_Bar[8]->setPen(pen);
     plot5_Bar[8]->setBrush(Plot4_AlarmColor9X);
 
     //设置横坐标
     plots[4]->xAxis->setAutoTicks( false );
     plots[4]->xAxis->setAutoTickLabels( false );
     plots[4]->xAxis->setSubTickCount(0);
     plots[4]->xAxis->grid()->setVisible( false );
     plots[4]->xAxis->setRange(0, Plot5_Count + 1);
 
     //横坐标赋值
     plots[4]->xAxis->setTickVector(plot5_keys);
     plots[4]->xAxis->setTickVectorLabels(plot5_labels);
}
 
void frmMain::LoadPlot1()
{
     plot1_values.clear();
     for ( int i = 0; i < Plot1_Count; i++) {
         double value = qrand() % Plot1_MaxY;
         plot1_values.append(value);
     }
     plots[0]->graph(0)->setData(plot1_keys, plot1_values);
     plots[0]->graph(0)->rescaleAxes();
     plots[0]->replot();
}
 
void frmMain::LoadPlot2()
{
     plot2_key = QDateTime::currentDateTime().toMSecsSinceEpoch() / 1000.0;
     plot2_value = qrand() % Plot2_MaxY;
     plots[1]->graph(0)->addData(plot2_key, plot2_value);
     plots[1]->graph(0)->removeDataBefore(plot2_key - Plot2_Count - 1);
     plots[1]->xAxis->setRange(plot2_key, Plot2_Count , Qt::AlignRight);
     plots[1]->replot();
}
 
void frmMain::LoadPlot3()
{
     plot3_values1.clear();
     plot3_values2.clear();
     plot3_values3.clear();
     for ( int i = 0; i < 10; i++) {
         double value1 = qrand() % 80;
         double value2 = qrand() % 100;
         double value3 = qrand() % 300;
         plot3_values1.append(value1);
         plot3_values2.append(value2);
         plot3_values3.append(value3);
     }
 
     //设置柱状图形数据
     plot3_Bar[0]->setData(plot3_keys, plot3_values1);
     plot3_Bar[1]->setData(plot3_keys, plot3_values2);
     plot3_Bar[2]->setData(plot3_keys, plot3_values3);
     plots[2]->replot();
}
 
void frmMain::LoadPlot4()
{
     plot4_values.clear();
     for ( int i = 0; i < Plot4_Count; i++) {
         double value = qrand() % (Plot4_MaxY - 10);
         plot4_values.append(value);
         plot4_Bar[i]->clearData();
         plot4_Bar[i]->addData(i + 1, plot4_values[i]);
     }
     plots[3]->replot();
}
 
void frmMain::LoadPlot5()
{
     maxValue = 0;
     plot5_currentValue.clear();
     plot5_values.clear();
     for ( int i = 0; i < Plot5_Count; i++) {
         double value = qrand() % (Plot5_MaxY - 1);
         plot5_currentValue.append(0);
         plot5_values.append(value);
     }
}
 
void frmMain::UpdatePlot5()
{
     for ( int i = 0; i < Plot5_Count; i++) {
         if (plot5_currentValue[i] < plot5_values[i]) {
             plot5_Bar[i]->clearData();
             plot5_Bar[i]->addData(i + 1, plot5_currentValue[i]);
             plot5_currentValue[i]++;
         }
     }
 
     maxValue++;
     plots[4]->replot();
 
     if (maxValue >= (Plot5_MaxY - 1)) {
         maxValue = 0;
         plot5_timer->stop();
     }
}
 
void frmMain::on_btnLoad_clicked()
{
     if (currentIndex == 0) {
         LoadPlot1();
     } else if (currentIndex == 1) {
         if (ui->btnLoad->text() == "开始模拟" ) {
             plot2_timer->start(100);
             ui->btnLoad->setText( "停止模拟" );
         } else {
             plot2_timer->stop();
             ui->btnLoad->setText( "开始模拟" );
         }
     } else if (currentIndex == 2) {
         LoadPlot3();
     } else if (currentIndex == 3) {
         LoadPlot4();
     } else if (currentIndex == 4) {
         LoadPlot5();
         //启动定时器动态加载柱状条
         plot5_timer->start(0);
     }
}
 
void frmMain::on_btnSkin_clicked()
{
     if (currentSkin == ":/image/dev.css" ) {
         currentSkin = ":/image/black.css" ;
     } else if (currentSkin == ":/image/black.css" ) {
         currentSkin = ":/image/brown.css" ;
     } else if (currentSkin == ":/image/brown.css" ) {
         currentSkin = ":/image/blue.css" ;
     } else if (currentSkin == ":/image/blue.css" ) {
         currentSkin = ":/image/gray.css" ;
     } else if (currentSkin == ":/image/gray.css" ) {
         currentSkin = ":/image/white.css" ;
     } else if (currentSkin == ":/image/white.css" ) {
         currentSkin = ":/image/silvery.css" ;
     } else if (currentSkin == ":/image/silvery.css" ) {
         currentSkin = ":/image/dev.css" ;
     }
     myHelper::SetStyle(currentSkin);
}
 
void frmMain::on_ckText_stateChanged( int arg1)
{
     bool value = (arg1 == 0 ? false : true );
     if (value) {
         plots[0]->legend->setVisible( true );
         plots[1]->legend->setVisible( true );
         plots[2]->legend->setVisible( true );
         plots[3]->legend->setVisible( true );
         plots[4]->legend->setVisible( true );
     } else {
         plots[0]->legend->setVisible( false );
         plots[1]->legend->setVisible( false );
         plots[2]->legend->setVisible( false );
         plots[3]->legend->setVisible( false );
         plots[4]->legend->setVisible( false );
     }
 
     foreach (QCustomPlot * plot, plots) {
         plot->replot();
     }
}
 
void frmMain::on_ckBackground_stateChanged( int arg1)
{
     bool value = (arg1 == 0 ? false : true );
     if (value) {
         plots[0]->graph(0)->setBrush(QBrush(Plot1_BGColor));
         plots[1]->graph(0)->setBrush(QBrush(Plot2_BGColor));
     } else {
         plots[0]->graph(0)->setBrush(QBrush(Plot_NoColor));
         plots[1]->graph(0)->setBrush(QBrush(Plot_NoColor));
     }
     plots[0]->replot();
     plots[1]->replot();
}
 
void frmMain::on_ckMove_stateChanged( int arg1)
{
     bool value = (arg1 == 0 ? false : true );
     if (value) {
         ui->plot1->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
         ui->plot2->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
         ui->plot3->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
         ui->plot4->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
         ui->plot5->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
     } else {
         ui->plot1->setInteractions(QCP::iSelectOther);
         ui->plot2->setInteractions(QCP::iSelectOther);
         ui->plot3->setInteractions(QCP::iSelectOther);
         ui->plot4->setInteractions(QCP::iSelectOther);
         ui->plot5->setInteractions(QCP::iSelectOther);
     }
}
 
void frmMain::on_tabWidget_currentChanged( int index)
{
     currentIndex = index;
     plot2_timer->stop();
     plot5_timer->stop();
     maxValue = 0;
 
     ui->plot2->graph(0)->clearData();
     ui->plot2->replot();
 
     if (currentIndex == 1) {
         ui->btnLoad->setText( "开始模拟" );
     } else {
         ui->btnLoad->setText( "加载数据" );
     }
}

3. [图片] android1.png    

4. [图片] xp4.jpg    

5. [图片] xp7.jpg    

6. [图片] ubuntu4.png    


网址:http://www.oschina.net/code/snippet_114502_47429#67973

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值