mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
core: remove get_dive() function
This implicitly accessed the global divelog. Most of the users were in the test/ folder anyway. Replace by explicit accesses to the global divelog.dives. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
176f544106
commit
3660241993
8 changed files with 45 additions and 78 deletions
|
@ -2878,13 +2878,6 @@ depth_t gas_mnd(struct gasmix mix, depth_t end, const struct dive *dive, int rou
|
|||
return rounded_depth;
|
||||
}
|
||||
|
||||
struct dive *get_dive(int nr)
|
||||
{
|
||||
if (nr < 0 || static_cast<size_t>(nr) >= divelog.dives.size())
|
||||
return nullptr;
|
||||
return divelog.dives[nr].get();
|
||||
}
|
||||
|
||||
struct dive_site *get_dive_site_for_dive(const struct dive *dive)
|
||||
{
|
||||
return dive->dive_site;
|
||||
|
|
|
@ -138,7 +138,6 @@ extern int mbar_to_depth(int mbar, const struct dive *dive);
|
|||
extern depth_t gas_mod(struct gasmix mix, pressure_t po2_limit, const struct dive *dive, int roundto);
|
||||
extern depth_t gas_mnd(struct gasmix mix, depth_t end, const struct dive *dive, int roundto);
|
||||
|
||||
extern struct dive *get_dive(int nr);
|
||||
extern struct dive_site *get_dive_site_for_dive(const struct dive *dive);
|
||||
extern std::string get_dive_country(const struct dive *dive);
|
||||
extern std::string get_dive_location(const struct dive *dive);
|
||||
|
|
|
@ -1090,28 +1090,28 @@ int get_authorship(git_repository *repo, git_signature **authorp)
|
|||
static void create_commit_message(struct membuffer *msg, bool create_empty)
|
||||
{
|
||||
int nr = static_cast<int>(divelog.dives.size());
|
||||
struct dive *dive = get_dive(nr-1);
|
||||
std::string changes_made = get_changes_made();
|
||||
|
||||
if (create_empty) {
|
||||
put_string(msg, "Initial commit to create empty repo.\n\n");
|
||||
} else if (!changes_made.empty()) {
|
||||
put_format(msg, "Changes made: \n\n%s\n", changes_made.c_str());
|
||||
} else if (dive) {
|
||||
dive_trip *trip = dive->divetrip;
|
||||
std::string location = get_dive_location(dive);
|
||||
} else if (!divelog.dives.empty()) {
|
||||
const struct dive &dive = *divelog.dives.back();
|
||||
dive_trip *trip = dive.divetrip;
|
||||
std::string location = get_dive_location(&dive);
|
||||
if (location.empty())
|
||||
location = "no location";
|
||||
const char *sep = "\n";
|
||||
|
||||
if (dive->number)
|
||||
nr = dive->number;
|
||||
if (dive.number)
|
||||
nr = dive.number;
|
||||
|
||||
put_format(msg, "dive %d: %s", nr, location.c_str());
|
||||
if (trip && !trip->location.empty() && location != trip->location)
|
||||
put_format(msg, " (%s)", trip->location.c_str());
|
||||
put_format(msg, "\n");
|
||||
for (auto &dc: dive->dcs) {
|
||||
for (auto &dc: dive.dcs) {
|
||||
if (!dc.model.empty()) {
|
||||
put_format(msg, "%s%s", sep, dc.model.c_str());
|
||||
sep = ", ";
|
||||
|
|
|
@ -94,8 +94,8 @@ void MapWidget::selectedDivesChanged(const QList<int> &list)
|
|||
std::vector<dive *> selection;
|
||||
selection.reserve(list.size());
|
||||
for (int idx: list) {
|
||||
if (dive *d = get_dive(idx))
|
||||
selection.push_back(d);
|
||||
if (idx >= 0 && static_cast<size_t>(idx) < divelog.dives.size())
|
||||
selection.push_back(divelog.dives[idx].get());
|
||||
}
|
||||
setSelection(std::move(selection), current_dive, -1);
|
||||
}
|
||||
|
|
|
@ -19,26 +19,17 @@ void TestAirPressure::initTestCase()
|
|||
|
||||
void TestAirPressure::get_dives()
|
||||
{
|
||||
struct dive *dive;
|
||||
verbose = 1;
|
||||
|
||||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/TestAtmPress.xml", &divelog), 0);
|
||||
dive = get_dive(0);
|
||||
dive->selected = true;
|
||||
QVERIFY(dive != NULL);
|
||||
QVERIFY(divelog.dives.size() >= 1);
|
||||
}
|
||||
|
||||
void TestAirPressure::testReadAirPressure()
|
||||
{
|
||||
struct dive *dive;
|
||||
dive = get_dive(0);
|
||||
QVERIFY(dive != NULL);
|
||||
dive->selected = true;
|
||||
QCOMPARE(1012, dive->surface_pressure.mbar);
|
||||
dive = get_dive(1);
|
||||
QVERIFY(dive != NULL);
|
||||
dive->selected = true;
|
||||
QCOMPARE(991, dive->surface_pressure.mbar);
|
||||
QVERIFY(divelog.dives.size() >= 2);
|
||||
QCOMPARE(1012, divelog.dives[0]->surface_pressure.mbar);
|
||||
QCOMPARE(991, divelog.dives[1]->surface_pressure.mbar);
|
||||
}
|
||||
|
||||
void TestAirPressure::testConvertAltitudetoAirPressure()
|
||||
|
@ -49,19 +40,14 @@ void TestAirPressure::testConvertAltitudetoAirPressure()
|
|||
|
||||
void TestAirPressure::testWriteReadBackAirPressure()
|
||||
{
|
||||
struct dive *dive;
|
||||
int32_t ap = 1111;
|
||||
dive = get_dive(0);
|
||||
QVERIFY(dive != NULL);
|
||||
dive->selected = true;
|
||||
dive->surface_pressure.mbar = ap;
|
||||
QVERIFY(divelog.dives.size() >= 1);
|
||||
divelog.dives[0]->surface_pressure.mbar = ap;
|
||||
QCOMPARE(save_dives("./testout.ssrf"), 0);
|
||||
clear_dive_file_data();
|
||||
QCOMPARE(parse_file("./testout.ssrf", &divelog), 0);
|
||||
dive = get_dive(0);
|
||||
QVERIFY(dive != NULL);
|
||||
dive->selected = true;
|
||||
QCOMPARE(ap, dive->surface_pressure.mbar);
|
||||
QVERIFY(divelog.dives.size() >= 1);
|
||||
QCOMPARE(ap, divelog.dives[0]->surface_pressure.mbar);
|
||||
}
|
||||
|
||||
QTEST_GUILESS_MAIN(TestAirPressure)
|
||||
|
|
|
@ -362,8 +362,8 @@ void TestGitStorage::testGitStorageCloudMerge2()
|
|||
// (1) open repo, delete second dive, save offline
|
||||
QCOMPARE(parse_file(cloudTestRepo.c_str(), &divelog), 0);
|
||||
divelog.process_loaded_dives();
|
||||
struct dive *dive = get_dive(1);
|
||||
divelog.delete_multiple_dives(std::vector<struct dive *>{ dive });
|
||||
QVERIFY(divelog.dives.size() >= 2);
|
||||
divelog.delete_multiple_dives(std::vector<struct dive *>{ divelog.dives[1].get() });
|
||||
QCOMPARE(save_dives("./SampleDivesMinus1.ssrf"), 0);
|
||||
git_local_only = true;
|
||||
QCOMPARE(save_dives(localCacheRepo.c_str()), 0);
|
||||
|
@ -375,10 +375,9 @@ void TestGitStorage::testGitStorageCloudMerge2()
|
|||
|
||||
// (3) now we open the cloud storage repo and modify that second dive
|
||||
QCOMPARE(parse_file(cloudTestRepo.c_str(), &divelog), 0);
|
||||
QVERIFY(divelog.dives.size() >= 2);
|
||||
divelog.process_loaded_dives();
|
||||
dive = get_dive(1);
|
||||
QVERIFY(dive != NULL);
|
||||
dive->notes = "These notes have been modified by TestGitStorage";
|
||||
divelog.dives[1]->notes = "These notes have been modified by TestGitStorage";
|
||||
QCOMPARE(save_dives(cloudTestRepo.c_str()), 0);
|
||||
clear_dive_file_data();
|
||||
|
||||
|
@ -410,25 +409,20 @@ void TestGitStorage::testGitStorageCloudMerge3()
|
|||
// (1) open repo, edit notes of first three dives
|
||||
QCOMPARE(parse_file(cloudTestRepo.c_str(), &divelog), 0);
|
||||
divelog.process_loaded_dives();
|
||||
struct dive *dive;
|
||||
QVERIFY((dive = get_dive(0)) != 0);
|
||||
dive->notes = "Create multi line dive notes\nLine 2\nLine 3\nLine 4\nLine 5\nThat should be enough";
|
||||
QVERIFY((dive = get_dive(1)) != 0);
|
||||
dive->notes = "Create multi line dive notes\nLine 2\nLine 3\nLine 4\nLine 5\nThat should be enough";
|
||||
QVERIFY((dive = get_dive(2)) != 0);
|
||||
dive->notes = "Create multi line dive notes\nLine 2\nLine 3\nLine 4\nLine 5\nThat should be enough";
|
||||
QVERIFY(divelog.dives.size() >= 3);
|
||||
divelog.dives[0]->notes = "Create multi line dive notes\nLine 2\nLine 3\nLine 4\nLine 5\nThat should be enough";
|
||||
divelog.dives[1]->notes = "Create multi line dive notes\nLine 2\nLine 3\nLine 4\nLine 5\nThat should be enough";
|
||||
divelog.dives[2]->notes = "Create multi line dive notes\nLine 2\nLine 3\nLine 4\nLine 5\nThat should be enough";
|
||||
QCOMPARE(save_dives(cloudTestRepo.c_str()), 0);
|
||||
clear_dive_file_data();
|
||||
|
||||
// (2) make different edits offline
|
||||
QCOMPARE(parse_file(cloudTestRepo.c_str(), &divelog), 0);
|
||||
divelog.process_loaded_dives();
|
||||
QVERIFY((dive = get_dive(0)) != 0);
|
||||
dive->notes = "Create multi line dive notes\nDifferent line 2 and removed 3-5\n\nThat should be enough";
|
||||
QVERIFY((dive = get_dive(1)) != 0);
|
||||
dive->notes = "Line 2\nLine 3\nLine 4\nLine 5"; // keep the middle, remove first and last");
|
||||
QVERIFY((dive = get_dive(2)) != 0);
|
||||
dive->notes = "single line dive notes";
|
||||
QVERIFY(divelog.dives.size() >= 3);
|
||||
divelog.dives[0]->notes = "Create multi line dive notes\nDifferent line 2 and removed 3-5\n\nThat should be enough";
|
||||
divelog.dives[1]->notes = "Line 2\nLine 3\nLine 4\nLine 5"; // keep the middle, remove first and last");
|
||||
divelog.dives[2]->notes = "single line dive notes";
|
||||
git_local_only = true;
|
||||
QCOMPARE(save_dives(cloudTestRepo.c_str()), 0);
|
||||
git_local_only = false;
|
||||
|
@ -439,12 +433,10 @@ void TestGitStorage::testGitStorageCloudMerge3()
|
|||
moveDir(localCacheDir, localCacheDir + "save");
|
||||
QCOMPARE(parse_file(cloudTestRepo.c_str(), &divelog), 0);
|
||||
divelog.process_loaded_dives();
|
||||
QVERIFY((dive = get_dive(0)) != 0);
|
||||
dive->notes = "Completely different dive notes\nBut also multi line";
|
||||
QVERIFY((dive = get_dive(1)) != 0);
|
||||
dive->notes = "single line dive notes";
|
||||
QVERIFY((dive = get_dive(2)) != 0);
|
||||
dive->notes = "Line 2\nLine 3\nLine 4\nLine 5"; // keep the middle, remove first and last");
|
||||
QVERIFY(divelog.dives.size() >= 3);
|
||||
divelog.dives[0]->notes = "Completely different dive notes\nBut also multi line";
|
||||
divelog.dives[1]->notes = "single line dive notes";
|
||||
divelog.dives[2]->notes = "Line 2\nLine 3\nLine 4\nLine 5"; // keep the middle, remove first and last");
|
||||
QCOMPARE(save_dives(cloudTestRepo.c_str()), 0);
|
||||
clear_dive_file_data();
|
||||
|
||||
|
|
|
@ -27,29 +27,29 @@ void TestPicture::addPicture()
|
|||
verbose = 1;
|
||||
|
||||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test44.xml", &divelog), 0);
|
||||
struct dive *dive = get_dive(0);
|
||||
QVERIFY(divelog.dives.size() >= 1);
|
||||
struct dive &dive = *divelog.dives[0];
|
||||
// Pictures will be added to selected dives
|
||||
dive->selected = true;
|
||||
QVERIFY(dive != NULL);
|
||||
dive.selected = true;
|
||||
// So far no picture in dive
|
||||
QVERIFY(dive->pictures.size() == 0);
|
||||
QVERIFY(dive.pictures.size() == 0);
|
||||
|
||||
{
|
||||
auto [pic1, dive1] = create_picture(SUBSURFACE_TEST_DATA "/dives/images/wreck.jpg", 0, false);
|
||||
auto [pic2, dive2] = create_picture(SUBSURFACE_TEST_DATA "/dives/images/data_after_EOI.jpg", 0, false);
|
||||
QVERIFY(pic1);
|
||||
QVERIFY(pic2);
|
||||
QVERIFY(dive1 == dive);
|
||||
QVERIFY(dive2 == dive);
|
||||
QVERIFY(dive1 == &dive);
|
||||
QVERIFY(dive2 == &dive);
|
||||
|
||||
add_picture(dive->pictures, std::move(*pic1));
|
||||
add_picture(dive->pictures, std::move(*pic2));
|
||||
add_picture(dive.pictures, std::move(*pic1));
|
||||
add_picture(dive.pictures, std::move(*pic2));
|
||||
}
|
||||
|
||||
// Now there are two pictures
|
||||
QVERIFY(dive->pictures.size() == 2);
|
||||
const picture &pic1 = dive->pictures[0];
|
||||
const picture &pic2 = dive->pictures[1];
|
||||
QVERIFY(dive.pictures.size() == 2);
|
||||
const picture &pic1 = dive.pictures[0];
|
||||
const picture &pic2 = dive.pictures[1];
|
||||
// 1st appearing at time 21:01
|
||||
// 2nd appearing at time 22:01
|
||||
QVERIFY(pic1.offset.seconds == 1261);
|
||||
|
|
|
@ -30,10 +30,7 @@ void TestRenumber::testMergeAndAppend()
|
|||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47c.xml", &log), 0);
|
||||
divelog.add_imported_dives(log, import_flags::merge_all_trips);
|
||||
QCOMPARE(divelog.dives.size(), 2);
|
||||
struct dive *d = get_dive(1);
|
||||
QVERIFY(d != NULL);
|
||||
if (d)
|
||||
QCOMPARE(d->number, 2);
|
||||
QCOMPARE(divelog.dives[1]->number, 2);
|
||||
}
|
||||
|
||||
QTEST_GUILESS_MAIN(TestRenumber)
|
||||
|
|
Loading…
Add table
Reference in a new issue