mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
core: convert taxonomy.c to C++
Since the taxonomy is now a real C++ struct with constructor and destructor, dive_site has to be converted to C++ as well. A bit hairy for now, but will ultimately be distinctly simpler. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
3c1401785b
commit
3f8b4604be
39 changed files with 259 additions and 336 deletions
|
@ -125,7 +125,7 @@ DivesAndTripsToAdd DiveListBase::removeDives(DivesAndSitesToRemove &divesAndSite
|
|||
{
|
||||
std::vector<DiveToAdd> divesToAdd;
|
||||
std::vector<OwningTripPtr> tripsToAdd;
|
||||
std::vector<OwningDiveSitePtr> sitesToAdd;
|
||||
std::vector<std::unique_ptr<dive_site>> sitesToAdd;
|
||||
divesToAdd.reserve(divesAndSitesToDelete.dives.size());
|
||||
sitesToAdd.reserve(divesAndSitesToDelete.sites.size());
|
||||
|
||||
|
@ -216,7 +216,7 @@ DivesAndSitesToRemove DiveListBase::addDives(DivesAndTripsToAdd &toAdd)
|
|||
toAdd.trips.clear();
|
||||
|
||||
// Finally, add any necessary dive sites
|
||||
for (OwningDiveSitePtr &ds: toAdd.sites) {
|
||||
for (std::unique_ptr<dive_site> &ds: toAdd.sites) {
|
||||
sites.push_back(ds.get());
|
||||
int idx = register_dive_site(ds.release()); // Return ownership to backend
|
||||
emit diveListNotifier.diveSiteAdded(sites.back(), idx);
|
||||
|
|
|
@ -24,7 +24,7 @@ struct DiveToAdd {
|
|||
struct DivesAndTripsToAdd {
|
||||
std::vector<DiveToAdd> dives;
|
||||
std::vector<OwningTripPtr> trips;
|
||||
std::vector<OwningDiveSitePtr> sites;
|
||||
std::vector<std::unique_ptr<dive_site>> sites;
|
||||
};
|
||||
|
||||
// Dives and sites that have to be removed for a command
|
||||
|
@ -111,7 +111,7 @@ private:
|
|||
struct device_table devicesToAddAndRemove;
|
||||
|
||||
// For redo
|
||||
std::vector<OwningDiveSitePtr> sitesToAdd;
|
||||
std::vector<std::unique_ptr<dive_site>> sitesToAdd;
|
||||
std::vector<std::pair<std::string,FilterData>>
|
||||
filterPresetsToAdd;
|
||||
|
||||
|
|
|
@ -15,13 +15,13 @@ namespace Command {
|
|||
|
||||
// Add a set of dive sites to the core. The dives that were associated with
|
||||
// that dive site will be restored to that dive site.
|
||||
static std::vector<dive_site *> addDiveSites(std::vector<OwningDiveSitePtr> &sites)
|
||||
static std::vector<dive_site *> addDiveSites(std::vector<std::unique_ptr<dive_site>> &sites)
|
||||
{
|
||||
std::vector<dive_site *> res;
|
||||
QVector<dive *> changedDives;
|
||||
res.reserve(sites.size());
|
||||
|
||||
for (OwningDiveSitePtr &ds: sites) {
|
||||
for (std::unique_ptr<dive_site> &ds: sites) {
|
||||
// Readd the dives that belonged to this site
|
||||
for (int i = 0; i < ds->dives.nr; ++i) {
|
||||
// TODO: send dive site changed signal
|
||||
|
@ -47,9 +47,9 @@ static std::vector<dive_site *> addDiveSites(std::vector<OwningDiveSitePtr> &sit
|
|||
// Remove a set of dive sites. Get owning pointers to them. The dives are set to
|
||||
// being at no dive site, but the dive site will retain a list of dives, so
|
||||
// that the dives can be readded to the site on undo.
|
||||
static std::vector<OwningDiveSitePtr> removeDiveSites(std::vector<dive_site *> &sites)
|
||||
static std::vector<std::unique_ptr<dive_site>> removeDiveSites(std::vector<dive_site *> &sites)
|
||||
{
|
||||
std::vector<OwningDiveSitePtr> res;
|
||||
std::vector<std::unique_ptr<dive_site>> res;
|
||||
QVector<dive *> changedDives;
|
||||
res.reserve(sites.size());
|
||||
|
||||
|
@ -77,7 +77,7 @@ static std::vector<OwningDiveSitePtr> removeDiveSites(std::vector<dive_site *> &
|
|||
AddDiveSite::AddDiveSite(const QString &name)
|
||||
{
|
||||
setText(Command::Base::tr("add dive site"));
|
||||
sitesToAdd.emplace_back(alloc_dive_site());
|
||||
sitesToAdd.push_back(std::make_unique<dive_site>());
|
||||
sitesToAdd.back()->name = copy_qstring(name);
|
||||
}
|
||||
|
||||
|
@ -107,7 +107,7 @@ ImportDiveSites::ImportDiveSites(struct dive_site_table *sites, const QString &s
|
|||
// the same name. We might want to be smarter here and merge dive site data, etc.
|
||||
struct dive_site *old_ds = get_same_dive_site(new_ds);
|
||||
if (old_ds) {
|
||||
free_dive_site(new_ds);
|
||||
delete new_ds;
|
||||
continue;
|
||||
}
|
||||
sitesToAdd.emplace_back(new_ds);
|
||||
|
@ -256,20 +256,20 @@ void EditDiveSiteNotes::undo()
|
|||
}
|
||||
|
||||
EditDiveSiteCountry::EditDiveSiteCountry(dive_site *dsIn, const QString &country) : ds(dsIn),
|
||||
value(country)
|
||||
value(country.toStdString())
|
||||
{
|
||||
setText(Command::Base::tr("Edit dive site country"));
|
||||
}
|
||||
|
||||
bool EditDiveSiteCountry::workToBeDone()
|
||||
{
|
||||
return !same_string(qPrintable(value), taxonomy_get_country(&ds->taxonomy));
|
||||
return value == taxonomy_get_country(ds->taxonomy);
|
||||
}
|
||||
|
||||
void EditDiveSiteCountry::redo()
|
||||
{
|
||||
QString old = taxonomy_get_country(&ds->taxonomy);
|
||||
taxonomy_set_country(&ds->taxonomy, qPrintable(value), taxonomy_origin::GEOMANUAL);
|
||||
std::string old = taxonomy_get_country(ds->taxonomy);
|
||||
taxonomy_set_country(ds->taxonomy, value, taxonomy_origin::GEOMANUAL);
|
||||
value = old;
|
||||
emit diveListNotifier.diveSiteChanged(ds, LocationInformationModel::TAXONOMY); // Inform frontend of changed dive site.
|
||||
}
|
||||
|
@ -310,14 +310,11 @@ void EditDiveSiteLocation::undo()
|
|||
EditDiveSiteTaxonomy::EditDiveSiteTaxonomy(dive_site *dsIn, taxonomy_data &taxonomy) : ds(dsIn),
|
||||
value(taxonomy)
|
||||
{
|
||||
// We did a dumb copy. Erase the source to remove double references to strings.
|
||||
memset(&taxonomy, 0, sizeof(taxonomy));
|
||||
setText(Command::Base::tr("Edit dive site taxonomy"));
|
||||
}
|
||||
|
||||
EditDiveSiteTaxonomy::~EditDiveSiteTaxonomy()
|
||||
{
|
||||
free_taxonomy(&value);
|
||||
}
|
||||
|
||||
bool EditDiveSiteTaxonomy::workToBeDone()
|
||||
|
@ -364,7 +361,7 @@ void MergeDiveSites::redo()
|
|||
// The dives of the above dive sites were reset to no dive sites.
|
||||
// Add them to the merged-into dive site. Thankfully, we remember
|
||||
// the dives in the sitesToAdd vector.
|
||||
for (const OwningDiveSitePtr &site: sitesToAdd) {
|
||||
for (const std::unique_ptr<dive_site> &site: sitesToAdd) {
|
||||
for (int i = 0; i < site->dives.nr; ++i) {
|
||||
add_dive_to_dive_site(site->dives.dives[i], ds);
|
||||
divesChanged.push_back(site->dives.dives[i]);
|
||||
|
@ -380,7 +377,7 @@ void MergeDiveSites::undo()
|
|||
|
||||
// Before readding the dive sites, unregister the corresponding dives so that they can be
|
||||
// readded to their old dive sites.
|
||||
for (const OwningDiveSitePtr &site: sitesToAdd) {
|
||||
for (const std::unique_ptr<dive_site> &site: sitesToAdd) {
|
||||
for (int i = 0; i < site->dives.nr; ++i) {
|
||||
unregister_dive_from_dive_site(site->dives.dives[i]);
|
||||
divesChanged.push_back(site->dives.dives[i]);
|
||||
|
|
|
@ -31,7 +31,7 @@ private:
|
|||
std::vector<dive_site *> sitesToRemove;
|
||||
|
||||
// For redo
|
||||
std::vector<OwningDiveSitePtr> sitesToAdd;
|
||||
std::vector<std::unique_ptr<dive_site>> sitesToAdd;
|
||||
};
|
||||
|
||||
class ImportDiveSites : public Base {
|
||||
|
@ -47,7 +47,7 @@ private:
|
|||
std::vector<dive_site *> sitesToRemove;
|
||||
|
||||
// For redo
|
||||
std::vector<OwningDiveSitePtr> sitesToAdd;
|
||||
std::vector<std::unique_ptr<dive_site>> sitesToAdd;
|
||||
};
|
||||
|
||||
class DeleteDiveSites : public Base {
|
||||
|
@ -62,7 +62,7 @@ private:
|
|||
std::vector<dive_site *> sitesToRemove;
|
||||
|
||||
// For undo
|
||||
std::vector<OwningDiveSitePtr> sitesToAdd;
|
||||
std::vector<std::unique_ptr<dive_site>> sitesToAdd;
|
||||
};
|
||||
|
||||
class PurgeUnusedDiveSites : public Base {
|
||||
|
@ -77,7 +77,7 @@ private:
|
|||
std::vector<dive_site *> sitesToRemove;
|
||||
|
||||
// For undo
|
||||
std::vector<OwningDiveSitePtr> sitesToAdd;
|
||||
std::vector<std::unique_ptr<dive_site>> sitesToAdd;
|
||||
};
|
||||
|
||||
class EditDiveSiteName : public Base {
|
||||
|
@ -125,7 +125,7 @@ private:
|
|||
void redo() override;
|
||||
|
||||
dive_site *ds;
|
||||
QString value; // Value to be set
|
||||
std::string value; // Value to be set
|
||||
};
|
||||
|
||||
class EditDiveSiteLocation : public Base {
|
||||
|
@ -167,7 +167,7 @@ private:
|
|||
std::vector<dive_site *> sitesToRemove;
|
||||
|
||||
// For undo
|
||||
std::vector<OwningDiveSitePtr> sitesToAdd;
|
||||
std::vector<std::unique_ptr<dive_site>> sitesToAdd;
|
||||
};
|
||||
|
||||
class ApplyGPSFixes : public Base {
|
||||
|
@ -183,7 +183,7 @@ private:
|
|||
std::vector<dive_site *> sitesToRemove;
|
||||
|
||||
// For redo
|
||||
std::vector<OwningDiveSitePtr> sitesToAdd;
|
||||
std::vector<std::unique_ptr<dive_site>> sitesToAdd;
|
||||
|
||||
// For redo and undo
|
||||
struct SiteAndLocation {
|
||||
|
|
|
@ -376,7 +376,7 @@ void EditDiveSite::redo()
|
|||
|
||||
static struct dive_site *createDiveSite(const QString &name)
|
||||
{
|
||||
struct dive_site *ds = alloc_dive_site();
|
||||
struct dive_site *ds = new dive_site;
|
||||
struct dive_site *old = current_dive ? current_dive->dive_site : nullptr;
|
||||
if (old) {
|
||||
copy_dive_site(old, ds);
|
||||
|
|
|
@ -208,7 +208,7 @@ public:
|
|||
// deriving from it and hooks into undo() and redo() to add / remove the dive site.
|
||||
class EditDiveSiteNew : public EditDiveSite {
|
||||
public:
|
||||
OwningDiveSitePtr diveSiteToAdd;
|
||||
std::unique_ptr<dive_site> diveSiteToAdd;
|
||||
struct dive_site *diveSiteToRemove;
|
||||
EditDiveSiteNew(const QString &newName, bool currentDiveOnly);
|
||||
void undo() override;
|
||||
|
@ -470,7 +470,7 @@ private:
|
|||
int changedFields;
|
||||
|
||||
dive_site *siteToRemove;
|
||||
OwningDiveSitePtr siteToAdd;
|
||||
std::unique_ptr<dive_site> siteToAdd;
|
||||
|
||||
dive_site *siteToEdit;
|
||||
location_t dsLocation;
|
||||
|
|
|
@ -171,9 +171,8 @@ AddPictures::AddPictures(const std::vector<PictureListForAddition> &pictures) :
|
|||
if (!ds) {
|
||||
// This dive doesn't yet have a dive site -> add a new dive site.
|
||||
QString name = Command::Base::tr("unnamed dive site");
|
||||
dive_site *ds = alloc_dive_site_with_gps(qPrintable(name), &it->location);
|
||||
sitesToAdd.emplace_back(ds);
|
||||
sitesToSet.push_back({ p.d, ds });
|
||||
sitesToAdd.push_back(std::make_unique<dive_site>(qPrintable(name), &it->location));
|
||||
sitesToSet.push_back({ p.d, sitesToAdd.back().get() });
|
||||
} else if (!dive_site_has_gps_location(ds)) {
|
||||
// This dive has a dive site, but without coordinates. Let's add them.
|
||||
sitesToEdit.push_back({ ds, it->location });
|
||||
|
@ -228,7 +227,7 @@ void AddPictures::undo()
|
|||
void AddPictures::redo()
|
||||
{
|
||||
// Add dive sites
|
||||
for (OwningDiveSitePtr &siteToAdd: sitesToAdd) {
|
||||
for (std::unique_ptr<dive_site> &siteToAdd: sitesToAdd) {
|
||||
sitesToRemove.push_back(siteToAdd.get());
|
||||
int idx = register_dive_site(siteToAdd.release()); // Return ownership to backend.
|
||||
emit diveListNotifier.diveSiteAdded(sitesToRemove.back(), idx); // Inform frontend of new dive site.
|
||||
|
|
|
@ -48,7 +48,7 @@ private:
|
|||
location_t location;
|
||||
};
|
||||
std::vector<PictureListForAddition> picturesToAdd; // for redo
|
||||
std::vector<OwningDiveSitePtr> sitesToAdd; //for redo
|
||||
std::vector<std::unique_ptr<dive_site>> sitesToAdd; //for redo
|
||||
std::vector<PictureListForDeletion> picturesToRemove; // for undo
|
||||
std::vector<dive_site *> sitesToRemove; // for undo
|
||||
std::vector<DiveSiteEntry> sitesToSet; // for redo and undo
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue