void DivePlannerPointsModel::createPlan(bool replanCopy) { // Ok, so, here the diveplan creates a dive struct deco_state *cache = NULL; bool oldRecalc = setRecalc(false); removeDeco(); createTemporaryPlan(); setRecalc(oldRecalc); //TODO: C-based function here? struct decostop stoptable[60]; plan(&diveplan, &displayed_dive, DECOTIMESTEP, stoptable, &cache, isPlanner(), true); free(cache); if (!current_dive || displayed_dive.id != current_dive->id) { // we were planning a new dive, not re-planning an existing on record_dive(clone_dive(&displayed_dive)); } else if (current_dive && displayed_dive.id == current_dive->id) { // we are replanning a dive - make sure changes are reflected // correctly in the dive structure and copy it back into the dive table displayed_dive.maxdepth.mm = 0; displayed_dive.dc.maxdepth.mm = 0; fixup_dive(&displayed_dive); // Try to identify old planner output and remove only this part // Treat user provided text as plain text. QTextDocument notesDocument; notesDocument.setHtml(current_dive->notes); QString oldnotes(notesDocument.toPlainText()); int disclaimerPosition = oldnotes.indexOf(disclaimer); if (disclaimerPosition == 0) oldnotes.clear(); else if (disclaimerPosition >= 1) oldnotes.truncate(disclaimerPosition-1); // Deal with line breaks oldnotes.replace("\n", "<br>"); oldnotes.append(displayed_dive.notes); displayed_dive.notes = strdup(oldnotes.toUtf8().data()); // If we save as new create a copy of the dive here if (replanCopy) { struct dive *copy = alloc_dive(); copy_dive(current_dive, copy); copy->id = 0; copy->selected = false; copy->divetrip = NULL; if (current_dive->divetrip) add_dive_to_trip(copy, current_dive->divetrip); record_dive(copy); } copy_dive(&displayed_dive, current_dive); } mark_divelist_changed(true); // Remove and clean the diveplan, so we don't delete // the dive by mistake. free_dps(&diveplan); setPlanMode(NOTHING); planCreated(); }
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 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 DivePictureModel::removePicture(const QString &fileUrl) { dive_remove_picture(fileUrl.toUtf8().data()); copy_dive(current_dive, &displayed_dive); updateDivePictures(); mark_divelist_changed(true); }
void DivePlannerPointsModel::createPlan() { // Ok, so, here the diveplan creates a dive char *cache = NULL; bool oldRecalc = plannerModel->setRecalc(false); removeDeco(); createTemporaryPlan(); plannerModel->setRecalc(oldRecalc); //TODO: C-based function here? plan(&diveplan, &cache, isPlanner(), true); if (!current_dive || displayed_dive.id != current_dive->id) { // we were planning a new dive, not re-planning an existing on record_dive(clone_dive(&displayed_dive)); } else if (current_dive && displayed_dive.id == current_dive->id) { // we are replanning a dive - make sure changes are reflected // correctly in the dive structure and copy it back into the dive table fixup_dive(&displayed_dive); copy_dive(&displayed_dive, current_dive); } mark_divelist_changed(true); // Remove and clean the diveplan, so we don't delete // the dive by mistake. free_dps(&diveplan); setPlanMode(NOTHING); planCreated(); }
void DivePlannerPointsModel::createPlan(bool replanCopy) { // Ok, so, here the diveplan creates a dive char *cache = NULL; bool oldRecalc = setRecalc(false); removeDeco(); createTemporaryPlan(); setRecalc(oldRecalc); //TODO: C-based function here? bool did_deco = plan(&diveplan, &cache, isPlanner(), true); free(cache); if (!current_dive || displayed_dive.id != current_dive->id) { // we were planning a new dive, not re-planning an existing on record_dive(clone_dive(&displayed_dive)); } else if (current_dive && displayed_dive.id == current_dive->id) { // we are replanning a dive - make sure changes are reflected // correctly in the dive structure and copy it back into the dive table displayed_dive.maxdepth.mm = 0; displayed_dive.dc.maxdepth.mm = 0; fixup_dive(&displayed_dive); if (replanCopy) { struct dive *copy = alloc_dive(); copy_dive(current_dive, copy); copy->id = 0; copy->selected = false; copy->divetrip = NULL; if (current_dive->divetrip) add_dive_to_trip(copy, current_dive->divetrip); record_dive(copy); QString oldnotes(current_dive->notes); if (oldnotes.indexOf(QString(disclaimer)) >= 0) oldnotes.truncate(oldnotes.indexOf(QString(disclaimer))); if (did_deco) oldnotes.append(displayed_dive.notes); displayed_dive.notes = strdup(oldnotes.toUtf8().data()); } copy_dive(&displayed_dive, current_dive); } mark_divelist_changed(true); // Remove and clean the diveplan, so we don't delete // the dive by mistake. free_dps(&diveplan); setPlanMode(NOTHING); planCreated(); }
void DivePlannerPointsModel::computeVariations() { bool oldRecalc = setRecalc(false); struct dive *dive = alloc_dive(); copy_dive(&displayed_dive, dive); struct decostop original[60], deeper[60], shallower[60], shorter[60], longer[60]; struct deco_state *cache = NULL, *save = NULL; struct diveplan plan_copy; struct divedatapoint *last_segment; if(in_planner() && prefs.display_variations) { cache_deco_state(&save); cloneDiveplan(&plan_copy); plan(&plan_copy, dive, 1, original, &cache, true, false); free_dps(&plan_copy); restore_deco_state(save, false); last_segment = cloneDiveplan(&plan_copy); last_segment->depth.mm += 1000; last_segment->next->depth.mm += 1000; plan(&plan_copy, dive, 1, deeper, &cache, true, false); free_dps(&plan_copy); restore_deco_state(save, false); last_segment = cloneDiveplan(&plan_copy); last_segment->depth.mm -= 1000; last_segment->next->depth.mm -= 1000; plan(&plan_copy, dive, 1, shallower, &cache, true, false); free_dps(&plan_copy); restore_deco_state(save, false); last_segment = cloneDiveplan(&plan_copy); last_segment->next->time += 60; plan(&plan_copy, dive, 1, longer, &cache, true, false); free_dps(&plan_copy); restore_deco_state(save, false); last_segment = cloneDiveplan(&plan_copy); last_segment->next->time -= 60; plan(&plan_copy, dive, 1, shorter, &cache, true, false); free_dps(&plan_copy); restore_deco_state(save, false); #ifdef SHOWSTOPVARIATIONS printf("\n\n"); #endif QString notes(displayed_dive.notes); free(displayed_dive.notes); char buf[200]; sprintf(buf, "+ %d:%02d /m + %d:%02d /min", FRACTION(analyzeVariations(shallower, original, deeper, "m"),60), FRACTION(analyzeVariations(shorter, original, longer, "min"), 60)); displayed_dive.notes = strdup(notes.replace("VARIATIONS", QString(buf)).toUtf8().data()); } setRecalc(oldRecalc); }
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; }