Print: enable printing with the new profile

Some weird things happen if we use a local instance of the
ProfileWidget2 class in printProfileDives(). Once we
exit the printing dialog the profile crashes, which could
hint of singleton issues.

Instead we are going to use the already active instance of
the class which we can retrieve from MainWindow. This should
also be faster because the class is pretty heavy.

In such a case the cleanup at the end of printProfileDives()
is still relevant (removed in ac9a23ef3b). First we
resize the widget for printing purposes and then resize it
back to the original values and re-plot the current selected
dive in the dive list.

Fixes #477, #478

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Lubomir I. Ivanov 2014-03-25 23:34:11 +02:00 committed by Dirk Hohndel
parent b3f6a4f994
commit 47c0ddbf30

View file

@ -131,9 +131,11 @@ void PrintLayout::printProfileDives(int divesPerRow, int divesPerColumn)
painter.scale(scaleX, scaleY);
// setup the profile widget
ProfileWidget2 profile;
profile.setFrameStyle(QFrame::NoFrame);
// profile->setPrintMode(true, !printOptions->color_selected);
QPointer<ProfileWidget2> profile = MainWindow::instance()->graphics();
const int profileFrameStyle = profile->frameStyle();
profile->setFrameStyle(QFrame::NoFrame);
profile->setPrintMode(true, !printOptions->color_selected);
QSize originalSize = profile->size();
// swap rows/col for landscape
if (printer->orientation() == QPrinter::Landscape) {
int swap = divesPerColumn;
@ -156,7 +158,7 @@ void PrintLayout::printProfileDives(int divesPerRow, int divesPerColumn)
// profilePrintTableMaxH updates after the table is created
const int tableH = profilePrintTableMaxH;
// resize the profile widget
profile.resize(scaledW, scaledH - tableH - padPT);
profile->resize(scaledW, scaledH - tableH - padPT);
// offset table or profile on top
int yOffsetProfile = 0, yOffsetTable = 0;
if (printOptions->notes_up)
@ -180,8 +182,8 @@ void PrintLayout::printProfileDives(int divesPerRow, int divesPerColumn)
// draw a profile
painter.translate((scaledW + padW) * col, (scaledH + padH) * row + yOffsetProfile);
profile.plotDives( QList<struct dive*>() << dive);
profile.render(&painter, QRect(0, 0, scaledW, scaledH - tableH - padPT));
profile->plotDives(QList<struct dive*>() << dive);
profile->render(&painter, QRect(0, 0, scaledW, scaledH - tableH - padPT));
painter.setTransform(origTransform);
// draw a table
@ -193,6 +195,13 @@ void PrintLayout::printProfileDives(int divesPerRow, int divesPerColumn)
printed++;
emit signalProgress((printed * 100) / total);
}
// cleanup
painter.end();
delete table;
profile->setFrameStyle(profileFrameStyle);
profile->setPrintMode(false);
profile->resize(originalSize);
profile->plotDives(QList<struct dive*>() << current_dive);
}
/* we create a table that has a fixed height, but can stretch to fit certain width */