]> sigrok.org Git - pulseview.git/blob - pv/view/analogsignal.cpp
Random simplifications, cosmetics/whitespace/consistency fixes.
[pulseview.git] / pv / view / analogsignal.cpp
1 /*
2  * This file is part of the PulseView project.
3  *
4  * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see <http://www.gnu.org/licenses/>.
18  */
19
20 #include <extdef.h>
21
22 #include <cassert>
23 #include <cmath>
24 #include <cstdlib>
25 #include <limits>
26 #include <vector>
27
28 #include <QApplication>
29 #include <QCheckBox>
30 #include <QComboBox>
31 #include <QFormLayout>
32 #include <QGridLayout>
33 #include <QLabel>
34 #include <QSpinBox>
35 #include <QString>
36
37 #include "analogsignal.hpp"
38 #include "pv/data/analog.hpp"
39 #include "pv/data/analogsegment.hpp"
40 #include "pv/data/logic.hpp"
41 #include "pv/data/logicsegment.hpp"
42 #include "pv/data/signalbase.hpp"
43 #include "pv/view/view.hpp"
44 #include "pv/view/logicsignal.hpp"
45 #include "pv/globalsettings.hpp"
46
47 #include <libsigrokcxx/libsigrokcxx.hpp>
48
49 using std::deque;
50 using std::div;
51 using std::div_t;
52 using std::max;
53 using std::make_pair;
54 using std::min;
55 using std::numeric_limits;
56 using std::pair;
57 using std::shared_ptr;
58 using std::vector;
59
60 namespace pv {
61 namespace views {
62 namespace TraceView {
63
64 const QColor AnalogSignal::SignalColours[4] = {
65         QColor(0xC4, 0xA0, 0x00),       // Yellow
66         QColor(0x87, 0x20, 0x7A),       // Magenta
67         QColor(0x20, 0x4A, 0x87),       // Blue
68         QColor(0x4E, 0x9A, 0x06)        // Green
69 };
70
71 const QColor AnalogSignal::GridMajorColor = QColor(0, 0, 0, 40 * 256 / 100);
72 const QColor AnalogSignal::GridMinorColor = QColor(0, 0, 0, 20 * 256 / 100);
73
74 const QColor AnalogSignal::SamplingPointColour(0x77, 0x77, 0x77);
75
76 const float AnalogSignal::EnvelopeThreshold = 256.0f;
77
78 const int AnalogSignal::MaximumVDivs = 10;
79 const int AnalogSignal::MinScaleIndex = -6;
80 const int AnalogSignal::MaxScaleIndex = 7;
81
82 const int AnalogSignal::InfoTextMarginRight = 20;
83 const int AnalogSignal::InfoTextMarginBottom = 5;
84
85 AnalogSignal::AnalogSignal(
86         pv::Session &session,
87         shared_ptr<data::SignalBase> base) :
88         Signal(session, base),
89         scale_index_(4), // 20 per div
90         scale_index_drag_offset_(0),
91         div_height_(3 * QFontMetrics(QApplication::font()).height()),
92         pos_vdivs_(1),
93         neg_vdivs_(1),
94         resolution_(0),
95         conversion_type_(data::SignalBase::NoConversion),
96         display_type_(DisplayBoth),
97         autoranging_(true)
98 {
99         pv::data::Analog* analog_data =
100                 dynamic_cast<pv::data::Analog*>(data().get());
101
102         connect(analog_data, SIGNAL(samples_added(QObject*, uint64_t, uint64_t)),
103                 this, SLOT(on_samples_added()));
104
105         base_->set_colour(SignalColours[base_->index() % countof(SignalColours)]);
106         update_scale();
107 }
108
109 shared_ptr<pv::data::SignalData> AnalogSignal::data() const
110 {
111         return base_->analog_data();
112 }
113
114 void AnalogSignal::save_settings(QSettings &settings) const
115 {
116         settings.setValue("pos_vdivs", pos_vdivs_);
117         settings.setValue("neg_vdivs", neg_vdivs_);
118         settings.setValue("scale_index", scale_index_);
119         settings.setValue("conversion_type", conversion_type_);
120         settings.setValue("display_type", display_type_);
121         settings.setValue("autoranging", autoranging_);
122 }
123
124 void AnalogSignal::restore_settings(QSettings &settings)
125 {
126         if (settings.contains("pos_vdivs"))
127                 pos_vdivs_ = settings.value("pos_vdivs").toInt();
128
129         if (settings.contains("neg_vdivs"))
130                 neg_vdivs_ = settings.value("neg_vdivs").toInt();
131
132         if (settings.contains("scale_index")) {
133                 scale_index_ = settings.value("scale_index").toInt();
134                 update_scale();
135         }
136
137         if (settings.contains("conversion_type")) {
138                 conversion_type_ = (data::SignalBase::ConversionType)(settings.value("conversion_type").toInt());
139                 update_conversion_type();
140         }
141
142         if (settings.contains("display_type"))
143                 display_type_ = (DisplayType)(settings.value("display_type").toInt());
144
145         if (settings.contains("autoranging"))
146                 autoranging_ = settings.value("autoranging").toBool();
147 }
148
149 pair<int, int> AnalogSignal::v_extents() const
150 {
151         const int ph = pos_vdivs_ * div_height_;
152         const int nh = neg_vdivs_ * div_height_;
153         return make_pair(-ph, nh);
154 }
155
156 int AnalogSignal::scale_handle_offset() const
157 {
158         const int h = (pos_vdivs_ + neg_vdivs_) * div_height_;
159
160         return ((scale_index_drag_offset_ - scale_index_) * h / 4) - h / 2;
161 }
162
163 void AnalogSignal::scale_handle_dragged(int offset)
164 {
165         const int h = (pos_vdivs_ + neg_vdivs_) * div_height_;
166
167         scale_index_ = scale_index_drag_offset_ - (offset + h / 2) / (h / 4);
168
169         update_scale();
170 }
171
172 void AnalogSignal::scale_handle_drag_release()
173 {
174         scale_index_drag_offset_ = scale_index_;
175         update_scale();
176 }
177
178 void AnalogSignal::paint_back(QPainter &p, const ViewItemPaintParams &pp)
179 {
180         if (base_->enabled()) {
181                 Trace::paint_back(p, pp);
182                 paint_axis(p, pp, get_visual_y());
183         }
184 }
185
186 void AnalogSignal::paint_mid(QPainter &p, const ViewItemPaintParams &pp)
187 {
188         assert(base_->analog_data());
189         assert(owner_);
190
191         const int y = get_visual_y();
192
193         if (!base_->enabled())
194                 return;
195
196         if ((display_type_ == DisplayAnalog) || (display_type_ == DisplayBoth)) {
197                 paint_grid(p, y, pp.left(), pp.right());
198
199                 const deque< shared_ptr<pv::data::AnalogSegment> > &segments =
200                         base_->analog_data()->analog_segments();
201                 if (segments.empty())
202                         return;
203
204                 const shared_ptr<pv::data::AnalogSegment> &segment =
205                         segments.front();
206
207                 const double pixels_offset = pp.pixels_offset();
208                 const double samplerate = max(1.0, segment->samplerate());
209                 const pv::util::Timestamp& start_time = segment->start_time();
210                 const int64_t last_sample = segment->get_sample_count() - 1;
211                 const double samples_per_pixel = samplerate * pp.scale();
212                 const pv::util::Timestamp start = samplerate * (pp.offset() - start_time);
213                 const pv::util::Timestamp end = start + samples_per_pixel * pp.width();
214
215                 const int64_t start_sample = min(max(floor(start).convert_to<int64_t>(),
216                         (int64_t)0), last_sample);
217                 const int64_t end_sample = min(max((ceil(end) + 1).convert_to<int64_t>(),
218                         (int64_t)0), last_sample);
219
220                 if (samples_per_pixel < EnvelopeThreshold)
221                         paint_trace(p, segment, y, pp.left(),
222                                 start_sample, end_sample,
223                                 pixels_offset, samples_per_pixel);
224                 else
225                         paint_envelope(p, segment, y, pp.left(),
226                                 start_sample, end_sample,
227                                 pixels_offset, samples_per_pixel);
228         }
229
230         if ((display_type_ == DisplayConverted) || (display_type_ == DisplayBoth)) {
231                 if (((conversion_type_ == data::SignalBase::A2LConversionByTreshold) ||
232                         (conversion_type_ == data::SignalBase::A2LConversionBySchmittTrigger))) {
233
234                         paint_logic_mid(p, pp);
235                 }
236         }
237 }
238
239 void AnalogSignal::paint_fore(QPainter &p, const ViewItemPaintParams &pp)
240 {
241         if (!enabled())
242                 return;
243
244         if ((display_type_ == DisplayAnalog) || (display_type_ == DisplayBoth)) {
245                 const int y = get_visual_y();
246
247                 // Show the info section on the right side of the trace
248                 const QString infotext = QString("%1 V/div").arg(resolution_);
249
250                 p.setPen(base_->colour());
251                 p.setFont(QApplication::font());
252
253                 const QRectF bounding_rect = QRectF(pp.left(),
254                                 y + v_extents().first,
255                                 pp.width() - InfoTextMarginRight,
256                                 v_extents().second - v_extents().first - InfoTextMarginBottom);
257
258                 p.drawText(bounding_rect, Qt::AlignRight | Qt::AlignBottom, infotext);
259         }
260 }
261
262 void AnalogSignal::paint_grid(QPainter &p, int y, int left, int right)
263 {
264         p.setRenderHint(QPainter::Antialiasing, false);
265
266         if (pos_vdivs_ > 0) {
267                 p.setPen(QPen(GridMajorColor, 1, Qt::DashLine));
268                 for (int i = 1; i <= pos_vdivs_; i++) {
269                         const float dy = i * div_height_;
270                         p.drawLine(QLineF(left, y - dy, right, y - dy));
271                 }
272
273                 p.setPen(QPen(GridMinorColor, 1, Qt::DashLine));
274                 for (int i = 0; i < pos_vdivs_; i++) {
275                         const float dy = i * div_height_;
276                         const float dy25 = dy + (0.25 * div_height_);
277                         const float dy50 = dy + (0.50 * div_height_);
278                         const float dy75 = dy + (0.75 * div_height_);
279                         p.drawLine(QLineF(left, y - dy25, right, y - dy25));
280                         p.drawLine(QLineF(left, y - dy50, right, y - dy50));
281                         p.drawLine(QLineF(left, y - dy75, right, y - dy75));
282                 }
283         }
284
285         if (neg_vdivs_ > 0) {
286                 p.setPen(QPen(GridMajorColor, 1, Qt::DashLine));
287                 for (int i = 1; i <= neg_vdivs_; i++) {
288                         const float dy = i * div_height_;
289                         p.drawLine(QLineF(left, y + dy, right, y + dy));
290                 }
291
292                 p.setPen(QPen(GridMinorColor, 1, Qt::DashLine));
293                 for (int i = 0; i < neg_vdivs_; i++) {
294                         const float dy = i * div_height_;
295                         const float dy25 = dy + (0.25 * div_height_);
296                         const float dy50 = dy + (0.50 * div_height_);
297                         const float dy75 = dy + (0.75 * div_height_);
298                         p.drawLine(QLineF(left, y + dy25, right, y + dy25));
299                         p.drawLine(QLineF(left, y + dy50, right, y + dy50));
300                         p.drawLine(QLineF(left, y + dy75, right, y + dy75));
301                 }
302         }
303
304         p.setRenderHint(QPainter::Antialiasing, true);
305 }
306
307 void AnalogSignal::paint_trace(QPainter &p,
308         const shared_ptr<pv::data::AnalogSegment> &segment,
309         int y, int left, const int64_t start, const int64_t end,
310         const double pixels_offset, const double samples_per_pixel)
311 {
312         p.setPen(base_->colour());
313
314         const int64_t points_count = end - start;
315
316         QPointF *points = new QPointF[points_count];
317         QPointF *point = points;
318
319         QRectF *const sampling_points = new QRectF[points_count];
320         QRectF *sampling_point = sampling_points;
321
322         pv::data::SegmentAnalogDataIterator* it =
323                 segment->begin_sample_iteration(start);
324
325         const int w = 2;
326         for (int64_t sample = start; sample != end; sample++) {
327                 const float x = (sample / samples_per_pixel -
328                         pixels_offset) + left;
329
330                 *point++ = QPointF(x, y - *((float*)it->value) * scale_);
331                 *sampling_point++ = QRectF(x - (w / 2), y - *((float*)it->value) * scale_ - (w / 2), w, w);
332
333                 segment->continue_sample_iteration(it, 1);
334         }
335         segment->end_sample_iteration(it);
336
337         p.drawPolyline(points, points_count);
338
339         // Paint the sampling points if enabled
340         GlobalSettings settings;
341         const bool show_sampling_points =
342                 settings.value(GlobalSettings::Key_View_ShowSamplingPoints).toBool();
343
344         if (show_sampling_points && (samples_per_pixel < 0.25)) {
345                 p.setPen(SamplingPointColour);
346                 p.drawRects(sampling_points, points_count);
347         }
348
349         delete[] points;
350         delete[] sampling_points;
351 }
352
353 void AnalogSignal::paint_envelope(QPainter &p,
354         const shared_ptr<pv::data::AnalogSegment> &segment,
355         int y, int left, const int64_t start, const int64_t end,
356         const double pixels_offset, const double samples_per_pixel)
357 {
358         using pv::data::AnalogSegment;
359
360         AnalogSegment::EnvelopeSection e;
361         segment->get_envelope_section(e, start, end, samples_per_pixel);
362
363         if (e.length < 2)
364                 return;
365
366         p.setPen(QPen(Qt::NoPen));
367         p.setBrush(base_->colour());
368
369         QRectF *const rects = new QRectF[e.length];
370         QRectF *rect = rects;
371
372         for (uint64_t sample = 0; sample < e.length - 1; sample++) {
373                 const float x = ((e.scale * sample + e.start) /
374                         samples_per_pixel - pixels_offset) + left;
375                 const AnalogSegment::EnvelopeSample *const s =
376                         e.samples + sample;
377
378                 // We overlap this sample with the next so that vertical
379                 // gaps do not appear during steep rising or falling edges
380                 const float b = y - max(s->max, (s + 1)->min) * scale_;
381                 const float t = y - min(s->min, (s + 1)->max) * scale_;
382
383                 float h = b - t;
384                 if (h >= 0.0f && h <= 1.0f)
385                         h = 1.0f;
386                 if (h <= 0.0f && h >= -1.0f)
387                         h = -1.0f;
388
389                 *rect++ = QRectF(x, t, 1.0f, h);
390         }
391
392         p.drawRects(rects, e.length);
393
394         delete[] rects;
395         delete[] e.samples;
396 }
397
398 void AnalogSignal::paint_logic_mid(QPainter &p, const ViewItemPaintParams &pp)
399 {
400         QLineF *line;
401
402         vector< pair<int64_t, bool> > edges;
403
404         assert(base_);
405
406         const int y = get_visual_y();
407
408         if (!base_->enabled())
409                 return;
410
411         const int signal_margin =
412                 QFontMetrics(QApplication::font()).height() / 2;
413
414         const int ph = min(pos_vdivs_, 1) * div_height_;
415         const int nh = min(neg_vdivs_, 1) * div_height_;
416         const float high_offset = y - ph + signal_margin + 0.5f;
417         const float low_offset = y + nh - signal_margin - 0.5f;
418
419         const deque< shared_ptr<pv::data::LogicSegment> > &segments =
420                 base_->logic_data()->logic_segments();
421         if (segments.empty())
422                 return;
423
424         const shared_ptr<pv::data::LogicSegment> &segment =
425                 segments.front();
426
427         double samplerate = segment->samplerate();
428
429         // Show sample rate as 1Hz when it is unknown
430         if (samplerate == 0.0)
431                 samplerate = 1.0;
432
433         const double pixels_offset = pp.pixels_offset();
434         const pv::util::Timestamp& start_time = segment->start_time();
435         const int64_t last_sample = segment->get_sample_count() - 1;
436         const double samples_per_pixel = samplerate * pp.scale();
437         const pv::util::Timestamp start = samplerate * (pp.offset() - start_time);
438         const pv::util::Timestamp end = start + samples_per_pixel * pp.width();
439
440         const int64_t start_sample = min(max(floor(start).convert_to<int64_t>(),
441                 (int64_t)0), last_sample);
442         const uint64_t end_sample = min(max(ceil(end).convert_to<int64_t>(),
443                 (int64_t)0), last_sample);
444
445         segment->get_subsampled_edges(edges, start_sample, end_sample,
446                 samples_per_pixel / LogicSignal::Oversampling, 0);
447         assert(edges.size() >= 2);
448
449         // Paint the edges
450         const unsigned int edge_count = edges.size() - 2;
451         QLineF *const edge_lines = new QLineF[edge_count];
452         line = edge_lines;
453
454         for (auto i = edges.cbegin() + 1; i != edges.cend() - 1; i++) {
455                 const float x = ((*i).first / samples_per_pixel -
456                         pixels_offset) + pp.left();
457                 *line++ = QLineF(x, high_offset, x, low_offset);
458         }
459
460         p.setPen(LogicSignal::EdgeColour);
461         p.drawLines(edge_lines, edge_count);
462         delete[] edge_lines;
463
464         // Paint the caps
465         const unsigned int max_cap_line_count = edges.size();
466         QLineF *const cap_lines = new QLineF[max_cap_line_count];
467
468         p.setPen(LogicSignal::HighColour);
469         paint_logic_caps(p, cap_lines, edges, true, samples_per_pixel,
470                 pixels_offset, pp.left(), high_offset);
471         p.setPen(LogicSignal::LowColour);
472         paint_logic_caps(p, cap_lines, edges, false, samples_per_pixel,
473                 pixels_offset, pp.left(), low_offset);
474
475         delete[] cap_lines;
476
477         // Return if we don't need to paint the sampling points
478         GlobalSettings settings;
479         const bool show_sampling_points =
480                 settings.value(GlobalSettings::Key_View_ShowSamplingPoints).toBool();
481
482         if (!show_sampling_points || (samples_per_pixel >= 0.25))
483                 return;
484
485         // Paint the sampling points
486         const uint64_t sampling_points_count = end_sample - start_sample + 1;
487         QRectF *const sampling_points = new QRectF[sampling_points_count];
488         QRectF *sampling_point = sampling_points;
489
490         const int w = 1;
491         const float y_middle = high_offset - ((high_offset - low_offset) / 2);
492         for (uint64_t i = start_sample; i < end_sample + 1; ++i) {
493                 const float x = (i / samples_per_pixel - pixels_offset) + pp.left();
494                 *sampling_point++ = QRectF(x - (w / 2), y_middle - (w / 2), w, w);
495         }
496
497         p.setPen(SamplingPointColour);
498         p.drawRects(sampling_points, sampling_points_count);
499         delete[] sampling_points;
500 }
501
502 void AnalogSignal::paint_logic_caps(QPainter &p, QLineF *const lines,
503         vector< pair<int64_t, bool> > &edges, bool level,
504         double samples_per_pixel, double pixels_offset, float x_offset,
505         float y_offset)
506 {
507         QLineF *line = lines;
508
509         for (auto i = edges.begin(); i != (edges.end() - 1); i++)
510                 if ((*i).second == level) {
511                         *line++ = QLineF(
512                                 ((*i).first / samples_per_pixel -
513                                         pixels_offset) + x_offset, y_offset,
514                                 ((*(i+1)).first / samples_per_pixel -
515                                         pixels_offset) + x_offset, y_offset);
516                 }
517
518         p.drawLines(lines, line - lines);
519 }
520
521 float AnalogSignal::get_resolution(int scale_index)
522 {
523         const float seq[] = {1.0f, 2.0f, 5.0f};
524
525         const int offset = numeric_limits<int>::max() / (2 * countof(seq));
526         const div_t d = div((int)(scale_index + countof(seq) * offset),
527                 countof(seq));
528
529         return powf(10.0f, d.quot - offset) * seq[d.rem];
530 }
531
532 void AnalogSignal::update_scale()
533 {
534         resolution_ = get_resolution(scale_index_);
535         scale_ = div_height_ / resolution_;
536 }
537
538 void AnalogSignal::update_conversion_type()
539 {
540         base_->set_conversion_type(conversion_type_);
541
542         if (owner_)
543                 owner_->row_item_appearance_changed(false, true);
544 }
545
546 void AnalogSignal::perform_autoranging(bool force_update)
547 {
548         const deque< shared_ptr<pv::data::AnalogSegment> > &segments =
549                 base_->analog_data()->analog_segments();
550
551         if (segments.empty())
552                 return;
553
554         static double prev_min = 0, prev_max = 0;
555         double min = 0, max = 0;
556
557         for (shared_ptr<pv::data::AnalogSegment> segment : segments) {
558                 pair<double, double> mm = segment->get_min_max();
559                 min = std::min(min, mm.first);
560                 max = std::max(max, mm.second);
561         }
562
563         if ((min == prev_min) && (max == prev_max) && !force_update)
564                 return;
565
566         prev_min = min;
567         prev_max = max;
568
569         // Use all divs for the positive range if there are no negative values
570         if ((min == 0) && (neg_vdivs_ > 0)) {
571                 pos_vdivs_ += neg_vdivs_;
572                 neg_vdivs_ = 0;
573         }
574
575         // Split up the divs if there are negative values but no negative divs
576         if ((min < 0) && (neg_vdivs_ == 0)) {
577                 neg_vdivs_ = pos_vdivs_ / 2;
578                 pos_vdivs_ -= neg_vdivs_;
579         }
580
581         double min_value_per_div;
582         if ((pos_vdivs_ > 0) && (neg_vdivs_ >  0))
583                 min_value_per_div = std::max(max / pos_vdivs_, -min / neg_vdivs_);
584         else if (pos_vdivs_ > 0)
585                 min_value_per_div = max / pos_vdivs_;
586         else
587                 min_value_per_div = -min / neg_vdivs_;
588
589         // Find first scale value that is bigger than the value we need
590         for (int i = MinScaleIndex; i < MaxScaleIndex; i++)
591                 if (get_resolution(i) > min_value_per_div) {
592                         scale_index_ = i;
593                         break;
594                 }
595
596         update_scale();
597 }
598
599 void AnalogSignal::populate_popup_form(QWidget *parent, QFormLayout *form)
600 {
601         // Add the standard options
602         Signal::populate_popup_form(parent, form);
603
604         QFormLayout *const layout = new QFormLayout;
605
606         // Add the number of vdivs
607         QSpinBox *pvdiv_sb = new QSpinBox(parent);
608         pvdiv_sb->setRange(0, MaximumVDivs);
609         pvdiv_sb->setValue(pos_vdivs_);
610         connect(pvdiv_sb, SIGNAL(valueChanged(int)),
611                 this, SLOT(on_pos_vdivs_changed(int)));
612         layout->addRow(tr("Number of pos vertical divs"), pvdiv_sb);
613
614         QSpinBox *nvdiv_sb = new QSpinBox(parent);
615         nvdiv_sb->setRange(0, MaximumVDivs);
616         nvdiv_sb->setValue(neg_vdivs_);
617         connect(nvdiv_sb, SIGNAL(valueChanged(int)),
618                 this, SLOT(on_neg_vdivs_changed(int)));
619         layout->addRow(tr("Number of neg vertical divs"), nvdiv_sb);
620
621         // Add the vertical resolution
622         resolution_cb_ = new QComboBox(parent);
623
624         for (int i = MinScaleIndex; i < MaxScaleIndex; i++) {
625                 const QString label = QString("%1").arg(get_resolution(i));
626                 resolution_cb_->insertItem(0, label, QVariant(i));
627         }
628
629         int cur_idx = resolution_cb_->findData(QVariant(scale_index_));
630         resolution_cb_->setCurrentIndex(cur_idx);
631
632         connect(resolution_cb_, SIGNAL(currentIndexChanged(int)),
633                 this, SLOT(on_resolution_changed(int)));
634
635         QGridLayout *const vdiv_layout = new QGridLayout;
636         QLabel *const vdiv_unit = new QLabel(tr("V/div"));
637         vdiv_layout->addWidget(resolution_cb_, 0, 0);
638         vdiv_layout->addWidget(vdiv_unit, 0, 1);
639
640         layout->addRow(tr("Vertical resolution"), vdiv_layout);
641
642         // Add the autoranging checkbox
643         QCheckBox* autoranging_cb = new QCheckBox();
644         autoranging_cb->setCheckState(autoranging_ ? Qt::Checked : Qt::Unchecked);
645
646         connect(autoranging_cb, SIGNAL(stateChanged(int)),
647                 this, SLOT(on_autoranging_changed(int)));
648
649         layout->addRow(tr("Autoranging"), autoranging_cb);
650
651         // Add the conversion type dropdown
652         conversion_cb_ = new QComboBox();
653
654         conversion_cb_->addItem("none", data::SignalBase::NoConversion);
655         conversion_cb_->addItem("to logic via threshold", data::SignalBase::A2LConversionByTreshold);
656         conversion_cb_->addItem("to logic via schmitt-trigger", data::SignalBase::A2LConversionBySchmittTrigger);
657
658         cur_idx = conversion_cb_->findData(QVariant(conversion_type_));
659         conversion_cb_->setCurrentIndex(cur_idx);
660
661         layout->addRow(tr("Conversion"), conversion_cb_);
662
663         connect(conversion_cb_, SIGNAL(currentIndexChanged(int)),
664                 this, SLOT(on_conversion_changed(int)));
665
666         // Add the display type dropdown
667         display_type_cb_ = new QComboBox();
668
669         display_type_cb_->addItem(tr("Analog"), DisplayAnalog);
670         display_type_cb_->addItem(tr("Converted"), DisplayConverted);
671         display_type_cb_->addItem(tr("Both"), DisplayBoth);
672
673         cur_idx = display_type_cb_->findData(QVariant(display_type_));
674         display_type_cb_->setCurrentIndex(cur_idx);
675
676         layout->addRow(tr("Traces to show:"), display_type_cb_);
677
678         connect(display_type_cb_, SIGNAL(currentIndexChanged(int)),
679                 this, SLOT(on_display_type_changed(int)));
680
681         form->addRow(layout);
682 }
683
684 void AnalogSignal::on_samples_added()
685 {
686         perform_autoranging();
687
688         if (owner_) {
689                 // Call order is important, otherwise the lazy event handler won't work
690                 owner_->extents_changed(false, true);
691                 owner_->row_item_appearance_changed(false, true);
692         }
693 }
694
695 void AnalogSignal::on_pos_vdivs_changed(int vdivs)
696 {
697         pos_vdivs_ = vdivs;
698
699         if (autoranging_)
700                 perform_autoranging(true);
701
702         if (owner_) {
703                 // Call order is important, otherwise the lazy event handler won't work
704                 owner_->extents_changed(false, true);
705                 owner_->row_item_appearance_changed(false, true);
706         }
707 }
708
709 void AnalogSignal::on_neg_vdivs_changed(int vdivs)
710 {
711         neg_vdivs_ = vdivs;
712
713         if (autoranging_)
714                 perform_autoranging(true);
715
716         if (owner_) {
717                 // Call order is important, otherwise the lazy event handler won't work
718                 owner_->extents_changed(false, true);
719                 owner_->row_item_appearance_changed(false, true);
720         }
721 }
722
723 void AnalogSignal::on_resolution_changed(int index)
724 {
725         scale_index_ = resolution_cb_->itemData(index).toInt();
726         update_scale();
727
728         if (owner_)
729                 owner_->row_item_appearance_changed(false, true);
730 }
731
732 void AnalogSignal::on_autoranging_changed(int state)
733 {
734         autoranging_ = (state == Qt::Checked);
735
736         if (autoranging_)
737                 perform_autoranging(true);
738
739         if (owner_) {
740                 // Call order is important, otherwise the lazy event handler won't work
741                 owner_->extents_changed(false, true);
742                 owner_->row_item_appearance_changed(false, true);
743         }
744 }
745
746 void AnalogSignal::on_conversion_changed(int index)
747 {
748         data::SignalBase::ConversionType old_conv_type = conversion_type_;
749
750         conversion_type_ = (data::SignalBase::ConversionType)(conversion_cb_->itemData(index).toInt());
751
752         if (conversion_type_ != old_conv_type) {
753                 base_->set_conversion_type(conversion_type_);
754                 update_conversion_type();
755         }
756 }
757
758 void AnalogSignal::on_display_type_changed(int index)
759 {
760         display_type_ = (DisplayType)(display_type_cb_->itemData(index).toInt());
761
762         if (owner_)
763                 owner_->row_item_appearance_changed(false, true);
764 }
765
766 } // namespace TraceView
767 } // namespace views
768 } // namespace pv