X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=pv%2Fwidgets%2Ftimestampspinbox.cpp;h=01424a5b7837654e50c36de5f3f4ce27c33ec8a1;hb=883041605ce8536ece950b1de191cfe71068dfba;hp=59af82f65407629b0937ec66bc14308b190188d1;hpb=d001f416aec37d5b13b804dec9ee9e1c011ffabb;p=pulseview.git diff --git a/pv/widgets/timestampspinbox.cpp b/pv/widgets/timestampspinbox.cpp index 59af82f6..01424a5b 100644 --- a/pv/widgets/timestampspinbox.cpp +++ b/pv/widgets/timestampspinbox.cpp @@ -14,8 +14,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * along with this program; if not, see . */ #include "timestampspinbox.hpp" @@ -32,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(); } @@ -76,7 +76,7 @@ QSize TimestampSpinBox::minimumSizeHint() const { const QFontMetrics fm(fontMetrics()); const int l = round(value_).str().size() + precision_ + 10; - const int w = fm.width(QString(l, '0')); + const int w = util::text_width(fm, QString(l, '0')); const int h = lineEdit()->minimumSizeHint().height(); return QSize(w, h); } @@ -88,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())) { @@ -104,8 +100,8 @@ void TimestampSpinBox::on_editingFinished() captures.removeFirst(); // remove entire match QString str = captures.join(""); setValue(pv::util::Timestamp(str.toStdString())); - } - else { + + } else { // replace the malformed entered string with the old value updateEdit(); } @@ -113,10 +109,14 @@ void TimestampSpinBox::on_editingFinished() void TimestampSpinBox::updateEdit() { - QString newtext = pv::util::format_si_value( - value_, "s", pv::util::SIPrefix::none, precision_); + 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