mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	Dive site rewrite: try to fix a crash
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
		
							parent
							
								
									2fec1a88de
								
							
						
					
					
						commit
						05c5bf0919
					
				
					 5 changed files with 41 additions and 8 deletions
				
			
		
							
								
								
									
										10
									
								
								divesite.c
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								divesite.c
									
										
									
									
									
								
							| 
						 | 
					@ -169,3 +169,13 @@ void copy_dive_site(struct dive_site *orig, struct dive_site *copy)
 | 
				
			||||||
	copy->notes = copy_string(orig->notes);
 | 
						copy->notes = copy_string(orig->notes);
 | 
				
			||||||
	copy->description = copy_string(orig->description);
 | 
						copy->description = copy_string(orig->description);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void clear_dive_site(struct dive_site *ds)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						free(ds->name);
 | 
				
			||||||
 | 
						free(ds->notes);
 | 
				
			||||||
 | 
						free(ds->description);
 | 
				
			||||||
 | 
						ds->latitude.udeg = 0;
 | 
				
			||||||
 | 
						ds->longitude.udeg = 0;
 | 
				
			||||||
 | 
						ds->uuid = 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -56,6 +56,7 @@ uint32_t get_dive_site_uuid_by_gps(degrees_t latitude, degrees_t longitude, stru
 | 
				
			||||||
uint32_t get_dive_site_uuid_by_gps_proximity(degrees_t latitude, degrees_t longitude, int distance, struct dive_site **dsp);
 | 
					uint32_t get_dive_site_uuid_by_gps_proximity(degrees_t latitude, degrees_t longitude, int distance, struct dive_site **dsp);
 | 
				
			||||||
bool dive_site_is_empty(struct dive_site *ds);
 | 
					bool dive_site_is_empty(struct dive_site *ds);
 | 
				
			||||||
void copy_dive_site(struct dive_site *orig, struct dive_site *copy);
 | 
					void copy_dive_site(struct dive_site *orig, struct dive_site *copy);
 | 
				
			||||||
 | 
					void clear_dive_site(struct dive_site *ds);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef __cplusplus
 | 
					#ifdef __cplusplus
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -229,7 +229,7 @@ void LocationInformationWidget::resetPallete()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SimpleDiveSiteEditDialog::SimpleDiveSiteEditDialog(QWidget *parent) :
 | 
					SimpleDiveSiteEditDialog::SimpleDiveSiteEditDialog(QWidget *parent) :
 | 
				
			||||||
	QDialog(parent,  Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::Popup),
 | 
						QDialog(parent,  Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::Popup),
 | 
				
			||||||
	ui(new Ui::SimpleDiveSiteEditDialog())
 | 
						ui(new Ui::SimpleDiveSiteEditDialog()), changed(false)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	ui->setupUi(this);
 | 
						ui->setupUi(this);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -262,31 +262,50 @@ void SimpleDiveSiteEditDialog::showEvent(QShowEvent *ev)
 | 
				
			||||||
	const char *gps_text = printGPSCoords(displayed_dive_site.latitude.udeg, displayed_dive_site.longitude.udeg);
 | 
						const char *gps_text = printGPSCoords(displayed_dive_site.latitude.udeg, displayed_dive_site.longitude.udeg);
 | 
				
			||||||
	ui->diveSiteCoordinates->setText(QString(gps_text));
 | 
						ui->diveSiteCoordinates->setText(QString(gps_text));
 | 
				
			||||||
	free( (void*) gps_text);
 | 
						free( (void*) gps_text);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						changed = false;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void SimpleDiveSiteEditDialog::on_diveSiteName_editingFinished()
 | 
					void SimpleDiveSiteEditDialog::on_diveSiteName_editingFinished()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						if (ui->diveSiteName->text() == displayed_dive_site.name)
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
	free(displayed_dive_site.name);
 | 
						free(displayed_dive_site.name);
 | 
				
			||||||
	displayed_dive_site.name = copy_string(qPrintable(ui->diveSiteName->text()));
 | 
						displayed_dive_site.name = copy_string(qPrintable(ui->diveSiteName->text()));
 | 
				
			||||||
 | 
						changed = true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void SimpleDiveSiteEditDialog::on_diveSiteCoordinates_editingFinished()
 | 
					void SimpleDiveSiteEditDialog::on_diveSiteCoordinates_editingFinished()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	double lat, lon;
 | 
						double lat, lon;
 | 
				
			||||||
 | 
						uint32_t uLat, uLon;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	parseGpsText(ui->diveSiteCoordinates->text(), &lat, &lon);
 | 
						parseGpsText(ui->diveSiteCoordinates->text(), &lat, &lon);
 | 
				
			||||||
	displayed_dive_site.latitude.udeg = lat * 1000000;
 | 
						uLat = lat * 1000000;
 | 
				
			||||||
	displayed_dive_site.longitude.udeg = lon * 1000000;
 | 
						uLon = lon * 1000000;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (uLat == displayed_dive_site.latitude.udeg && uLon == displayed_dive_site.longitude.udeg)
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						displayed_dive_site.latitude.udeg = uLat;
 | 
				
			||||||
 | 
						displayed_dive_site.longitude.udeg = uLon;
 | 
				
			||||||
 | 
						changed = true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void SimpleDiveSiteEditDialog::on_diveSiteDescription_editingFinished()
 | 
					void SimpleDiveSiteEditDialog::on_diveSiteDescription_editingFinished()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						if (ui->diveSiteDescription->text() == displayed_dive_site.description)
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
	free(displayed_dive_site.description);
 | 
						free(displayed_dive_site.description);
 | 
				
			||||||
	displayed_dive_site.description = copy_string(qPrintable(ui->diveSiteDescription->text()));
 | 
						displayed_dive_site.description = copy_string(qPrintable(ui->diveSiteDescription->text()));
 | 
				
			||||||
 | 
						changed = true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void SimpleDiveSiteEditDialog::on_diveSiteNotes_editingFinished()
 | 
					void SimpleDiveSiteEditDialog::on_diveSiteNotes_editingFinished()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						if (ui->diveSiteNotes->text() == displayed_dive_site.notes)
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
	free(displayed_dive_site.notes);
 | 
						free(displayed_dive_site.notes);
 | 
				
			||||||
	displayed_dive_site.notes = copy_string(qPrintable(ui->diveSiteNotes->text()));
 | 
						displayed_dive_site.notes = copy_string(qPrintable(ui->diveSiteNotes->text()));
 | 
				
			||||||
 | 
						changed = true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -51,6 +51,7 @@ Q_OBJECT
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
	SimpleDiveSiteEditDialog(QWidget *parent);
 | 
						SimpleDiveSiteEditDialog(QWidget *parent);
 | 
				
			||||||
	virtual ~SimpleDiveSiteEditDialog();
 | 
						virtual ~SimpleDiveSiteEditDialog();
 | 
				
			||||||
 | 
						bool changed;
 | 
				
			||||||
public slots:
 | 
					public slots:
 | 
				
			||||||
	void on_diveSiteName_editingFinished();
 | 
						void on_diveSiteName_editingFinished();
 | 
				
			||||||
	void on_diveSiteCoordinates_editingFinished();
 | 
						void on_diveSiteCoordinates_editingFinished();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -492,10 +492,15 @@ void MainTab::updateDiveInfo(bool clear)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!clear) {
 | 
						if (!clear) {
 | 
				
			||||||
		struct dive_site *ds = get_dive_site_by_uuid(displayed_dive.dive_site_uuid);
 | 
							struct dive_site *ds = get_dive_site_by_uuid(displayed_dive.dive_site_uuid);
 | 
				
			||||||
		if (ds)
 | 
							if (ds) {
 | 
				
			||||||
			ui.location->setText(ds->name);
 | 
								ui.location->setText(ds->name);
 | 
				
			||||||
		else
 | 
								ui.locationTags->setText(ds->description); // TODO: This should be three tags following davide's explanation.
 | 
				
			||||||
 | 
								copy_dive_site(get_dive_site_by_uuid(displayed_dive.dive_site_uuid), &displayed_dive_site);
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
			ui.location->clear();
 | 
								ui.location->clear();
 | 
				
			||||||
 | 
								clear_dive_site(&displayed_dive_site);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Subsurface always uses "local time" as in "whatever was the local time at the location"
 | 
							// Subsurface always uses "local time" as in "whatever was the local time at the location"
 | 
				
			||||||
		// so all time stamps have no time zone information and are in UTC
 | 
							// so all time stamps have no time zone information and are in UTC
 | 
				
			||||||
		QDateTime localTime = QDateTime::fromTime_t(displayed_dive.when - gettimezoneoffset(displayed_dive.when));
 | 
							QDateTime localTime = QDateTime::fromTime_t(displayed_dive.when - gettimezoneoffset(displayed_dive.when));
 | 
				
			||||||
| 
						 | 
					@ -698,13 +703,10 @@ void MainTab::updateDiveInfo(bool clear)
 | 
				
			||||||
				gasUsedString.append(QString("O2: %2\n").arg(get_volume_string(o2_tot, true)));
 | 
									gasUsedString.append(QString("O2: %2\n").arg(get_volume_string(o2_tot, true)));
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		ui.gasConsumption->setText(gasUsedString);
 | 
							ui.gasConsumption->setText(gasUsedString);
 | 
				
			||||||
		ui.locationTags->setText(ds->description); // TODO: This should be three tags following davide's explanation.
 | 
					 | 
				
			||||||
		if(ui.locationTags->text().isEmpty())
 | 
							if(ui.locationTags->text().isEmpty())
 | 
				
			||||||
			ui.locationTags->hide();
 | 
								ui.locationTags->hide();
 | 
				
			||||||
		else
 | 
							else
 | 
				
			||||||
			ui.locationTags->show();
 | 
								ui.locationTags->show();
 | 
				
			||||||
		copy_dive_site(get_dive_site_by_uuid(displayed_dive.dive_site_uuid), &displayed_dive_site);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		/* clear the fields */
 | 
							/* clear the fields */
 | 
				
			||||||
		clearInfo();
 | 
							clearInfo();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue