mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	Cleanup: Improve the Use of 'Planned dive' and 'Manually added dive'.
- standardise the naming; - use it consistently; - apply the 'samples < 50' only when putting manually added dives into edit mode - everywhere else manually added dives should be treated as such; - do not show a warning before editing a manually added dive in planner. Signed-off-by: Michael Keller <github@ike.ch>
This commit is contained in:
		
							parent
							
								
									ecc6f64d10
								
							
						
					
					
						commit
						1aa5438b2d
					
				
					 10 changed files with 47 additions and 34 deletions
				
			
		|  | @ -2309,8 +2309,8 @@ static int likely_same_dive(const struct dive *a, const struct dive *b) | |||
| 	int match, fuzz = 20 * 60; | ||||
| 
 | ||||
| 	/* don't merge manually added dives with anything */ | ||||
| 	if (is_manually_added_dc(&a->dc) || | ||||
| 	    is_manually_added_dc(&b->dc)) | ||||
| 	if (is_dc_manually_added_dive(&a->dc) || | ||||
| 	    is_dc_manually_added_dive(&b->dc)) | ||||
| 		return 0; | ||||
| 
 | ||||
| 	/*
 | ||||
|  | @ -3244,11 +3244,11 @@ extern "C" int depth_to_mbar(int depth, const struct dive *dive) | |||
| 
 | ||||
| extern "C" double depth_to_mbarf(int depth, const struct dive *dive) | ||||
| { | ||||
| 	// To downloaded and planned dives, use DC's values
 | ||||
| 	// For downloaded and planned dives, use DC's values
 | ||||
| 	int salinity = dive->dc.salinity; | ||||
| 	pressure_t surface_pressure = dive->dc.surface_pressure; | ||||
| 
 | ||||
| 	if (is_manually_added_dc(&dive->dc)) { // To manual dives, salinity and pressure in another place...
 | ||||
| 	if (is_dc_manually_added_dive(&dive->dc)) { // For manual dives, salinity and pressure in another place...
 | ||||
| 		surface_pressure = dive->surface_pressure; | ||||
| 		salinity = dive->user_salinity; | ||||
| 	} | ||||
|  | @ -3271,8 +3271,8 @@ extern "C" double depth_to_atm(int depth, const struct dive *dive) | |||
|  * take care of this, but the Uemis we support natively */ | ||||
| extern "C" int rel_mbar_to_depth(int mbar, const struct dive *dive) | ||||
| { | ||||
| 	// To downloaded and planned dives, use DC's salinity. Manual dives, use user's salinity
 | ||||
| 	int salinity = is_manually_added_dc(&dive->dc) ? dive->user_salinity : dive->dc.salinity; | ||||
| 	// For downloaded and planned dives, use DC's salinity. Manual dives, use user's salinity
 | ||||
| 	int salinity = is_dc_manually_added_dive(&dive->dc) ? dive->user_salinity : dive->dc.salinity; | ||||
| 	if (!salinity) | ||||
| 		salinity = SEAWATER_SALINITY; | ||||
| 
 | ||||
|  | @ -3283,8 +3283,8 @@ extern "C" int rel_mbar_to_depth(int mbar, const struct dive *dive) | |||
| 
 | ||||
| extern "C" int mbar_to_depth(int mbar, const struct dive *dive) | ||||
| { | ||||
| 	// To downloaded and planned dives, use DC's pressure. Manual dives, use user's pressure
 | ||||
| 	pressure_t surface_pressure = is_manually_added_dc(&dive->dc) | ||||
| 	// For downloaded and planned dives, use DC's pressure. Manual dives, use user's pressure
 | ||||
| 	pressure_t surface_pressure = is_dc_manually_added_dive(&dive->dc) | ||||
| 		? dive->surface_pressure | ||||
| 		: dive->dc.surface_pressure; | ||||
| 
 | ||||
|  |  | |||
|  | @ -492,11 +492,6 @@ void add_extra_data(struct divecomputer *dc, const char *key, const char *value) | |||
| 	} | ||||
| } | ||||
| 
 | ||||
| bool is_dc_planner(const struct divecomputer *dc) | ||||
| { | ||||
| 	return same_string(dc->model, "planned dive"); | ||||
| } | ||||
| 
 | ||||
