From ad9eb73d73b0200150d34807616ebcc8dd2a4b4f Mon Sep 17 00:00:00 2001 From: Yosef Hamza Date: Sun, 13 Apr 2014 18:19:15 +0200 Subject: Mark Air/Water temp field red for wrong input. As a warining for the user mark the field red. If the user inputs invalid input that will be ignored while parsing. But with adding a one character error margin to prevent it from toggling between Red and Yellow while editing existing values, for example "After Deleting unit and last number after '.'" Signed-off-by: Yousef Hamza Signed-off-by: Dirk Hohndel --- qt-ui/maintab.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'qt-ui/maintab.cpp') diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 227d89b58..594ac562a 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -881,14 +881,43 @@ void MainTab::on_airtemp_textChanged(const QString &text) { EDIT_SELECTED_DIVES(select_dc(mydive)->airtemp.mkelvin = parseTemperatureToMkelvin(text)); markChangedWidget(ui.airtemp); + validate_temp_field(ui.airtemp, text); } void MainTab::on_watertemp_textChanged(const QString &text) { EDIT_SELECTED_DIVES(select_dc(mydive)->watertemp.mkelvin = parseTemperatureToMkelvin(text)); markChangedWidget(ui.watertemp); + validate_temp_field(ui.watertemp, text); } +void MainTab::validate_temp_field(QLineEdit *tempField,const QString &text) +{ + static bool missing_unit = false; + static bool missing_precision = false; + if (!text.contains(QRegExp("^[-+]{0,1}[0-9]+([,.][0-9]+){0,1}(°[CF]){0,1}$")) && + !text.isEmpty() && + !text.contains(QRegExp("^[-+]$"))) { + if (text.contains(QRegExp("^[-+]{0,1}[0-9]+([,.][0-9]+){0,1}(°)$")) && !missing_unit) { + if (!missing_unit) { + missing_unit = true; + return; + } + } + if (text.contains(QRegExp("^[-+]{0,1}[0-9]+([,.]){0,1}(°[CF]){0,1}$")) && !missing_precision) { + if (!missing_precision) { + missing_precision = true; + return; + } + } + QPalette p; + p.setBrush(QPalette::Base, QColor(Qt::red).lighter()); + tempField->setPalette(p); + } else { + missing_unit = false; + missing_precision = false; + } +} void MainTab::on_dateTimeEdit_dateTimeChanged(const QDateTime &datetime) { QDateTime dateTimeUtc(datetime); -- cgit v1.2.3-70-g09d2