]> sigrok.org Git - pulseview.git/commitdiff
Accept new position on enter press in cursor popups
authorjaseg <redacted>
Sun, 9 Jun 2019 11:53:05 +0000 (20:53 +0900)
committerUwe Hermann <redacted>
Fri, 5 Jul 2019 20:49:08 +0000 (22:49 +0200)
pv/views/trace/timemarker.cpp
pv/views/trace/timemarker.hpp
pv/widgets/timestampspinbox.cpp

index ec4c97d78937fb8d76ec42e8e69fa670897ce3f7..3249d3da77daaa7cfaf40960fcddc38fc970ea7e 100644 (file)
@@ -50,8 +50,7 @@ TimeMarker::TimeMarker(
        color_(color),
        time_(time),
        value_action_(nullptr),
-       value_widget_(nullptr),
-       updating_value_widget_(false)
+       value_widget_(nullptr)
 {
 }
 
@@ -65,9 +64,8 @@ void TimeMarker::set_time(const pv::util::Timestamp& time)
        time_ = time;
 
        if (value_widget_) {
-               updating_value_widget_ = true;
+               QSignalBlocker blocker(value_widget_);
                value_widget_->setValue(view_.ruler()->get_ruler_time_from_absolute_time(time));
-               updating_value_widget_ = false;
        }
 
        view_.time_item_appearance_changed(true, true);
@@ -192,8 +190,7 @@ pv::widgets::Popup* TimeMarker::create_popup(QWidget *parent)
 
 void TimeMarker::on_value_changed(const pv::util::Timestamp& value)
 {
-       if (!updating_value_widget_)
-               set_time(view_.ruler()->get_absolute_time_from_ruler_time(value));
+       set_time(view_.ruler()->get_absolute_time_from_ruler_time(value));
 }
 
 } // namespace trace
index 48afc16bb77e9c346ec75e80c06ab3564873ecc1..28bcd73aba40c327662a6e47beaf43aea2006bdc 100644 (file)
@@ -128,7 +128,6 @@ protected:
 
        QWidgetAction *value_action_;
        pv::widgets::TimestampSpinBox *value_widget_;
-       bool updating_value_widget_;
 };
 
 } // namespace trace
index 21b3d0d7a50c1610a3365bcabbe16730dcca696b..fea8175e8e00b74b21f6690cf9d726e3a9cd418c 100644 (file)
@@ -31,6 +31,7 @@ TimestampSpinBox::TimestampSpinBox(QWidget* parent)
        , stepsize_("1e-6")
 {
        connect(this, SIGNAL(editingFinished()), this, SLOT(on_editingFinished()));
+       connect(lineEdit(), SIGNAL(editingFinished()), this, SLOT(on_editingFinished()));
 
        updateEdit();
 }
@@ -92,10 +93,6 @@ void TimestampSpinBox::setValue(const pv::util::Timestamp& val)
 
 void TimestampSpinBox::on_editingFinished()
 {
-       if (!lineEdit()->isModified())
-               return;
-       lineEdit()->setModified(false);
-
        QRegExp re(R"(\s*([-+]?)\s*([0-9]+\.?[0-9]*).*)");
 
        if (re.exactMatch(text())) {
@@ -103,6 +100,7 @@ void TimestampSpinBox::on_editingFinished()
                captures.removeFirst(); // remove entire match
                QString str = captures.join("");
                setValue(pv::util::Timestamp(str.toStdString()));
+
        } else {
                // replace the malformed entered string with the old value
                updateEdit();
@@ -113,7 +111,11 @@ void TimestampSpinBox::updateEdit()
 {
        QString newtext = pv::util::format_time_si(
                value_, pv::util::SIPrefix::none, precision_);
+       const QSignalBlocker blocker(lineEdit());
+       // Keep cursor position
+       int cursor = lineEdit()->cursorPosition();
        lineEdit()->setText(newtext);
+       lineEdit()->setCursorPosition(cursor);
 }
 
 }  // namespace widgets