From 80e50e169de2fb34573b7a5229848c0919297df7 Mon Sep 17 00:00:00 2001 From: Jonathan Marten Date: Mon, 2 Dec 2024 13:23:19 +0000 Subject: [PATCH] Unix printing: Check for a valid page range before accepting dialog QPrintDialog::accept() checks for valid page ranges if the "Pages" option is selected, but it did that before calling setupPrinter() to read the settings from the user input. The page ranges would not yet have been parsed at this point, so giving the error message whenever this option is used even if a valid page range string is entered. Perform an equivalent check before the dialog is accepted: that is, that the entered page range string is not empty and that it can be parsed to a valid QPageRanges. Fixes: QTBUG-112346 Change-Id: Idc1a3154055a425967596d66f26477e41b0b138b Reviewed-by: Albert Astals Cid Reviewed-by: David Faure (cherry picked from commit ec7589fc9b0855c789dc4d5d5558b476a7873d45) Reviewed-by: Qt Cherry-pick Bot --- src/printsupport/dialogs/qprintdialog_unix.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/printsupport/dialogs/qprintdialog_unix.cpp b/src/printsupport/dialogs/qprintdialog_unix.cpp index aab5e2c7f05..8846fc3643e 100644 --- a/src/printsupport/dialogs/qprintdialog_unix.cpp +++ b/src/printsupport/dialogs/qprintdialog_unix.cpp @@ -991,13 +991,16 @@ void QPrintDialog::accept() { Q_D(QPrintDialog); #if QT_CONFIG(cups) && QT_CONFIG(messagebox) - if (d->options.pagesRadioButton->isChecked() && printer()->pageRanges().isEmpty()) { - QMessageBox::critical(this, tr("Invalid Pages Definition"), - tr("%1 does not follow the correct syntax. Please use ',' to separate " - "ranges and pages, '-' to define ranges and make sure ranges do " - "not intersect with each other.").arg(d->options.pagesLineEdit->text()), - QMessageBox::Ok, QMessageBox::Ok); - return; + if (d->options.pagesRadioButton->isChecked()) { + const QString rangesText = d->options.pagesLineEdit->text(); + if (rangesText.isEmpty() || QPageRanges::fromString(rangesText).isEmpty()) { + QMessageBox::critical(this, tr("Invalid Pages Definition"), + tr("%1 does not follow the correct syntax. Please use ',' to separate " + "ranges and pages, '-' to define ranges and make sure ranges do " + "not intersect with each other.").arg(rangesText), + QMessageBox::Ok, QMessageBox::Ok); + return; + } } if (d->top->d->m_duplexPpdOption && d->top->d->m_duplexPpdOption->conflicted) { const QMessageBox::StandardButton answer = QMessageBox::warning(this, tr("Duplex Settings Conflicts"),