export: show progress dialog for profile exports

Simply reuse QProgressDialog interface for the TeX exports.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2021-05-01 21:21:50 +02:00 committed by Dirk Hohndel
parent 9ee8807af7
commit 38d0fac2d1
3 changed files with 11 additions and 4 deletions

View file

@ -29,7 +29,7 @@ bool ExportCallback::canceled() const
} }
#if !defined(SUBSURFACE_MOBILE) #if !defined(SUBSURFACE_MOBILE)
void exportProfile(QString filename, bool selected_only) void exportProfile(QString filename, bool selected_only, ExportCallback &cb)
{ {
struct dive *dive; struct dive *dive;
int i; int i;
@ -38,9 +38,14 @@ void exportProfile(QString filename, bool selected_only)
filename = filename.append(".png"); filename = filename.append(".png");
QFileInfo fi(filename); QFileInfo fi(filename);
int todo = selected_only ? amount_selected : dive_table.nr;
int done = 0;
for_each_dive (i, dive) { for_each_dive (i, dive) {
if (cb.canceled())
return;
if (selected_only && !dive->selected) if (selected_only && !dive->selected)
continue; continue;
cb.setProgress(done++ * 1000 / todo);
if (count) if (count)
exportProfile(dive, fi.path() + QDir::separator() + fi.completeBaseName().append(QString("-%1.").arg(count)) + fi.suffix()); exportProfile(dive, fi.path() + QDir::separator() + fi.completeBaseName().append(QString("-%1.").arg(count)) + fi.suffix());
else else

View file

@ -13,7 +13,7 @@ struct ExportCallback {
virtual bool canceled() const; virtual bool canceled() const;
}; };
void exportProfile(QString filename, bool selected_only); void exportProfile(QString filename, bool selected_only, ExportCallback &cb);
void export_TeX(const char *filename, bool selected_only, bool plain, ExportCallback &cb); void export_TeX(const char *filename, bool selected_only, bool plain, ExportCallback &cb);
void export_depths(const char *filename, bool selected_only); void export_depths(const char *filename, bool selected_only);
std::vector<const dive_site *> getDiveSitesToExport(bool selectedOnly); std::vector<const dive_site *> getDiveSitesToExport(bool selectedOnly);

View file

@ -222,8 +222,10 @@ void DiveLogExportDialog::on_buttonBox_accepted()
} }
} else if (ui->exportProfile->isChecked()) { } else if (ui->exportProfile->isChecked()) {
filename = QFileDialog::getSaveFileName(this, tr("Save profile image"), lastDir); filename = QFileDialog::getSaveFileName(this, tr("Save profile image"), lastDir);
if (!filename.isEmpty()) if (!filename.isEmpty()) {
exportProfile(qPrintable(filename), ui->exportSelected->isChecked()); ProgressDialogCallback cb;
exportProfile(qPrintable(filename), ui->exportSelected->isChecked(), cb);
}
} else if (ui->exportProfileData->isChecked()) { } else if (ui->exportProfileData->isChecked()) {
filename = QFileDialog::getSaveFileName(this, tr("Save profile data"), lastDir); filename = QFileDialog::getSaveFileName(this, tr("Save profile data"), lastDir);
if (!filename.isEmpty()) if (!filename.isEmpty())