summaryrefslogtreecommitdiffstats
path: root/desktop-widgets/divelogexportdialog.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-09-21 14:10:53 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-09-21 16:07:24 -0700
commit44a291a09f06733ff84dc99d532351d6cbc927c6 (patch)
treeb905d21f3a9a1b369b45370ea76b5b48819545e6 /desktop-widgets/divelogexportdialog.cpp
parentfe7c0b30856d1286ea9a521ca9fb01e4952b6275 (diff)
downloadsubsurface-44a291a09f06733ff84dc99d532351d6cbc927c6.tar.gz
Export: move dive site selection logic to C++
When exporting dive sites, the dive sites to be selected were collected in the C-core. But that doesn't have access to the selected dive sites if in dive site mode. Therefore, collect the dive sites in C++ and pass down to the core. Use a std::vector to avoid memory management woes. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets/divelogexportdialog.cpp')
-rw-r--r--desktop-widgets/divelogexportdialog.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/desktop-widgets/divelogexportdialog.cpp b/desktop-widgets/divelogexportdialog.cpp
index 9bf8c16a8..2b1409aea 100644
--- a/desktop-widgets/divelogexportdialog.cpp
+++ b/desktop-widgets/divelogexportdialog.cpp
@@ -130,6 +130,21 @@ void DiveLogExportDialog::on_exportGroup_buttonClicked(QAbstractButton*)
showExplanation();
}
+static std::vector<const dive_site *> getDiveSitesToExport(bool selectedOnly)
+{
+ std::vector<const dive_site *> res;
+ res.reserve(dive_site_table.nr);
+ for (int i = 0; i < dive_site_table.nr; i++) {
+ struct dive_site *ds = get_dive_site(i, &dive_site_table);
+ if (dive_site_is_empty(ds))
+ continue;
+ if (selectedOnly && !is_dive_site_selected(ds))
+ continue;
+ res.push_back(ds);
+ }
+ return res;
+}
+
void DiveLogExportDialog::on_buttonBox_accepted()
{
QString filename;
@@ -178,7 +193,8 @@ void DiveLogExportDialog::on_buttonBox_accepted()
if (!filename.contains('.'))
filename.append(".xml");
QByteArray bt = QFile::encodeName(filename);
- save_dive_sites_logic(bt.data(), ui->exportSelected->isChecked(), ui->anonymize->isChecked());
+ std::vector<const dive_site *> sites = getDiveSitesToExport(ui->exportSelected->isChecked());
+ save_dive_sites_logic(bt.data(), &sites[0], (int)sites.size(), ui->anonymize->isChecked());
}
} else if (ui->exportImageDepths->isChecked()) {
filename = QFileDialog::getSaveFileName(this, tr("Save image depths"), lastDir);