/
QwtPlotPropertySetDialog.cpp
824 lines (749 loc) · 28.7 KB
/
QwtPlotPropertySetDialog.cpp
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
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
#include "QwtPlotPropertySetDialog.h"
#include <QBrush>
#include <QPen>
#include <qwt_scale_draw.h>
#include <qwt_date_scale_draw.h>
#include <qwt_interval.h>
#include <qwt_scale_widget.h>
#include <qwt_plot_item.h>
#define PROPERTY_ATTRIBUTE_CURVE_PTR QStringLiteral("curve_ptr")
#define ID_GroupPlot 1
//"图表参数"
#define ID_PlotTitle 2
//"图表标题"
#define ID_PlotFooter 3
//"脚标"
#define ID_XBottomTitle 4
//"X底轴标题"
#define ID_XTopTitle 5
//"X顶轴标题"
#define ID_YLeftTitle 6
//"Y左轴标题"
#define ID_YRightTitle 7
//"Y右轴标题"
#define ID_XBottomScale 8
//"X底轴Scale样式"
#define ID_XTopScale 9
//"X顶轴Scale样式"
#define ID_YLeftScale 10
//"Y左轴Scale样式"
#define ID_YRightScale 11
//"Y右轴Scale样式"
#define ID_XBottomDateScaleType 12
//"X底轴DateScale样式"
#define ID_XTopDateScaleType 13
//"X顶轴DateScale样式"
#define ID_YLeftDateScaleType 14
//"Y左轴DateScale样式"
#define ID_YRightDateScaleType 15
//"Y右轴DateScale样式"
#define ID_PlotCanvasBackground 16
//"画布背景"
#define ID_PlotEnableZoomerScroll 17
//"缩放滚动条"
#define ID_PlotAxisSet 18
//"坐标轴设置"
#define ID_GroupXBottomSet 19
//"x底轴设置"
#define ID_GroupXTopSet 20
//"x顶轴设置"
#define ID_GroupyLeftSet 21
//"y左轴设置"
#define ID_GroupyRightSet 22
//"y右轴设置"
#define ID_XBottomInterval 23
//"X底轴IntervalMin
#define ID_XTopInterval 24
//"X顶轴IntervalMin
#define ID_YLeftInterval 25
//"Y左轴IntervalMin
#define ID_YRightInterval 26
//"Y右轴IntervalMin
#define ID_XBottomLabelRotation 27
//"X底轴IntervalMin
#define ID_XTopLabelRotation 28
//"X顶轴IntervalMin
#define ID_YLeftLabelRotation 29
//"Y左轴IntervalMin
#define ID_YRightLabelRotation 30
//"Y右轴IntervalMin
//////////////////////////////////////////////
#define ID_CurveIDBase 0x800
//记录曲线id的基本位 ,在位数大于ID_CurveIDBase的为曲线id
#define ID_CurvePropertyIDBase 0x7FF
//用于与出曲线的属性位
#define ID_CurveTitle 300
//曲线标题
#define ID_CurveColore 301
//曲线颜色
#define ID_CurvePenStyle 302
//曲线线宽
#define ID_CurveWidth 303
//曲线线形
#define xBottomFlag 0x1
#define xTopFlag 0x2
#define yLeftFlag 0x4
#define yRightFlag 0x8
int QwtPlotPropertySetDialog::makeCurvePropertyID(int CurveBaseID,int curvePropertyID)
{
return (CurveBaseID|curvePropertyID);
}
int QwtPlotPropertySetDialog::getCurveID(int curvePropertyID)
{
return (curvePropertyID&(~ID_CurvePropertyIDBase));
}
int QwtPlotPropertySetDialog::makeCurveBaseID(QwtPlotCurve *cur)
{
static int s_curve_id = ID_CurveIDBase;
s_curve_id+=ID_CurveIDBase;
m_baseID2curve[s_curve_id] = cur;
m_curve2baseID[cur] = s_curve_id;
return s_curve_id;
}
int QwtPlotPropertySetDialog::getCurvePropertyID(int id)
{
return (ID_CurvePropertyIDBase&id);
}
QwtPlotPropertySetDialog::QwtPlotPropertySetDialog(QWidget *parent,ChartWave_qwt* plot)
: QWidget(parent)
,m_plot(plot)
,m_enableSet(false)
{
createUI();
buildConnect();
}
QwtPlotPropertySetDialog::~QwtPlotPropertySetDialog()
{
}
void QwtPlotPropertySetDialog::createUI()
{
m_mainHorizontalLayout = new QHBoxLayout(this);
m_mainHorizontalLayout->setSpacing(1);
m_mainHorizontalLayout->setContentsMargins(1, 1, 1, 1);
m_mainHorizontalLayout->setObjectName(QStringLiteral("mainHorizontalLayout"));
m_mainHorizontalLayout->setContentsMargins(1, 1, 1, 1);
m_property = new QtTreePropertyBrowser(this);
m_mainHorizontalLayout->addWidget(m_property);
m_propertyGroup = new QtGroupPropertyManager(m_property);
m_variantManager = new QtVariantPropertyManager(m_property);
m_variantFactory = new QtVariantEditorFactory(m_property);
m_property->setFactoryForManager(m_variantManager,m_variantFactory);
connect(m_variantManager,&QtVariantPropertyManager::valueChanged
,this,&QwtPlotPropertySetDialog::onPropertyValueChanged);
addPlotSet(m_plot);
addCurveSet(m_plot);
}
void QwtPlotPropertySetDialog::updateAllValue()
{
m_property_id.setVarPropertyData(ID_PlotTitle,m_plot->title().text());
m_property_id.setVarPropertyData(ID_PlotFooter,m_plot->footer().text());
m_property_id.setVarPropertyData(ID_PlotCanvasBackground,m_plot->canvasBackground().color());
m_property_id.setVarPropertyData(ID_PlotEnableZoomerScroll,m_plot->isEnableZoomerScroll());
m_property_id.setVarPropertyData(ID_PlotAxisSet,getAxisEnable(m_plot));
updateAxisValue(QwtPlot::xBottom);
updateAxisValue(QwtPlot::yLeft);
updateAxisValue(QwtPlot::xTop);
updateAxisValue(QwtPlot::yRight);
QList<QwtPlotCurve*> curs = m_plot->getCurveList();
for (auto ite = curs.begin();ite != curs.end();++ite)
{
updateCurveValue(*ite);
}
}
void QwtPlotPropertySetDialog::buildConnect()
{
connect(m_plot,&QwtPlot::itemAttached,this,&QwtPlotPropertySetDialog::itemAttached);
QwtScaleWidget* aw = m_plot->axisWidget(QwtPlot::xBottom);
if(aw)
connect(aw,&QwtScaleWidget::scaleDivChanged,this,&QwtPlotPropertySetDialog::onScaleDivChangedXBottom);
aw = m_plot->axisWidget(QwtPlot::xTop);
if(aw)
connect(aw,&QwtScaleWidget::scaleDivChanged,this,&QwtPlotPropertySetDialog::onScaleDivChangedXTop);
aw = m_plot->axisWidget(QwtPlot::yLeft);
if(aw)
connect(aw,&QwtScaleWidget::scaleDivChanged,this,&QwtPlotPropertySetDialog::onScaleDivChangedYLeft);
aw = m_plot->axisWidget(QwtPlot::yRight);
if(aw)
connect(aw,&QwtScaleWidget::scaleDivChanged,this,&QwtPlotPropertySetDialog::onScaleDivChangedYRight);
}
void QwtPlotPropertySetDialog::disChartConnect()
{
QwtScaleWidget* aw = m_plot->axisWidget(QwtPlot::xBottom);
if(aw)
disconnect(aw,&QwtScaleWidget::scaleDivChanged,this,&QwtPlotPropertySetDialog::onScaleDivChangedXBottom);
aw = m_plot->axisWidget(QwtPlot::xTop);
if(aw)
disconnect(aw,&QwtScaleWidget::scaleDivChanged,this,&QwtPlotPropertySetDialog::onScaleDivChangedXTop);
aw = m_plot->axisWidget(QwtPlot::yLeft);
if(aw)
disconnect(aw,&QwtScaleWidget::scaleDivChanged,this,&QwtPlotPropertySetDialog::onScaleDivChangedYLeft);
aw = m_plot->axisWidget(QwtPlot::yRight);
if(aw)
disconnect(aw,&QwtScaleWidget::scaleDivChanged,this,&QwtPlotPropertySetDialog::onScaleDivChangedYRight);
}
void QwtPlotPropertySetDialog::addPlotSet(ChartWave_qwt* plot)
{
m_enableSet = false;
//图表参数
QtVariantProperty *pro = nullptr;
QtProperty *groupItem = m_propertyGroup->addProperty(QStringLiteral("图表参数"));
m_property_id.rememberTheProperty(ID_GroupPlot,groupItem);
m_property_id.addVariantPropertyInGroup(m_variantManager,QVariant::String
,groupItem,QStringLiteral("图表标题"),ID_PlotTitle,m_plot->title().text());
m_property_id.addVariantPropertyInGroup(m_variantManager,QVariant::String
,groupItem,QStringLiteral("脚标"),ID_PlotFooter,m_plot->footer().text());
m_property_id.addVariantPropertyInGroup(m_variantManager,QVariant::Color
,groupItem,QStringLiteral("画布背景"),ID_PlotCanvasBackground,m_plot->canvasBackground().color());
m_property_id.addVariantPropertyInGroup(m_variantManager,QVariant::Bool
,groupItem,QStringLiteral("缩放滚动条"),ID_PlotEnableZoomerScroll,m_plot->isEnableZoomerScroll());
//坐标轴设置
pro = m_property_id.addVariantPropertyInGroup(m_variantManager,QtVariantPropertyManager::flagTypeId()
,groupItem,QStringLiteral("坐标轴设置"),ID_PlotAxisSet,getAxisEnable(plot));
pro->setAttribute(QLatin1String("flagNames"), QStringList()
<<QStringLiteral("x底")
<<QStringLiteral("x顶")
<<QStringLiteral("y左")
<<QStringLiteral("y右")
);//在setAttribute过程中会触发onPropertyValueChanged,而onPropertyValueChanged的值是0,需要使用m_enableAxisEnableSet来抑制
pro->setValue(getAxisEnable(plot));
//轴详细设置
addAxisSet(groupItem,plot,QwtPlot::xBottom);
addAxisSet(groupItem,plot,QwtPlot::yLeft);
addAxisSet(groupItem,plot,QwtPlot::xTop);
addAxisSet(groupItem,plot,QwtPlot::yRight);
m_property->addProperty(groupItem);
m_enableSet = true;
}
void QwtPlotPropertySetDialog::addAxisSet(QtProperty* parentGroup, ChartWave_qwt* plot,QwtPlot::Axis axis)
{
m_enableSet = false;
QtVariantProperty *pro = nullptr;
//QwtScaleWidget* scaleWidget = plot->axisWidget(axis);
QwtScaleDraw *scaleDraw = plot->axisScaleDraw(axis);
QwtDateScaleDraw* dateScale = dynamic_cast<QwtDateScaleDraw*>(scaleDraw);
//轴详细设置
QtProperty *childGroup = m_property_id.addGroupInGroup(m_variantManager,parentGroup
,QStringLiteral("%1轴设置").arg(axisString(axis))
,axisPropertyID(axis,0));
childGroup->setEnabled(plot->axisEnabled(axis));//在轴允许时才让设置
QwtInterval inv= plot->axisInterval(axis);
m_property_id.addVariantPropertyInGroup(m_variantManager,QVariant::PointF
,childGroup
,QStringLiteral("坐标范围")
,axisPropertyID(axis,4)
,QPointF(inv.minValue(),inv.maxValue()));
m_property_id.addVariantPropertyInGroup(m_variantManager,QVariant::String
,childGroup,QStringLiteral("标题")
,axisPropertyID(axis,1)
,m_plot->axisTitle(axis).text());
//
m_property_id.addVariantPropertyInGroup(m_variantManager,QVariant::Double
,childGroup,QStringLiteral("刻度文字角度")
,axisPropertyID(axis,5)
,scaleDraw->labelRotation());
pro = m_property_id.addVariantPropertyInGroup(m_variantManager,QtVariantPropertyManager::enumTypeId()
,childGroup
,QStringLiteral("%1轴样式").arg(axisString(axis))
,axisPropertyID(axis,2)
,0);
pro->setAttribute(QLatin1String("enumNames"),QStringList()
<<QStringLiteral("正常坐标轴")
<<QStringLiteral("时间坐标轴")
);
ScaleDraw sd = NormalScale;
sd = ((dateScale == nullptr) ? NormalScale : DateScale);
pro->setValue(int(sd));
pro = m_property_id.addVariantPropertyInGroup(m_variantManager,QtVariantPropertyManager::enumTypeId()
,childGroup
,QStringLiteral("时间格式")
,axisPropertyID(axis,3)
,int(ChartWave_qwt::hh_mm_ss));
pro->setAttribute(QLatin1String("enumNames"), QStringList()
<<QStringLiteral("h_m")
<<QStringLiteral("hh_mm")
<<QStringLiteral("h_m_s")
<<QStringLiteral("hh_mm_ss")
<<QStringLiteral("yyyy_M_d")
<<QStringLiteral("yyyy_M_d_h_m")
<<QStringLiteral("yyyy_M_d_h_m_s")
<<QStringLiteral("yyyy_MM_dd")
<<QStringLiteral("yyyy_MM_dd_hh_mm")
<<QStringLiteral("yyyy_MM_dd_hh_mm_ss")
);//在setAttribute过程中会触发onPropertyValueChanged,而onPropertyValueChanged的值是0,需要使用m_enableAxisEnableSet来抑制
pro->setValue(int(ChartWave_qwt::hh_mm_ss));
pro->setEnabled(sd == DateScale);
m_enableSet = true;
}
QString QwtPlotPropertySetDialog::axisString(QwtPlot::Axis axis) const
{
switch(axis)
{
case QwtPlot::xBottom:return QStringLiteral("x底");
case QwtPlot::xTop:return QStringLiteral("x顶");
case QwtPlot::yLeft:return QStringLiteral("y左");
case QwtPlot::yRight:return QStringLiteral("y右");
}
return QStringLiteral("");
}
int QwtPlotPropertySetDialog::axisPropertyID(QwtPlot::Axis axis, int order) const
{
if(0 == order)
{
switch(axis)
{
case QwtPlot::xBottom:return ID_GroupXBottomSet;
case QwtPlot::xTop:return ID_GroupXTopSet;
case QwtPlot::yLeft:return ID_GroupyLeftSet;
case QwtPlot::yRight:return ID_GroupyRightSet;
}
}
else if(1 == order)
{
switch(axis)
{
case QwtPlot::xBottom:return ID_XBottomTitle;
case QwtPlot::xTop:return ID_XTopTitle;
case QwtPlot::yLeft:return ID_YLeftTitle;
case QwtPlot::yRight:return ID_YRightTitle;
}
}
else if(2 == order)
{
switch(axis)
{
case QwtPlot::xBottom:return ID_XBottomScale;
case QwtPlot::xTop:return ID_XTopScale;
case QwtPlot::yLeft:return ID_YLeftScale;
case QwtPlot::yRight:return ID_YRightScale;
}
}
else if(3 == order)
{
switch(axis)
{
case QwtPlot::xBottom:return ID_XBottomDateScaleType;
case QwtPlot::xTop:return ID_XTopDateScaleType;
case QwtPlot::yLeft:return ID_YLeftDateScaleType;
case QwtPlot::yRight:return ID_YRightDateScaleType;
}
}
else if(4==order)
{
switch(axis)
{
case QwtPlot::xBottom:return ID_XBottomInterval;
case QwtPlot::xTop:return ID_XTopInterval;
case QwtPlot::yLeft:return ID_YLeftInterval;
case QwtPlot::yRight:return ID_YRightInterval;
}
}
else if(5==order)
{
switch(axis)
{
case QwtPlot::xBottom:return ID_XBottomLabelRotation;
case QwtPlot::xTop:return ID_XTopLabelRotation;
case QwtPlot::yLeft:return ID_YLeftLabelRotation;
case QwtPlot::yRight:return ID_YRightLabelRotation;
}
}
return -1;
}
void QwtPlotPropertySetDialog::addCurveSet(ChartWave_qwt* plot)
{
QList<QwtPlotCurve*> curs = plot->getCurveList();
for (auto ite = curs.begin();ite != curs.end();++ite)
{
addCurveSet(*ite);
}
}
QString QwtPlotPropertySetDialog::penStyle2Chinese(const Qt::PenStyle penStyle)
{
switch(penStyle){
case Qt::SolidLine:
return QStringLiteral("实线");
case Qt::DashLine:
return QStringLiteral("虚线");
case Qt::DotLine:
return QStringLiteral("点线");
case Qt::DashDotLine:
return QStringLiteral("点划线");
case Qt::DashDotDotLine:
return QStringLiteral("双点划线");
}
return QString();
}
Qt::PenStyle QwtPlotPropertySetDialog::Chinese2PenStyle(const QString str)
{
if (str == QStringLiteral("实线"))
{
return Qt::SolidLine;
}
else if (str == QStringLiteral("点线"))
{
return Qt::DotLine;
}
else if (str == QStringLiteral("点划线"))
{
return Qt::DashDotLine;
}
else if (str == QStringLiteral("双点划线"))
{
return Qt::DashDotDotLine;
}
return Qt::NoPen;
}
void QwtPlotPropertySetDialog::setChartPtr(ChartWave_qwt *chart)
{
if(m_plot)//如果已经关联了图表,需要先接触连接
disChartConnect();
m_plot = chart;
buildConnect();
}
void QwtPlotPropertySetDialog::updateAxisValue(QwtPlot::Axis axis)
{
QwtInterval inv= m_plot->axisInterval(axis);
//QwtScaleWidget* scaleWidget = m_plot->axisWidget(axis);
QwtScaleDraw *scaleDraw = m_plot->axisScaleDraw(axis);
QwtDateScaleDraw* dateScale = dynamic_cast<QwtDateScaleDraw*>(scaleDraw);
m_property_id.setVarPropertyData(axisPropertyID(axis,4)
,QPointF(inv.minValue(),inv.maxValue()));
m_property_id.setVarPropertyData(axisPropertyID(axis,1)
,m_plot->axisTitle(axis).text());
ScaleDraw sd = NormalScale;
sd = ((dateScale == nullptr) ? NormalScale : DateScale);
m_property_id.setVarPropertyData(axisPropertyID(axis,2),int(sd));
m_property_id.setVarPropertyData(axisPropertyID(axis,5),scaleDraw->labelRotation());
}
void QwtPlotPropertySetDialog::updateCurveValue(QwtPlotCurve *cur)
{
int baseID = getCurveBaseID(cur);
m_property_id.setVarPropertyData(makeCurvePropertyID(baseID,ID_CurveTitle)
,cur->title().text());
const QPen pen = cur->pen();
m_property_id.setVarPropertyData(makeCurvePropertyID(baseID,ID_CurveColore)
,pen.color());
m_property_id.setVarPropertyData(makeCurvePropertyID(baseID,ID_CurveWidth)
,pen.width());
m_property_id.setVarPropertyData(makeCurvePropertyID(baseID,ID_CurvePenStyle)
,penStyle2Order(pen.style()));
}
void QwtPlotPropertySetDialog::addCurveSet(QwtPlotCurve* curve)
{
m_enableSet = false;
int curveID = makeCurveBaseID(curve);
QString name = QStringLiteral("%1-图表参数").arg(curve->title().text());
QtProperty *groupItem = m_propertyGroup->addProperty(name);
QtVariantProperty *pro = nullptr;
m_property_id.rememberTheProperty(curveID,groupItem);
pro = m_property_id.addVariantPropertyInGroup(m_variantManager,QVariant::String
,groupItem,QStringLiteral("标题")
,makeCurvePropertyID(curveID,ID_CurveTitle)
,curve->title().text());
const QPen pen = curve->pen();
pro= m_property_id.addVariantPropertyInGroup(m_variantManager,QVariant::Color
,groupItem,QStringLiteral("颜色")
,makeCurvePropertyID(curveID,ID_CurveColore)
,pen.color());
pro = m_property_id.addVariantPropertyInGroup(m_variantManager,QVariant::Int
,groupItem,QStringLiteral("线宽")
,makeCurvePropertyID(curveID,ID_CurveWidth)
,pen.width());
pro->setAttribute(QStringLiteral("singleStep"), 1);
pro = m_property_id.addVariantPropertyInGroup(m_variantManager,QtVariantPropertyManager::enumTypeId()
,groupItem,QStringLiteral("线形")
,makeCurvePropertyID(curveID,ID_CurvePenStyle)
,penStyle2Order(pen.style()));
pro->setAttribute(QLatin1String("enumNames"),QStringList()
<<QStringLiteral("实线")
<<QStringLiteral("虚线")
<<QStringLiteral("点线")
<<QStringLiteral("点划线")
<<QStringLiteral("双点划线")
);
m_property->addProperty(groupItem);
m_enableSet = true;
}
int QwtPlotPropertySetDialog::penStyle2Order(Qt::PenStyle style) const
{
switch (style) {
case Qt::SolidLine:return 0;
case Qt::DashLine:return 1;
case Qt::DotLine:return 2;
case Qt::DashDotLine:return 3;
case Qt::DashDotDotLine:return 4;
default:
return 0;
}
return 0;
}
Qt::PenStyle QwtPlotPropertySetDialog::order2penStyle(int order) const
{
switch (order) {
case 0:return Qt::SolidLine;
case 1:return Qt::DashLine;
case 2:return Qt::DotLine;
case 3:return Qt::DashDotLine;
case 4:return Qt::DashDotDotLine;
default:
return Qt::SolidLine;
}
return Qt::SolidLine;
}
///
/// \brief 获取坐标轴设置对应的flagTypeId,QtVariantPropertyManager里,flagTypeId用位来标示
/// \param plot
/// \return
///
int QwtPlotPropertySetDialog::getAxisEnable(QwtPlot* plot) const
{
int res = 0;
if(plot->axisEnabled(QwtPlot::xBottom))
res |= xBottomFlag;
if(plot->axisEnabled(QwtPlot::xTop))
res |= xTopFlag;
if(plot->axisEnabled(QwtPlot::yLeft))
res |= yLeftFlag;
if(plot->axisEnabled(QwtPlot::yRight))
res |= yRightFlag;
return res;
}
QwtPlotCurve* QwtPlotPropertySetDialog::getCurvePtr(int id)
{
int curid = getCurveID(id);
auto i = m_baseID2curve.find(curid);
if(i == m_baseID2curve.end())
return nullptr;
return i.value();
}
int QwtPlotPropertySetDialog::getCurveBaseID(QwtPlotCurve *cur)
{
auto i = m_curve2baseID.find(cur);
if(i == m_curve2baseID.end())
return -1;
return i.value();
}
void QwtPlotPropertySetDialog::setAxisScaleDrawStyle(QwtPlot::Axis axis, const QVariant& value)
{
ScaleDraw sType = ScaleDraw( value.toInt());//强制转换,因为已经设置好枚举的值,所以这里可以进行强制转换
QwtScaleDraw *scaleDraw = m_plot->axisScaleDraw(axis);
QwtDateScaleDraw* dateScale = dynamic_cast<QwtDateScaleDraw*>(scaleDraw);
QtProperty * property = m_property_id.getProperty(axisPropertyID(axis,3));
if(NormalScale == sType)
{
if(property)
property->setEnabled(false);
if(dateScale)
{//说明当前是时间坐标轴
QwtScaleDraw* scale = nullptr;
scale = new QwtScaleDraw;
m_plot->setAxisScaleDraw(axis,scale);
}
}
else if(DateScale == sType)
{
ChartWave_qwt::AxisDateScaleType st(ChartWave_qwt::hh_mm_ss);
if(property)
{
property->setEnabled(true);
st = ChartWave_qwt::AxisDateScaleType( static_cast<QtVariantProperty*>(property)->value().toInt() );
}
if(!dateScale)
{//说明当前不是时间坐标轴
m_plot->setDateAxis(st,axis,QwtDate::Second);
}
}
}
void QwtPlotPropertySetDialog::itemAttached(QwtPlotItem *plotItem, bool on)
{
if(plotItem->rtti() == QwtPlotItem::Rtti_PlotCurve)
{
QwtPlotCurve* cur = static_cast<QwtPlotCurve*>(plotItem);
//说明曲线有删减或添加
if(on)
{
//曲线添加
addCurveSet(cur);
}
else
{
//曲线删除
int id = getCurveBaseID(cur);
if(-1 == id)
return;
m_property_id.deleteProperty(id);
}
}
}
void QwtPlotPropertySetDialog::setAxisEnable(int axisSet)
{
m_plot->enableAxis(QwtPlot::xBottom,axisSet & xBottomFlag);
m_property_id.getProperty(ID_GroupXBottomSet)->setEnabled(axisSet & xBottomFlag);
m_plot->enableAxis(QwtPlot::xTop,axisSet & xTopFlag);
m_property_id.getProperty(ID_GroupXTopSet)->setEnabled(axisSet & xTopFlag);
m_plot->enableAxis(QwtPlot::yLeft,axisSet & yLeftFlag);
m_property_id.getProperty(ID_GroupyLeftSet)->setEnabled(axisSet & yLeftFlag);
m_plot->enableAxis(QwtPlot::yRight,axisSet & yRightFlag);
m_property_id.getProperty(ID_GroupyRightSet)->setEnabled(axisSet & yRightFlag);
}
void QwtPlotPropertySetDialog::setAxisScale(int id, QPointF minMax, double step)
{
switch (id) {
case ID_XBottomInterval:
m_plot->setAxisScale(QwtPlot::xBottom,minMax.x(),minMax.y(),step);
return;
case ID_XTopInterval:
m_plot->setAxisScale(QwtPlot::xTop,minMax.x(),minMax.y(),step);
return;
case ID_YLeftInterval:
m_plot->setAxisScale(QwtPlot::yLeft,minMax.x(),minMax.y(),step);
return;
case ID_YRightInterval:
m_plot->setAxisScale(QwtPlot::yRight,minMax.x(),minMax.y(),step);
return;
}
}
void QwtPlotPropertySetDialog::setAxisTitle(int id, const QString& title)
{
switch (id) {
case ID_XBottomTitle:
m_plot->setAxisTitle(QwtPlot::xBottom,title);
return;
case ID_XTopTitle:
m_plot->setAxisTitle(QwtPlot::xTop,title);
return;
case ID_YLeftTitle:
m_plot->setAxisTitle(QwtPlot::yLeft,title);
return;
case ID_YRightTitle:
m_plot->setAxisTitle(QwtPlot::yRight,title);
return;
}
}
void QwtPlotPropertySetDialog::setAxislabelRotation(int id, double r)
{
switch (id) {
case ID_XBottomLabelRotation:
m_plot->setAxisLabelRotation(QwtPlot::xBottom,r);
return;
case ID_XTopLabelRotation:
m_plot->setAxisLabelRotation(QwtPlot::xTop,r);
return;
case ID_YLeftLabelRotation:
m_plot->setAxisLabelRotation(QwtPlot::yLeft,r);
return;
case ID_YRightLabelRotation:
m_plot->setAxisLabelRotation(QwtPlot::yRight,r);
return;
}
}
void QwtPlotPropertySetDialog::onScaleDivChangedXBottom()
{
updateAxisValue(QwtPlot::xBottom);
}
void QwtPlotPropertySetDialog::onScaleDivChangedXTop()
{
updateAxisValue(QwtPlot::xTop);
}
void QwtPlotPropertySetDialog::onScaleDivChangedYLeft()
{
updateAxisValue(QwtPlot::yLeft);
}
void QwtPlotPropertySetDialog::onScaleDivChangedYRight()
{
updateAxisValue(QwtPlot::yRight);
}
void QwtPlotPropertySetDialog::onPropertyValueChanged(QtProperty * property, const QVariant & value)
{
if(!m_enableSet)
return;
int id = m_property_id.getPropertyID(property);
if (id < ID_CurveIDBase)
{
switch(id)
{
case ID_PlotTitle:
m_plot->setTitle(value.toString());
return;
case ID_PlotFooter:
m_plot->setFooter(value.toString());
return;
case ID_PlotCanvasBackground:
m_plot->setCanvasBackground(QBrush(value.value<QColor>()));
return;
case ID_PlotEnableZoomerScroll:
m_plot->enableZoomerScroll(value.toBool());
return;
case ID_PlotAxisSet:
setAxisEnable(value.toInt());
return;
case ID_XBottomScale:
setAxisScaleDrawStyle(QwtPlot::xBottom,value);
return;
case ID_XTopScale:
setAxisScaleDrawStyle(QwtPlot::xTop,value);
return;
case ID_YLeftScale:
setAxisScaleDrawStyle(QwtPlot::yLeft,value);
return;
case ID_YRightScale:
setAxisScaleDrawStyle(QwtPlot::yRight,value);
return;
case ID_XBottomDateScaleType:
m_plot->setAxisDateFormat(QwtPlot::xBottom,ChartWave_qwt::AxisDateScaleType(value.toInt()));
return;
case ID_XTopDateScaleType:
m_plot->setAxisDateFormat(QwtPlot::xTop,ChartWave_qwt::AxisDateScaleType(value.toInt()));
return;
case ID_YLeftDateScaleType:
m_plot->setAxisDateFormat(QwtPlot::yLeft,ChartWave_qwt::AxisDateScaleType(value.toInt()));
return;
case ID_YRightDateScaleType:
m_plot->setAxisDateFormat(QwtPlot::yRight,ChartWave_qwt::AxisDateScaleType(value.toInt()));
return;
case ID_XBottomInterval:
case ID_XTopInterval:
case ID_YLeftInterval:
case ID_YRightInterval:
setAxisScale(id,value.toPointF());
return;
case ID_XBottomTitle:
case ID_XTopTitle:
case ID_YLeftTitle:
case ID_YRightTitle:
setAxisTitle(id,value.toString());
return;
case ID_XBottomLabelRotation:
case ID_XTopLabelRotation:
case ID_YLeftLabelRotation:
case ID_YRightLabelRotation:
setAxislabelRotation(id,value.toDouble());
return;
}
}
else
{
QwtPlotCurve* cur = getCurvePtr(id);
if(!cur)
return;
const int propertyID = getCurvePropertyID(id);
if (ID_CurveTitle == propertyID)
{
cur->setTitle(value.toString());
return;
}
QPen newPen(cur->pen());
switch (propertyID) {
case ID_CurveColore:
newPen.setColor(value.value<QColor>());
break;
case ID_CurveWidth:
newPen.setWidth(value.toInt());
break;
case ID_CurvePenStyle:
newPen.setStyle(order2penStyle(value.toInt()));
break;
}
cur->setPen(newPen);
}
}