diff options
author | Szabolcs David <davidsz@inf.u-szeged.hu> | 2019-04-08 13:25:54 +0200 |
---|---|---|
committer | Szabolcs David <davidsz@inf.u-szeged.hu> | 2020-04-09 16:45:32 +0200 |
commit | 926a0886d1961a3f384d3e6c36919e6dd8055dce (patch) | |
tree | 8512058bcec7250a4828f9244b4b431c02eecfa7 /src/printsupport/kernel/qprinter.cpp | |
parent | 4c66b75c894cf2cc7ec15896729d0f93de92f310 (diff) |
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 <qt_ci_bot@qt-project.org>
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Diffstat (limited to 'src/printsupport/kernel/qprinter.cpp')
-rw-r--r-- | src/printsupport/kernel/qprinter.cpp | 31 |
1 files changed, 20 insertions, 11 deletions
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 <qcoreapplication.h> #include <qfileinfo.h> +#include <QtGui/qrangecollection.h> #include <private/qpagedpaintdevice_p.h> @@ -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; } /*! |