mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
Undo: update cylinder and weight models on paste
When pasting (or undoing paste) the cylinders or weights may change. Send the appropriate signals and update the models accordingly. Currently, this means copying from current dive to displayed dive, but hopefully we can get rid of "displayed_dive" in the not so distant future. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
9ed5cf16a4
commit
9fd87fa080
8 changed files with 52 additions and 5 deletions
15
core/dive.c
15
core/dive.c
|
@ -649,6 +649,15 @@ struct dive *clone_dive(struct dive *s)
|
|||
if (what._component) \
|
||||
d->_component = copy_string(s->_component)
|
||||
|
||||
void copy_weights(const struct dive *s, struct dive *d)
|
||||
{
|
||||
for (int i = 0; i < MAX_WEIGHTSYSTEMS; i++) {
|
||||
free((void *)d->weightsystem[i].description);
|
||||
d->weightsystem[i] = s->weightsystem[i];
|
||||
d->weightsystem[i].description = copy_string(s->weightsystem[i].description);
|
||||
}
|
||||
}
|
||||
|
||||
// copy elements, depending on bits in what that are set
|
||||
void selective_copy_dive(const struct dive *s, struct dive *d, struct dive_components what, bool clear)
|
||||
{
|
||||
|
@ -671,11 +680,7 @@ void selective_copy_dive(const struct dive *s, struct dive *d, struct dive_compo
|
|||
if (what.cylinders)
|
||||
copy_cylinders(s, d, false);
|
||||
if (what.weights)
|
||||
for (int i = 0; i < MAX_WEIGHTSYSTEMS; i++) {
|
||||
free((void *)d->weightsystem[i].description);
|
||||
d->weightsystem[i] = s->weightsystem[i];
|
||||
d->weightsystem[i].description = copy_string(s->weightsystem[i].description);
|
||||
}
|
||||
copy_weights(s, d);
|
||||
}
|
||||
#undef CONDITIONAL_COPY_STRING
|
||||
|
||||
|
|
|
@ -546,6 +546,7 @@ extern void copy_events(const struct divecomputer *s, struct divecomputer *d);
|
|||
extern void free_events(struct event *ev);
|
||||
extern void copy_cylinders(const struct dive *s, struct dive *d, bool used_only);
|
||||
extern void copy_samples(const struct divecomputer *s, struct divecomputer *d);
|
||||
extern void copy_weights(const struct dive *s, struct dive *d);
|
||||
extern bool is_cylinder_used(const struct dive *dive, int idx);
|
||||
extern bool is_cylinder_prot(const struct dive *dive, int idx);
|
||||
extern void fill_default_cylinder(cylinder_t *cyl);
|
||||
|
|
|
@ -51,6 +51,9 @@ signals:
|
|||
void divesMovedBetweenTrips(dive_trip *from, dive_trip *to, bool deleteFrom, bool createTo, const QVector<dive *> &dives);
|
||||
void divesTimeChanged(dive_trip *trip, timestamp_t delta, const QVector<dive *> &dives);
|
||||
|
||||
void cylindersReset(dive_trip *trip, const QVector<dive *> &dives);
|
||||
void weightsystemsReset(dive_trip *trip, const QVector<dive *> &dives);
|
||||
|
||||
// Selection-signals come in two kinds:
|
||||
// - divesSelected, divesDeselected and currentDiveChanged are finer grained and are
|
||||
// called batch-wise per trip (except currentDiveChanged, of course). These signals
|
||||
|
|
|
@ -760,6 +760,10 @@ void PasteDives::undo()
|
|||
emit diveListNotifier.divesChanged(trip, divesInTrip, DiveField::DIVESITE);
|
||||
if (what.tags)
|
||||
emit diveListNotifier.divesChanged(trip, divesInTrip, DiveField::TAGS);
|
||||
if (what.cylinders)
|
||||
emit diveListNotifier.cylindersReset(trip, divesInTrip);
|
||||
if (what.weights)
|
||||
emit diveListNotifier.weightsystemsReset(trip, divesInTrip);
|
||||
});
|
||||
|
||||
if (diveSiteListChanged)
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "core/color.h"
|
||||
#include "qt-models/diveplannermodel.h"
|
||||
#include "core/gettextfromc.h"
|
||||
#include "core/subsurface-qt/DiveListNotifier.h"
|
||||
|
||||
CylindersModel::CylindersModel(QObject *parent) :
|
||||
CleanerTableModel(parent),
|
||||
|
@ -16,6 +17,7 @@ CylindersModel::CylindersModel(QObject *parent) :
|
|||
setHeaderDataStrings(QStringList() << "" << tr("Type") << tr("Size") << tr("Work press.") << tr("Start press.") << tr("End press.") << tr("O₂%") << tr("He%")
|
||||
<< tr("Deco switch at") <<tr("Bot. MOD") <<tr("MND") << tr("Use"));
|
||||
|
||||
connect(&diveListNotifier, &DiveListNotifier::cylindersReset, this, &CylindersModel::cylindersReset);
|
||||
}
|
||||
|
||||
QVariant CylindersModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
|
@ -630,3 +632,17 @@ bool CylindersModel::updateBestMixes()
|
|||
emit dataChanged(createIndex(0, 0), createIndex(MAX_CYLINDERS - 1, COLUMNS - 1));
|
||||
return gasUpdated;
|
||||
}
|
||||
|
||||
void CylindersModel::cylindersReset(dive_trip *trip, const QVector<dive *> &dives)
|
||||
{
|
||||
// This model only concerns the currently displayed dive. If this is not among the
|
||||
// dives that had their cylinders reset, exit.
|
||||
if (!current_dive || std::find(dives.begin(), dives.end(), current_dive) == dives.end())
|
||||
return;
|
||||
|
||||
// Copy the cylinders from the current dive to the displayed dive.
|
||||
copy_cylinders(current_dive, &displayed_dive, false);
|
||||
|
||||
// And update the model..
|
||||
updateDive();
|
||||
}
|
||||
|
|
|
@ -48,6 +48,7 @@ public:
|
|||
public
|
||||
slots:
|
||||
void remove(const QModelIndex &index);
|
||||
void cylindersReset(dive_trip *trip, const QVector<dive *> &dives);
|
||||
bool updateBestMixes();
|
||||
|
||||
private:
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "core/gettextfromc.h"
|
||||
#include "core/metrics.h"
|
||||
#include "core/qthelper.h"
|
||||
#include "core/subsurface-qt/DiveListNotifier.h"
|
||||
#include "qt-models/weightsysteminfomodel.h"
|
||||
|
||||
WeightModel::WeightModel(QObject *parent) : CleanerTableModel(parent),
|
||||
|
@ -12,6 +13,7 @@ WeightModel::WeightModel(QObject *parent) : CleanerTableModel(parent),
|
|||
{
|
||||
//enum Column {REMOVE, TYPE, WEIGHT};
|
||||
setHeaderDataStrings(QStringList() << tr("") << tr("Type") << tr("Weight"));
|
||||
connect(&diveListNotifier, &DiveListNotifier::weightsystemsReset, this, &WeightModel::weightsystemsReset);
|
||||
}
|
||||
|
||||
weightsystem_t *WeightModel::weightSystemAt(const QModelIndex &index)
|
||||
|
@ -173,3 +175,17 @@ void WeightModel::updateDive()
|
|||
endInsertRows();
|
||||
}
|
||||
}
|
||||
|
||||
void WeightModel::weightsystemsReset(dive_trip *trip, const QVector<dive *> &dives)
|
||||
{
|
||||
// This model only concerns the currently displayed dive. If this is not among the
|
||||
// dives that had their cylinders reset, exit.
|
||||
if (!current_dive || std::find(dives.begin(), dives.end(), current_dive) == dives.end())
|
||||
return;
|
||||
|
||||
// Copy the cylinders from the current dive to the displayed dive.
|
||||
copy_weights(current_dive, &displayed_dive);
|
||||
|
||||
// And update the model..
|
||||
updateDive();
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ public:
|
|||
public
|
||||
slots:
|
||||
void remove(const QModelIndex &index);
|
||||
void weightsystemsReset(dive_trip *trip, const QVector<dive *> &dives);
|
||||
|
||||
private:
|
||||
int rows;
|
||||
|
|
Loading…
Reference in a new issue