mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 14:25:27 +00:00
Dive site: implement purge of unused dive sites
Add a "purge unused dive sites" button to the dive site list. Connect it to a new PurgeUnusedDiveSites command. Implementation was trivial: simply copy the DeleteDiveSites command. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
fde80eeaa5
commit
8858bfa1f8
7 changed files with 59 additions and 0 deletions
|
@ -123,4 +123,9 @@ void mergeDiveSites(dive_site *ds, const QVector<dive_site *> &sites)
|
||||||
execute(new MergeDiveSites(ds, sites));
|
execute(new MergeDiveSites(ds, sites));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void purgeUnusedDiveSites()
|
||||||
|
{
|
||||||
|
execute(new PurgeUnusedDiveSites);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Command
|
} // namespace Command
|
||||||
|
|
|
@ -49,6 +49,7 @@ void editDiveSiteLocation(dive_site *ds, location_t value);
|
||||||
void editDiveSiteTaxonomy(dive_site *ds, taxonomy_data &value); // value is consumed (i.e. will be erased after call)!
|
void editDiveSiteTaxonomy(dive_site *ds, taxonomy_data &value); // value is consumed (i.e. will be erased after call)!
|
||||||
void addDiveSite(const QString &name);
|
void addDiveSite(const QString &name);
|
||||||
void mergeDiveSites(dive_site *ds, const QVector<dive_site *> &sites);
|
void mergeDiveSites(dive_site *ds, const QVector<dive_site *> &sites);
|
||||||
|
void purgeUnusedDiveSites();
|
||||||
|
|
||||||
} // namespace Command
|
} // namespace Command
|
||||||
|
|
||||||
|
|
|
@ -105,6 +105,31 @@ void DeleteDiveSites::undo()
|
||||||
sitesToRemove = std::move(addDiveSites(sitesToAdd));
|
sitesToRemove = std::move(addDiveSites(sitesToAdd));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PurgeUnusedDiveSites::PurgeUnusedDiveSites()
|
||||||
|
{
|
||||||
|
setText(tr("purge unused dive sites"));
|
||||||
|
for (int i = 0; i < dive_site_table.nr; ++i) {
|
||||||
|
dive_site *ds = dive_site_table.dive_sites[i];
|
||||||
|
if (ds->dives.nr == 0)
|
||||||
|
sitesToRemove.push_back(ds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PurgeUnusedDiveSites::workToBeDone()
|
||||||
|
{
|
||||||
|
return !sitesToRemove.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PurgeUnusedDiveSites::redo()
|
||||||
|
{
|
||||||
|
sitesToAdd = std::move(removeDiveSites(sitesToRemove));
|
||||||
|
}
|
||||||
|
|
||||||
|
void PurgeUnusedDiveSites::undo()
|
||||||
|
{
|
||||||
|
sitesToRemove = std::move(addDiveSites(sitesToAdd));
|
||||||
|
}
|
||||||
|
|
||||||
// Helper function: swap C and Qt string
|
// Helper function: swap C and Qt string
|
||||||
static void swap(char *&c, QString &q)
|
static void swap(char *&c, QString &q)
|
||||||
{
|
{
|
||||||
|
|
|
@ -43,6 +43,21 @@ private:
|
||||||
std::vector<OwningDiveSitePtr> sitesToAdd;
|
std::vector<OwningDiveSitePtr> sitesToAdd;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class PurgeUnusedDiveSites : public Base {
|
||||||
|
public:
|
||||||
|
PurgeUnusedDiveSites();
|
||||||
|
private:
|
||||||
|
bool workToBeDone() override;
|
||||||
|
void undo() override;
|
||||||
|
void redo() override;
|
||||||
|
|
||||||
|
// For redo
|
||||||
|
std::vector<dive_site *> sitesToRemove;
|
||||||
|
|
||||||
|
// For undo
|
||||||
|
std::vector<OwningDiveSitePtr> sitesToAdd;
|
||||||
|
};
|
||||||
|
|
||||||
class EditDiveSiteName : public Base {
|
class EditDiveSiteName : public Base {
|
||||||
public:
|
public:
|
||||||
EditDiveSiteName(dive_site *ds, const QString &name);
|
EditDiveSiteName(dive_site *ds, const QString &name);
|
||||||
|
|
|
@ -69,3 +69,8 @@ void TabDiveSite::diveSiteChanged(struct dive_site *ds, int field)
|
||||||
QModelIndex localIdx = model.mapFromSource(globalIdx);
|
QModelIndex localIdx = model.mapFromSource(globalIdx);
|
||||||
ui.diveSites->view()->scrollTo(localIdx);
|
ui.diveSites->view()->scrollTo(localIdx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TabDiveSite::on_purgeUnused_clicked()
|
||||||
|
{
|
||||||
|
Command::purgeUnusedDiveSites();
|
||||||
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ private slots:
|
||||||
void add();
|
void add();
|
||||||
void diveSiteAdded(struct dive_site *, int idx);
|
void diveSiteAdded(struct dive_site *, int idx);
|
||||||
void diveSiteChanged(struct dive_site *ds, int field);
|
void diveSiteChanged(struct dive_site *ds, int field);
|
||||||
|
void on_purgeUnused_clicked();
|
||||||
private:
|
private:
|
||||||
Ui::TabDiveSite ui;
|
Ui::TabDiveSite ui;
|
||||||
DiveSiteSortedModel model;
|
DiveSiteSortedModel model;
|
||||||
|
|
|
@ -14,6 +14,13 @@
|
||||||
<string>Dive sites</string>
|
<string>Dive sites</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QToolButton" name="purgeUnused">
|
||||||
|
<property name="text">
|
||||||
|
<string>Purge unused dive sites</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="TableView" name="diveSites" native="true"/>
|
<widget class="TableView" name="diveSites" native="true"/>
|
||||||
</item>
|
</item>
|
||||||
|
|
Loading…
Add table
Reference in a new issue