mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 18:23:23 +00:00
code cleanup: add empty table structures
It seemed to make sense to combine all three types in one commit. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
70cabb968c
commit
e1cd055111
13 changed files with 47 additions and 41 deletions
|
@ -469,10 +469,10 @@ ImportDives::ImportDives(struct dive_table *dives, struct trip_table *trips, str
|
|||
// this only matters if undoit were called before redoit
|
||||
currentDive = nullptr;
|
||||
|
||||
struct dive_table dives_to_add = { 0, 0, 0 };
|
||||
struct dive_table dives_to_remove = { 0, 0, 0 };
|
||||
struct trip_table trips_to_add = { 0, 0, 0 };
|
||||
struct dive_site_table sites_to_add = { 0, 0, 0 };
|
||||
struct dive_table dives_to_add = empty_dive_table;
|
||||
struct dive_table dives_to_remove = empty_dive_table;
|
||||
struct trip_table trips_to_add = empty_trip_table;
|
||||
struct dive_site_table sites_to_add = empty_dive_site_table;
|
||||
process_imported_dives(dives, trips, sites, flags, &dives_to_add, &dives_to_remove, &trips_to_add, &sites_to_add);
|
||||
|
||||
// Add trips to the divesToAdd.trips structure
|
||||
|
|
|
@ -133,6 +133,8 @@ typedef struct dive_table {
|
|||
struct dive **dives;
|
||||
} dive_table_t;
|
||||
|
||||
static const dive_table_t empty_dive_table = { 0, 0, (struct dive **)0 };
|
||||
|
||||
struct picture;
|
||||
struct dive_site;
|
||||
struct dive_site_table;
|
||||
|
|
|
@ -992,10 +992,10 @@ static bool merge_dive_tables(struct dive_table *dives_from, struct dive_table *
|
|||
void add_imported_dives(struct dive_table *import_table, struct trip_table *import_trip_table, struct dive_site_table *import_sites_table, int flags)
|
||||
{
|
||||
int i, idx;
|
||||
struct dive_table dives_to_add = { 0 };
|
||||
struct dive_table dives_to_remove = { 0 };
|
||||
struct trip_table trips_to_add = { 0 };
|
||||
struct dive_site_table dive_sites_to_add = { 0 };
|
||||
struct dive_table dives_to_add = empty_dive_table;
|
||||
struct dive_table dives_to_remove = empty_dive_table;
|
||||
struct trip_table trips_to_add = empty_trip_table;
|
||||
struct dive_site_table dive_sites_to_add = empty_dive_site_table;
|
||||
|
||||
/* Process imported dives and generate lists of dives
|
||||
* to-be-added and to-be-removed */
|
||||
|
@ -1121,7 +1121,7 @@ void process_imported_dives(struct dive_table *import_table, struct trip_table *
|
|||
/* If the caller didn't pass an import_trip_table because all
|
||||
* dives are tripless, provide a local table. This may be
|
||||
* necessary if the trips are autogrouped */
|
||||
struct trip_table local_trip_table = { 0 };
|
||||
struct trip_table local_trip_table = empty_trip_table;
|
||||
if (!import_trip_table)
|
||||
import_trip_table = &local_trip_table;
|
||||
|
||||
|
|
|
@ -31,6 +31,8 @@ typedef struct dive_site_table {
|
|||
struct dive_site **dive_sites;
|
||||
} dive_site_table_t;
|
||||
|
||||
static const dive_site_table_t empty_dive_site_table = { 0, 0, (struct dive_site **)0 };
|
||||
|
||||
extern struct dive_site_table dive_site_table;
|
||||
|
||||
static inline struct dive_site *get_dive_site(int nr, struct dive_site_table *ds_table)
|
||||
|
|
|
@ -24,6 +24,8 @@ typedef struct trip_table {
|
|||
struct dive_trip **trips;
|
||||
} trip_table_t;
|
||||
|
||||
static const trip_table_t empty_trip_table = { 0, 0, (struct dive_trip **)0 };
|
||||
|
||||
extern void add_dive_to_trip(struct dive *, dive_trip_t *);
|
||||
extern struct dive_trip *unregister_dive_from_trip(struct dive *dive);
|
||||
extern void remove_dive_from_trip(struct dive *dive, struct trip_table *trip_table_arg);
|
||||
|
|
|
@ -904,9 +904,9 @@ int DiveLogImportDialog::parseTxtHeader(QString fileName, char **params, int pnr
|
|||
|
||||
void DiveLogImportDialog::on_buttonBox_accepted()
|
||||
{
|
||||
struct dive_table table = { 0 };
|
||||
struct trip_table trips = { 0 };
|
||||
struct dive_site_table sites = { 0 };
|
||||
struct dive_table table = empty_dive_table;
|
||||
struct trip_table trips = empty_trip_table;
|
||||
struct dive_site_table sites = empty_dive_site_table;
|
||||
QStringList r = resultModel->result();
|
||||
if (ui->knownImports->currentText() != "Manual import") {
|
||||
for (int i = 0; i < fileNames.size(); ++i) {
|
||||
|
|
|
@ -65,7 +65,7 @@ void DivesiteImportDialog::on_cancel_clicked()
|
|||
void DivesiteImportDialog::on_ok_clicked()
|
||||
{
|
||||
// delete non-selected dive sites
|
||||
struct dive_site_table selectedSites = { 0 };
|
||||
struct dive_site_table selectedSites = empty_dive_site_table;
|
||||
for (int i = 0; i < importedSites.nr; i++)
|
||||
if (divesiteImportedModel->data(divesiteImportedModel->index(i, 0), Qt::CheckStateRole) == Qt::Checked) {
|
||||
struct dive_site *newSite = alloc_dive_site();
|
||||
|
|
|
@ -1662,9 +1662,9 @@ void MainWindow::importFiles(const QStringList fileNames)
|
|||
return;
|
||||
|
||||
QByteArray fileNamePtr;
|
||||
struct dive_table table = { 0 };
|
||||
struct trip_table trips = { 0 };
|
||||
struct dive_site_table sites = { 0 };
|
||||
struct dive_table table = empty_dive_table;
|
||||
struct trip_table trips = empty_trip_table;
|
||||
struct dive_site_table sites = empty_dive_site_table;
|
||||
|
||||
for (int i = 0; i < fileNames.size(); ++i) {
|
||||
fileNamePtr = QFile::encodeName(fileNames.at(i));
|
||||
|
@ -1757,9 +1757,9 @@ void MainWindow::on_actionImportDiveSites_triggered()
|
|||
return;
|
||||
updateLastUsedDir(QFileInfo(fileNames[0]).dir().path());
|
||||
|
||||
struct dive_table table = { 0 };
|
||||
struct trip_table trips = { 0 };
|
||||
struct dive_site_table sites = { 0 };
|
||||
struct dive_table table = empty_dive_table;
|
||||
struct trip_table trips = empty_trip_table;
|
||||
struct dive_site_table sites = empty_dive_site_table;
|
||||
|
||||
for (const QString &s: fileNames) {
|
||||
QByteArray fileNamePtr = QFile::encodeName(s);
|
||||
|
|
|
@ -453,9 +453,9 @@ void DivelogsDeWebServices::buttonClicked(QAbstractButton *button)
|
|||
break;
|
||||
}
|
||||
/* parse file and import dives */
|
||||
struct dive_table table = { 0 };
|
||||
struct trip_table trips = { 0 };
|
||||
struct dive_site_table sites = { 0 };
|
||||
struct dive_table table = empty_dive_table;
|
||||
struct trip_table trips = empty_trip_table;
|
||||
struct dive_site_table sites = empty_dive_site_table;
|
||||
parse_file(QFile::encodeName(zipFile.fileName()), &table, &trips, &sites);
|
||||
Command::importDives(&table, &trips, &sites, IMPORT_MERGE_ALL_TRIPS, QStringLiteral("divelogs.de"));
|
||||
|
||||
|
|
|
@ -380,9 +380,9 @@ void QMLManager::updateAllGlobalLists()
|
|||
void QMLManager::mergeLocalRepo()
|
||||
{
|
||||
char *filename = NOCLOUD_LOCALSTORAGE;
|
||||
struct dive_table table = { 0 };
|
||||
struct trip_table trips = { 0 };
|
||||
struct dive_site_table sites = { 0 };
|
||||
struct dive_table table = empty_dive_table;
|
||||
struct trip_table trips = empty_trip_table;
|
||||
struct dive_site_table sites = empty_dive_site_table;
|
||||
parse_file(filename, &table, &trips, &sites);
|
||||
add_imported_dives(&table, &trips, &sites, IMPORT_MERGE_ALL_TRIPS);
|
||||
}
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
#include "core/divelist.h"
|
||||
|
||||
DiveImportedModel::DiveImportedModel(QObject *o) : QAbstractTableModel(o),
|
||||
diveTable({ 0 }),
|
||||
sitesTable({ 0 })
|
||||
diveTable(empty_dive_table),
|
||||
sitesTable(empty_dive_site_table)
|
||||
{
|
||||
connect(&thread, &QThread::finished, this, &DiveImportedModel::downloadThreadFinished);
|
||||
}
|
||||
|
@ -147,8 +147,8 @@ std::pair<struct dive_table, struct dive_site_table> DiveImportedModel::consumeT
|
|||
beginResetModel();
|
||||
|
||||
// Move tables to result
|
||||
struct dive_table dives = { 0 };
|
||||
struct dive_site_table sites = { 0 };
|
||||
struct dive_table dives = empty_dive_table;
|
||||
struct dive_site_table sites = empty_dive_site_table;
|
||||
move_dive_table(&diveTable, &dives);
|
||||
move_dive_site_table(&sitesTable, &sites);
|
||||
|
||||
|
|
|
@ -21,9 +21,9 @@ void TestMerge::testMergeEmpty()
|
|||
/*
|
||||
* check that we correctly merge mixed cylinder dives
|
||||
*/
|
||||
struct dive_table table = { 0 };
|
||||
struct trip_table trips = { 0 };
|
||||
struct dive_site_table sites = { 0 };
|
||||
struct dive_table table = empty_dive_table;
|
||||
struct trip_table trips = empty_trip_table;
|
||||
struct dive_site_table sites = empty_dive_site_table;
|
||||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &table, &trips, &sites), 0);
|
||||
add_imported_dives(&table, &trips, &sites, IMPORT_MERGE_ALL_TRIPS);
|
||||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test48.xml", &table, &trips, &sites), 0);
|
||||
|
@ -47,9 +47,9 @@ void TestMerge::testMergeBackwards()
|
|||
/*
|
||||
* check that we correctly merge mixed cylinder dives
|
||||
*/
|
||||
struct dive_table table = { 0 };
|
||||
struct trip_table trips = { 0 };
|
||||
struct dive_site_table sites = { 0 };
|
||||
struct dive_table table = empty_dive_table;
|
||||
struct trip_table trips = empty_trip_table;
|
||||
struct dive_site_table sites = empty_dive_site_table;
|
||||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test48.xml", &table, &trips, &sites), 0);
|
||||
add_imported_dives(&table, &trips, &sites, IMPORT_MERGE_ALL_TRIPS);
|
||||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &table, &trips, &sites), 0);
|
||||
|
|
|
@ -13,9 +13,9 @@ void TestRenumber::setup()
|
|||
|
||||
void TestRenumber::testMerge()
|
||||
{
|
||||
struct dive_table table = { 0 };
|
||||
struct trip_table trips = { 0 };
|
||||
struct dive_site_table sites = { 0 };
|
||||
struct dive_table table = empty_dive_table;
|
||||
struct trip_table trips = empty_trip_table;
|
||||
struct dive_site_table sites = empty_dive_site_table;
|
||||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47b.xml", &table, &trips, &sites), 0);
|
||||
add_imported_dives(&table, &trips, &sites, IMPORT_MERGE_ALL_TRIPS);
|
||||
QCOMPARE(dive_table.nr, 1);
|
||||
|
@ -25,9 +25,9 @@ void TestRenumber::testMerge()
|
|||
|
||||
void TestRenumber::testMergeAndAppend()
|
||||
{
|
||||
struct dive_table table = { 0 };
|
||||
struct trip_table trips = { 0 };
|
||||
struct dive_site_table sites = { 0 };
|
||||
struct dive_table table = empty_dive_table;
|
||||
struct trip_table trips = empty_trip_table;
|
||||
struct dive_site_table sites = empty_dive_site_table;
|
||||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47c.xml", &table, &trips, &sites), 0);
|
||||
add_imported_dives(&table, &trips, &sites, IMPORT_MERGE_ALL_TRIPS);
|
||||
QCOMPARE(dive_table.nr, 2);
|
||||
|
|
Loading…
Add table
Reference in a new issue