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 "pv/data/analog.hpp"
38 #include "pv/data/analogsegment.hpp"
39 #include "pv/data/logic.hpp"
40 #include "pv/data/logicsegment.hpp"
41 #include "pv/data/signalbase.hpp"
42 #include "pv/globalsettings.hpp"
43 #include "pv/view/logicsignal.hpp"
44 #include "pv/view/view.hpp"
46 #include <libsigrokcxx/libsigrokcxx.hpp>
54 using std::numeric_limits;
56 using std::shared_ptr;
63 const QColor AnalogSignal::SignalColours[4] = {
64 QColor(0xC4, 0xA0, 0x00), // Yellow
65 QColor(0x87, 0x20, 0x7A), // Magenta
66 QColor(0x20, 0x4A, 0x87), // Blue
67 QColor(0x4E, 0x9A, 0x06) // Green
70 const QColor AnalogSignal::GridMajorColor = QColor(0, 0, 0, 40 * 256 / 100);
71 const QColor AnalogSignal::GridMinorColor = QColor(0, 0, 0, 20 * 256 / 100);
73 const QColor AnalogSignal::SamplingPointColour(0x77, 0x77, 0x77);
75 const int64_t AnalogSignal::TracePaintBlockSize = 1024 * 1024; // 4 MiB (due to float)
76 const float AnalogSignal::EnvelopeThreshold = 64.0f;
78 const int AnalogSignal::MaximumVDivs = 10;
79 const int AnalogSignal::MinScaleIndex = -6;
80 const int AnalogSignal::MaxScaleIndex = 7;
82 const int AnalogSignal::InfoTextMarginRight = 20;
83 const int AnalogSignal::InfoTextMarginBottom = 5;
85 AnalogSignal::AnalogSignal(
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()),
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()));
105 base_->set_colour(SignalColours[base_->index() % countof(SignalColours)]);
109 shared_ptr<pv::data::SignalData> AnalogSignal::data() const
111 return base_->analog_data();
114 void AnalogSignal::save_settings(QSettings &settings) const
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_);
124 void AnalogSignal::restore_settings(QSettings &settings)
126 if (settings.contains("pos_vdivs"))
127 pos_vdivs_ = settings.value("pos_vdivs").toInt();
129 if (settings.contains("neg_vdivs"))
130 neg_vdivs_ = settings.value("neg_vdivs").toInt();
132 if (settings.contains("scale_index")) {
133 scale_index_ = settings.value("scale_index").toInt();
137 if (settings.contains("conversion_type")) {
138 conversion_type_ = (data::SignalBase::ConversionType)(settings.value("conversion_type").toInt());
139 update_conversion_type();
142 if (settings.contains("display_type"))
143 display_type_ = (DisplayType)(settings.value("display_type").toInt());
145 if (settings.contains("autoranging"))
146 autoranging_ = settings.value("autoranging").toBool();
149 pair<int, int> AnalogSignal::v_extents() const
151 const int ph = pos_vdivs_ * div_height_;
152 const int nh = neg_vdivs_ * div_height_;
153 return make_pair(-ph, nh);
156 int AnalogSignal::scale_handle_offset() const
158 const int h = (pos_vdivs_ + neg_vdivs_) * div_height_;
160 return ((scale_index_drag_offset_ - scale_index_) * h / 4) - h / 2;
163 void AnalogSignal::scale_handle_dragged(int offset)
165 const int h = (pos_vdivs_ + neg_vdivs_) * div_height_;
167 scale_index_ = scale_index_drag_offset_ - (offset + h / 2) / (h / 4);
172 void AnalogSignal::scale_handle_drag_release()
174 scale_index_drag_offset_ = scale_index_;
178 void AnalogSignal::paint_back(QPainter &p, ViewItemPaintParams &pp)
180 if (base_->enabled()) {
181 Trace::paint_back(p, pp);
182 paint_axis(p, pp, get_visual_y());
186 void AnalogSignal::paint_mid(QPainter &p, ViewItemPaintParams &pp)
188 assert(base_->analog_data());
191 const int y = get_visual_y();
193 if (!base_->enabled())
196 if ((display_type_ == DisplayAnalog) || (display_type_ == DisplayBoth)) {
197 paint_grid(p, y, pp.left(), pp.right());
199 const deque< shared_ptr<pv::data::AnalogSegment> > &segments =
200 base_->analog_data()->analog_segments();
201 if (segments.empty())
204 const shared_ptr<pv::data::AnalogSegment> &segment =
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();
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);
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);
225 paint_envelope(p, segment, y, pp.left(),
226 start_sample, end_sample,
227 pixels_offset, samples_per_pixel);
230 if ((display_type_ == DisplayConverted) || (display_type_ == DisplayBoth)) {
231 if (((conversion_type_ == data::SignalBase::A2LConversionByTreshold) ||
232 (conversion_type_ == data::SignalBase::A2LConversionBySchmittTrigger))) {
234 paint_logic_mid(p, pp);
239 void AnalogSignal::paint_fore(QPainter &p, ViewItemPaintParams &pp)
244 if ((display_type_ == DisplayAnalog) || (display_type_ == DisplayBoth)) {
245 const int y = get_visual_y();
247 // Show the info section on the right side of the trace
248 const QString infotext = QString("%1 V/div").arg(resolution_);
250 p.setPen(base_->colour());
251 p.setFont(QApplication::font());
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);
258 p.drawText(bounding_rect, Qt::AlignRight | Qt::AlignBottom, infotext);
262 void AnalogSignal::paint_grid(QPainter &p, int y, int left, int right)
264 p.setRenderHint(QPainter::Antialiasing, false);
266 GlobalSettings settings;
267 const bool show_analog_minor_grid =
268 settings.value(GlobalSettings::Key_View_ShowAnalogMinorGrid).toBool();
270 if (pos_vdivs_ > 0) {
271 p.setPen(QPen(GridMajorColor, 1, Qt::DashLine));
272 for (int i = 1; i <= pos_vdivs_; i++) {
273 const float dy = i * div_height_;
274 p.drawLine(QLineF(left, y - dy, right, y - dy));
278 if ((pos_vdivs_ > 0) && show_analog_minor_grid) {
279 p.setPen(QPen(GridMinorColor, 1, Qt::DashLine));
280 for (int i = 0; i < pos_vdivs_; i++) {
281 const float dy = i * div_height_;
282 const float dy25 = dy + (0.25 * div_height_);
283 const float dy50 = dy + (0.50 * div_height_);
284 const float dy75 = dy + (0.75 * div_height_);
285 p.drawLine(QLineF(left, y - dy25, right, y - dy25));
286 p.drawLine(QLineF(left, y - dy50, right, y - dy50));
287 p.drawLine(QLineF(left, y - dy75, right, y - dy75));
291 if (neg_vdivs_ > 0) {
292 p.setPen(QPen(GridMajorColor, 1, Qt::DashLine));
293 for (int i = 1; i <= neg_vdivs_; i++) {
294 const float dy = i * div_height_;
295 p.drawLine(QLineF(left, y + dy, right, y + dy));
299 if ((pos_vdivs_ > 0) && show_analog_minor_grid) {
300 p.setPen(QPen(GridMinorColor, 1, Qt::DashLine));
301 for (int i = 0; i < neg_vdivs_; i++) {
302 const float dy = i * div_height_;
303 const float dy25 = dy + (0.25 * div_height_);
304 const float dy50 = dy + (0.50 * div_height_);
305 const float dy75 = dy + (0.75 * div_height_);
306 p.drawLine(QLineF(left, y + dy25, right, y + dy25));
307 p.drawLine(QLineF(left, y + dy50, right, y + dy50));
308 p.drawLine(QLineF(left, y + dy75, right, y + dy75));
312 p.setRenderHint(QPainter::Antialiasing, true);
315 void AnalogSignal::paint_trace(QPainter &p,
316 const shared_ptr<pv::data::AnalogSegment> &segment,
317 int y, int left, const int64_t start, const int64_t end,
318 const double pixels_offset, const double samples_per_pixel)
323 // Calculate and paint the sampling points if enabled and useful
324 GlobalSettings settings;
325 const bool show_sampling_points =
326 settings.value(GlobalSettings::Key_View_ShowSamplingPoints).toBool() &&
327 (samples_per_pixel < 0.25);
329 p.setPen(base_->colour());
331 const int64_t points_count = end - start;
333 QPointF *points = new QPointF[points_count];
334 QPointF *point = points;
336 QRectF *sampling_points = nullptr;
337 if (show_sampling_points)
338 sampling_points = new QRectF[points_count];
339 QRectF *sampling_point = sampling_points;
341 int64_t sample_count = min(points_count, TracePaintBlockSize);
342 int64_t block_sample = 0;
343 const float *sample_block = segment->get_samples(start, start + sample_count);
346 for (int64_t sample = start; sample != end; sample++, block_sample++) {
348 if (block_sample == TracePaintBlockSize) {
350 delete[] sample_block;
351 sample_count = min(points_count - sample, TracePaintBlockSize);
352 sample_block = segment->get_samples(sample, sample + sample_count);
355 const float x = (sample / samples_per_pixel -
356 pixels_offset) + left;
358 *point++ = QPointF(x, y - sample_block[block_sample] * scale_);
360 if (show_sampling_points)
362 QRectF(x - (w / 2), y - sample_block[block_sample] * scale_ - (w / 2), w, w);
364 delete[] sample_block;
366 p.drawPolyline(points, points_count);
368 if (show_sampling_points) {
369 p.setPen(SamplingPointColour);
370 p.drawRects(sampling_points, points_count);
371 delete[] sampling_points;
377 void AnalogSignal::paint_envelope(QPainter &p,
378 const shared_ptr<pv::data::AnalogSegment> &segment,
379 int y, int left, const int64_t start, const int64_t end,
380 const double pixels_offset, const double samples_per_pixel)
382 using pv::data::AnalogSegment;
384 AnalogSegment::EnvelopeSection e;
385 segment->get_envelope_section(e, start, end, samples_per_pixel);
390 p.setPen(QPen(Qt::NoPen));
391 p.setBrush(base_->colour());
393 QRectF *const rects = new QRectF[e.length];
394 QRectF *rect = rects;
396 for (uint64_t sample = 0; sample < e.length - 1; sample++) {
397 const float x = ((e.scale * sample + e.start) /
398 samples_per_pixel - pixels_offset) + left;
399 const AnalogSegment::EnvelopeSample *const s =
402 // We overlap this sample with the next so that vertical
403 // gaps do not appear during steep rising or falling edges
404 const float b = y - max(s->max, (s + 1)->min) * scale_;
405 const float t = y - min(s->min, (s + 1)->max) * scale_;
408 if (h >= 0.0f && h <= 1.0f)
410 if (h <= 0.0f && h >= -1.0f)
413 *rect++ = QRectF(x, t, 1.0f, h);
416 p.drawRects(rects, e.length);
422 void AnalogSignal::paint_logic_mid(QPainter &p, ViewItemPaintParams &pp)
426 vector< pair<int64_t, bool> > edges;
430 const int y = get_visual_y();
432 if (!base_->enabled() || !base_->logic_data())
435 const int signal_margin =
436 QFontMetrics(QApplication::font()).height() / 2;
438 const int ph = min(pos_vdivs_, 1) * div_height_;
439 const int nh = min(neg_vdivs_, 1) * div_height_;
440 const float high_offset = y - ph + signal_margin + 0.5f;
441 const float low_offset = y + nh - signal_margin - 0.5f;
443 const deque< shared_ptr<pv::data::LogicSegment> > &segments =
444 base_->logic_data()->logic_segments();
446 if (segments.empty())
449 const shared_ptr<pv::data::LogicSegment> &segment =
452 double samplerate = segment->samplerate();
454 // Show sample rate as 1Hz when it is unknown
455 if (samplerate == 0.0)
458 const double pixels_offset = pp.pixels_offset();
459 const pv::util::Timestamp& start_time = segment->start_time();
460 const int64_t last_sample = segment->get_sample_count() - 1;
461 const double samples_per_pixel = samplerate * pp.scale();
462 const double pixels_per_sample = 1 / samples_per_pixel;
463 const pv::util::Timestamp start = samplerate * (pp.offset() - start_time);
464 const pv::util::Timestamp end = start + samples_per_pixel * pp.width();
466 const int64_t start_sample = min(max(floor(start).convert_to<int64_t>(),
467 (int64_t)0), last_sample);
468 const uint64_t end_sample = min(max(ceil(end).convert_to<int64_t>(),
469 (int64_t)0), last_sample);
471 segment->get_subsampled_edges(edges, start_sample, end_sample,
472 samples_per_pixel / LogicSignal::Oversampling, 0);
473 assert(edges.size() >= 2);
475 // Check whether we need to paint the sampling points
476 GlobalSettings settings;
477 const bool show_sampling_points =
478 settings.value(GlobalSettings::Key_View_ShowSamplingPoints).toBool() &&
479 (samples_per_pixel < 0.25);
481 vector<QRectF> sampling_points;
482 float sampling_point_x = 0.0f;
483 int64_t sampling_point_sample = start_sample;
486 if (show_sampling_points) {
487 sampling_points.reserve(end_sample - start_sample + 1);
488 sampling_point_x = (edges.cbegin()->first / samples_per_pixel - pixels_offset) + pp.left();
492 const unsigned int edge_count = edges.size() - 2;
493 QLineF *const edge_lines = new QLineF[edge_count];
496 for (auto i = edges.cbegin() + 1; i != edges.cend() - 1; i++) {
497 const float x = ((*i).first / samples_per_pixel -
498 pixels_offset) + pp.left();
499 *line++ = QLineF(x, high_offset, x, low_offset);
501 if (show_sampling_points)
502 while (sampling_point_sample < (*i).first) {
503 const float y = (*i).second ? low_offset : high_offset;
504 sampling_points.emplace_back(
505 QRectF(sampling_point_x - (w / 2), y - (w / 2), w, w));
506 sampling_point_sample++;
507 sampling_point_x += pixels_per_sample;
511 // Calculate the sample points from the last edge to the end of the trace
512 if (show_sampling_points)
513 while ((uint64_t)sampling_point_sample <= end_sample) {
514 // Signal changed after the last edge, so the level is inverted
515 const float y = (edges.cend() - 1)->second ? high_offset : low_offset;
516 sampling_points.emplace_back(
517 QRectF(sampling_point_x - (w / 2), y - (w / 2), w, w));
518 sampling_point_sample++;
519 sampling_point_x += pixels_per_sample;
522 p.setPen(LogicSignal::EdgeColour);
523 p.drawLines(edge_lines, edge_count);
527 const unsigned int max_cap_line_count = edges.size();
528 QLineF *const cap_lines = new QLineF[max_cap_line_count];
530 p.setPen(LogicSignal::HighColour);
531 paint_logic_caps(p, cap_lines, edges, true, samples_per_pixel,
532 pixels_offset, pp.left(), high_offset);
533 p.setPen(LogicSignal::LowColour);
534 paint_logic_caps(p, cap_lines, edges, false, samples_per_pixel,
535 pixels_offset, pp.left(), low_offset);
539 // Paint the sampling points
540 if (show_sampling_points) {
541 p.setPen(SamplingPointColour);
542 p.drawRects(sampling_points.data(), sampling_points.size());
546 void AnalogSignal::paint_logic_caps(QPainter &p, QLineF *const lines,
547 vector< pair<int64_t, bool> > &edges, bool level,
548 double samples_per_pixel, double pixels_offset, float x_offset,
551 QLineF *line = lines;
553 for (auto i = edges.begin(); i != (edges.end() - 1); i++)
554 if ((*i).second == level) {
556 ((*i).first / samples_per_pixel -
557 pixels_offset) + x_offset, y_offset,
558 ((*(i+1)).first / samples_per_pixel -
559 pixels_offset) + x_offset, y_offset);
562 p.drawLines(lines, line - lines);
565 float AnalogSignal::get_resolution(int scale_index)
567 const float seq[] = {1.0f, 2.0f, 5.0f};
569 const int offset = numeric_limits<int>::max() / (2 * countof(seq));
570 const div_t d = div((int)(scale_index + countof(seq) * offset),
573 return powf(10.0f, d.quot - offset) * seq[d.rem];
576 void AnalogSignal::update_scale()
578 resolution_ = get_resolution(scale_index_);
579 scale_ = div_height_ / resolution_;
582 void AnalogSignal::update_conversion_type()
584 base_->set_conversion_type(conversion_type_);
587 owner_->row_item_appearance_changed(false, true);
590 void AnalogSignal::perform_autoranging(bool keep_divs, bool force_update)
592 const deque< shared_ptr<pv::data::AnalogSegment> > &segments =
593 base_->analog_data()->analog_segments();
595 if (segments.empty())
598 static double prev_min = 0, prev_max = 0;
599 double min = 0, max = 0;
601 for (shared_ptr<pv::data::AnalogSegment> segment : segments) {
602 pair<double, double> mm = segment->get_min_max();
603 min = std::min(min, mm.first);
604 max = std::max(max, mm.second);
607 if ((min == prev_min) && (max == prev_max) && !force_update)
613 // If we're allowed to alter the div assignment...
615 // Use all divs for the positive range if there are no negative values
616 if ((min == 0) && (neg_vdivs_ > 0)) {
617 pos_vdivs_ += neg_vdivs_;
621 // Split up the divs if there are negative values but no negative divs
622 if ((min < 0) && (neg_vdivs_ == 0)) {
623 neg_vdivs_ = pos_vdivs_ / 2;
624 pos_vdivs_ -= neg_vdivs_;
628 // If there is still no positive div when we need it, add one
629 // (this can happen when pos_vdivs==neg_vdivs==0)
630 if ((max > 0) && (pos_vdivs_ == 0)) {
632 owner_->extents_changed(false, true);
635 // If there is still no negative div when we need it, add one
636 // (this can happen when pos_vdivs was 0 or 1 when trying to split)
637 if ((min < 0) && (neg_vdivs_ == 0)) {
639 owner_->extents_changed(false, true);
642 double min_value_per_div;
643 if ((pos_vdivs_ > 0) && (neg_vdivs_ > 0))
644 min_value_per_div = std::max(max / pos_vdivs_, -min / neg_vdivs_);
645 else if (pos_vdivs_ > 0)
646 min_value_per_div = max / pos_vdivs_;
648 min_value_per_div = -min / neg_vdivs_;
650 // Find first scale value that is bigger than the value we need
651 for (int i = MinScaleIndex; i < MaxScaleIndex; i++)
652 if (get_resolution(i) > min_value_per_div) {
660 void AnalogSignal::populate_popup_form(QWidget *parent, QFormLayout *form)
662 // Add the standard options
663 Signal::populate_popup_form(parent, form);
665 QFormLayout *const layout = new QFormLayout;
667 // Add the number of vdivs
668 pvdiv_sb_ = new QSpinBox(parent);
669 pvdiv_sb_->setRange(0, MaximumVDivs);
670 pvdiv_sb_->setValue(pos_vdivs_);
671 connect(pvdiv_sb_, SIGNAL(valueChanged(int)),
672 this, SLOT(on_pos_vdivs_changed(int)));
673 layout->addRow(tr("Number of pos vertical divs"), pvdiv_sb_);
675 nvdiv_sb_ = new QSpinBox(parent);
676 nvdiv_sb_->setRange(0, MaximumVDivs);
677 nvdiv_sb_->setValue(neg_vdivs_);
678 connect(nvdiv_sb_, SIGNAL(valueChanged(int)),
679 this, SLOT(on_neg_vdivs_changed(int)));
680 layout->addRow(tr("Number of neg vertical divs"), nvdiv_sb_);
682 // Add the vertical resolution
683 resolution_cb_ = new QComboBox(parent);
685 for (int i = MinScaleIndex; i < MaxScaleIndex; i++) {
686 const QString label = QString("%1").arg(get_resolution(i));
687 resolution_cb_->insertItem(0, label, QVariant(i));
690 int cur_idx = resolution_cb_->findData(QVariant(scale_index_));
691 resolution_cb_->setCurrentIndex(cur_idx);
693 connect(resolution_cb_, SIGNAL(currentIndexChanged(int)),
694 this, SLOT(on_resolution_changed(int)));
696 QGridLayout *const vdiv_layout = new QGridLayout;
697 QLabel *const vdiv_unit = new QLabel(tr("V/div"));
698 vdiv_layout->addWidget(resolution_cb_, 0, 0);
699 vdiv_layout->addWidget(vdiv_unit, 0, 1);
701 layout->addRow(tr("Vertical resolution"), vdiv_layout);
703 // Add the autoranging checkbox
704 QCheckBox* autoranging_cb = new QCheckBox();
705 autoranging_cb->setCheckState(autoranging_ ? Qt::Checked : Qt::Unchecked);
707 connect(autoranging_cb, SIGNAL(stateChanged(int)),
708 this, SLOT(on_autoranging_changed(int)));
710 layout->addRow(tr("Autoranging"), autoranging_cb);
712 // Add the conversion type dropdown
713 conversion_cb_ = new QComboBox();
715 conversion_cb_->addItem("none", data::SignalBase::NoConversion);
716 conversion_cb_->addItem("to logic via threshold", data::SignalBase::A2LConversionByTreshold);
717 conversion_cb_->addItem("to logic via schmitt-trigger", data::SignalBase::A2LConversionBySchmittTrigger);
719 cur_idx = conversion_cb_->findData(QVariant(conversion_type_));
720 conversion_cb_->setCurrentIndex(cur_idx);
722 // layout->addRow(tr("Conversion"), conversion_cb_);
724 connect(conversion_cb_, SIGNAL(currentIndexChanged(int)),
725 this, SLOT(on_conversion_changed(int)));
727 // Add the display type dropdown
728 display_type_cb_ = new QComboBox();
730 display_type_cb_->addItem(tr("Analog"), DisplayAnalog);
731 display_type_cb_->addItem(tr("Converted"), DisplayConverted);
732 display_type_cb_->addItem(tr("Both"), DisplayBoth);
734 cur_idx = display_type_cb_->findData(QVariant(display_type_));
735 display_type_cb_->setCurrentIndex(cur_idx);
737 // layout->addRow(tr("Traces to show:"), display_type_cb_);
739 connect(display_type_cb_, SIGNAL(currentIndexChanged(int)),
740 this, SLOT(on_display_type_changed(int)));
742 form->addRow(layout);
745 void AnalogSignal::on_samples_added()
747 perform_autoranging(false, false);
750 void AnalogSignal::on_pos_vdivs_changed(int vdivs)
752 if (vdivs == pos_vdivs_)
757 // There has to be at least one div, positive or negative
758 if ((neg_vdivs_ == 0) && (pos_vdivs_ == 0)) {
761 pvdiv_sb_->setValue(pos_vdivs_);
765 perform_autoranging(true, true);
767 // It could be that a positive or negative div was added, so update
769 pvdiv_sb_->setValue(pos_vdivs_);
770 nvdiv_sb_->setValue(neg_vdivs_);
775 // Call order is important, otherwise the lazy event handler won't work
776 owner_->extents_changed(false, true);
777 owner_->row_item_appearance_changed(false, true);
781 void AnalogSignal::on_neg_vdivs_changed(int vdivs)
783 if (vdivs == neg_vdivs_)
788 // There has to be at least one div, positive or negative
789 if ((neg_vdivs_ == 0) && (pos_vdivs_ == 0)) {
792 pvdiv_sb_->setValue(pos_vdivs_);
796 perform_autoranging(true, true);
798 // It could be that a positive or negative div was added, so update
800 pvdiv_sb_->setValue(pos_vdivs_);
801 nvdiv_sb_->setValue(neg_vdivs_);
806 // Call order is important, otherwise the lazy event handler won't work
807 owner_->extents_changed(false, true);
808 owner_->row_item_appearance_changed(false, true);
812 void AnalogSignal::on_resolution_changed(int index)
814 scale_index_ = resolution_cb_->itemData(index).toInt();
818 owner_->row_item_appearance_changed(false, true);
821 void AnalogSignal::on_autoranging_changed(int state)
823 autoranging_ = (state == Qt::Checked);
826 perform_autoranging(false, true);
829 // Call order is important, otherwise the lazy event handler won't work
830 owner_->extents_changed(false, true);
831 owner_->row_item_appearance_changed(false, true);
835 void AnalogSignal::on_conversion_changed(int index)
837 data::SignalBase::ConversionType old_conv_type = conversion_type_;
839 conversion_type_ = (data::SignalBase::ConversionType)(conversion_cb_->itemData(index).toInt());
841 if (conversion_type_ != old_conv_type) {
842 base_->set_conversion_type(conversion_type_);
843 update_conversion_type();
847 void AnalogSignal::on_display_type_changed(int index)
849 display_type_ = (DisplayType)(display_type_cb_->itemData(index).toInt());
852 owner_->row_item_appearance_changed(false, true);
855 } // namespace TraceView