| /*
 | ||||
|  * Match two dive computer entries against each other, and | ||||
|  * tell if it's the same dive. Return 0 if "don't know", | ||||
|  | @ -548,14 +543,27 @@ void free_dc(struct divecomputer *dc) | |||
| 	free(dc); | ||||
| } | ||||
| 
 | ||||
| static const char *manual_dc_name = "manually added dive"; | ||||
| bool is_manually_added_dc(const struct divecomputer *dc) | ||||
| static const char *planner_dc_name = "planned dive"; | ||||
| 
 | ||||
| bool is_dc_planner(const struct divecomputer *dc) | ||||
| { | ||||
| 	return dc && dc->samples <= 50 && | ||||
| 	       same_string(dc->model, manual_dc_name); | ||||
| 	return dc && same_string(dc->model, planner_dc_name); | ||||
| } | ||||
| 
 | ||||
| void make_manually_added_dc(struct divecomputer *dc) | ||||
| void make_planner_dc(struct divecomputer *dc) | ||||
| { | ||||
| 	free((void *)dc->model); | ||||
| 	dc->model = strdup(planner_dc_name); | ||||
| } | ||||
| 
 | ||||
| const char *manual_dc_name = "manually added dive"; | ||||
| 
 | ||||
| bool is_dc_manually_added_dive(const struct divecomputer *dc) | ||||
| { | ||||
| 	return dc && same_string(dc->model, manual_dc_name); | ||||
| } | ||||
| 
 | ||||
| void make_manually_added_dive_dc(struct divecomputer *dc) | ||||
| { | ||||
| 	free((void *)dc->model); | ||||
| 	dc->model = strdup(manual_dc_name); | ||||
|  |  | |||
|  | @ -67,10 +67,12 @@ extern void add_event_to_dc(struct divecomputer *dc, struct event *ev); | |||
| extern struct event *add_event(struct divecomputer *dc, unsigned int time, int type, int flags, int value, const char *name); | ||||
| extern void remove_event_from_dc(struct divecomputer *dc, struct event *event); | ||||
| extern void add_extra_data(struct divecomputer *dc, const char *key, const char *value); | ||||
| extern bool is_dc_planner(const struct divecomputer *dc); | ||||
| extern uint32_t calculate_string_hash(const char *str); | ||||
| extern bool is_manually_added_dc(const struct divecomputer *dc); | ||||
| extern void make_manually_added_dc(struct divecomputer *dc); | ||||
| extern bool is_dc_planner(const struct divecomputer *dc); | ||||
| extern void make_planner_dc(struct divecomputer *dc); | ||||
| extern const char *manual_dc_name; | ||||
| extern bool is_dc_manually_added_dive(const struct divecomputer *dc); | ||||
| extern void make_manually_added_dive_dc(struct divecomputer *dc); | ||||
| 
 | ||||
| /* Check if two dive computer entries are the exact same dive (-1=no/0=maybe/1=yes) */ | ||||
| extern int match_one_dc(const struct divecomputer *a, const struct divecomputer *b); | ||||
|  |  | |||
|  | @ -665,8 +665,10 @@ void MainWindow::on_actionReplanDive_triggered() | |||
| { | ||||
| 	if (!plannerStateClean() || !current_dive || !userMayChangeAppState()) | ||||
| 		return; | ||||
| 	else if (!is_dc_planner(get_dive_dc(current_dive, profile->dc))) { | ||||
| 		if (QMessageBox::warning(this, tr("Warning"), tr("Trying to replan a dive dive profile that is not a dive plan."), | ||||
| 
 | ||||
| 	const struct divecomputer *dc = get_dive_dc(current_dive, profile->dc); | ||||
| 	if (!(is_dc_planner(dc) || is_dc_manually_added_dive(dc))) { | ||||
| 		if (QMessageBox::warning(this, tr("Warning"), tr("Trying to replan a dive profile that has not been manually added."), | ||||
| 					 QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Cancel) | ||||
| 					return; | ||||
| 	} | ||||
|  | @ -707,7 +709,7 @@ void MainWindow::on_actionAddDive_triggered() | |||
| 	d.dc.duration.seconds = 40 * 60; | ||||
| 	d.dc.maxdepth.mm = M_OR_FT(15, 45); | ||||
| 	d.dc.meandepth.mm = M_OR_FT(13, 39); // this creates a resonable looking safety stop
 | ||||
| 	make_manually_added_dc(&d.dc); | ||||
| 	make_manually_added_dive_dc(&d.dc); | ||||
| 	fake_dc(&d.dc); | ||||
| 	fixup_dive(&d); | ||||
| 
 | ||||
|  |  | |||
|  | @ -210,7 +210,7 @@ void ProfileWidget::plotDive(dive *dIn, int dcIn) | |||
| 	if (d && !editedDive && | ||||
| 	    DivePlannerPointsModel::instance()->currentMode() == DivePlannerPointsModel::NOTHING) { | ||||
| 		struct divecomputer *comp = get_dive_dc(d, dc); | ||||
| 		if (comp && is_manually_added_dc(comp) && comp->samples) | ||||
| 		if (comp && is_dc_manually_added_dive(comp) && comp->samples && comp->samples <= 50) | ||||
| 			editDive(); | ||||
| 	} | ||||
| 
 | ||||
|  |  | |||
|  | @ -254,7 +254,7 @@ void TabDiveNotes::updateData(const std::vector<dive *> &, dive *currentDive, in | |||
| 		ui.LocationLabel->setText(tr("Location")); | ||||
| 		ui.NotesLabel->setText(tr("Notes")); | ||||
| 		ui.tagWidget->setText(QString::fromStdString(taglist_get_tagstring(currentDive->tag_list))); | ||||
| 		bool isManual = is_manually_added_dc(¤tDive->dc); | ||||
| 		bool isManual = is_dc_manually_added_dive(¤tDive->dc); | ||||
| 		ui.depth->setVisible(isManual); | ||||
| 		ui.depthLabel->setVisible(isManual); | ||||
| 		ui.duration->setVisible(isManual); | ||||
|  |  | |||
|  | @ -1135,7 +1135,7 @@ bool QMLManager::checkDuration(struct dive *d, QString duration) | |||
| 			m = m6.captured(1).toInt(); | ||||
| 		} | ||||
| 		d->dc.duration.seconds = d->duration.seconds = h * 3600 + m * 60 + s; | ||||
| 		if (is_manually_added_dc(&d->dc)) | ||||
| 		if (is_dc_manually_added_dive(&d->dc)) | ||||
| 			free_samples(&d->dc); | ||||
| 		else | ||||
| 			appendTextToLog("Cannot change the duration on a dive that wasn't manually added"); | ||||
|  | @ -1153,7 +1153,7 @@ bool QMLManager::checkDepth(dive *d, QString depth) | |||
| 		// the depth <= 500m
 | ||||
| 		if (0 <= depthValue && depthValue <= 500000) { | ||||
| 			d->maxdepth.mm = depthValue; | ||||
| 			if (is_manually_added_dc(&d->dc)) { | ||||
| 			if (is_dc_manually_added_dive(&d->dc)) { | ||||
| 				d->dc.maxdepth.mm = d->maxdepth.mm; | ||||
| 				free_samples(&d->dc); | ||||
| 			} | ||||
|  | @ -1359,7 +1359,7 @@ void QMLManager::commitChanges(QString diveId, QString number, QString date, QSt | |||
| 	if (diveChanged) { | ||||
| 		if (d->maxdepth.mm == d->dc.maxdepth.mm && | ||||
| 		    d->maxdepth.mm > 0 && | ||||
| 		    is_manually_added_dc(&d->dc) && | ||||
| 		    is_dc_manually_added_dive(&d->dc) && | ||||
| 		    d->dc.samples == 0) { | ||||
| 			// so we have depth > 0, a manually added dive and no samples
 | ||||
| 			// let's create an actual profile so the desktop version can work it
 | ||||
|  | @ -1736,7 +1736,7 @@ int QMLManager::addDive() | |||
| 	d.dc.duration.seconds = 40 * 60; | ||||
| 	d.dc.maxdepth.mm = M_OR_FT(15, 45); | ||||
| 	d.dc.meandepth.mm = M_OR_FT(13, 39); // this creates a resonable looking safety stop
 | ||||
| 	make_manually_added_dc(&d.dc); | ||||
| 	make_manually_added_dive_dc(&d.dc); | ||||
| 	fake_dc(&d.dc); | ||||
| 	fixup_dive(&d); | ||||
| 
 | ||||
|  |  | |||
|  | @ -8,6 +8,7 @@ | |||
| #include "divetextitem.h" | ||||
| #include "tankitem.h" | ||||
| #include "core/device.h" | ||||
| #include "core/divecomputer.h" | ||||
| #include "core/event.h" | ||||
| #include "core/pref.h" | ||||
| #include "core/profile.h" | ||||
|  | @ -579,9 +580,9 @@ void ProfileScene::plotDive(const struct dive *dIn, int dcIn, DivePlannerPointsM | |||
| 	} | ||||
| 
 | ||||
| 	QString dcText = get_dc_nickname(currentdc); | ||||
| 	if (dcText == "planned dive") | ||||
| 	if (is_dc_planner(currentdc)) | ||||
| 		dcText = tr("Planned dive"); | ||||
| 	else if (dcText == "manually added dive") | ||||
| 	else if (is_dc_manually_added_dive(currentdc)) | ||||
| 		dcText = tr("Manually added dive"); | ||||
| 	else if (dcText.isEmpty()) | ||||
| 		dcText = tr("Unknown dive computer"); | ||||
|  |  | |||
|  | @ -69,7 +69,7 @@ void DivePlannerPointsModel::createSimpleDive(struct dive *dIn) | |||
| 	clear_dive(d); | ||||
| 	d->id = dive_getUniqID(); | ||||
| 	d->when = QDateTime::currentMSecsSinceEpoch() / 1000L + gettimezoneoffset() + 3600; | ||||
| 	d->dc.model = strdup("planned dive"); // don't translate! this is stored in the XML file
 | ||||
| 	make_planner_dc(&d->dc); | ||||
| 
 | ||||
| 	clear(); | ||||
| 	removeDeco(); | ||||
|  |  | |||
|  | @ -824,7 +824,7 @@ static dc_status_t prepare_data(int data_model, char *serial, dc_family_t dc_fam | |||
| 	dev_data->device = NULL; | ||||
| 	dev_data->context = NULL; | ||||
| 	if (!data_model) { | ||||
| 		dev_data->model = copy_string("manually added dive"); | ||||
| 		dev_data->model = copy_string(manual_dc_name); | ||||
| 		dev_data->descriptor = NULL; | ||||
| 		return DC_STATUS_NODEVICE; | ||||
| 	} | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue