QPrintDialog manual test: Break endless loop for invalid DPI.

Change-Id: I8684f144e27392f834f91adef17826b77de60b93
Reviewed-by: John Layt <jlayt@kde.org>
This commit is contained in:
Friedemann Kleint 2014-01-28 11:48:38 +01:00 committed by The Qt Project
parent 68fa04590a
commit 22ec4ed866

View File

@ -211,15 +211,9 @@ static void print(QPrinter *printer)
QPainter painter(printer);
const QRectF pageF = printer->pageRect();
painter.drawRect(pageF);
drawHorizCmRuler(painter, pageF.x(), pageF.right(), pageF.height() /2);
drawVertCmRuler(painter, pageF.x() + pageF.width() / 2, pageF.top(), pageF.bottom());
QFont font = painter.font();
font.setFamily("Courier");
font.setPointSize(10);
painter.setFont(font);
// Format message.
const int charHeight = QFontMetrics(font).boundingRect('X').height();
@ -233,6 +227,17 @@ static void print(QPrinter *printer)
<< "\nFont: " << font.family() << ' ' << font.pointSize() << '\n'
<< *printer;
if (!painter.device()->logicalDpiY() || !painter.device()->logicalDpiX()) {
qWarning() << Q_FUNC_INFO << "Bailing out due to invalid DPI: " << msg;
return;
}
painter.drawRect(pageF);
drawHorizCmRuler(painter, pageF.x(), pageF.right(), pageF.height() /2);
drawVertCmRuler(painter, pageF.x() + pageF.width() / 2, pageF.top(), pageF.bottom());
painter.setFont(font);
QPointF textPoint = pageF.topLeft() + QPoint(10, charHeight + 10);
foreach (const QString &line, msg.split('\n')) {
painter.drawText(textPoint, line);