void QMLManager::deleteDive(int id) { struct dive *d = get_dive_by_uniq_id(id); if (!d) { qDebug() << "oops, trying to delete non-existing dive"; return; } // clean up (or create) the storage for the deleted dive and trip (if applicable) if (!deletedDive) deletedDive = alloc_dive(); else clear_dive(deletedDive); copy_dive(d, deletedDive); if (!deletedTrip) { deletedTrip = (struct dive_trip *)calloc(1, sizeof(struct dive_trip)); } else { free(deletedTrip->location); free(deletedTrip->notes); memset(deletedTrip, 0, sizeof(struct dive_trip)); } // if this is the last dive in that trip, remember the trip as well if (d->divetrip && d->divetrip->nrdives == 1) { *deletedTrip = *d->divetrip; deletedTrip->location = copy_string(d->divetrip->location); deletedTrip->notes = copy_string(d->divetrip->notes); deletedTrip->nrdives = 0; deletedDive->divetrip = deletedTrip; } DiveListModel::instance()->removeDiveById(id); delete_single_dive(get_idx_by_uniq_id(id)); changesNeedSaving(); }
void MainWindow::on_actionClose_triggered() { if (unsaved_changes() && (askSaveChanges() == FALSE)) return; /* free the dives and trips */ while (dive_table.nr) delete_single_dive(0); /* clear the selection and the statistics */ selected_dive = -1; //WARNING: Port this to Qt. //process_selected_dives(); ui->InfoWidget->clearStats(); ui->InfoWidget->clearInfo(); ui->InfoWidget->clearEquipment(); ui->InfoWidget->updateDiveInfo(-1); ui->ProfileWidget->clear(); ui->ListWidget->reload(DiveTripModel::TREE); ui->globe->reload(); setTitle(MWTF_DEFAULT); mark_divelist_changed(FALSE); clear_events(); }
void UndoDeleteDive::redo() { QList<struct dive*> newList; for (int i = 0; i < diveList.count(); i++) { // make a copy of the dive before deleting it struct dive* d = alloc_dive(); copy_dive(diveList.at(i), d); newList.append(d); // check for trip - if this is the last dive in the trip // the trip will get deleted, so we need to remember it as well if (d->divetrip && d->divetrip->nrdives == 1) { struct dive_trip *undo_trip = (struct dive_trip *)calloc(1, sizeof(struct dive_trip)); *undo_trip = *d->divetrip; undo_trip->location = copy_string(d->divetrip->location); undo_trip->notes = copy_string(d->divetrip->notes); undo_trip->nrdives = 0; undo_trip->next = NULL; undo_trip->dives = NULL; // update all the dives who were in this trip to point to the copy of the // trip that we are about to delete implicitly when deleting its last dive below Q_FOREACH(struct dive *inner_dive, newList) if (inner_dive->divetrip == d->divetrip) inner_dive->divetrip = undo_trip; d->divetrip = undo_trip; tripList.append(undo_trip); } //delete the dive delete_single_dive(get_divenr(diveList.at(i))); } mark_divelist_changed(true); MainWindow::instance()->refreshDisplay(); diveList.clear(); diveList = newList; }
void MainWindow::on_actionClose_triggered() { if (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING || ui.InfoWidget->isEditing()) { QMessageBox::warning(this, tr("Warning"), tr("Please save or cancel the current dive edit before closing the file.")); return; } if (unsaved_changes() && (askSaveChanges() == false)) return; ui.newProfile->setEmptyState(); /* free the dives and trips */ clear_git_id(); while (dive_table.nr) delete_single_dive(0); dive_list()->clearSelection(); /* clear the selection and the statistics */ selected_dive = -1; if (existing_filename) { free((void *)existing_filename); existing_filename = NULL; } cleanUpEmpty(); mark_divelist_changed(false); clear_events(); }
void UndoDeleteDive::redo() { QList<struct dive*> newList; for (int i = 0; i < diveList.count(); i++) { //make a copy of the dive before deleting it struct dive* d = alloc_dive(); copy_dive(diveList.at(i), d); newList.append(d); //delete the dive delete_single_dive(get_divenr(diveList.at(i))); } mark_divelist_changed(true); MainWindow::instance()->refreshDisplay(); diveList.clear(); diveList = newList; }
void MainWindow::closeCurrentFile() { ui.newProfile->setEmptyState(); /* free the dives and trips */ clear_git_id(); while (dive_table.nr) delete_single_dive(0); free((void *)existing_filename); existing_filename = NULL; cleanUpEmpty(); mark_divelist_changed(false); clear_events(); }
void MainWindow::on_actionClose_triggered() { if (unsaved_changes() && (askSaveChanges() == FALSE)) return; /* free the dives and trips */ while (dive_table.nr) delete_single_dive(0); /* clear the selection and the statistics */ selected_dive = -1; cleanUpEmpty(); mark_divelist_changed(FALSE); clear_events(); }
/* * This doesn't really report anything at all. We just sort the * dives, the GUI does the reporting */ void report_dives(gboolean is_imported, gboolean prefer_imported) { int i; int preexisting = dive_table.preexisting; struct dive *last; /* check if we need a nickname for the divecomputer for newly downloaded dives; * since we know they all came from the same divecomputer we just check for the * first one */ if (preexisting < dive_table.nr && dive_table.dives[preexisting]->downloaded) set_dc_nickname(dive_table.dives[preexisting]); else /* they aren't downloaded, so record / check all new ones */ for (i = preexisting; i < dive_table.nr; i++) set_dc_nickname(dive_table.dives[i]); /* This does the right thing for -1: NULL */ last = get_dive(preexisting-1); sort_table(&dive_table); for (i = 1; i < dive_table.nr; i++) { struct dive **pp = &dive_table.dives[i-1]; struct dive *prev = pp[0]; struct dive *dive = pp[1]; struct dive *merged; /* only try to merge overlapping dives - or if one of the dives has * zero duration (that might be a gps marker from the webservice) */ if (prev->duration.seconds && dive->duration.seconds && prev->when + prev->duration.seconds < dive->when) continue; merged = try_to_merge(prev, dive, prefer_imported); if (!merged) continue; /* careful - we might free the dive that last points to. Oops... */ if (last == prev || last == dive) last = merged; /* Redo the new 'i'th dive */ i--; add_single_dive(i, merged); delete_single_dive(i+1); delete_single_dive(i+1); } /* make sure no dives are still marked as downloaded */ for (i = 1; i < dive_table.nr; i++) dive_table.dives[i]->downloaded = FALSE; if (is_imported) { /* If there are dives in the table, are they numbered */ if (!last || last->number) try_to_renumber(last, preexisting); /* did we add dives to the dive table? */ if (preexisting != dive_table.nr) mark_divelist_changed(TRUE); } dive_list_update_dives(); }