-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathSignalRow.qml
684 lines (589 loc) · 22 KB
/
SignalRow.qml
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
import QtQuick 2.2
import QtQuick.Layouts 1.0
import Plot 1.0
import QtQuick.Controls 1.0
import QtQuick.Controls.Styles 1.1
import QtQml 2.2
Rectangle {
id: signalBlock
property alias ymin: axes.ymin;
property alias ymax: axes.ymax;
property var xaxis
property var signal
property int ygridticks: axes.ygridticks
color: '#444'
property int currentFontSize: 11;
visible: !(signal.label === "Current" && channel.mode === 0)
property color gradColor: Qt.rgba(1,1,1,0.08)
property color gradColor2: Qt.rgba(0,0,0,0.0)
function constrainValue(value, min, max) {
if (value < min)
value = min;
else if (value > max)
value = max;
return value;
}
function updateMode() {
channel.mode = {'Voltage': 1, 'Current': 2}[signal.label];
var target = parent.parent.parent;
for (var sig in target.children)
if (target.children[sig].children[0])
target.children[sig].children[0].updateMode();
}
function switchToConstant() {
signalBlock.updateMode()
signal.src.src = 'constant'
}
function switchToPeriodic(type) {
signalBlock.updateMode()
if (signal.src.src == 'constant') {
if ((signal.src.v1 == 0) || (signal.src.v2 == 0))
signal.src.v2 = (channel.mode == 1) ? 2.5 : 0.050;
else
signal.src.v2 = 0;
signal.src.v1 = 0
signal.src.period = 100
}
signal.src.src = type
}
Button {
anchors.top: parent.top
anchors.left: parent.left
width: timelinePane.spacing
height: timelinePane.spacing
iconSource: 'qrc:/icons/' + signal.src.src + '.png'
style: ButtonStyle {
background: Rectangle {
opacity: control.pressed ? 0.3 : control.checked ? 0.2 : 0.1
color: 'black'
}
}
menu: Menu {
MenuItem { text: "Constant"
onTriggered: signalBlock.switchToConstant()
}
MenuItem { text: "Sine"
onTriggered: signalBlock.switchToPeriodic('sine')
}
MenuItem { text: "Triangle"
onTriggered: signalBlock.switchToPeriodic('triangle')
}
MenuItem { text: "Sawtooth"
onTriggered: signalBlock.switchToPeriodic('sawtooth')
}
MenuItem { text: "Stairstep"
onTriggered: signalBlock.switchToPeriodic('stairstep')
}
MenuItem { text: "Square"
onTriggered: signalBlock.switchToPeriodic('square')
}
}
}
Text {
color: 'white'
text: signal.label
rotation: -90
transformOrigin: Item.TopLeft
font.pixelSize: 18 / session.devices.length
y: width + timelinePane.spacing + 8
x: (timelinePane.spacing - height) / 2
}
Rectangle {
id: idRectangle
x: parent.width
width: xaxis.width
anchors.top: parent.top
height: timelinePane.spacing
gradient: Gradient {
GradientStop { position: 1.0; color: gradColor }
GradientStop { position: 0.0; color: gradColor2 }
}
RowLayout {
id: editWaveform
anchors.fill: parent
property bool isVoltageSignal: signal.label === "Voltage" ? true : false
property real up_dn_Sensitivity : isVoltageSignal ? 0.01 : 0.001;
property real pgUp_pgDn_Sensitivity : isVoltageSignal ? 1.0 : 0.1;
// V1
TextInput {
id: v1TextBox
text: signal.isOutput ? signal.src.v1.toFixed(4) : signal.peak_to_peak.toFixed(4)
color: "#FFF"
selectByMouse: true
font.pixelSize: currentFontSize
readOnly: !signal.isOutput
property real position: idRectangle.x + idRectangle.width * 10/100;
Binding {
target: v1TextBox; property: 'text'
value: signal.isOutput ? signal.src.v1.toFixed(4) : signal.peak_to_peak.toFixed(4)
}
onEditingFinished: {
if (readOnly)
return;
var value = constrainValue(Number.fromLocaleString(text), axes.ymin + axes.overrangeSpan, axes.ymax - axes.overrangeSpan);
text = value.toFixed(4);
signal.src.v1 = text;
signalBlock.updateMode() // enough to call it for V1 (not necessary for V2, Freq - not visible when sourcing current anyway)
}
Keys.onPressed: {
var value;
if (readOnly)
return;
switch (event.key) {
case Qt.Key_Escape:
text = signal.src.v1.toFixed(4);
break;
case Qt.Key_Down:
value = Number.fromLocaleString(text) - editWaveform.up_dn_Sensitivity;
text = value.toFixed(4);
accepted();
break;
case Qt.Key_Up:
value = Number.fromLocaleString(text) + editWaveform.up_dn_Sensitivity;
text = value.toFixed(4);
accepted();
break;
case Qt.Key_PageDown:
value = Number.fromLocaleString(text) - editWaveform.pgUp_pgDn_Sensitivity;
text = value.toFixed(4);
accepted();
break;
case Qt.Key_PageUp:
value = Number.fromLocaleString(text) + editWaveform.pgUp_pgDn_Sensitivity;
text = value.toFixed(4);
accepted();
break;
}
}
validator: DoubleValidator{}
anchors.left: parent.left
anchors.leftMargin: idRectangle.width * 10/100;
}
Text {
id: v1UnitLabel
color: 'white'
text: (signal.label == "Voltage" ? " Volts" : " Amperes") + (signal.isOutput ? "" : " (peak to peak)");
anchors.left: v1TextBox.right
anchors.leftMargin: idRectangle.width * 1/100
font.pixelSize: currentFontSize
property real position: v1TextBox.position + v1TextBox.width + idRectangle.width * 1/100;
}
// Resistance
Text {
color: 'white'
visible: signal.src.src == 'constant' && signal.isOutput == true
text: {
var r = Math.abs((channel.signals[0].measurement / channel.signals[1].measurement)).toFixed();
(Math.abs(channel.signals[1].measurement) > 0.001) ? " " + r + " Ohms" : ""
}
anchors.left: v1UnitLabel.right
anchors.leftMargin: idRectangle.width * 1/100
font.pixelSize: currentFontSize
property real position: v1TextBox.position + v1TextBox.width + idRectangle.width * 1/100;
}
// V2
TextInput {
id: v2TextBox
visible: signal.isOutput ;
text: overlay_periodic.visible? signal.src.v2.toFixed(4) : "";
color: "#FFF"
selectByMouse: true
font.pixelSize: currentFontSize
property real position: v1UnitLabel.position + v1UnitLabel.width + idRectangle.width * 10/100
Binding {
target: v2TextBox; property: 'text'
value: overlay_periodic.visible ? signal.src.v2.toFixed(4) : "";
}
onEditingFinished: {
if (readOnly)
return;
var value = constrainValue(Number.fromLocaleString(text), axes.ymin + axes.overrangeSpan, axes.ymax - axes.overrangeSpan);
text = value.toFixed(4);
signal.src.v2 = text;
}
Keys.onPressed: {
var value;
if (readOnly)
return;
switch (event.key) {
case Qt.Key_Escape:
text = signal.src.v1.toFixed(4);
break;
case Qt.Key_Down:
value = Number.fromLocaleString(text) - editWaveform.up_dn_Sensitivity;
text = value.toFixed(4);
accepted();
break;
case Qt.Key_Up:
value = Number.fromLocaleString(text) + editWaveform.up_dn_Sensitivity;
text = value.toFixed(4);
accepted();
break;
case Qt.Key_PageDown:
value = Number.fromLocaleString(text) - editWaveform.pgUp_pgDn_Sensitivity;
text = value.toFixed(4);
accepted();
break;
case Qt.Key_PageUp:
value = Number.fromLocaleString(text) + editWaveform.pgUp_pgDn_Sensitivity;
text = value.toFixed(4);
accepted();
break;
}
}
validator: DoubleValidator{}
anchors.left: v1UnitLabel.right
anchors.leftMargin: idRectangle.width * 10/100
}
Text {
id: v2UnitLabel
color: 'white'
text: overlay_periodic.visible ? (signal.label == "Voltage" ? " Volts" : " Amperes") : ""
anchors.left: v2TextBox.right
anchors.leftMargin: idRectangle.width * 1/100
font.pixelSize: currentFontSize
property real position: v2TextBox.position + v2TextBox.width + idRectangle.width * 1/100;
}
// Freq
TextInput {
id: perTextBox
visible: (perUnitLabel.position + perUnitLabel.width <= idRectangle.x + idRectangle.width) && !(signal.isOutput && signal.src.src === 'constant')
text: signal.isOutput ? (signal.src.src != 'constant' ? Math.abs(controller.sampleRate / signal.src.period).toFixed(3) : "") : signal.rms.toFixed(4);
color: "#FFF"
selectByMouse: true
font.pixelSize: currentFontSize
readOnly: !signal.isOutput
property real position: (signal.isOutput ? v2UnitLabel.position + v2UnitLabel.width : v1UnitLabel.position + v1UnitLabel.width) + idRectangle.width * 10/100
property real up_dn_freq_Sensivity: 1
property real pgUp_pgDn_freq_Sensivity: 100
onEditingFinished: {
if (readOnly)
return;
var value = constrainValue(Number.fromLocaleString(text), controller.minOutSignalFreq, controller.maxOutSignalFreq);
text = parseFloat(value).toFixed(3)
signal.src.period = controller.sampleRate / text
}
Binding {
target: perTextBox; property: 'text';
value: signal.isOutput ? (signal.src.src != 'constant' ? Math.abs(controller.sampleRate / signal.src.period).toFixed(3) : ""): signal.rms.toFixed(4);
}
Keys.onPressed: {
var value;
if (readOnly)
return;
switch (event.key) {
case Qt.Key_Escape:
text = signal.src.v1.toFixed(4);
break;
case Qt.Key_Down:
value = Number.fromLocaleString(text) - up_dn_freq_Sensivity;
text = parseFloat(value).toFixed(3);
accepted();
break;
case Qt.Key_Up:
value = Number.fromLocaleString(text) + up_dn_freq_Sensivity;
text = parseFloat(value).toFixed(3);
accepted();
break;
case Qt.Key_PageDown:
value = Number.fromLocaleString(text) - pgUp_pgDn_freq_Sensivity;
text = parseFloat(value).toFixed(3);
accepted();
break;
case Qt.Key_PageUp:
value = Number.fromLocaleString(text) + pgUp_pgDn_freq_Sensivity;
text = parseFloat(value).toFixed(3);
accepted();
break;
}
}
validator: DoubleValidator{}
anchors.left: signal.isOutput ? v2UnitLabel.right : v1UnitLabel.right;
anchors.leftMargin: idRectangle.width * 10/100
}
Text {
id: perUnitLabel
color: 'white'
visible: perUnitLabel.position + perUnitLabel.width <= idRectangle.x + idRectangle.width;
anchors.left: perTextBox.right
anchors.leftMargin: idRectangle.width * 1/100
text: signal.isOutput ? (signal.src.src != 'constant' ? "Hertz" : ""): "RMS (AC)";
font.pixelSize: currentFontSize
property real position: perTextBox.position + perTextBox.width + idRectangle.width * 1/100;
}
Text {
id: averageTextBox
visible: averageLabel.position + averageLabel.width <= idRectangle.x + idRectangle.width;
text: signal.isOutput ? "" : signal.mean.toFixed(4);
color: "#FFF"
font.pixelSize: currentFontSize
property real position: perUnitLabel.position + perUnitLabel.width + idRectangle.width * 10/100
Binding {
target: averageTextBox; property: 'text';
value: signal.isOutput ? "" : signal.mean.toFixed(4);
}
anchors.left: perUnitLabel.right
anchors.leftMargin: idRectangle.width * 10/100
}
Text {
id: averageLabel;
color: "white";
visible: averageLabel.position + averageLabel.width <= idRectangle.x + idRectangle.width;
anchors.left: averageTextBox.right;
anchors.leftMargin: idRectangle.width * 1/100;
text: signal.isOutput ? "" : "Average";
font.pixelSize: currentFontSize;
property real position: averageTextBox.position + averageTextBox.width + idRectangle.width * 1/100;
}
//Max Input
Text {
id: maxLabel;
color: "white";
visible:(signal.isOutput ? (maxLabel.position > perUnitLabel.position+perUnitLabel.width+10) :
(maxLabel.position > averageTextBox.position+averageTextBox.width+10));
anchors.right: maxInput.left;
anchors.rightMargin: idRectangle.width * 1/100;
text: (signal.label == "Voltage" ? "Max V" : "Max A")
font.pixelSize: currentFontSize;
property real position: maxInput.position-idRectangle.width*1/100-maxLabel.width;
}
TextInput {
id: maxInput
visible: maxLabel.visible
text: axes.ymax.toFixed(3);
color: "#FFF"
selectByMouse: true
font.pixelSize: currentFontSize
readOnly: false;
property real position: minLabel.position-idRectangle.width*3/100-maxInput.width;
onEditingFinished: {
var value = constrainValue(Number.fromLocaleString(text), signal.min-axes.overrangeSpan, signal.max+axes.overrangeSpan)
value = Math.max(value,axes.ymin);
text = parseFloat(value).toFixed(3)
axes.ymax = value;
}
Binding {
target: maxInput; property: 'text';
value: axes.ymax.toFixed(3);
}
validator: DoubleValidator{}
anchors.right: minLabel.left;
anchors.rightMargin: idRectangle.width * 3/100;
}
//Min Input
Text {
id: minLabel;
color: "white";
visible: (signal.isOutput ? minLabel.position > perUnitLabel.position+perUnitLabel.width+10 :
minLabel.position > averageTextBox.position+averageTextBox.width+10);
anchors.right: minInput.left;
anchors.rightMargin: idRectangle.width * 1/100;
text: (signal.label == "Voltage" ? "Min V" : "Min A")
font.pixelSize: currentFontSize;
property real position: parent.width-minInput.width-idRectangle.width*1/100+35-minLabel.width;
}
TextInput {
id: minInput
visible: minLabel.visible;
text: axes.ymin.toFixed(3);
color: "#FFF"
selectByMouse: true
font.pixelSize: currentFontSize
readOnly: false;
property real position: parent.width+35-minInput.width;
onEditingFinished: {
var value = constrainValue(Number.fromLocaleString(text), signal.min-axes.overrangeSpan, signal.max+axes.overrangeSpan)
value =Math.min(value,axes.ymax);
text = parseFloat(value).toFixed(3)
axes.ymin = value;
}
Binding {
target: minInput; property: 'text';
value: axes.ymin.toFixed(3);
}
validator: DoubleValidator{}
anchors.right: parent.right;
anchors.rightMargin: -35;
}
}
}
Item {
id: vertAxes
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.left: axes.right
anchors.topMargin: timelinePane.spacing
width: timelinePane.width - xaxis.width - signalsPane.width
MouseArea {
anchors.fill: parent
property var zoomParams
acceptedButtons: Qt.RightButton
onPressed: {
if (mouse.button == Qt.RightButton) {
zoomParams = {
firstY : mouse.y,
prevY : mouse.y,
}
} else {
mouse.accepted = false;
}
}
onReleased: {
zoomParams = null
}
onPositionChanged: {
if (zoomParams) {
var delta = (mouse.y - zoomParams.prevY)
zoomParams.prevY = mouse.y
var s = Math.pow(1.01, delta)
var y = axes.pxToY(zoomParams.firstY);
var resolution = signal.label === 'Current' ? signal.resolution * 10 : signal.resolution;
if (axes.ymax - axes.ymin < resolution * ygridticks && s < 1) return;
axes.ymin = Math.max(y - s * (y - axes.ymin), signal.min-axes.overrangeSpan);
axes.ymax = Math.min(y - s * (y - axes.ymax), signal.max+axes.overrangeSpan);
}
}
}
}
Axes {
id: axes
property real overrangeSpan: (signal.max - signal.min) * 0.02 // 2% of full range
x: parent.width
width: xaxis.width
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.topMargin: timelinePane.spacing
ymin: signal.min - overrangeSpan
ymax: signal.max + overrangeSpan
xgridticks: 2
yleft: false
yright: true
xbottom: false
gridColor: window.signalAxesColor
textColor: '#FFF'
states: [
State {
name: "floating"
PropertyChanges { target: axes
anchors.top: undefined
anchors.bottom: undefined
gridColor: '#111'
textColor: '#444'
}
PropertyChanges { target: axes_mouse_area
drag.target: axes
drag.axis: Drag.YAxis
}
PropertyChanges { target: overlay_periodic; visible: false }
PropertyChanges { target: overlay_constant; visible: false }
}
]
MouseArea {
id: axes_mouse_area
anchors.fill: parent
acceptedButtons: Qt.LeftButton | Qt.MiddleButton
property var panStart
onPressed: {
if (mouse.button == Qt.MiddleButton) {
axesBackground.opacity = 0;
for(var d = 0; d < deviceRepeater.count; d++) {
var dev = deviceRepeater.itemAt(d);
dev.z = -2;
for(var c = 0; c < channelRepeater.count; c++){
var ch = dev.channelRepeater.itemAt(c);
ch.z = -2;
for(var s = 0; s < signalRepeater.count; s++){
ch.signalRepeater.itemAt(s).z = -2;
}
}
}
signalBlock.parent.parent.parent.z = 2;
signalBlock.parent.parent.z = 2;
signalBlock.z = 2;
axes.state = "floating"
} else if (mouse.button == Qt.LeftButton && mouse.modifiers & Qt.ShiftModifier) {
panStart = {
y: mouse.y,
ymin: axes.ymin,
ymax: axes.ymax,
}
} else {
mouse.accepted = false;
}
}
onReleased: {
axesBackground.opacity = 1;
axes.state = ""
panStart = null
}
onPositionChanged: {
// Shift + drag for Y-axis pan
if (panStart) {
var delta = (mouse.y - panStart.y) / axes.yscale
delta = Math.max(delta, signal.min - panStart.ymin)
delta = Math.min(delta, signal.max - panStart.ymax)
axes.ymin = panStart.ymin + delta
axes.ymax = panStart.ymax + delta
}
}
onWheel: {
// Shift + scroll for Y-axis zoom
if (wheel.modifiers & Qt.ShiftModifier) {
var s = Math.pow(1.15, -wheel.angleDelta.y/120);
var y = axes.pxToY(wheel.y);
var resolution = signal.label === 'Current' ? signal.resolution * 10 : signal.resolution;
if (axes.ymax - axes.ymin < resolution * ygridticks && s < 1) return;
axes.ymin = Math.max(y - s * (y - axes.ymin), signal.min - axes.overrangeSpan);
axes.ymax = Math.min(y - s * (y - axes.ymax), signal.max + axes.overrangeSpan);
}
else {
wheel.accepted = false
}
}
}
Rectangle {
anchors.top: parent.bottom
anchors.left: parent.left
anchors.right: parent.right
height: 2
color: window.signalAxesColor
}
Rectangle {
anchors.bottom: parent.top
anchors.left: parent.left
anchors.right: parent.right
height: 1
color: window.signalAxesColor
}
Rectangle {
id: axesBackground
anchors.fill: parent
color: window.signalRowColor
z: -1
opacity: 1
}
PhosphorRender {
id: line
anchors.fill: parent
clip: true
buffer: signal.buffer
pointSize: Math.min(25, Math.max(2, xaxis.xscale/session.sampleRate*3) * window.dotSizeSignal * 10)
color: signal.label == 'Current' ? window.dotSignalCurrent : window.dotSignalVoltage
xmin: xaxis.visibleMin
xmax: xaxis.visibleMax
ymin: axes.ymin
ymax: axes.ymax
Component.onCompleted: {
signal.buffer.setIgnoredFirstSamplesCount(controller.delaySampleCount)
}
}
OverlayPeriodic {
id: overlay_periodic
visible: (signal.src.src == 'sine' || signal.src.src == 'triangle' || signal.src.src == 'sawtooth' || signal.src.src == 'stairstep' || signal.src.src == 'square') && (channel.mode == {'Voltage': 1, 'Current': 2}[signal.label])
}
OverlayConstant {
id: overlay_constant
visible: signal.src.src == 'constant'
}
}
}