提交 | 用户 | age
|
d3687b
|
1 |
#include "dialogscence2.h" |
Q |
2 |
#include "ui_dialogscence2.h" |
|
3 |
|
|
4 |
#include <QChart> |
|
5 |
//#include <QtCharts> |
|
6 |
//#include <QtCharts/QChart> |
|
7 |
#include <QtCharts/QChartView> |
|
8 |
#include <QtCharts/QBarSeries> |
|
9 |
#include <QtCharts/QBarSet> |
|
10 |
#include <QLineSeries> |
|
11 |
#include <QPieSeries> |
|
12 |
#include <QAreaSeries> |
|
13 |
#include <QSplineSeries> |
|
14 |
#include <QScatterSeries> |
|
15 |
#include <QBarCategoryAxis> |
|
16 |
#include <QValueAxis> |
|
17 |
|
|
18 |
#include <QGraphicsDropShadowEffect> |
|
19 |
|
|
20 |
#include <QDateTime> |
|
21 |
#include <QtDebug> |
|
22 |
#include <QDialog> |
|
23 |
#include <QKeyEvent> |
|
24 |
#include <QTimer> |
|
25 |
#include <QTimerEvent> |
|
26 |
#include <QDateTime> |
|
27 |
|
|
28 |
#include "mainwindow.h" |
|
29 |
|
|
30 |
DialogScence2::DialogScence2(QWidget *parent) : |
|
31 |
QDialog(parent), |
|
32 |
ui(new Ui::DialogScence2) |
|
33 |
{ |
|
34 |
ui->setupUi(this); |
|
35 |
// 产生一个定时器 |
|
36 |
QTimer *timer = new QTimer(this); |
|
37 |
|
|
38 |
//连接这个定时器的信号和槽,利用定时器的timeout(),从而触发clear()槽函数 |
|
39 |
connect(timer, &QTimer::timeout, this, &DialogScence2::timerProc); |
|
40 |
|
|
41 |
//开始定时器,并设定定时周期,每隔5秒就会重启定时器,会重复触发定时,除非你利用stop()将定时器关掉 |
|
42 |
timer->start(100); |
|
43 |
|
|
44 |
// 仅仅启动定时器一次 |
|
45 |
// timer->setSingleShot(true); |
|
46 |
InitDisplay(); |
|
47 |
|
|
48 |
//label->setPixmap(QPixmap("./pic.jpg")); |
|
49 |
// ui->label_27->setPixmap(QPixmap(":/Image/JPEG.webp")); |
|
50 |
ShowParams(); |
|
51 |
// ui->centralwidget->installEventFilter(this);//在label上安装事件过滤器,this指针指定当事件发生时调用当前类中的事件过滤器进行处理 |
|
52 |
QTimer::singleShot(100,this,&DialogScence2::DelayInit); |
|
53 |
|
|
54 |
} |
|
55 |
|
|
56 |
DialogScence2::~DialogScence2() |
|
57 |
{ |
|
58 |
delete ui; |
|
59 |
} |
|
60 |
|
|
61 |
void DialogScence2::InitDisplay() |
|
62 |
{ |
|
63 |
//设置具体阴影 |
|
64 |
QGraphicsDropShadowEffect * shadow_effect = new QGraphicsDropShadowEffect(this); |
|
65 |
shadow_effect->setOffset(0,0); |
|
66 |
//阴影颜色 |
|
67 |
shadow_effect->setColor(QColor(38,78,119,127)); |
|
68 |
|
|
69 |
//阴影半径 |
|
70 |
shadow_effect->setBlurRadius(20); |
|
71 |
ui->frame->setGraphicsEffect(shadow_effect); |
|
72 |
ui->frame_2->setGraphicsEffect(shadow_effect); |
|
73 |
ui->frame_3->setGraphicsEffect(shadow_effect); |
|
74 |
ui->frame_4->setGraphicsEffect(shadow_effect); |
|
75 |
ui->frame_5->setGraphicsEffect(shadow_effect); |
|
76 |
|
|
77 |
qDebug() << "Scence2 Show Charts"; |
|
78 |
|
|
79 |
///* |
|
80 |
auto charview1 = new QChartView; |
|
81 |
ui->verticalLayout_3->addWidget(charview1); |
|
82 |
charview1->setStyleSheet("background: transparent"); |
|
83 |
auto chart1 = CreateBarChart(); |
|
84 |
chart1->setBackgroundVisible(false); |
|
85 |
charview1->setChart(chart1); |
|
86 |
|
|
87 |
//*/ |
|
88 |
/* |
|
89 |
auto charview6 = new QChartView; |
|
90 |
ui->horizontalLayout_11->addWidget(charview6); |
|
91 |
auto chart6 = createScatterChart(); |
|
92 |
charview6->setChart(chart6); |
|
93 |
*/ |
|
94 |
qDebug() << "Scence2 Show Charts Done"; |
|
95 |
QStringList alerts; |
|
96 |
QString s1; |
|
97 |
alerts<<u8"全自动浮砂清理设备报警"<<u8"全自动水研磨设备报警"<<u8"1#切割倒棱设备报警"<<u8"2#切割倒棱设备报警"; |
|
98 |
s1=alerts.join("\n"); |
|
99 |
ui->label_Alert->setText(s1); |
|
100 |
// ui->label_Alert->installEventFilter(this); |
|
101 |
// ui->centralwidget->installEventFilter(this);//在label上安装事件过滤器,this指针指定当事件发生时调用当前类中的事件过滤器进行处理 |
|
102 |
|
|
103 |
} |
|
104 |
|
|
105 |
void DialogScence2::DelayInit() |
|
106 |
{ |
|
107 |
|
|
108 |
resizeCtrls(); |
|
109 |
} |
|
110 |
|
|
111 |
void DialogScence2::myDraw(QWidget *widget) |
|
112 |
{ |
|
113 |
QPainter painter(widget); |
|
114 |
painter.setRenderHint(QPainter::Antialiasing); |
|
115 |
|
|
116 |
//取得画布大小和中心方形。 |
|
117 |
int w = this->rect().width(); |
|
118 |
int h = this->rect().height(); |
|
119 |
int s; |
|
120 |
int wmargin=10; |
|
121 |
int hmargin=10; |
|
122 |
int ButtomMgn = 32; |
|
123 |
QRect rect1(wmargin,hmargin,w-wmargin*2,h-hmargin*2 -ButtomMgn); |
|
124 |
if (w>h) { |
|
125 |
s= h; |
|
126 |
wmargin=(w-s)/2; |
|
127 |
|
|
128 |
}else{ |
|
129 |
s= w; |
|
130 |
hmargin=(h-s)/2; |
|
131 |
} |
|
132 |
//画边框 |
|
133 |
QColor color1(0xFF6060); |
|
134 |
QColor color2(0x60F080); |
|
135 |
QColor color3(0x6080FF); |
|
136 |
QBrush brush1(QColor(0xFFB060)); |
|
137 |
|
|
138 |
QConicalGradient gradient; |
|
139 |
gradient.setCenter(rect1.center()); |
|
140 |
gradient.setAngle(360*16 - nPos*4); |
|
141 |
|
|
142 |
gradient.setColorAt(0, color1); |
|
143 |
gradient.setColorAt(0.3, color2); |
|
144 |
gradient.setColorAt(0.6, color3); |
|
145 |
gradient.setColorAt(1, color1); |
|
146 |
|
|
147 |
QPen pen0(gradient,8); |
|
148 |
painter.setPen(pen0); |
|
149 |
|
|
150 |
painter.drawRoundRect(rect1,5,5); |
|
151 |
} |
|
152 |
|
|
153 |
bool DialogScence2::eventFilter(QObject * obj, QEvent * eve) |
|
154 |
{ |
|
155 |
if (eve->type()== QEvent::Resize) |
|
156 |
{ |
|
157 |
if (obj == ui->label_Alert){ |
|
158 |
double height = ui->label_Alert->height(); |
|
159 |
auto font = ui->label_Alert->font(); |
|
160 |
font.setPointSize(height/5); |
|
161 |
ui->label_Alert->setFont(font); |
|
162 |
QString s1; |
|
163 |
s1=QString::number(height); |
|
164 |
ui->label_Alert->setText(s1); |
|
165 |
return true; |
|
166 |
} |
|
167 |
}else if(eve->type() == QEvent::Paint)//发生绘图事件, |
|
168 |
{ |
|
169 |
if (obj == ui->frame ){ |
|
170 |
if(flag == 1)//标志位为1才在label上绘图,否者不绘图 |
|
171 |
{ |
|
172 |
//myDraw(obj); |
|
173 |
//return true; |
|
174 |
} else { |
|
175 |
//return false; |
|
176 |
} |
|
177 |
} |
|
178 |
|
|
179 |
} |
|
180 |
else {} |
|
181 |
|
|
182 |
return QDialog::eventFilter(obj,eve);//其它绘图事件交给父类处理 |
|
183 |
} |
|
184 |
|
|
185 |
|
|
186 |
void DialogScence2::keyPressEvent(QKeyEvent *event) |
|
187 |
{ |
|
188 |
switch (event->key()) |
|
189 |
{ |
|
190 |
case Qt::Key_Enter: |
|
191 |
break; |
|
192 |
case Qt::Key_F11: |
|
193 |
if (bfull==0) |
|
194 |
{ |
|
195 |
oldsize = this->size(); |
|
196 |
// showMaximized(); |
|
197 |
// setWindowFlags ( Qt::FramelessWindowHint); |
|
198 |
showFullScreen(); |
|
199 |
bfull = 1; |
|
200 |
} |
|
201 |
break; |
|
202 |
case Qt::Key_Escape: |
|
203 |
if (bfull == 1){ |
|
204 |
// setWindowFlags (Qt::Window ); |
|
205 |
showNormal(); |
|
206 |
// this->resize(oldsize); |
|
207 |
bfull=0; |
|
208 |
resizeCtrls(); |
|
209 |
bNeedResize=2; |
|
210 |
} |
|
211 |
else {QDialog::keyPressEvent(event);} |
|
212 |
break; |
|
213 |
default: |
|
214 |
QDialog::keyPressEvent(event); |
|
215 |
} |
|
216 |
} |
|
217 |
|
|
218 |
void DialogScence2::timerProc() |
|
219 |
{ |
|
220 |
QString s1; |
|
221 |
s1 = QDateTime::currentDateTime().toString(u8"M月dd ddd h:mm:ss"); //"yyyy-MM-dd HH:mm:ss" |
|
222 |
ui->label_Time_3->setText(s1); |
|
223 |
nPos+=1; |
|
224 |
// ui->centralwidget->repaint(); |
|
225 |
if (bNeedResize) { |
|
226 |
bNeedResize--; |
|
227 |
if (bNeedResize==0){ |
|
228 |
resizeCtrls(); |
|
229 |
} |
|
230 |
} |
|
231 |
this->repaint(); |
|
232 |
} |
|
233 |
|
|
234 |
void DialogScence2::paintEvent(QPaintEvent *event) |
|
235 |
{ |
|
236 |
|
|
237 |
QPainter painter(this); |
|
238 |
painter.setRenderHint(QPainter::Antialiasing); |
|
239 |
|
|
240 |
//取得画布大小和中心方形。 |
|
241 |
int w = this->rect().width(); |
|
242 |
int h = this->rect().height(); |
|
243 |
int s; |
|
244 |
int wmargin=10; |
|
245 |
int hmargin=10; |
|
246 |
int ButtomMgn = 0; |
|
247 |
QRect rect1(wmargin,hmargin,w-wmargin*2,h-hmargin*2 -ButtomMgn); |
|
248 |
if (w>h) { |
|
249 |
s= h; |
|
250 |
wmargin=(w-s)/2; |
|
251 |
|
|
252 |
}else{ |
|
253 |
s= w; |
|
254 |
hmargin=(h-s)/2; |
|
255 |
} |
|
256 |
//画边框 |
|
257 |
// QPen pen0(QColor("#FFFFFF")); |
|
258 |
// painter.setPen(pen0); |
|
259 |
// painter.drawRoundRect(this->rect(),5,5); |
|
260 |
|
|
261 |
QColor color1(0xFF6060); |
|
262 |
QColor color2(0x60F080); |
|
263 |
QColor color3(0x6080FF); |
|
264 |
QBrush brush1(QColor(0xFFB060)); |
|
265 |
|
|
266 |
QConicalGradient gradient; |
|
267 |
gradient.setCenter(rect1.center()); |
|
268 |
gradient.setAngle(360*16 - nPos*4); |
|
269 |
|
|
270 |
gradient.setColorAt(0, color1); |
|
271 |
gradient.setColorAt(0.3, color2); |
|
272 |
gradient.setColorAt(0.6, color3); |
|
273 |
gradient.setColorAt(1, color1); |
|
274 |
|
|
275 |
QPen pen0(gradient,8); |
|
276 |
painter.setPen(pen0); |
|
277 |
|
|
278 |
painter.drawRoundRect(rect1,5,5); |
|
279 |
} |
|
280 |
void DialogScence2::resizeLabelFont(QLabel * label1,int lines, const QString & color) |
|
281 |
{ |
|
282 |
QString s1; |
|
283 |
double height = label1->height(); |
|
284 |
height = label1->geometry().height(); |
|
285 |
// s1=QString::number(height); |
|
286 |
// label1->setText(s1); |
|
287 |
//auto font1=label1->font(); |
|
288 |
//font1.setPointSize(height/5); |
|
289 |
//label1->setFont(font1); |
|
290 |
QString colorseg; |
|
291 |
if (!color.isEmpty()) {colorseg= QString("color:%1;").arg(color);} |
|
292 |
int sheight=height/1.5/(lines+0.5); |
|
293 |
if (sheight>80) {sheight=80;} |
|
294 |
qDebug()<<"height" << height << "lines" << lines << "sHeight" << sheight; |
|
295 |
s1=QString("QLabel{font:%1px;%2}").arg(sheight).arg(colorseg); |
|
296 |
label1->setStyleSheet(s1); |
|
297 |
//label1->setScaledContents(true); |
|
298 |
} |
|
299 |
|
|
300 |
void DialogScence2::resizeCtrls() |
|
301 |
{ |
|
302 |
/* |
|
303 |
*{ |
|
304 |
background:qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(40, 60, 100, 255), stop:1 rgba(20, 40, 80, 255)); |
|
305 |
font-size:18pt; |
|
306 |
font-style:MingLiU-ExtB; |
|
307 |
} |
|
308 |
|
|
309 |
QFrame{ |
|
310 |
background-color: rgb(0,30,80,160); |
|
311 |
border-radius:10px; |
|
312 |
border:1px solid rgb(100,169,139); |
|
313 |
} |
|
314 |
QLabel{ background:rgba(85,170,255,0); color:white; font-style:MingLiU-ExtB; font-size:22pt; } |
|
315 |
QLabel:hover{ background:rgba(85,170,255,0); color:white; font-style:MingLiU-ExtB; font-size:22pt; } |
|
316 |
QLabel:TimeDisplay{ background:rgba(85,170,255,0); color:white; font-style:MingLiU-ExtB; font-size:22pt; } |
|
317 |
*/ |
|
318 |
|
|
319 |
resizeLabelFont(ui->label_46,1); |
|
320 |
resizeLabelFont(ui->label_Time_3,2); |
|
321 |
resizeLabelFont(ui->label,1); |
|
322 |
resizeLabelFont(ui->label_2,1); |
|
323 |
|
|
324 |
resizeLabelFont(ui->label_Alert,4,"yellow"); |
|
325 |
//resizeLabelFont(ui->label_Info,20); |
|
326 |
|
|
327 |
resizeLabelFont(ui->label_4,1); |
|
328 |
resizeLabelFont(ui->label_5,2); |
|
329 |
resizeLabelFont(ui->label_6,1); |
|
330 |
resizeLabelFont(ui->label_7,2); |
|
331 |
resizeLabelFont(ui->label_8,1); |
|
332 |
resizeLabelFont(ui->label_9,2); |
|
333 |
resizeLabelFont(ui->label_47,3); |
|
334 |
|
|
335 |
QString s1; |
|
336 |
QFont font1 = ui->plainTextEdit_Info->font(); |
|
337 |
double height = ui->plainTextEdit_Info->height(); |
|
338 |
s1=QString("color:white;font:%1px;background-color:rgb(0,30,80,160)").arg(int(height/15)); |
|
339 |
ui->plainTextEdit_Info->setStyleSheet(s1); |
|
340 |
font1.setPixelSize(height/5); |
|
341 |
ui->plainTextEdit_Info->setFont(font1); |
|
342 |
} |
|
343 |
|
|
344 |
void DialogScence2::resizeEvent(QResizeEvent *event) |
|
345 |
{ |
|
346 |
QDialog::resizeEvent(event); |
|
347 |
|
|
348 |
resizeCtrls(); |
|
349 |
} |
|
350 |
void DialogScence2::ShowParams() |
|
351 |
{ |
|
352 |
|
|
353 |
} |
|
354 |
|
|
355 |
void DialogScence2::setChartAttribute(QChart *chart, QString title) |
|
356 |
{ |
|
357 |
// 创建默认坐标轴 |
|
358 |
chart->createDefaultAxes(); |
|
359 |
// 设置标题 |
|
360 |
chart->setTitle(title); |
|
361 |
// 设置data,在设置标题时使用 |
|
362 |
chart->setData(Qt::UserRole, title); |
|
363 |
} |
|
364 |
|
|
365 |
QChart * DialogScence2::CreateBarChart() |
|
366 |
{ |
|
367 |
// 创建QChart对象 |
|
368 |
QChart *chart = new QChart(); |
|
369 |
// 创建饼图系列对象 |
|
370 |
QBarSeries *series = new QBarSeries(chart); |
|
371 |
|
|
372 |
qsrand(QDateTime::currentMSecsSinceEpoch() % 20000); |
|
373 |
|
|
374 |
// 添加图表值 |
|
375 |
for(int count = 0; count < 3; ++count) |
|
376 |
{ |
|
377 |
// 创建曲线图系列对象 |
|
378 |
QBarSet *set = new QBarSet(QString(65 + count)+u8"班"); |
|
379 |
for(int index = 0; index < 4; ++index) |
|
380 |
{ |
|
381 |
set->append(33 + rand() % 50); |
|
382 |
} |
|
383 |
series->append(set); |
|
384 |
} |
|
385 |
series->setLabelsPosition(QAbstractBarSeries::LabelsOutsideEnd); |
|
386 |
series->setLabelsVisible(true); |
|
387 |
|
|
388 |
chart->setTheme(QChart::ChartThemeBlueCerulean); |
|
389 |
chart->addSeries(series); |
|
390 |
chart->setAnimationOptions(QChart::SeriesAnimations); |
|
391 |
QString title = u8"班组加工数据分析汇总"; |
|
392 |
chart->setTitle(title); |
|
393 |
chart->setData(Qt::UserRole, title); |
|
394 |
QFont font1; |
|
395 |
font1.setPixelSize(24); |
|
396 |
//chart->setFont(QFont("宋体",32)); |
|
397 |
chart->setTitleFont(font1); |
|
398 |
//setChartAttribute(chart, ); |
|
399 |
//坐标轴// |
|
400 |
QStringList categories; |
|
401 |
categories <<u8"刷锅"<<u8"研磨"<<u8"切割1"<<u8"切割2"; |
|
402 |
QBarCategoryAxis * axisX = new QBarCategoryAxis(); |
|
403 |
axisX->append(categories); |
|
404 |
chart->addAxis(axisX,Qt::AlignBottom); |
|
405 |
series->attachAxis(axisX); |
|
406 |
QValueAxis *axisY = new QValueAxis(); |
|
407 |
axisY->setRange(0,100); |
|
408 |
|
|
409 |
chart->addAxis(axisY,Qt::AlignLeft); |
|
410 |
series->attachAxis(axisY); |
|
411 |
QFont font2; |
|
412 |
font2.setPixelSize(22); |
|
413 |
|
|
414 |
QFont font3; |
|
415 |
font3.setPixelSize(16); |
|
416 |
|
|
417 |
axisX->setLabelsFont(font2); |
|
418 |
|
|
419 |
axisY->setLabelsFont(font3); |
|
420 |
// axisX->setTitleFont(font2); |
|
421 |
// 将series添加到QChart对象中 |
|
422 |
|
|
423 |
// 设置通用属性 |
|
424 |
QFont font4; |
|
425 |
font4.setPixelSize(24); |
|
426 |
chart->legend()->setFont(font4); |
|
427 |
|
|
428 |
// chart->axisX()->setLabelsFont(font2); |
|
429 |
// chart->axisY()->setLabelsFont(font2); |
|
430 |
// chart->axes(Qt::Vertical).at(0)->setGridLineVisible(false); |
|
431 |
// chart->axes(Qt::Horizontal).at(0)->setGridLineVisible(false); |
|
432 |
// 返回QChart对象 |
|
433 |
// chart->legend()->setVisible(true); |
|
434 |
// chart->legend()->setAlignment(Qt::AlignBottom); |
|
435 |
return chart; |
|
436 |
} |
|
437 |
|
|
438 |
QChart *DialogScence2::createPieChart() |
|
439 |
{ |
|
440 |
// 创建QChart对象 |
|
441 |
QChart *chart = new QChart(); |
|
442 |
// 创建饼图系列对象 |
|
443 |
QPieSeries *series = new QPieSeries(chart); |
|
444 |
// 遍历假数据容器将数据添加到series对象中 |
|
445 |
|
|
446 |
qsrand(QDateTime::currentMSecsSinceEpoch() % 20000); |
|
447 |
|
|
448 |
// 添加图表值 |
|
449 |
for(int index = 0; index != 5; ++index) |
|
450 |
{ |
|
451 |
series->append(QString(65 + index), rand() % 100); |
|
452 |
} |
|
453 |
|
|
454 |
// 将series添加到QChart对象中 |
|
455 |
chart->addSeries(series); |
|
456 |
|
|
457 |
// 设置通用属性 |
|
458 |
setChartAttribute(chart, u8"饼图"); |
|
459 |
chart->legend()->setAlignment(Qt::AlignRight); |
|
460 |
// 返回QChart对象 |
|
461 |
return chart; |
|
462 |
} |
|
463 |
|
|
464 |
QChart *DialogScence2::createAreaChart() |
|
465 |
{ |
|
466 |
// 创建QChart对象 |
|
467 |
QChart *chart = new QChart(); |
|
468 |
|
|
469 |
// 添加图表值 |
|
470 |
//! 创建区域图系列对象 |
|
471 |
//! 区域图的系列对象 |
|
472 |
QLineSeries *lowerSeries = nullptr; |
|
473 |
for(int count = 1; count != 3; ++count) |
|
474 |
{ |
|
475 |
// 创建折线图系列对象 |
|
476 |
QLineSeries *upperSeries = new QLineSeries(chart); |
|
477 |
for(int index = 1; index != 5; ++index) |
|
478 |
{ |
|
479 |
upperSeries->append(index , index * count * 5 + rand() % 5); |
|
480 |
} |
|
481 |
// 将series添加到QChart对象中 |
|
482 |
QAreaSeries *series = new QAreaSeries(upperSeries, lowerSeries); |
|
483 |
lowerSeries = upperSeries; |
|
484 |
chart->addSeries(series); |
|
485 |
} |
|
486 |
|
|
487 |
// 设置通用属性 |
|
488 |
setChartAttribute(chart, u8"面积图 "); |
|
489 |
// 返回QChart对象 |
|
490 |
return chart; |
|
491 |
} |
|
492 |
|
|
493 |
QChart *DialogScence2::createLineChart() |
|
494 |
{ |
|
495 |
// 创建QChart对象 |
|
496 |
QChart *chart = new QChart(); |
|
497 |
|
|
498 |
// 添加图表值 |
|
499 |
for(int count = 0; count != 3; ++count) |
|
500 |
{ |
|
501 |
// 创建折线图系列对象 |
|
502 |
QLineSeries *series = new QLineSeries(chart); |
|
503 |
for(int index = 0; index != 5; ++index) |
|
504 |
{ |
|
505 |
series->append(index * count, index * count - rand() % 3); |
|
506 |
} |
|
507 |
// 将series添加到QChart对象中 |
|
508 |
chart->addSeries(series); |
|
509 |
} |
|
510 |
|
|
511 |
// 设置通用属性 |
|
512 |
setChartAttribute(chart, u8"折线图 "); |
|
513 |
// 返回QChart对象 |
|
514 |
return chart; |
|
515 |
} |
|
516 |
|
|
517 |
QChart *DialogScence2::createSpLineChart() |
|
518 |
{ |
|
519 |
// 创建QChart对象 |
|
520 |
QChart *chart = new QChart(); |
|
521 |
|
|
522 |
// 添加图表值 |
|
523 |
for(int count = 0; count != 3; ++count) |
|
524 |
{ |
|
525 |
// 创建曲线图系列对象 |
|
526 |
QSplineSeries *series = new QSplineSeries(chart); |
|
527 |
for(int index = 0; index != 5; ++index) |
|
528 |
{ |
|
529 |
series->append(index * count, index * count - rand() % 8); |
|
530 |
} |
|
531 |
// 将series添加到QChart对象中 |
|
532 |
chart->addSeries(series); |
|
533 |
} |
|
534 |
|
|
535 |
// 设置通用属性 |
|
536 |
setChartAttribute(chart, u8"曲线图 "); |
|
537 |
// 返回QChart对象 |
|
538 |
return chart; |
|
539 |
} |
|
540 |
|
|
541 |
QChart *DialogScence2::createScatterChart() |
|
542 |
{ |
|
543 |
// 创建QChart对象 |
|
544 |
QChart *chart = new QChart(); |
|
545 |
|
|
546 |
// 添加图表值 |
|
547 |
for(int count = 0; count != 3; ++count) |
|
548 |
{ |
|
549 |
// 创建曲线图系列对象 |
|
550 |
QScatterSeries *series = new QScatterSeries(chart); |
|
551 |
for(int index = 0; index != 5; ++index) |
|
552 |
{ |
|
553 |
series->append(index , index * count * 5 + rand() % 5); |
|
554 |
} |
|
555 |
// 将series添加到QChart对象中 |
|
556 |
chart->addSeries(series); |
|
557 |
} |
|
558 |
|
|
559 |
// 设置通用属性 |
|
560 |
setChartAttribute(chart, u8"散点图 "); |
|
561 |
// 返回QChart对象 |
|
562 |
return chart; |
|
563 |
} |
|
564 |
|
|
565 |
/* |
|
566 |
void DialogScence2::on_comboBox_currentIndexChanged(int index) |
|
567 |
{ |
|
568 |
// 拿到chart容器中相同索引位置的QChart对象,并将其设置到view对象上 |
|
569 |
QChart *chart = m_chartVector[index]; |
|
570 |
m_chartView->setChart(chart); |
|
571 |
} |
|
572 |
|
|
573 |
void DialogScence2::on_legendGroupButtonClicked(QAbstractButton *button) |
|
574 |
{ |
|
575 |
// 拿到发送信号的单选按钮 |
|
576 |
QRadioButton *btn = dynamic_cast<QRadioButton *>(button); |
|
577 |
// 遍历图表容器,将legend的aign属性设为当前按钮对应的属性状态 |
|
578 |
foreach(QChart *chart, m_chartVector) |
|
579 |
{ |
|
580 |
//! 拿到当前单选按钮的属性值并强转为Qt::Alignment类型 |
|
581 |
//! |
|
582 |
Qt::Alignment align = static_cast<Qt::Alignment>(btn->property("LegendValue").toUInt()); |
|
583 |
// 将类型值设置到当前图表上 |
|
584 |
chart->legend()->setAlignment(align); |
|
585 |
} |
|
586 |
} |
|
587 |
|
|
588 |
void DialogScence2::on_animationGroup_buttonClicked(QAbstractButton *button) |
|
589 |
{ |
|
590 |
// 拿到发送信号的单选按钮 |
|
591 |
QRadioButton *btn = dynamic_cast<QRadioButton *>(button); |
|
592 |
// 遍历图表容器,将chart的动画设为当前按钮对应的属性状态 |
|
593 |
foreach(QChart *chart, m_chartVector) |
|
594 |
{ |
|
595 |
//! 拿到当前单选按钮的属性值并强转为Qt::AnimationOption |
|
596 |
//! 其属性值为对应动画的int值,可通过帮助查看具体值 |
|
597 |
QChart::AnimationOption animation = static_cast<QChart::AnimationOption>(btn->property("AnimationValue").toUInt()); |
|
598 |
// 将类型值设置到当前图表上 |
|
599 |
chart->setAnimationOptions(animation); |
|
600 |
} |
|
601 |
|
|
602 |
} |
|
603 |
|
|
604 |
void DialogScence2::on_otherGroup_buttonClicked(QAbstractButton *button) |
|
605 |
{ |
|
606 |
// 拿到发送信号的复选按钮 |
|
607 |
QCheckBox *btn = dynamic_cast<QCheckBox *>(button); |
|
608 |
// 判断所点击按钮的勾选状态 |
|
609 |
bool checked = btn->isChecked(); |
|
610 |
// 通过按钮动态属性判断按钮操作 |
|
611 |
switch(btn->property("btnType").toInt()) |
|
612 |
{ |
|
613 |
case 0: |
|
614 |
{ |
|
615 |
// 设置view的防锯齿,其还包含其他防锯齿选项,可查看帮助了解 |
|
616 |
m_chartView->setRenderHint(QPainter::Antialiasing, checked); |
|
617 |
break; |
|
618 |
} |
|
619 |
case 1: |
|
620 |
{ |
|
621 |
foreach(QChart *chart, m_chartVector) |
|
622 |
{ |
|
623 |
// 通过三目运算符判断标题是否获取data中的值 |
|
624 |
QString title = checked? chart->data(Qt::UserRole).toString(): ""; |
|
625 |
// 设置标题 |
|
626 |
chart->setTitle(title); |
|
627 |
} |
|
628 |
break; |
|
629 |
} |
|
630 |
default: |
|
631 |
break; |
|
632 |
} |
|
633 |
|
|
634 |
} |
|
635 |
|
|
636 |
*/ |