]> sigrok.org Git - pulseview.git/commitdiff
AnalogSignal: Make div height adjustable
authorSoeren Apel <redacted>
Sun, 16 Jul 2017 20:10:16 +0000 (22:10 +0200)
committerSoeren Apel <redacted>
Sun, 16 Jul 2017 20:37:12 +0000 (22:37 +0200)
pv/views/trace/analogsignal.cpp
pv/views/trace/analogsignal.hpp

index f94a70f80f92e6322996969324d149016a8bc06d..e26b203a2d197aa1161c3d63752ebf0ea3dcdfc9 100644 (file)
@@ -89,7 +89,6 @@ AnalogSignal::AnalogSignal(
        Signal(session, base),
        scale_index_(4), // 20 per div
        scale_index_drag_offset_(0),
-       div_height_(3 * QFontMetrics(QApplication::font()).height()),
        pos_vdivs_(1),
        neg_vdivs_(1),
        resolution_(0),
@@ -103,6 +102,9 @@ AnalogSignal::AnalogSignal(
        connect(analog_data, SIGNAL(samples_added(QObject*, uint64_t, uint64_t)),
                this, SLOT(on_samples_added()));
 
+       GlobalSettings gs;
+       div_height_ = gs.value(GlobalSettings::Key_View_DefaultDivHeight).toInt();
+
        base_->set_colour(SignalColours[base_->index() % countof(SignalColours)]);
        update_scale();
 }
@@ -120,6 +122,7 @@ void AnalogSignal::save_settings(QSettings &settings) const
        settings.setValue("conversion_type", conversion_type_);
        settings.setValue("display_type", display_type_);
        settings.setValue("autoranging", autoranging_);
+       settings.setValue("div_height", div_height_);
 }
 
 void AnalogSignal::restore_settings(QSettings &settings)
@@ -145,6 +148,17 @@ void AnalogSignal::restore_settings(QSettings &settings)
 
        if (settings.contains("autoranging"))
                autoranging_ = settings.value("autoranging").toBool();
+
+       if (settings.contains("div_height")) {
+               const int old_height = div_height_;
+               div_height_ = settings.value("div_height").toInt();
+
+               if ((div_height_ != old_height) && owner_) {
+                       // Call order is important, otherwise the lazy event handler won't work
+                       owner_->extents_changed(false, true);
+                       owner_->row_item_appearance_changed(false, true);
+               }
+       }
 }
 
 pair<int, int> AnalogSignal::v_extents() const
@@ -665,7 +679,7 @@ void AnalogSignal::populate_popup_form(QWidget *parent, QFormLayout *form)
 
        QFormLayout *const layout = new QFormLayout;
 
-       // Add the number of vdivs
+       // Add div-related settings
        pvdiv_sb_ = new QSpinBox(parent);
        pvdiv_sb_->setRange(0, MaximumVDivs);
        pvdiv_sb_->setValue(pos_vdivs_);
@@ -680,6 +694,15 @@ void AnalogSignal::populate_popup_form(QWidget *parent, QFormLayout *form)
                this, SLOT(on_neg_vdivs_changed(int)));
        layout->addRow(tr("Number of neg vertical divs"), nvdiv_sb_);
 
+       div_height_sb_ = new QSpinBox(parent);
+       div_height_sb_->setRange(20, 1000);
+       div_height_sb_->setSingleStep(5);
+       div_height_sb_->setSuffix(tr(" pixels"));
+       div_height_sb_->setValue(div_height_);
+       connect(div_height_sb_, SIGNAL(valueChanged(int)),
+               this, SLOT(on_div_height_changed(int)));
+       layout->addRow(tr("Div height"), div_height_sb_);
+
        // Add the vertical resolution
        resolution_cb_ = new QComboBox(parent);
 
@@ -810,6 +833,18 @@ void AnalogSignal::on_neg_vdivs_changed(int vdivs)
        }
 }
 
+void AnalogSignal::on_div_height_changed(int height)
+{
+       div_height_ = height;
+       update_scale();
+
+       if (owner_) {
+               // Call order is important, otherwise the lazy event handler won't work
+               owner_->extents_changed(false, true);
+               owner_->row_item_appearance_changed(false, true);
+       }
+}
+
 void AnalogSignal::on_resolution_changed(int index)
 {
        scale_index_ = resolution_cb_->itemData(index).toInt();
index a1b3eeefac0139e916921a167322404acb1c8ab3..a67c4ff37185d1ee63bebf8c6b8c32516a1f9a3c 100644 (file)
@@ -156,6 +156,7 @@ private Q_SLOTS:
 
        void on_pos_vdivs_changed(int vdivs);
        void on_neg_vdivs_changed(int vdivs);
+       void on_div_height_changed(int height);
 
        void on_resolution_changed(int index);
 
@@ -167,7 +168,7 @@ private Q_SLOTS:
 
 private:
        QComboBox *resolution_cb_, *conversion_cb_, *display_type_cb_;
-       QSpinBox *pvdiv_sb_, *nvdiv_sb_;
+       QSpinBox *pvdiv_sb_, *nvdiv_sb_, *div_height_sb_;
 
        float scale_;
        int scale_index_;