From d6df214412d9278aeee8f06c33cabbfce1faff09 Mon Sep 17 00:00:00 2001 From: Fred Gleason Date: Wed, 11 Aug 2021 13:43:54 -0400 Subject: [PATCH] 2021-08-11 Fred Gleason * Tightened up the validation checking in 'RDTimeEdit'. Signed-off-by: Fred Gleason --- ChangeLog | 2 ++ lib/rdtimeedit.cpp | 31 +++++++++++++++++++++++++++++-- lib/rdtimeedit.h | 3 ++- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 50a878d5..d288bb2b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -22206,3 +22206,5 @@ 2021-08-11 Fred Gleason * Adjusted layout in 'RDLogEventDialog' to be compatible with 12 hour time format. +2021-08-11 Fred Gleason + * Tightened up the validation checking in 'RDTimeEdit'. diff --git a/lib/rdtimeedit.cpp b/lib/rdtimeedit.cpp index ff6cad09..490fcc27 100644 --- a/lib/rdtimeedit.cpp +++ b/lib/rdtimeedit.cpp @@ -29,8 +29,8 @@ RDTimeEdit::RDTimeEdit(QWidget *parent) { d_show_hours=true; d_show_tenths=false; - d_current_step_size=1; d_step_enabled=StepDownEnabled|StepUpEnabled; + d_width_variance=0; SetFormat(); } @@ -74,7 +74,8 @@ QValidator::State RDTimeEdit::validate(QString &input,int &pos) const return ret; } if(ret==QValidator::Acceptable) { - if(input.length()!=displayFormat().length()) { + if((input.length()!=displayFormat().length())&& + (input.length()!=(displayFormat().length()+d_width_variance))) { return QValidator::Intermediate; } } @@ -82,6 +83,24 @@ QValidator::State RDTimeEdit::validate(QString &input,int &pos) const } +void RDTimeEdit::fixup(QString &input) const +{ + // + // Don't allow higher precision than tenths of a second + // + if(d_show_tenths) { + QStringList f0=input.split(".",QString::KeepEmptyParts); + if(f0.size()==2) { + QStringList f1=f0.at(1).split(" "); + if(f1.at(0).length()>1) { + input.replace("."+f1.at(0),"."+f1.at(0).left(1)); + } + } + } + QTimeEdit::fixup(input); +} + + void RDTimeEdit::stepBy(int steps) { int step_size=1; @@ -170,17 +189,21 @@ void RDTimeEdit::SetFormat() if(d_show_tenths) { if(d_show_hours) { setDisplayFormat(RD_TWELVE_HOUR_TENTHS_FORMAT); + d_width_variance=1; } else { setDisplayFormat(RD_OFFSET_TENTHS_FORMAT); + d_width_variance=0; } } else { if(d_show_hours) { setDisplayFormat(RD_TWELVE_HOUR_FORMAT); + d_width_variance=0; } else { setDisplayFormat(RD_OFFSET_FORMAT); + d_width_variance=0; } } } @@ -188,17 +211,21 @@ void RDTimeEdit::SetFormat() if(d_show_tenths) { if(d_show_hours) { setDisplayFormat(RD_TWENTYFOUR_HOUR_TENTHS_FORMAT); + d_width_variance=0; } else { setDisplayFormat(RD_OFFSET_TENTHS_FORMAT); + d_width_variance=0; } } else { if(d_show_hours) { setDisplayFormat(RD_TWENTYFOUR_HOUR_FORMAT); + d_width_variance=0; } else { setDisplayFormat(RD_OFFSET_FORMAT); + d_width_variance=0; } } } diff --git a/lib/rdtimeedit.h b/lib/rdtimeedit.h index 28e34150..ec61882c 100644 --- a/lib/rdtimeedit.h +++ b/lib/rdtimeedit.h @@ -36,6 +36,7 @@ class RDTimeEdit : public QTimeEdit protected: QValidator::State validate(QString &input,int &pos) const; + void fixup(QString &input) const; void stepBy(int steps); QAbstractSpinBox::StepEnabled stepEnabled() const; @@ -43,7 +44,7 @@ class RDTimeEdit : public QTimeEdit void SetFormat(); bool d_show_hours; bool d_show_tenths; - int d_current_step_size; + int d_width_variance; QAbstractSpinBox::StepEnabled d_step_enabled; };