mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
Fix edit & show of divesites for new and existing dives.
The UI detects when it should refresh the loction after the user finished editting a divesite. Creating and editting divesites is now working even when the current dive is not saved yet. Signed-off-by: Sander Kleijwegt <sander@myowndomain.nl> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
954c30c4cf
commit
d22a135343
6 changed files with 43 additions and 13 deletions
13
divesite.c
13
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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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*);
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Reference in a new issue