From 926a0886d1961a3f384d3e6c36919e6dd8055dce Mon Sep 17 00:00:00 2001 From: Szabolcs David Date: Mon, 8 Apr 2019 13:25:54 +0200 Subject: Support multiple page ranges in QPrinter Add a new QRangeCollection type to store and manage multiple page ranges. This moves out the parser and validator logic from the platform dependent (UNIX) dialog and makes it publicly available from QPrinter. This improves the usability of QPrinter in those applications which doesn't use print dialog to configure printer. (e.g.: QTextDocument, QWebEnginePage) Change-Id: I0be5a8a64781c411f83b96a24f216605a84958e5 Reviewed-by: Qt CI Bot Reviewed-by: Allan Sandfeld Jensen Reviewed-by: Leena Miettinen --- src/printsupport/kernel/qprinter.cpp | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'src/printsupport/kernel/qprinter.cpp') diff --git a/src/printsupport/kernel/qprinter.cpp b/src/printsupport/kernel/qprinter.cpp index fbf5e5c2ba..25855d6da7 100644 --- a/src/printsupport/kernel/qprinter.cpp +++ b/src/printsupport/kernel/qprinter.cpp @@ -49,6 +49,7 @@ #include "qlist.h" #include #include +#include #include @@ -1981,12 +1982,12 @@ void QPrinter::setPrinterSelectionOption(const QString &option) \note If fromPage() and toPage() both return 0, this indicates that \e{the whole document will be printed}. - \sa setFromTo(), toPage() + \sa setFromTo(), toPage(), rangeCollection() */ int QPrinter::fromPage() const { - return d->fromPage; + return d->rangeCollection->firstPage(); } /*! @@ -2005,12 +2006,12 @@ int QPrinter::fromPage() const The programmer is responsible for reading this setting and printing accordingly. - \sa setFromTo(), fromPage() + \sa setFromTo(), fromPage(), rangeCollection() */ int QPrinter::toPage() const { - return d->toPage; + return d->rangeCollection->lastPage(); } /*! @@ -2027,17 +2028,25 @@ int QPrinter::toPage() const This function is mostly used to set a default value that the user can override in the print dialog when you call setup(). - \sa fromPage(), toPage() + \sa fromPage(), toPage(), rangeCollection() */ void QPrinter::setFromTo(int from, int to) { - if (from > to) { - qWarning("QPrinter::setFromTo: 'from' must be less than or equal to 'to'"); - from = to; - } - d->fromPage = from; - d->toPage = to; + d->rangeCollection->clear(); + d->rangeCollection->addRange(from, to); +} + +/*! + \since 6.0 + + Returns the range collection associated with this device. + + \sa QRangeCollection, fromPage(), toPage() +*/ +QRangeCollection *QPrinter::rangeCollection() +{ + return d->rangeCollection; } /*! -- cgit v1.2.3