mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
export: move initialization/resetting of profile out of loop
When multiple profiles were exported, for every exported image the profile-widget was switched to/from print mode. Move this out of the loop, i.e. initialize and reset the profile only once. This should slightly speed up export, but not by a lot, since most of the time is spent by compressing the PNGs. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
8f0e2245c2
commit
60b82de058
1 changed files with 26 additions and 13 deletions
|
@ -35,23 +35,33 @@ bool ExportCallback::canceled() const
|
|||
|
||||
#include "desktop-widgets/mainwindow.h" // Currently needed for profile printing. TODO: remove.
|
||||
|
||||
static void exportProfile(const struct dive *dive, const QString filename)
|
||||
static void exportProfile(ProfileWidget2 *profile, const struct dive *dive, const QString &filename)
|
||||
{
|
||||
ProfileWidget2 *profile = MainWindow::instance()->graphics;
|
||||
profile->setToolTipVisibile(false);
|
||||
profile->setPrintMode(true);
|
||||
double scale = profile->getFontPrintScale();
|
||||
profile->setFontPrintScale(4 * scale);
|
||||
profile->plotDive(dive, 0, false, true);
|
||||
QImage image = QImage(profile->size() * 4, QImage::Format_RGB32);
|
||||
QPainter paint;
|
||||
paint.begin(&image);
|
||||
profile->render(&paint);
|
||||
image.save(filename);
|
||||
}
|
||||
|
||||
static ProfileWidget2 *getPrintProfile()
|
||||
{
|
||||
ProfileWidget2 *profile = MainWindow::instance()->graphics;
|
||||
profile->setToolTipVisibile(false);
|
||||
profile->setPrintMode(true);
|
||||
double scale = profile->getFontPrintScale();
|
||||
profile->setFontPrintScale(4 * scale);
|
||||
return profile;
|
||||
}
|
||||
|
||||
static void resetProfile()
|
||||
{
|
||||
ProfileWidget2 *profile = MainWindow::instance()->graphics;
|
||||
profile->setToolTipVisibile(true);
|
||||
profile->setFontPrintScale(scale);
|
||||
profile->setFontPrintScale(1.0);
|
||||
profile->setPrintMode(false);
|
||||
profile->plotDive(dive, 0, true); // TODO: Shouldn't this plot the current dive?
|
||||
profile->plotDive(current_dive, 0, true);
|
||||
}
|
||||
|
||||
void exportProfile(QString filename, bool selected_only, ExportCallback &cb)
|
||||
|
@ -65,18 +75,19 @@ void exportProfile(QString filename, bool selected_only, ExportCallback &cb)
|
|||
|
||||
int todo = selected_only ? amount_selected : dive_table.nr;
|
||||
int done = 0;
|
||||
ProfileWidget2 *profile = getPrintProfile();
|
||||
for_each_dive (i, dive) {
|
||||
if (cb.canceled())
|
||||
return;
|
||||
if (selected_only && !dive->selected)
|
||||
continue;
|
||||
cb.setProgress(done++ * 1000 / todo);
|
||||
if (count)
|
||||
exportProfile(dive, fi.path() + QDir::separator() + fi.completeBaseName().append(QString("-%1.").arg(count)) + fi.suffix());
|
||||
else
|
||||
exportProfile(dive, filename);
|
||||
QString fn = count ? fi.path() + QDir::separator() + fi.completeBaseName().append(QString("-%1.").arg(count)) + fi.suffix()
|
||||
: filename;
|
||||
exportProfile(profile, dive, fn);
|
||||
++count;
|
||||
}
|
||||
resetProfile();
|
||||
}
|
||||
|
||||
void export_TeX(const char *filename, bool selected_only, bool plain, ExportCallback &cb)
|
||||
|
@ -134,13 +145,14 @@ void export_TeX(const char *filename, bool selected_only, bool plain, ExportCall
|
|||
|
||||
int todo = selected_only ? amount_selected : dive_table.nr;
|
||||
int done = 0;
|
||||
ProfileWidget2 *profile = getPrintProfile();
|
||||
for_each_dive (i, dive) {
|
||||
if (cb.canceled())
|
||||
return;
|
||||
if (selected_only && !dive->selected)
|
||||
continue;
|
||||
cb.setProgress(done++ * 1000 / todo);
|
||||
exportProfile(dive, texdir.filePath(QString("profile%1.png").arg(dive->number)));
|
||||
exportProfile(profile, dive, texdir.filePath(QString("profile%1.png").arg(dive->number)));
|
||||
struct tm tm;
|
||||
utc_mkdate(dive->when, &tm);
|
||||
|
||||
|
@ -261,6 +273,7 @@ void export_TeX(const char *filename, bool selected_only, bool plain, ExportCall
|
|||
|
||||
put_format(&buf, "\\%spage\n", ssrf);
|
||||
}
|
||||
resetProfile();
|
||||
|
||||
if (plain)
|
||||
put_format(&buf, "\\bye\n");
|
||||
|
|
Loading…
Reference in a new issue