summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--divesite.c13
-rw-r--r--divesite.h1
-rw-r--r--qt-ui/locationinformation.cpp20
-rw-r--r--qt-ui/maintab.cpp18
-rw-r--r--qt-ui/maintab.h1
-rw-r--r--qt-ui/mainwindow.cpp3
6 files changed, 43 insertions, 13 deletions
diff --git a/divesite.c b/divesite.c
index 93bd35e59..71ffb698f 100644
--- a/divesite.c
+++ b/divesite.c
@@ -182,6 +182,19 @@ uint32_t create_dive_site(const char *name, timestamp_t divetime)
return uuid;
}
+/* same as before, but with current time if no current_dive is present */
+uint32_t create_dive_site_from_current_dive(const char *name)
+{
+ if (current_dive != NULL) {
+ return create_dive_site(name, current_dive->when);
+ } else {
+ timestamp_t when;
+ time_t now = time(0);
+ when = utc_mktime(localtime(&now));
+ return create_dive_site(name, when);
+ }
+}
+
/* same as before, but with GPS data */
uint32_t create_dive_site_with_gps(const char *name, degrees_t latitude, degrees_t longitude, timestamp_t divetime)
{
diff --git a/divesite.h b/divesite.h
index 52901e9b4..30cc18da2 100644
--- a/divesite.h
+++ b/divesite.h
@@ -55,6 +55,7 @@ int nr_of_dives_at_dive_site(uint32_t uuid, bool select_only);
bool is_dive_site_used(uint32_t uuid, bool select_only);
void delete_dive_site(uint32_t id);
uint32_t create_dive_site(const char *name, timestamp_t divetime);
+uint32_t create_dive_site_from_current_dive(const char *name);
uint32_t create_dive_site_with_gps(const char *name, degrees_t latitude, degrees_t longitude, timestamp_t divetime);
uint32_t get_dive_site_uuid_by_name(const char *name, struct dive_site **dsp);
uint32_t get_dive_site_uuid_by_gps(degrees_t latitude, degrees_t longitude, struct dive_site **dsp);
diff --git a/qt-ui/locationinformation.cpp b/qt-ui/locationinformation.cpp
index 8cd9e20be..6006b18e5 100644
--- a/qt-ui/locationinformation.cpp
+++ b/qt-ui/locationinformation.cpp
@@ -78,10 +78,16 @@ void LocationInformationWidget::acceptChanges()
{
emit stopFilterDiveSite();
char *uiString;
- struct dive_site *currentDs = get_dive_site_by_uuid(displayed_dive_site.uuid);
+ struct dive_site *currentDs;
+ uiString = ui.diveSiteName->text().toUtf8().data();
+
+ if (get_dive_site_by_uuid(displayed_dive_site.uuid) != NULL)
+ currentDs = get_dive_site_by_uuid(displayed_dive_site.uuid);
+ else
+ currentDs = get_dive_site_by_uuid(create_dive_site_from_current_dive(uiString));
+
currentDs->latitude = displayed_dive_site.latitude;
currentDs->longitude = displayed_dive_site.longitude;
- uiString = ui.diveSiteName->text().toUtf8().data();
if (!same_string(uiString, currentDs->name)) {
free(currentDs->name);
currentDs->name = copy_string(uiString);
@@ -106,6 +112,7 @@ void LocationInformationWidget::acceptChanges()
LocationInformationModel::instance()->removeRow(get_divesite_idx(currentDs));
displayed_dive.dive_site_uuid = 0;
}
+ copy_dive_site(currentDs, &displayed_dive_site);
mark_divelist_changed(true);
resetState();
emit endRequestCoordinates();
@@ -238,14 +245,7 @@ void LocationManagementEditHelper::handleActivation(const QModelIndex& activated
/* if we are in 'recently added divesite mode, create a new divesite,
* and go to dive site edit edit mode. */
if (last_uuid == RECENTLY_ADDED_DIVESITE) {
- timestamp_t when;
- if (current_dive != NULL) {
- when = current_dive->when;
- } else {
- time_t now = time(0);
- when = utc_mktime(localtime(&now));
- }
- uint32_t ds_uuid = create_dive_site(qPrintable(activated.data().toString()), when);
+ uint32_t ds_uuid = create_dive_site_from_current_dive(qPrintable(activated.data().toString()));
qDebug() << "ds_uuid" << ds_uuid;
struct dive_site *ds = get_dive_site_by_uuid(ds_uuid);
copy_dive_site(ds, &displayed_dive_site);
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index 5f7e7da47..06bfca91c 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -76,6 +76,7 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
locationManagementEditHelper, &LocationManagementEditHelper::handleActivation);
ui.location->setCompleter(completer);
+ ui.editDiveSiteButton->setEnabled(true);
connect(ui.editDiveSiteButton, SIGNAL(clicked()), MainWindow::instance(), SIGNAL(startDiveSiteEdit()));
QAction *action = new QAction(tr("Apply changes"), this);
@@ -546,7 +547,7 @@ void MainTab::updateDiveInfo(bool clear)
if (ds)
copy_dive_site(ds, &displayed_dive_site);
}
- ui.editDiveSiteButton->setEnabled(ds);
+
if (ds) {
// construct the location tags
QString locationTag;
@@ -861,6 +862,14 @@ MainTab::EditMode MainTab::getEditMode() const
mydive->what = displayed_dive.what; \
}
+void MainTab::refreshDisplayedDiveSite()
+{
+ if (displayed_dive_site.uuid) {
+ copy_dive_site(get_dive_site_by_uuid(displayed_dive_site.uuid), &displayed_dive_site);
+ ui.location->setText(displayed_dive_site.name);
+ }
+}
+
void MainTab::updateDisplayedDiveSite()
{
const QString new_name = ui.location->text();
@@ -926,8 +935,11 @@ void MainTab::updateDiveSite(int divenr)
if (pickedUuid) {
qDebug() << "assign dive_site" << pickedUuid << "to current dive";
cd->dive_site_uuid = pickedUuid;
+ } else if (newUuid) {
+ // user created a new divesite
+ cd->dive_site_uuid = newUuid;
} else if (!newName.isEmpty()) {
- // user entered a name but didn't pick a dive site, so copy that data
+ // user entered a name but didn't pick or create a dive site, so create a divesite
uint32_t createdUuid = create_dive_site(displayed_dive_site.name, cd->when);
struct dive_site *newDs = get_dive_site_by_uuid(createdUuid);
copy_dive_site(&displayed_dive_site, newDs);
@@ -935,7 +947,7 @@ void MainTab::updateDiveSite(int divenr)
cd->dive_site_uuid = createdUuid;
qDebug() << "create a new dive site with name" << newName << "which is now named" << newDs->name << "and assign it as uuid" << createdUuid;
} else {
- qDebug() << "neither uuid nor name found";
+ qDebug() << "neither uuid picked, uuid created nor new name found";
}
} else {
qDebug() << "current dive had dive site with uuid" << origUuid;
diff --git a/qt-ui/maintab.h b/qt-ui/maintab.h
index eeb19a7c1..26dd3853e 100644
--- a/qt-ui/maintab.h
+++ b/qt-ui/maintab.h
@@ -52,6 +52,7 @@ public:
void initialUiSetup();
bool isEditing();
void updateCoordinatesText(qreal lat, qreal lon);
+ void refreshDisplayedDiveSite();
void nextInputField(QKeyEvent *event);
void showAndTriggerEditSelective(struct dive_components what);
virtual bool eventFilter(QObject*, QEvent*);
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index 945204e26..1d98f2b59 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -118,6 +118,9 @@ MainWindow::MainWindow() : QMainWindow(),
connect(diveSiteEdit, &LocationInformationWidget::endEditDiveSite,
mainTab, &MainTab::refreshDiveInfo);
+ connect(diveSiteEdit, &LocationInformationWidget::endEditDiveSite,
+ mainTab, &MainTab::refreshDisplayedDiveSite);
+
QWidget *diveSitePictures = new QWidget(); // Placeholder
std::pair<QByteArray, QVariant> enabled = std::make_pair("enabled", QVariant(true));