2 * This file is part of the PulseView project.
4 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
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.
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.
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/>.
28 #include <QApplication>
31 #include <QFormLayout>
32 #include <QGridLayout>
36 #include "analogsignal.hpp"
37 #include "logicsignal.hpp"
40 #include "pv/data/analog.hpp"
41 #include "pv/data/analogsegment.hpp"
42 #include "pv/data/logic.hpp"
43 #include "pv/data/logicsegment.hpp"
44 #include "pv/data/signalbase.hpp"
45 #include "pv/globalsettings.hpp"
47 #include <libsigrokcxx/libsigrokcxx.hpp>
55 using std::numeric_limits;
57 using std::shared_ptr;
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
71 const QColor AnalogSignal::GridMajorColor = QColor(0, 0, 0, 40 * 256 / 100);
72 const QColor AnalogSignal::GridMinorColor = QColor(0, 0, 0, 20 * 256 / 100);
74 const QColor AnalogSignal::SamplingPointColour(0x77, 0x77, 0x77);
76 const int64_t AnalogSignal::TracePaintBlockSize = 1024 * 1024; // 4 MiB (due to float)
77 const float AnalogSignal::EnvelopeThreshold = 64.0f;
79 const int AnalogSignal::MaximumVDivs = 10;
80 const int AnalogSignal::MinScaleIndex = -6;
81 const int AnalogSignal::MaxScaleIndex = 7;
83 const int AnalogSignal::InfoTextMarginRight = 20;
84 const int AnalogSignal::InfoTextMarginBottom = 5;
86 AnalogSignal::AnalogSignal(
88 shared_ptr<data::SignalBase> base) :
89 Signal(session, base),
90 scale_index_(4), // 20 per div
91 scale_index_drag_offset_(0),
95 conversion_type_(data::SignalBase::NoConversion),
96 display_type_(DisplayBoth),
99 pv::data::Analog* analog_data =
100 dynamic_cast<pv::data::Analog*>(data().get());
102 connect(analog_data, SIGNAL(samples_added(QObject*, uint64_t, uint64_t)),
103 this, SLOT(on_samples_added()));
106 div_height_ = gs.value(GlobalSettings::Key_View_DefaultDivHeight).toInt();
108 base_->set_colour(SignalColours[base_->index() % countof(SignalColours)]);
112 shared_ptr<pv::data::SignalData> AnalogSignal::data() const
114 return base_->analog_data();
117 void AnalogSignal::save_settings(QSettings &settings) const
119 settings.setValue("pos_vdivs", pos_vdivs_);
120 settings.setValue("neg_vdivs", neg_vdivs_);
121 settings.setValue("scale_index", scale_index_);
122 settings.setValue("conversion_type", conversion_type_);
123 settings.setValue("display_type", display_type_);
124 settings.setValue("autoranging", autoranging_);
125 settings.setValue("div_height", div_height_);
128 void AnalogSignal::restore_settings(QSettings &settings)
130 if (settings.contains("pos_vdivs"))
131 pos_vdivs_ = settings.value("pos_vdivs").toInt();
133 if (settings.contains("neg_vdivs"))
134 neg_vdivs_ = settings.value("neg_vdivs").toInt();
136 if (settings.contains("scale_index")) {
137 scale_index_ = settings.value("scale_index").toInt();
141 if (settings.contains("conversion_type")) {
142 conversion_type_ = (data::SignalBase::ConversionType)(settings.value("conversion_type").toInt());
143 update_conversion_type();
146 if (settings.contains("display_type"))
147 display_type_ = (DisplayType)(settings.value("display_type").toInt());
149 if (settings.contains("autoranging"))
150 autoranging_ = settings.value("autoranging").toBool();
152 if (settings.contains("div_height")) {
153 const int old_height = div_height_;
154 div_height_ = settings.value("div_height").toInt();
156 if ((div_height_ != old_height) && owner_) {
157 // Call order is important, otherwise the lazy event handler won't work
158 owner_->extents_changed(false, true);
159 owner_->row_item_appearance_changed(false, true);
164 pair<int, int> AnalogSignal::v_extents() const
166 const int ph = pos_vdivs_ * div_height_;
167 const int nh = neg_vdivs_ * div_height_;
168 return make_pair(-ph, nh);
171 int AnalogSignal::scale_handle_offset() const
173 const int h = (pos_vdivs_ + neg_vdivs_) * div_height_;
175 return ((scale_index_drag_offset_ - scale_index_) * h / 4) - h / 2;
178 void AnalogSignal::scale_handle_dragged(int offset)
180 const int h = (pos_vdivs_ + neg_vdivs_) * div_height_;
182 scale_index_ = scale_index_drag_offset_ - (offset + h / 2) / (h / 4);
187 void AnalogSignal::scale_handle_drag_release()
189 scale_index_drag_offset_ = scale_index_;
193 void AnalogSignal::paint_back(QPainter &p, ViewItemPaintParams &pp)
195 if (base_->enabled()) {
196 Trace::paint_back(p, pp);
197 paint_axis(p, pp, get_visual_y());
201 void AnalogSignal::paint_mid(QPainter &p, ViewItemPaintParams &pp)
203 assert(base_->analog_data());
206 const int y = get_visual_y();
208 if (!base_->enabled())
211 if ((display_type_ == DisplayAnalog) || (display_type_ == DisplayBoth)) {
212 paint_grid(p, y, pp.left(), pp.right());
214 const deque< shared_ptr<pv::data::AnalogSegment> > &segments =
215 base_->analog_data()->analog_segments();
216 if (segments.empty())
219 const shared_ptr<pv::data::AnalogSegment> &segment =
222 const double pixels_offset = pp.pixels_offset();
223 const double samplerate = max(1.0, segment->samplerate());
224 const pv::util::Timestamp& start_time = segment->start_time();
225 const int64_t last_sample = segment->get_sample_count() - 1;
226 const double samples_per_pixel = samplerate * pp.scale();
227 const pv::util::Timestamp start = samplerate * (pp.offset() - start_time);
228 const pv::util::Timestamp end = start + samples_per_pixel * pp.width();
230 const int64_t start_sample = min(max(floor(start).convert_to<int64_t>(),
231 (int64_t)0), last_sample);
232 const int64_t end_sample = min(max((ceil(end) + 1).convert_to<int64_t>(),
233 (int64_t)0), last_sample);
235 if (samples_per_pixel < EnvelopeThreshold)
236 paint_trace(p, segment, y, pp.left(),
237 start_sample, end_sample,
238 pixels_offset, samples_per_pixel);
240 paint_envelope(p, segment, y, pp.left(),
241 start_sample, end_sample,
242 pixels_offset, samples_per_pixel);
245 if ((display_type_ == DisplayConverted) || (display_type_ == DisplayBoth)) {
246 if (((conversion_type_ == data::SignalBase::A2LConversionByTreshold) ||
247 (conversion_type_ == data::SignalBase::A2LConversionBySchmittTrigger))) {
249 paint_logic_mid(p, pp);
254 void AnalogSignal::paint_fore(QPainter &p, ViewItemPaintParams &pp)
259 if ((display_type_ == DisplayAnalog) || (display_type_ == DisplayBoth)) {
260 const int y = get_visual_y();
262 // Show the info section on the right side of the trace
263 const QString infotext = QString("%1 V/div").arg(resolution_);
265 p.setPen(base_->colour());
266 p.setFont(QApplication::font());
268 const QRectF bounding_rect = QRectF(pp.left(),
269 y + v_extents().first,
270 pp.width() - InfoTextMarginRight,
271 v_extents().second - v_extents().first - InfoTextMarginBottom);
273 p.drawText(bounding_rect, Qt::AlignRight | Qt::AlignBottom, infotext);
277 void AnalogSignal::paint_grid(QPainter &p, int y, int left, int right)
279 p.setRenderHint(QPainter::Antialiasing, false);
281 GlobalSettings settings;
282 const bool show_analog_minor_grid =
283 settings.value(GlobalSettings::Key_View_ShowAnalogMinorGrid).toBool();
285 if (pos_vdivs_ > 0) {
286 p.setPen(QPen(GridMajorColor, 1, Qt::DashLine));
287 for (int i = 1; i <= pos_vdivs_; i++) {
288 const float dy = i * div_height_;
289 p.drawLine(QLineF(left, y - dy, right, y - dy));
293 if ((pos_vdivs_ > 0) && show_analog_minor_grid) {
294 p.setPen(QPen(GridMinorColor, 1, Qt::DashLine));
295 for (int i = 0; i < pos_vdivs_; i++) {
296 const float dy = i * div_height_;
297 const float dy25 = dy + (0.25 * div_height_);
298 const float dy50 = dy + (0.50 * div_height_);
299 const float dy75 = dy + (0.75 * div_height_);
300 p.drawLine(QLineF(left, y - dy25, right, y - dy25));
301 p.drawLine(QLineF(left, y - dy50, right, y - dy50));
302 p.drawLine(QLineF(left, y - dy75, right, y - dy75));
306 if (neg_vdivs_ > 0) {
307 p.setPen(QPen(GridMajorColor, 1, Qt::DashLine));
308 for (int i = 1; i <= neg_vdivs_; i++) {
309 const float dy = i * div_height_;
310 p.drawLine(QLineF(left, y + dy, right, y + dy));
314 if ((pos_vdivs_ > 0) && show_analog_minor_grid) {
315 p.setPen(QPen(GridMinorColor, 1, Qt::DashLine));
316 for (int i = 0; i < neg_vdivs_; i++) {
317 const float dy = i * div_height_;
318 const float dy25 = dy + (0.25 * div_height_);
319 const float dy50 = dy + (0.50 * div_height_);
320 const float dy75 = dy + (0.75 * div_height_);
321 p.drawLine(QLineF(left, y + dy25, right, y + dy25));
322 p.drawLine(QLineF(left, y + dy50, right, y + dy50));
323 p.drawLine(QLineF(left, y + dy75, right, y + dy75));
327 p.setRenderHint(QPainter::Antialiasing, true);
330 void AnalogSignal::paint_trace(QPainter &p,
331 const shared_ptr<pv::data::AnalogSegment> &segment,
332 int y, int left, const int64_t start, const int64_t end,
333 const double pixels_offset, const double samples_per_pixel)
338 // Calculate and paint the sampling points if enabled and useful
339 GlobalSettings settings;
340 const bool show_sampling_points =
341 settings.value(GlobalSettings::Key_View_ShowSamplingPoints).toBool() &&
342 (samples_per_pixel < 0.25);
344 p.setPen(base_->colour());
346 const int64_t points_count = end - start;
348 QPointF *points = new QPointF[points_count];
349 QPointF *point = points;
351 QRectF *sampling_points = nullptr;
352 if (show_sampling_points)
353 sampling_points = new QRectF[points_count];
354 QRectF *sampling_point = sampling_points;
356 int64_t sample_count = min(points_count, TracePaintBlockSize);
357 int64_t block_sample = 0;
358 float *sample_block = new float[TracePaintBlockSize];
359 segment->get_samples(start, start + sample_count, sample_block);
362 for (int64_t sample = start; sample != end; sample++, block_sample++) {
364 if (block_sample == TracePaintBlockSize) {
366 sample_count = min(points_count - sample, TracePaintBlockSize);
367 segment->get_samples(sample, sample + sample_count, sample_block);
370 const float x = (sample / samples_per_pixel -
371 pixels_offset) + left;
373 *point++ = QPointF(x, y - sample_block[block_sample] * scale_);
375 if (show_sampling_points)
377 QRectF(x - (w / 2), y - sample_block[block_sample] * scale_ - (w / 2), w, w);
379 delete[] sample_block;
381 p.drawPolyline(points, points_count);
383 if (show_sampling_points) {
384 p.setPen(SamplingPointColour);
385 p.drawRects(sampling_points, points_count);
386 delete[] sampling_points;
392 void AnalogSignal::paint_envelope(QPainter &p,
393 const shared_ptr<pv::data::AnalogSegment> &segment,
394 int y, int left, const int64_t start, const int64_t end,
395 const double pixels_offset, const double samples_per_pixel)
397 using pv::data::AnalogSegment;
399 AnalogSegment::EnvelopeSection e;
400 segment->get_envelope_section(e, start, end, samples_per_pixel);
405 p.setPen(QPen(Qt::NoPen));
406 p.setBrush(base_->colour());
408 QRectF *const rects = new QRectF[e.length];
409 QRectF *rect = rects;
411 for (uint64_t sample = 0; sample < e.length - 1; sample++) {
412 const float x = ((e.scale * sample + e.start) /
413 samples_per_pixel - pixels_offset) + left;
414 const AnalogSegment::EnvelopeSample *const s =
417 // We overlap this sample with the next so that vertical
418 // gaps do not appear during steep rising or falling edges
419 const float b = y - max(s->max, (s + 1)->min) * scale_;
420 const float t = y - min(s->min, (s + 1)->max) * scale_;
423 if (h >= 0.0f && h <= 1.0f)
425 if (h <= 0.0f && h >= -1.0f)
428 *rect++ = QRectF(x, t, 1.0f, h);
431 p.drawRects(rects, e.length);
437 void AnalogSignal::paint_logic_mid(QPainter &p, ViewItemPaintParams &pp)
441 vector< pair<int64_t, bool> > edges;
445 const int y = get_visual_y();
447 if (!base_->enabled() || !base_->logic_data())
450 const int signal_margin =
451 QFontMetrics(QApplication::font()).height() / 2;
453 const int ph = min(pos_vdivs_, 1) * div_height_;
454 const int nh = min(neg_vdivs_, 1) * div_height_;
455 const float high_offset = y - ph + signal_margin + 0.5f;
456 const float low_offset = y + nh - signal_margin - 0.5f;
458 const deque< shared_ptr<pv::data::LogicSegment> > &segments =
459 base_->logic_data()->logic_segments();
461 if (segments.empty())
464 const shared_ptr<pv::data::LogicSegment> &segment =
467 double samplerate = segment->samplerate();
469 // Show sample rate as 1Hz when it is unknown
470 if (samplerate == 0.0)
473 const double pixels_offset = pp.pixels_offset();
474 const pv::util::Timestamp& start_time = segment->start_time();
475 const int64_t last_sample = segment->get_sample_count() - 1;
476 const double samples_per_pixel = samplerate * pp.scale();
477 const double pixels_per_sample = 1 / samples_per_pixel;
478 const pv::util::Timestamp start = samplerate * (pp.offset() - start_time);
479 const pv::util::Timestamp end = start + samples_per_pixel * pp.width();
481 const int64_t start_sample = min(max(floor(start).convert_to<int64_t>(),
482 (int64_t)0), last_sample);
483 const uint64_t end_sample = min(max(ceil(end).convert_to<int64_t>(),
484 (int64_t)0), last_sample);
486 segment->get_subsampled_edges(edges, start_sample, end_sample,
487 samples_per_pixel / LogicSignal::Oversampling, 0);
488 assert(edges.size() >= 2);
490 // Check whether we need to paint the sampling points
491 GlobalSettings settings;
492 const bool show_sampling_points =
493 settings.value(GlobalSettings::Key_View_ShowSamplingPoints).toBool() &&
494 (samples_per_pixel < 0.25);
496 vector<QRectF> sampling_points;
497 float sampling_point_x = 0.0f;
498 int64_t sampling_point_sample = start_sample;
501 if (show_sampling_points) {
502 sampling_points.reserve(end_sample - start_sample + 1);
503 sampling_point_x = (edges.cbegin()->first / samples_per_pixel - pixels_offset) + pp.left();
507 const unsigned int edge_count = edges.size() - 2;
508 QLineF *const edge_lines = new QLineF[edge_count];
511 for (auto i = edges.cbegin() + 1; i != edges.cend() - 1; i++) {
512 const float x = ((*i).first / samples_per_pixel -
513 pixels_offset) + pp.left();
514 *line++ = QLineF(x, high_offset, x, low_offset);
516 if (show_sampling_points)
517 while (sampling_point_sample < (*i).first) {
518 const float y = (*i).second ? low_offset : high_offset;
519 sampling_points.emplace_back(
520 QRectF(sampling_point_x - (w / 2), y - (w / 2), w, w));
521 sampling_point_sample++;
522 sampling_point_x += pixels_per_sample;
526 // Calculate the sample points from the last edge to the end of the trace
527 if (show_sampling_points)
528 while ((uint64_t)sampling_point_sample <= end_sample) {
529 // Signal changed after the last edge, so the level is inverted
530 const float y = (edges.cend() - 1)->second ? high_offset : low_offset;
531 sampling_points.emplace_back(
532 QRectF(sampling_point_x - (w / 2), y - (w / 2), w, w));
533 sampling_point_sample++;
534 sampling_point_x += pixels_per_sample;
537 p.setPen(LogicSignal::EdgeColour);
538 p.drawLines(edge_lines, edge_count);
542 const unsigned int max_cap_line_count = edges.size();
543 QLineF *const cap_lines = new QLineF[max_cap_line_count];
545 p.setPen(LogicSignal::HighColour);
546 paint_logic_caps(p, cap_lines, edges, true, samples_per_pixel,
547 pixels_offset, pp.left(), high_offset);
548 p.setPen(LogicSignal::LowColour);
549 paint_logic_caps(p, cap_lines, edges, false, samples_per_pixel,
550 pixels_offset, pp.left(), low_offset);
554 // Paint the sampling points
555 if (show_sampling_points) {
556 p.setPen(SamplingPointColour);
557 p.drawRects(sampling_points.data(), sampling_points.size());
561 void AnalogSignal::paint_logic_caps(QPainter &p, QLineF *const lines,
562 vector< pair<int64_t, bool> > &edges, bool level,
563 double samples_per_pixel, double pixels_offset, float x_offset,
566 QLineF *line = lines;
568 for (auto i = edges.begin(); i != (edges.end() - 1); i++)
569 if ((*i).second == level) {
571 ((*i).first / samples_per_pixel -
572 pixels_offset) + x_offset, y_offset,
573 ((*(i+1)).first / samples_per_pixel -
574 pixels_offset) + x_offset, y_offset);
577 p.drawLines(lines, line - lines);
580 float AnalogSignal::get_resolution(int scale_index)
582 const float seq[] = {1.0f, 2.0f, 5.0f};
584 const int offset = numeric_limits<int>::max() / (2 * countof(seq));
585 const div_t d = div((int)(scale_index + countof(seq) * offset),
588 return powf(10.0f, d.quot - offset) * seq[d.rem];
591 void AnalogSignal::update_scale()
593 resolution_ = get_resolution(scale_index_);
594 scale_ = div_height_ / resolution_;
597 void AnalogSignal::update_conversion_type()
599 base_->set_conversion_type(conversion_type_);
602 owner_->row_item_appearance_changed(false, true);
605 void AnalogSignal::perform_autoranging(bool keep_divs, bool force_update)
607 const deque< shared_ptr<pv::data::AnalogSegment> > &segments =
608 base_->analog_data()->analog_segments();
610 if (segments.empty())
613 static double prev_min = 0, prev_max = 0;
614 double min = 0, max = 0;
616 for (shared_ptr<pv::data::AnalogSegment> segment : segments) {
617 pair<double, double> mm = segment->get_min_max();
618 min = std::min(min, mm.first);
619 max = std::max(max, mm.second);
622 if ((min == prev_min) && (max == prev_max) && !force_update)
628 // If we're allowed to alter the div assignment...
630 // Use all divs for the positive range if there are no negative values
631 if ((min == 0) && (neg_vdivs_ > 0)) {
632 pos_vdivs_ += neg_vdivs_;
636 // Split up the divs if there are negative values but no negative divs
637 if ((min < 0) && (neg_vdivs_ == 0)) {
638 neg_vdivs_ = pos_vdivs_ / 2;
639 pos_vdivs_ -= neg_vdivs_;
643 // If there is still no positive div when we need it, add one
644 // (this can happen when pos_vdivs==neg_vdivs==0)
645 if ((max > 0) && (pos_vdivs_ == 0)) {
647 owner_->extents_changed(false, true);
650 // If there is still no negative div when we need it, add one
651 // (this can happen when pos_vdivs was 0 or 1 when trying to split)
652 if ((min < 0) && (neg_vdivs_ == 0)) {
654 owner_->extents_changed(false, true);
657 double min_value_per_div;
658 if ((pos_vdivs_ > 0) && (neg_vdivs_ > 0))
659 min_value_per_div = std::max(max / pos_vdivs_, -min / neg_vdivs_);
660 else if (pos_vdivs_ > 0)
661 min_value_per_div = max / pos_vdivs_;
663 min_value_per_div = -min / neg_vdivs_;
665 // Find first scale value that is bigger than the value we need
666 for (int i = MinScaleIndex; i < MaxScaleIndex; i++)
667 if (get_resolution(i) > min_value_per_div) {
675 void AnalogSignal::populate_popup_form(QWidget *parent, QFormLayout *form)
677 // Add the standard options
678 Signal::populate_popup_form(parent, form);
680 QFormLayout *const layout = new QFormLayout;
682 // Add div-related settings
683 pvdiv_sb_ = new QSpinBox(parent);
684 pvdiv_sb_->setRange(0, MaximumVDivs);
685 pvdiv_sb_->setValue(pos_vdivs_);
686 connect(pvdiv_sb_, SIGNAL(valueChanged(int)),
687 this, SLOT(on_pos_vdivs_changed(int)));
688 layout->addRow(tr("Number of pos vertical divs"), pvdiv_sb_);
690 nvdiv_sb_ = new QSpinBox(parent);
691 nvdiv_sb_->setRange(0, MaximumVDivs);
692 nvdiv_sb_->setValue(neg_vdivs_);
693 connect(nvdiv_sb_, SIGNAL(valueChanged(int)),
694 this, SLOT(on_neg_vdivs_changed(int)));
695 layout->addRow(tr("Number of neg vertical divs"), nvdiv_sb_);
697 div_height_sb_ = new QSpinBox(parent);
698 div_height_sb_->setRange(20, 1000);
699 div_height_sb_->setSingleStep(5);
700 div_height_sb_->setSuffix(tr(" pixels"));
701 div_height_sb_->setValue(div_height_);
702 connect(div_height_sb_, SIGNAL(valueChanged(int)),
703 this, SLOT(on_div_height_changed(int)));
704 layout->addRow(tr("Div height"), div_height_sb_);
706 // Add the vertical resolution
707 resolution_cb_ = new QComboBox(parent);
709 for (int i = MinScaleIndex; i < MaxScaleIndex; i++) {
710 const QString label = QString("%1").arg(get_resolution(i));
711 resolution_cb_->insertItem(0, label, QVariant(i));
714 int cur_idx = resolution_cb_->findData(QVariant(scale_index_));
715 resolution_cb_->setCurrentIndex(cur_idx);
717 connect(resolution_cb_, SIGNAL(currentIndexChanged(int)),
718 this, SLOT(on_resolution_changed(int)));
720 QGridLayout *const vdiv_layout = new QGridLayout;
721 QLabel *const vdiv_unit = new QLabel(tr("V/div"));
722 vdiv_layout->addWidget(resolution_cb_, 0, 0);
723 vdiv_layout->addWidget(vdiv_unit, 0, 1);
725 layout->addRow(tr("Vertical resolution"), vdiv_layout);
727 // Add the autoranging checkbox
728 QCheckBox* autoranging_cb = new QCheckBox();
729 autoranging_cb->setCheckState(autoranging_ ? Qt::Checked : Qt::Unchecked);
731 connect(autoranging_cb, SIGNAL(stateChanged(int)),
732 this, SLOT(on_autoranging_changed(int)));
734 layout->addRow(tr("Autoranging"), autoranging_cb);
736 // Add the conversion type dropdown
737 conversion_cb_ = new QComboBox();
739 conversion_cb_->addItem("none", data::SignalBase::NoConversion);
740 conversion_cb_->addItem("to logic via threshold", data::SignalBase::A2LConversionByTreshold);
741 conversion_cb_->addItem("to logic via schmitt-trigger", data::SignalBase::A2LConversionBySchmittTrigger);
743 cur_idx = conversion_cb_->findData(QVariant(conversion_type_));
744 conversion_cb_->setCurrentIndex(cur_idx);
746 layout->addRow(tr("Conversion"), conversion_cb_);
748 connect(conversion_cb_, SIGNAL(currentIndexChanged(int)),
749 this, SLOT(on_conversion_changed(int)));
751 // Add the display type dropdown
752 display_type_cb_ = new QComboBox();
754 display_type_cb_->addItem(tr("Analog"), DisplayAnalog);
755 display_type_cb_->addItem(tr("Converted"), DisplayConverted);
756 display_type_cb_->addItem(tr("Both"), DisplayBoth);
758 cur_idx = display_type_cb_->findData(QVariant(display_type_));
759 display_type_cb_->setCurrentIndex(cur_idx);
761 layout->addRow(tr("Traces to show:"), display_type_cb_);
763 connect(display_type_cb_, SIGNAL(currentIndexChanged(int)),
764 this, SLOT(on_display_type_changed(int)));
766 form->addRow(layout);
769 void AnalogSignal::on_samples_added()
771 perform_autoranging(false, false);
774 void AnalogSignal::on_pos_vdivs_changed(int vdivs)
776 if (vdivs == pos_vdivs_)
781 // There has to be at least one div, positive or negative
782 if ((neg_vdivs_ == 0) && (pos_vdivs_ == 0)) {
785 pvdiv_sb_->setValue(pos_vdivs_);
789 perform_autoranging(true, true);
791 // It could be that a positive or negative div was added, so update
793 pvdiv_sb_->setValue(pos_vdivs_);
794 nvdiv_sb_->setValue(neg_vdivs_);
799 // Call order is important, otherwise the lazy event handler won't work
800 owner_->extents_changed(false, true);
801 owner_->row_item_appearance_changed(false, true);
805 void AnalogSignal::on_neg_vdivs_changed(int vdivs)
807 if (vdivs == neg_vdivs_)
812 // There has to be at least one div, positive or negative
813 if ((neg_vdivs_ == 0) && (pos_vdivs_ == 0)) {
816 pvdiv_sb_->setValue(pos_vdivs_);
820 perform_autoranging(true, true);
822 // It could be that a positive or negative div was added, so update
824 pvdiv_sb_->setValue(pos_vdivs_);
825 nvdiv_sb_->setValue(neg_vdivs_);
830 // Call order is important, otherwise the lazy event handler won't work
831 owner_->extents_changed(false, true);
832 owner_->row_item_appearance_changed(false, true);
836 void AnalogSignal::on_div_height_changed(int height)
838 div_height_ = height;
842 // Call order is important, otherwise the lazy event handler won't work
843 owner_->extents_changed(false, true);
844 owner_->row_item_appearance_changed(false, true);
848 void AnalogSignal::on_resolution_changed(int index)
850 scale_index_ = resolution_cb_->itemData(index).toInt();
854 owner_->row_item_appearance_changed(false, true);
857 void AnalogSignal::on_autoranging_changed(int state)
859 autoranging_ = (state == Qt::Checked);
862 perform_autoranging(false, true);
865 // Call order is important, otherwise the lazy event handler won't work
866 owner_->extents_changed(false, true);
867 owner_->row_item_appearance_changed(false, true);
871 void AnalogSignal::on_conversion_changed(int index)
873 data::SignalBase::ConversionType old_conv_type = conversion_type_;
875 conversion_type_ = (data::SignalBase::ConversionType)(conversion_cb_->itemData(index).toInt());
877 if (conversion_type_ != old_conv_type) {
878 base_->set_conversion_type(conversion_type_);
879 update_conversion_type();
883 void AnalogSignal::on_display_type_changed(int index)
885 display_type_ = (DisplayType)(display_type_cb_->itemData(index).toInt());
888 owner_->row_item_appearance_changed(false, true);