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::setupForAddAndPlan(const char *model) { // clean out the dive and give it an id and the correct dc model clear_dive(&displayed_dive); displayed_dive.id = dive_getUniqID(&displayed_dive); displayed_dive.when = QDateTime::currentMSecsSinceEpoch() / 1000L + gettimezoneoffset() + 3600; displayed_dive.dc.model = model; // don't translate! this is stored in the XML file // setup the dive cylinders DivePlannerPointsModel::instance()->clear(); DivePlannerPointsModel::instance()->setupCylinders(); }