mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Allow editing of date & time and air & water temperatures
Add two more rows to the widget - this is getting quite busy. There still is some weirdness where the focus isn't returned where it should be and a few other details, but overall getting there. Added helper functions to parse a temperature and to deal with the timezone offset - with that latter one I also fixed the time offset bug in the planner. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
acd3599548
commit
a8888eaf26
6 changed files with 154 additions and 22 deletions
|
@ -25,6 +25,8 @@ void set_default_dive_computer(const char *vendor, const char *product);
|
|||
void set_default_dive_computer_device(const char *name);
|
||||
QString getSubsurfaceDataPath(QString folderToFind);
|
||||
extern const QString get_dc_nickname(const char *model, uint32_t deviceid);
|
||||
int gettimezoneoffset();
|
||||
int parseTemperatureToMkelvin(const QString& text);
|
||||
|
||||
extern DiveComputerList dcList;
|
||||
|
||||
|
|
31
qt-gui.cpp
31
qt-gui.cpp
|
@ -36,6 +36,8 @@
|
|||
#include <QMap>
|
||||
#include <QMultiMap>
|
||||
#include <QNetworkProxy>
|
||||
#include <QDateTime>
|
||||
#include <QRegExp>
|
||||
|
||||
const char *default_dive_computer_vendor;
|
||||
const char *default_dive_computer_product;
|
||||
|
@ -379,4 +381,33 @@ void call_for_each_dc(FILE *f, void (*callback)(FILE *, const char *, uint32_t,
|
|||
}
|
||||
}
|
||||
|
||||
int gettimezoneoffset()
|
||||
{
|
||||
QDateTime dt1 = QDateTime::currentDateTime();
|
||||
QDateTime dt2 = dt1.toUTC();
|
||||
dt1.setTimeSpec(Qt::UTC);
|
||||
return dt2.secsTo(dt1);
|
||||
}
|
||||
|
||||
int parseTemperatureToMkelvin(const QString& text)
|
||||
{
|
||||
int mkelvin;
|
||||
QString numOnly = text;
|
||||
numOnly.replace(",",".").remove(QRegExp("[^0-9.]"));
|
||||
if (numOnly == "")
|
||||
return 0;
|
||||
double number = numOnly.toDouble();
|
||||
switch (prefs.units.temperature) {
|
||||
case units::CELSIUS:
|
||||
mkelvin = C_to_mkelvin(number);
|
||||
break;
|
||||
case units::FAHRENHEIT:
|
||||
mkelvin = F_to_mkelvin(number);
|
||||
break;
|
||||
default:
|
||||
mkelvin = 0;
|
||||
}
|
||||
return mkelvin;
|
||||
|
||||
}
|
||||
#include "qt-gui.moc"
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "../dive.h"
|
||||
#include "../divelist.h"
|
||||
#include "../planner.h"
|
||||
#include "helpers.h"
|
||||
|
||||
#include <QMouseEvent>
|
||||
#include <QDebug>
|
||||
|
@ -1056,7 +1057,7 @@ void DivePlannerPointsModel::setLastStop6m(bool value)
|
|||
|
||||
void DivePlannerPointsModel::setStartTime(const QTime& t)
|
||||
{
|
||||
diveplan.when = (t.msec() + QDateTime::currentMSecsSinceEpoch()) / 1000 - Qt::OffsetFromUTC * 3600;
|
||||
diveplan.when = (t.msec() + QDateTime::currentMSecsSinceEpoch()) / 1000 - gettimezoneoffset();
|
||||
emit dataChanged(createIndex(0, 0), createIndex(rowCount()-1, COLUMNS-1));
|
||||
}
|
||||
|
||||
|
|
|
@ -56,6 +56,9 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
|
|||
ui->notes->viewport()->installEventFilter(this);
|
||||
ui->rating->installEventFilter(this);
|
||||
ui->visibility->installEventFilter(this);
|
||||
ui->airtemp->installEventFilter(this);
|
||||
ui->watertemp->installEventFilter(this);
|
||||
ui->dateTimeEdit->installEventFilter(this);
|
||||
|
||||
QList<QObject *> statisticsTabWidgets = ui->statisticsTab->children();
|
||||
Q_FOREACH(QObject* obj, statisticsTabWidgets) {
|
||||
|
@ -142,6 +145,9 @@ void MainTab::enableEdition()
|
|||
notesBackup[mydive].latitude = mydive->latitude;
|
||||
notesBackup[mydive].longitude = mydive->longitude;
|
||||
notesBackup[mydive].coordinates = ui->coordinates->text();
|
||||
notesBackup[mydive].airtemp = get_temperature_string(mydive->airtemp, true);
|
||||
notesBackup[mydive].watertemp = get_temperature_string(mydive->watertemp, true);
|
||||
notesBackup[mydive].datetime = QDateTime::fromTime_t(mydive->when - gettimezoneoffset()).toString(QString("M/d/yy h:mm"));
|
||||
}
|
||||
editMode = DIVE;
|
||||
}
|
||||
|
@ -149,7 +155,12 @@ void MainTab::enableEdition()
|
|||
|
||||
bool MainTab::eventFilter(QObject* object, QEvent* event)
|
||||
{
|
||||
if (isEnabled() && event->type() == QEvent::FocusIn && (object == ui->rating || object == ui->visibility)){
|
||||
if (isEnabled() && event->type() == QEvent::KeyPress && object == ui->dateTimeEdit) {
|
||||
tabBar()->setTabIcon(currentIndex(), QIcon(":warning"));
|
||||
enableEdition();
|
||||
}
|
||||
|
||||
if (isEnabled() && event->type() == QEvent::FocusIn && (object == ui->rating || object == ui->visibility)) {
|
||||
tabBar()->setTabIcon(currentIndex(), QIcon(":warning"));
|
||||
enableEdition();
|
||||
}
|
||||
|
@ -197,6 +208,13 @@ void MainTab::clearStats()
|
|||
else \
|
||||
ui->field->setText(d->field)
|
||||
|
||||
#define UPDATE_TEMP(d, field) \
|
||||
if (!d || d->field.mkelvin == 0) \
|
||||
ui->field->setText(""); \
|
||||
else \
|
||||
ui->field->setText(get_temperature_string(d->field, TRUE));
|
||||
|
||||
|
||||
void MainTab::updateDiveInfo(int dive)
|
||||
{
|
||||
if(!isEnabled())
|
||||
|
@ -221,7 +239,9 @@ void MainTab::updateDiveInfo(int dive)
|
|||
UPDATE_TEXT(d, suit);
|
||||
UPDATE_TEXT(d, divemaster);
|
||||
UPDATE_TEXT(d, buddy);
|
||||
|
||||
UPDATE_TEMP(d, airtemp);
|
||||
UPDATE_TEMP(d, watertemp);
|
||||
ui->dateTimeEdit->setDateTime(QDateTime::fromTime_t(d->when - gettimezoneoffset()));
|
||||
if (d) {
|
||||
char buffer[256];
|
||||
print_gps_coordinates(buffer, sizeof buffer, d->latitude.udeg, d->longitude.udeg);
|
||||
|
@ -385,10 +405,13 @@ void MainTab::acceptChanges()
|
|||
notesBackup[curr].divemaster != ui->divemaster->text() ||
|
||||
notesBackup[curr].location != ui->location->text() ||
|
||||
notesBackup[curr].coordinates != ui->coordinates->text() ||
|
||||
notesBackup[curr].rating != ui->visibility->currentStars() ||
|
||||
notesBackup[curr].visibility != ui->rating->currentStars())
|
||||
|
||||
notesBackup[curr].rating != ui->visibility->currentStars() ||
|
||||
notesBackup[curr].airtemp != ui->airtemp->text() ||
|
||||
notesBackup[curr].watertemp != ui->watertemp->text() ||
|
||||
notesBackup[curr].datetime != ui->dateTimeEdit->dateTime().toString(QString("M/d/yy h:mm")) ||
|
||||
notesBackup[curr].visibility != ui->rating->currentStars()) {
|
||||
mark_divelist_changed(TRUE);
|
||||
}
|
||||
if (notesBackup[curr].location != ui->location->text() ||
|
||||
notesBackup[curr].coordinates != ui->coordinates->text()) {
|
||||
mainWindow()->globe()->reload();
|
||||
|
@ -414,6 +437,9 @@ void MainTab::acceptChanges()
|
|||
ui->coordinates->setPalette(p);
|
||||
ui->divemaster->setPalette(p);
|
||||
ui->suit->setPalette(p);
|
||||
ui->airtemp->setPalette(p);
|
||||
ui->watertemp->setPalette(p);
|
||||
ui->dateTimeEdit->setPalette(p);
|
||||
}
|
||||
|
||||
#define EDIT_TEXT2(what, text) \
|
||||
|
@ -445,6 +471,9 @@ void MainTab::rejectChanges()
|
|||
ui->divemaster->setText(notesBackup[curr].divemaster);
|
||||
ui->rating->setCurrentStars(notesBackup[curr].rating);
|
||||
ui->visibility->setCurrentStars(notesBackup[curr].visibility);
|
||||
ui->airtemp->setText(notesBackup[curr].airtemp);
|
||||
ui->watertemp->setText(notesBackup[curr].watertemp);
|
||||
ui->dateTimeEdit->setDateTime(QDateTime::fromString(notesBackup[curr].datetime, QString("M/d/y h:mm")));
|
||||
|
||||
struct dive *mydive;
|
||||
for (int i = 0; i < dive_table.nr; i++) {
|
||||
|
@ -480,6 +509,9 @@ void MainTab::rejectChanges()
|
|||
ui->coordinates->setPalette(p);
|
||||
ui->divemaster->setPalette(p);
|
||||
ui->suit->setPalette(p);
|
||||
ui->airtemp->setPalette(p);
|
||||
ui->watertemp->setPalette(p);
|
||||
ui->dateTimeEdit->setPalette(p);
|
||||
if (editMode == ADD) {
|
||||
// clean up
|
||||
delete_single_dive(selected_dive);
|
||||
|
@ -525,6 +557,24 @@ void MainTab::on_divemaster_textChanged(const QString& text)
|
|||
markChangedWidget(ui->divemaster);
|
||||
}
|
||||
|
||||
void MainTab::on_airtemp_textChanged(const QString& text)
|
||||
{
|
||||
EDIT_SELECTED_DIVES( mydive->airtemp.mkelvin = parseTemperatureToMkelvin(text) );
|
||||
markChangedWidget(ui->airtemp);
|
||||
}
|
||||
|
||||
void MainTab::on_watertemp_textChanged(const QString& text)
|
||||
{
|
||||
EDIT_SELECTED_DIVES( mydive->watertemp.mkelvin = parseTemperatureToMkelvin(text) );
|
||||
markChangedWidget(ui->watertemp);
|
||||
}
|
||||
|
||||
void MainTab::on_dateTimeEdit_dateTimeChanged(const QDateTime& datetime)
|
||||
{
|
||||
EDIT_SELECTED_DIVES( mydive->when = datetime.toTime_t() + gettimezoneoffset() );
|
||||
markChangedWidget(ui->dateTimeEdit);
|
||||
}
|
||||
|
||||
void MainTab::on_location_textChanged(const QString& text)
|
||||
{
|
||||
if (editMode == NONE)
|
||||
|
|
|
@ -21,6 +21,9 @@ namespace Ui
|
|||
}
|
||||
|
||||
struct NotesBackup{
|
||||
QString airtemp;
|
||||
QString watertemp;
|
||||
QString datetime;
|
||||
QString location;
|
||||
QString coordinates;
|
||||
degrees_t latitude;
|
||||
|
@ -64,6 +67,9 @@ public slots:
|
|||
void on_buddy_textChanged(const QString& text);
|
||||
void on_suit_textChanged(const QString& text);
|
||||
void on_notes_textChanged();
|
||||
void on_airtemp_textChanged(const QString& text);
|
||||
void on_watertemp_textChanged(const QString& text);
|
||||
void on_dateTimeEdit_dateTimeChanged(const QDateTime& datetime);
|
||||
void on_rating_valueChanged(int value);
|
||||
void on_visibility_valueChanged(int value);
|
||||
void editCylinderWidget(const QModelIndex& index);
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>505</width>
|
||||
<height>459</height>
|
||||
<height>610</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -21,70 +21,70 @@
|
|||
<string>Dive Notes</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="4" column="0" colspan="2">
|
||||
<item row="6" column="0" colspan="2">
|
||||
<widget class="QLineEdit" name="coordinates">
|
||||
<property name="readOnly">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="11" column="0" colspan="2">
|
||||
<item row="13" column="0" colspan="2">
|
||||
<widget class="QTextEdit" name="notes">
|
||||
<property name="readOnly">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="LocationLabel">
|
||||
<property name="text">
|
||||
<string>Location</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<item row="8" column="0">
|
||||
<widget class="QLineEdit" name="divemaster">
|
||||
<property name="readOnly">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="1">
|
||||
<item row="10" column="1">
|
||||
<widget class="QLineEdit" name="suit">
|
||||
<property name="readOnly">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<item row="8" column="1">
|
||||
<widget class="QLineEdit" name="buddy">
|
||||
<property name="readOnly">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<item row="4" column="0" colspan="2">
|
||||
<widget class="QLineEdit" name="location">
|
||||
<property name="readOnly">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<item row="7" column="0">
|
||||
<widget class="QLabel" name="DivemasterLabel">
|
||||
<property name="text">
|
||||
<string>Divemaster</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<item row="7" column="1">
|
||||
<widget class="QLabel" name="BuddyLabel">
|
||||
<property name="text">
|
||||
<string>Buddy</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<item row="9" column="0">
|
||||
<layout class="QHBoxLayout" name="ratingVisibilityLabels">
|
||||
<item>
|
||||
<widget class="QLabel" name="RatingLabel">
|
||||
|
@ -102,21 +102,21 @@
|
|||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="7" column="1">
|
||||
<item row="9" column="1">
|
||||
<widget class="QLabel" name="SuitLabel">
|
||||
<property name="text">
|
||||
<string>Suit</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" column="0">
|
||||
<item row="11" column="0">
|
||||
<widget class="QLabel" name="NotesLabel">
|
||||
<property name="text">
|
||||
<string>Notes</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="0">
|
||||
<item row="10" column="0">
|
||||
<layout class="QHBoxLayout" name="ratingVisibilityWidgets">
|
||||
<item>
|
||||
<widget class="StarWidget" name="rating" native="true"/>
|
||||
|
@ -126,23 +126,65 @@
|
|||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="CoordinatedLabel">
|
||||
<property name="text">
|
||||
<string>Coordinates</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="DateTimeLabel">
|
||||
<property name="text">
|
||||
<string>Starttime</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="KMessageWidget" name="diveNotesMessage" native="true"/>
|
||||
</item>
|
||||
<item row="12" column="0" colspan="2">
|
||||
<item row="14" column="0" colspan="2">
|
||||
<widget class="QDialogButtonBox" name="notesButtonBox">
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QDateTimeEdit" name="dateTimeEdit">
|
||||
<property name="displayFormat">
|
||||
<string>M/d/yy h:mm</string>
|
||||
</property>
|
||||
<property name="calendarPopup">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<layout class="QHBoxLayout" name="airWaterTempLayout">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="airtemp">
|
||||
<property name="readOnly">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="watertemp">
|
||||
<property name="readOnly">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="TemperaturesLabel">
|
||||
<property name="text">
|
||||
<string>air / water Temperatures</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="equipmentTab">
|
||||
|
|
Loading…
Add table
Reference in a new issue