mirror of
https://github.com/subsurface/subsurface.git
synced 2024-12-02 23:20:20 +00:00
core: move freestanding functions into divelog class
There were only two of them, from the time C-code had to access the divelog: clear_divelog() and delete_single_dive(). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
90d5bab4e9
commit
6e352d5281
9 changed files with 16 additions and 22 deletions
|
@ -976,7 +976,7 @@ void add_imported_dives(struct divelog *import_log, int flags)
|
||||||
/* Remove old dives */
|
/* Remove old dives */
|
||||||
for (i = 0; i < dives_to_remove.nr; i++) {
|
for (i = 0; i < dives_to_remove.nr; i++) {
|
||||||
idx = get_divenr(dives_to_remove.dives[i]);
|
idx = get_divenr(dives_to_remove.dives[i]);
|
||||||
delete_single_dive(&divelog, idx);
|
divelog.delete_single_dive(idx);
|
||||||
}
|
}
|
||||||
dives_to_remove.nr = 0;
|
dives_to_remove.nr = 0;
|
||||||
|
|
||||||
|
@ -1272,7 +1272,7 @@ void clear_dive_file_data()
|
||||||
select_single_dive(NULL); // This is propagated up to the UI and clears all the information.
|
select_single_dive(NULL); // This is propagated up to the UI and clears all the information.
|
||||||
|
|
||||||
current_dive = NULL;
|
current_dive = NULL;
|
||||||
clear_divelog(&divelog);
|
divelog.clear();
|
||||||
|
|
||||||
clear_event_types();
|
clear_event_types();
|
||||||
|
|
||||||
|
|
|
@ -62,22 +62,22 @@ struct divelog &divelog::operator=(divelog &&log)
|
||||||
|
|
||||||
/* this implements the mechanics of removing the dive from the
|
/* this implements the mechanics of removing the dive from the
|
||||||
* dive log and the trip, but doesn't deal with updating dive trips, etc */
|
* dive log and the trip, but doesn't deal with updating dive trips, etc */
|
||||||
void delete_single_dive(struct divelog *log, int idx)
|
void divelog::delete_single_dive(int idx)
|
||||||
{
|
{
|
||||||
if (idx < 0 || idx > log->dives->nr) {
|
if (idx < 0 || idx > dives->nr) {
|
||||||
report_info("Warning: deleting unexisting dive with index %d", idx);
|
report_info("Warning: deleting unexisting dive with index %d", idx);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
struct dive *dive = log->dives->dives[idx];
|
struct dive *dive = dives->dives[idx];
|
||||||
remove_dive_from_trip(dive, log->trips);
|
remove_dive_from_trip(dive, trips);
|
||||||
unregister_dive_from_dive_site(dive);
|
unregister_dive_from_dive_site(dive);
|
||||||
delete_dive_from_table(log->dives, idx);
|
delete_dive_from_table(dives, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void divelog::clear()
|
void divelog::clear()
|
||||||
{
|
{
|
||||||
while (dives->nr > 0)
|
while (dives->nr > 0)
|
||||||
delete_single_dive(this, dives->nr - 1);
|
delete_single_dive(dives->nr - 1);
|
||||||
sites->clear();
|
sites->clear();
|
||||||
if (trips->nr != 0) {
|
if (trips->nr != 0) {
|
||||||
report_info("Warning: trip table not empty in divelog::clear()!");
|
report_info("Warning: trip table not empty in divelog::clear()!");
|
||||||
|
@ -86,8 +86,3 @@ void divelog::clear()
|
||||||
clear_device_table(devices);
|
clear_device_table(devices);
|
||||||
filter_presets->clear();
|
filter_presets->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear_divelog(struct divelog *log)
|
|
||||||
{
|
|
||||||
log->clear();
|
|
||||||
}
|
|
||||||
|
|
|
@ -18,16 +18,15 @@ struct divelog {
|
||||||
struct device_table *devices;
|
struct device_table *devices;
|
||||||
struct filter_preset_table *filter_presets;
|
struct filter_preset_table *filter_presets;
|
||||||
bool autogroup;
|
bool autogroup;
|
||||||
void clear();
|
|
||||||
divelog();
|
divelog();
|
||||||
~divelog();
|
~divelog();
|
||||||
divelog(divelog &&log); // move constructor (argument is consumed).
|
divelog(divelog &&log); // move constructor (argument is consumed).
|
||||||
divelog &operator=(divelog &&log); // move assignment (argument is consumed).
|
divelog &operator=(divelog &&log); // move assignment (argument is consumed).
|
||||||
|
void delete_single_dive(int idx);
|
||||||
|
void clear();
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct divelog divelog;
|
extern struct divelog divelog;
|
||||||
|
|
||||||
void clear_divelog(struct divelog *);
|
|
||||||
extern void delete_single_dive(struct divelog *, int idx);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -97,7 +97,7 @@ void DownloadThread::run()
|
||||||
|
|
||||||
report_info("Starting download from %s", qPrintable(getTransportString(transports)));
|
report_info("Starting download from %s", qPrintable(getTransportString(transports)));
|
||||||
report_info("downloading %s dives", internalData->force_download ? "all" : "only new");
|
report_info("downloading %s dives", internalData->force_download ? "all" : "only new");
|
||||||
clear_divelog(&log);
|
log.clear();
|
||||||
|
|
||||||
Q_ASSERT(internalData->log != nullptr);
|
Q_ASSERT(internalData->log != nullptr);
|
||||||
std::string errorText;
|
std::string errorText;
|
||||||
|
|
|
@ -116,7 +116,7 @@ Qt::ItemFlags DiveImportedModel::flags(const QModelIndex &index) const
|
||||||
void DiveImportedModel::clearTable()
|
void DiveImportedModel::clearTable()
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
clear_divelog(&log);
|
log.clear();
|
||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -106,7 +106,7 @@ int main(int argc, char **argv)
|
||||||
if (!quit)
|
if (!quit)
|
||||||
run_ui();
|
run_ui();
|
||||||
exit_ui();
|
exit_ui();
|
||||||
clear_divelog(&divelog);
|
divelog.clear();
|
||||||
parse_xml_exit();
|
parse_xml_exit();
|
||||||
subsurface_console_exit();
|
subsurface_console_exit();
|
||||||
|
|
||||||
|
|
|
@ -109,7 +109,7 @@ int main(int argc, char **argv)
|
||||||
printf("No log files given, not saving dive data.\n");
|
printf("No log files given, not saving dive data.\n");
|
||||||
printf("Give a log file name as argument, or configure a cloud URL.\n");
|
printf("Give a log file name as argument, or configure a cloud URL.\n");
|
||||||
}
|
}
|
||||||
clear_divelog(&divelog);
|
divelog.clear();
|
||||||
parse_xml_exit();
|
parse_xml_exit();
|
||||||
|
|
||||||
// Sync struct preferences to disk
|
// Sync struct preferences to disk
|
||||||
|
|
|
@ -92,7 +92,7 @@ int main(int argc, char **argv)
|
||||||
if (!quit)
|
if (!quit)
|
||||||
run_mobile_ui(initial_font_size);
|
run_mobile_ui(initial_font_size);
|
||||||
exit_ui();
|
exit_ui();
|
||||||
clear_divelog(&divelog);
|
divelog.clear();
|
||||||
parse_xml_exit();
|
parse_xml_exit();
|
||||||
subsurface_console_exit();
|
subsurface_console_exit();
|
||||||
|
|
||||||
|
|
|
@ -363,7 +363,7 @@ void TestGitStorage::testGitStorageCloudMerge2()
|
||||||
QCOMPARE(parse_file(cloudTestRepo.c_str(), &divelog), 0);
|
QCOMPARE(parse_file(cloudTestRepo.c_str(), &divelog), 0);
|
||||||
process_loaded_dives();
|
process_loaded_dives();
|
||||||
struct dive *dive = get_dive(1);
|
struct dive *dive = get_dive(1);
|
||||||
delete_single_dive(&divelog, 1);
|
divelog.delete_single_dive(1);
|
||||||
QCOMPARE(save_dives("./SampleDivesMinus1.ssrf"), 0);
|
QCOMPARE(save_dives("./SampleDivesMinus1.ssrf"), 0);
|
||||||
git_local_only = true;
|
git_local_only = true;
|
||||||
QCOMPARE(save_dives(localCacheRepo.c_str()), 0);
|
QCOMPARE(save_dives(localCacheRepo.c_str()), 0);
|
||||||
|
|
Loading…
Reference in a new issue