mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
cleanup: use getDiveSelection() to loop over selected dives
getDiveSelection() returns a vector of the selected dives. Use that instead of looping over the dive table and checking manually. This removes a few lines of code. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
7b196a5ef9
commit
00abc04913
4 changed files with 18 additions and 53 deletions
|
@ -4,6 +4,7 @@
|
||||||
#include "subsurface-string.h"
|
#include "subsurface-string.h"
|
||||||
#include "device.h"
|
#include "device.h"
|
||||||
#include "errorhelper.h" // for verbose flag
|
#include "errorhelper.h" // for verbose flag
|
||||||
|
#include "selection.h"
|
||||||
#include "core/settings/qPrefDiveComputer.h"
|
#include "core/settings/qPrefDiveComputer.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -305,12 +306,8 @@ extern "C" void call_for_each_dc (void *f, void (*callback)(void *, const char *
|
||||||
for (const DiveComputerNode &node : values) {
|
for (const DiveComputerNode &node : values) {
|
||||||
bool found = false;
|
bool found = false;
|
||||||
if (select_only) {
|
if (select_only) {
|
||||||
int j;
|
for (dive *d: getDiveSelection()) {
|
||||||
struct dive *d;
|
|
||||||
for_each_dive (j, d) {
|
|
||||||
struct divecomputer *dc;
|
struct divecomputer *dc;
|
||||||
if (!d->selected)
|
|
||||||
continue;
|
|
||||||
for_each_dc (d, dc) {
|
for_each_dc (d, dc) {
|
||||||
if (dc->deviceid == node.deviceId) {
|
if (dc->deviceid == node.deviceId) {
|
||||||
found = true;
|
found = true;
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "exif.h"
|
#include "exif.h"
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
#include "picture.h"
|
#include "picture.h"
|
||||||
|
#include "selection.h"
|
||||||
#include "tag.h"
|
#include "tag.h"
|
||||||
#include "trip.h"
|
#include "trip.h"
|
||||||
#include "imagedownloader.h"
|
#include "imagedownloader.h"
|
||||||
|
@ -387,12 +388,9 @@ static bool lessThan(const QPair<QString, int> &a, const QPair<QString, int> &b)
|
||||||
|
|
||||||
QVector<QPair<QString, int>> selectedDivesGasUsed()
|
QVector<QPair<QString, int>> selectedDivesGasUsed()
|
||||||
{
|
{
|
||||||
int i, j;
|
int j;
|
||||||
struct dive *d;
|
|
||||||
QMap<QString, int> gasUsed;
|
QMap<QString, int> gasUsed;
|
||||||
for_each_dive (i, d) {
|
for (dive *d: getDiveSelection()) {
|
||||||
if (!d->selected)
|
|
||||||
continue;
|
|
||||||
volume_t *diveGases = get_gas_used(d);
|
volume_t *diveGases = get_gas_used(d);
|
||||||
for (j = 0; j < d->cylinders.nr; j++) {
|
for (j = 0; j < d->cylinders.nr; j++) {
|
||||||
if (diveGases[j].mliter) {
|
if (diveGases[j].mliter) {
|
||||||
|
|
|
@ -609,16 +609,12 @@ static bool can_merge(const struct dive *a, const struct dive *b, enum asked_use
|
||||||
|
|
||||||
void DiveListView::mergeDives()
|
void DiveListView::mergeDives()
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
struct dive *d;
|
|
||||||
enum asked_user have_asked = NOTYET;
|
enum asked_user have_asked = NOTYET;
|
||||||
|
|
||||||
// Collect a vector of batches of dives to merge (i.e. a vector of vector of dives)
|
// Collect a vector of batches of dives to merge (i.e. a vector of vector of dives)
|
||||||
QVector<QVector<dive *>> merge_batches;
|
QVector<QVector<dive *>> merge_batches;
|
||||||
QVector<dive *> current_batch;
|
QVector<dive *> current_batch;
|
||||||
for_each_dive (i, d) {
|
for (dive *d: getDiveSelection()) {
|
||||||
if (!d->selected)
|
|
||||||
continue;
|
|
||||||
if (current_batch.empty()) {
|
if (current_batch.empty()) {
|
||||||
current_batch.append(d);
|
current_batch.append(d);
|
||||||
} else if (can_merge(current_batch.back(), d, &have_asked)) {
|
} else if (can_merge(current_batch.back(), d, &have_asked)) {
|
||||||
|
@ -638,16 +634,7 @@ void DiveListView::mergeDives()
|
||||||
|
|
||||||
void DiveListView::splitDives()
|
void DiveListView::splitDives()
|
||||||
{
|
{
|
||||||
int i;
|
for (struct dive *d: getDiveSelection())
|
||||||
struct dive *dive;
|
|
||||||
|
|
||||||
// Let's collect the dives to be split first, so that we don't catch newly inserted dives!
|
|
||||||
QVector<struct dive *> dives;
|
|
||||||
for_each_dive (i, dive) {
|
|
||||||
if (dive->selected)
|
|
||||||
dives.append(dive);
|
|
||||||
}
|
|
||||||
for (struct dive *d: dives)
|
|
||||||
Command::splitDives(d, duration_t{-1});
|
Command::splitDives(d, duration_t{-1});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -748,15 +735,7 @@ void DiveListView::addToTrip(int delta)
|
||||||
// no dive, no trip? get me out of here
|
// no dive, no trip? get me out of here
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QVector<dive *> dives;
|
Command::addDivesToTrip(QVector<dive *>::fromStdVector(getDiveSelection()), trip);
|
||||||
if (d->selected) { // there are possibly other selected dives that we should add
|
|
||||||
int idx;
|
|
||||||
for_each_dive (idx, d) {
|
|
||||||
if (d->selected)
|
|
||||||
dives.append(d);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Command::addDivesToTrip(dives, trip);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiveListView::markDiveInvalid()
|
void DiveListView::markDiveInvalid()
|
||||||
|
@ -775,13 +754,7 @@ void DiveListView::deleteDive()
|
||||||
if (!d)
|
if (!d)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int i;
|
Command::deleteDive(QVector<dive *>::fromStdVector(getDiveSelection()));
|
||||||
QVector<struct dive*> deletedDives;
|
|
||||||
for_each_dive (i, d) {
|
|
||||||
if (d->selected)
|
|
||||||
deletedDives.append(d);
|
|
||||||
}
|
|
||||||
Command::deleteDive(deletedDives);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiveListView::contextMenuEvent(QContextMenuEvent *event)
|
void DiveListView::contextMenuEvent(QContextMenuEvent *event)
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "core/imagedownloader.h"
|
#include "core/imagedownloader.h"
|
||||||
#include "core/picture.h"
|
#include "core/picture.h"
|
||||||
#include "core/qthelper.h"
|
#include "core/qthelper.h"
|
||||||
|
#include "core/selection.h"
|
||||||
#include "core/subsurface-qt/divelistnotifier.h"
|
#include "core/subsurface-qt/divelistnotifier.h"
|
||||||
#include "commands/command.h"
|
#include "commands/command.h"
|
||||||
|
|
||||||
|
@ -87,19 +88,15 @@ void DivePictureModel::updateDivePictures()
|
||||||
Thumbnailer::instance()->clearWorkQueue();
|
Thumbnailer::instance()->clearWorkQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
int i;
|
for (struct dive *dive: getDiveSelection()) {
|
||||||
struct dive *dive;
|
size_t first = pictures.size();
|
||||||
for_each_dive (i, dive) {
|
FOR_EACH_PICTURE(dive)
|
||||||
if (dive->selected) {
|
pictures.push_back(PictureEntry(dive, *picture));
|
||||||
size_t first = pictures.size();
|
|
||||||
FOR_EACH_PICTURE(dive)
|
|
||||||
pictures.push_back(PictureEntry(dive, *picture));
|
|
||||||
|
|
||||||
// Sort pictures of this dive by offset.
|
// Sort pictures of this dive by offset.
|
||||||
// Thus, the list will be sorted by (dive, offset).
|
// Thus, the list will be sorted by (dive, offset).
|
||||||
std::sort(pictures.begin() + first, pictures.end(),
|
std::sort(pictures.begin() + first, pictures.end(),
|
||||||
[](const PictureEntry &a, const PictureEntry &b) { return a.offsetSeconds < b.offsetSeconds; });
|
[](const PictureEntry &a, const PictureEntry &b) { return a.offsetSeconds < b.offsetSeconds; });
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updateThumbnails();
|
updateThumbnails();
|
||||||
|
|
Loading…
Add table
Reference in a new issue