aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--qt-ui/maintab.cpp29
-rw-r--r--qt-ui/maintab.h1
2 files changed, 30 insertions, 0 deletions
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);
diff --git a/qt-ui/maintab.h b/qt-ui/maintab.h
index eee07a31d..4a0b0b9c5 100644
--- a/qt-ui/maintab.h
+++ b/qt-ui/maintab.h
@@ -81,6 +81,7 @@ slots:
void on_notes_textChanged();
void on_airtemp_textChanged(const QString &text);
void on_watertemp_textChanged(const QString &text);
+ void validate_temp_field(QLineEdit *tempField,const QString &text);
void on_dateTimeEdit_dateTimeChanged(const QDateTime &datetime);
void on_rating_valueChanged(int value);
void on_visibility_valueChanged(int value);