X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=pv%2Fwidgets%2Ftimestampspinbox.cpp;h=fea8175e8e00b74b21f6690cf9d726e3a9cd418c;hb=e887fe9e6ede73b9fe9ace9c6bfd4f6a096eb3b2;hp=f5d8d0bf5e39ce55ea13f9b7da9b6bdda5b0feaa;hpb=efdec55aec1a137460fa362a381ed1904182bfed;p=pulseview.git diff --git a/pv/widgets/timestampspinbox.cpp b/pv/widgets/timestampspinbox.cpp index f5d8d0bf..fea8175e 100644 --- a/pv/widgets/timestampspinbox.cpp +++ b/pv/widgets/timestampspinbox.cpp @@ -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(); } @@ -87,15 +88,11 @@ void TimestampSpinBox::setValue(const pv::util::Timestamp& val) value_ = val; updateEdit(); - Q_EMIT valueChanged(value_); + valueChanged(value_); } 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,8 +111,12 @@ 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); } -} // widgets -} // pv +} // namespace widgets +} // namespace pv