OpenCoverage

qabstractprintdialog.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/printsupport/dialogs/qabstractprintdialog.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtGui module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include "qabstractprintdialog_p.h"-
41#include "qcoreapplication.h"-
42#include "qprintdialog.h"-
43#include "qprinter.h"-
44#include "private/qprinter_p.h"-
45-
46#ifndef QT_NO_PRINTDIALOG-
47-
48QT_BEGIN_NAMESPACE-
49-
50// hack-
51class QPrintDialogPrivate : public QAbstractPrintDialogPrivate-
52{-
53};-
54-
55/*!-
56 \class QAbstractPrintDialog-
57 \brief The QAbstractPrintDialog class provides a base implementation for-
58 print dialogs used to configure printers.-
59-
60 \ingroup printing-
61 \inmodule QtPrintSupport-
62-
63 This class implements getter and setter functions that are used to-
64 customize settings shown in print dialogs, but it is not used directly.-
65 Use QPrintDialog to display a print dialog in your application.-
66-
67 \sa QPrintDialog, QPrinter-
68*/-
69-
70/*!-
71 \enum QAbstractPrintDialog::PrintRange-
72-
73 Used to specify the print range selection option.-
74-
75 \value AllPages All pages should be printed.-
76 \value Selection Only the selection should be printed.-
77 \value PageRange The specified page range should be printed.-
78 \value CurrentPage Only the currently visible page should be printed.-
79-
80 \sa QPrinter::PrintRange-
81*/-
82-
83/*!-
84 \enum QAbstractPrintDialog::PrintDialogOption-
85-
86 Used to specify which parts of the print dialog should be visible.-
87-
88 \value None None of the options are enabled.-
89 \value PrintToFile The print to file option is enabled.-
90 \value PrintSelection The print selection option is enabled.-
91 \value PrintPageRange The page range selection option is enabled.-
92 \value PrintShowPageSize Show the page size + margins page only if this is enabled.-
93 \value PrintCollateCopies The collate copies option is enabled-
94 \value PrintCurrentPage The print current page option is enabled-
95-
96 This value is obsolete and does nothing since Qt 4.5:-
97-
98 \value DontUseSheet In previous versions of Qt, exec() the print dialog-
99 would create a sheet by default the dialog was given a parent.-
100 This is no longer supported in Qt 4.5. If you want to use sheets, use-
101 QPrintDialog::open() instead.-
102*/-
103-
104/*!-
105 Constructs an abstract print dialog for \a printer with \a parent-
106 as parent widget.-
107*/-
108QAbstractPrintDialog::QAbstractPrintDialog(QPrinter *printer, QWidget *parent)-
109 : QDialog(*(new QAbstractPrintDialogPrivate), parent)-
110{-
111 Q_D(QAbstractPrintDialog);-
112 setWindowTitle(QCoreApplication::translate("QPrintDialog", "Print"));-
113 d->setPrinter(printer);-
114 d->minPage = printer->fromPage();-
115 int to = printer->toPage();-
116 d->maxPage = to > 0 ? to : INT_MAX;
to > 0Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • tst_QAbstractPrintDialog
0-3
117}
executed 3 times by 1 test: end of block
Executed by:
  • tst_QAbstractPrintDialog
3
118-
119/*!-
120 \internal-
121*/-
122QAbstractPrintDialog::QAbstractPrintDialog(QAbstractPrintDialogPrivate &ptr,-
123 QPrinter *printer,-
124 QWidget *parent)-
125 : QDialog(ptr, parent)-
126{-
127 Q_D(QAbstractPrintDialog);-
128 setWindowTitle(QCoreApplication::translate("QPrintDialog", "Print"));-
129 d->setPrinter(printer);-
130}
executed 3 times by 1 test: end of block
Executed by:
  • tst_QPrinter
3
131-
132/*!-
133 \internal-
134*/-
135QAbstractPrintDialog::~QAbstractPrintDialog()-
136{-
137 Q_D(QAbstractPrintDialog);-
138 if (d->ownsPrinter)
d->ownsPrinterDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QPrinter
FALSEevaluated 5 times by 2 tests
Evaluated by:
  • tst_QAbstractPrintDialog
  • tst_QPrinter
1-5
139 delete d->printer;
executed 1 time by 1 test: delete d->printer;
Executed by:
  • tst_QPrinter
1
140}
executed 6 times by 2 tests: end of block
Executed by:
  • tst_QAbstractPrintDialog
  • tst_QPrinter
6
141-
142/*!-
143 Sets the given \a option to be enabled if \a on is true;-
144 otherwise, clears the given \a option.-
145-
146 \sa options, testOption()-
147*/-
148void QPrintDialog::setOption(PrintDialogOption option, bool on)-
149{-
150 Q_D(QPrintDialog);-
151 if (!(d->options & option) != !on)
!(d->options & option) != !onDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QPrinter
FALSEnever evaluated
0-1
152 setOptions(d->options ^ option);
executed 1 time by 1 test: setOptions(d->options ^ option);
Executed by:
  • tst_QPrinter
1
153}
executed 1 time by 1 test: end of block
Executed by:
  • tst_QPrinter
1
154-
155/*!-
156 Returns \c true if the given \a option is enabled; otherwise, returns-
157 false.-
158-
159 \sa options, setOption()-
160*/-
161bool QPrintDialog::testOption(PrintDialogOption option) const-
162{-
163 Q_D(const QPrintDialog);-
164 return (d->options & option) != 0;
never executed: return (d->options & option) != 0;
0
165}-
166-
167/*!-
168 \property QPrintDialog::options-
169 \brief the various options that affect the look and feel of the dialog-
170 \since 4.5-
171-
172 By default, all options are disabled.-
173-
174 Options should be set before showing the dialog. Setting them while the-
175 dialog is visible is not guaranteed to have an immediate effect on the-
176 dialog (depending on the option and on the platform).-
177-
178 \sa setOption(), testOption()-
179*/-
180void QPrintDialog::setOptions(PrintDialogOptions options)-
181{-
182 Q_D(QPrintDialog);-
183-
184 PrintDialogOptions changed = (options ^ d->options);-
185 if (!changed)
!changedDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QPrinter
0-1
186 return;
never executed: return;
0
187-
188 d->options = options;-
189}
executed 1 time by 1 test: end of block
Executed by:
  • tst_QPrinter
1
190-
191QPrintDialog::PrintDialogOptions QPrintDialog::options() const-
192{-
193 Q_D(const QPrintDialog);-
194 return d->options;
never executed: return d->options;
0
195}-
196-
197/*!-
198 \obsolete-
199-
200 Use QPrintDialog::setOptions() instead.-
201*/-
202void QAbstractPrintDialog::setEnabledOptions(PrintDialogOptions options)-
203{-
204 Q_D(QAbstractPrintDialog);-
205 d->options = options;-
206}
executed 10 times by 2 tests: end of block
Executed by:
  • tst_QAbstractPrintDialog
  • tst_QPrinter
10
207-
208/*!-
209 \obsolete-
210-
211 Use QPrintDialog::setOption(\a option, true) instead.-
212*/-
213void QAbstractPrintDialog::addEnabledOption(PrintDialogOption option)-
214{-
215 Q_D(QAbstractPrintDialog);-
216 d->options |= option;-
217}
never executed: end of block
0
218-
219/*!-
220 \obsolete-
221-
222 Use QPrintDialog::options() instead.-
223*/-
224QAbstractPrintDialog::PrintDialogOptions QAbstractPrintDialog::enabledOptions() const-
225{-
226 Q_D(const QAbstractPrintDialog);-
227 return d->options;
executed 5 times by 1 test: return d->options;
Executed by:
  • tst_QAbstractPrintDialog
5
228}-
229-
230/*!-
231 \obsolete-
232-
233 Use QPrintDialog::testOption(\a option) instead.-
234*/-
235bool QAbstractPrintDialog::isOptionEnabled(PrintDialogOption option) const-
236{-
237 Q_D(const QAbstractPrintDialog);-
238 return d->options & option;
executed 27 times by 1 test: return d->options & option;
Executed by:
  • tst_QPrinter
27
239}-
240-
241/*!-
242 Sets the print range option in to be \a range.-
243 */-
244void QAbstractPrintDialog::setPrintRange(PrintRange range)-
245{-
246 Q_D(QAbstractPrintDialog);-
247 d->printer->setPrintRange(QPrinter::PrintRange(range));-
248}
executed 3 times by 1 test: end of block
Executed by:
  • tst_QAbstractPrintDialog
3
249-
250/*!-
251 Returns the print range.-
252*/-
253QAbstractPrintDialog::PrintRange QAbstractPrintDialog::printRange() const-
254{-
255 Q_D(const QAbstractPrintDialog);-
256 return QAbstractPrintDialog::PrintRange(d->pd->printRange);
executed 4 times by 2 tests: return QAbstractPrintDialog::PrintRange(d->pd->printRange);
Executed by:
  • tst_QAbstractPrintDialog
  • tst_QPrinter
4
257}-
258-
259/*!-
260 Sets the page range in this dialog to be from \a min to \a max. This also-
261 enables the PrintPageRange option.-
262*/-
263void QAbstractPrintDialog::setMinMax(int min, int max)-
264{-
265 Q_D(QAbstractPrintDialog);-
266 Q_ASSERT_X(min <= max, "QAbstractPrintDialog::setMinMax",-
267 "'min' must be less than or equal to 'max'");-
268 d->minPage = min;-
269 d->maxPage = max;-
270 d->options |= PrintPageRange;-
271}
executed 2 times by 1 test: end of block
Executed by:
  • tst_QAbstractPrintDialog
2
272-
273/*!-
274 Returns the minimum page in the page range.-
275 By default, this value is set to 1.-
276*/-
277int QAbstractPrintDialog::minPage() const-
278{-
279 Q_D(const QAbstractPrintDialog);-
280 return d->minPage;
executed 4 times by 2 tests: return d->minPage;
Executed by:
  • tst_QAbstractPrintDialog
  • tst_QPrinter
4
281}-
282-
283/*!-
284 Returns the maximum page in the page range. As of Qt 4.4, this-
285 function returns INT_MAX by default. Previous versions returned 1-
286 by default.-
287*/-
288int QAbstractPrintDialog::maxPage() const-
289{-
290 Q_D(const QAbstractPrintDialog);-
291 return d->maxPage;
executed 4 times by 2 tests: return d->maxPage;
Executed by:
  • tst_QAbstractPrintDialog
  • tst_QPrinter
4
292}-
293-
294/*!-
295 Sets the range in the print dialog to be from \a from to \a to.-
296*/-
297void QAbstractPrintDialog::setFromTo(int from, int to)-
298{-
299 Q_D(QAbstractPrintDialog);-
300 Q_ASSERT_X(from <= to, "QAbstractPrintDialog::setFromTo",-
301 "'from' must be less than or equal to 'to'");-
302 d->printer->setFromTo(from, to);-
303-
304 if (d->minPage == 0 && d->maxPage == 0)
d->minPage == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QAbstractPrintDialog
FALSEnever evaluated
d->maxPage == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QAbstractPrintDialog
FALSEnever evaluated
0-1
305 setMinMax(1, to);
executed 1 time by 1 test: setMinMax(1, to);
Executed by:
  • tst_QAbstractPrintDialog
1
306}
executed 1 time by 1 test: end of block
Executed by:
  • tst_QAbstractPrintDialog
1
307-
308/*!-
309 Returns the first page to be printed-
310 By default, this value is set to 0.-
311*/-
312int QAbstractPrintDialog::fromPage() const-
313{-
314 Q_D(const QAbstractPrintDialog);-
315 return d->printer->fromPage();
executed 3 times by 2 tests: return d->printer->fromPage();
Executed by:
  • tst_QAbstractPrintDialog
  • tst_QPrinter
3
316}-
317-
318/*!-
319 Returns the last page to be printed.-
320 By default, this value is set to 0.-
321*/-
322int QAbstractPrintDialog::toPage() const-
323{-
324 Q_D(const QAbstractPrintDialog);-
325 return d->printer->toPage();
executed 3 times by 2 tests: return d->printer->toPage();
Executed by:
  • tst_QAbstractPrintDialog
  • tst_QPrinter
3
326}-
327-
328-
329/*!-
330 Returns the printer that this printer dialog operates-
331 on.-
332*/-
333QPrinter *QAbstractPrintDialog::printer() const-
334{-
335 Q_D(const QAbstractPrintDialog);-
336 return d->printer;
executed 9 times by 2 tests: return d->printer;
Executed by:
  • tst_QAbstractPrintDialog
  • tst_QPrinter
9
337}-
338-
339void QAbstractPrintDialogPrivate::setPrinter(QPrinter *newPrinter)-
340{-
341 if (newPrinter) {
newPrinterDescription
TRUEevaluated 5 times by 2 tests
Evaluated by:
  • tst_QAbstractPrintDialog
  • tst_QPrinter
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QPrinter
1-5
342 printer = newPrinter;-
343 ownsPrinter = false;-
344 if (printer->fromPage() || printer->toPage())
printer->fromPage()Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QPrinter
FALSEevaluated 4 times by 2 tests
Evaluated by:
  • tst_QAbstractPrintDialog
  • tst_QPrinter
printer->toPage()Description
TRUEnever evaluated
FALSEevaluated 4 times by 2 tests
Evaluated by:
  • tst_QAbstractPrintDialog
  • tst_QPrinter
0-4
345 options |= QAbstractPrintDialog::PrintPageRange;
executed 1 time by 1 test: options |= QAbstractPrintDialog::PrintPageRange;
Executed by:
  • tst_QPrinter
1
346 } else {
executed 5 times by 2 tests: end of block
Executed by:
  • tst_QAbstractPrintDialog
  • tst_QPrinter
5
347 printer = new QPrinter;-
348 ownsPrinter = true;-
349 }
executed 1 time by 1 test: end of block
Executed by:
  • tst_QPrinter
1
350 pd = printer->d_func();-
351}
executed 6 times by 2 tests: end of block
Executed by:
  • tst_QAbstractPrintDialog
  • tst_QPrinter
6
352-
353/*!-
354 \fn int QAbstractPrintDialog::exec()-
355-
356 This virtual function is called to pop up the dialog. It must be-
357 reimplemented in subclasses.-
358*/-
359-
360/*!-
361 \class QPrintDialog-
362-
363 \brief The QPrintDialog class provides a dialog for specifying-
364 the printer's configuration.-
365-
366 \ingroup standard-dialogs-
367 \ingroup printing-
368 \inmodule QtPrintSupport-
369-
370 The dialog allows users to change document-related settings, such-
371 as the paper size and orientation, type of print (color or-
372 grayscale), range of pages, and number of copies to print.-
373-
374 Controls are also provided to enable users to choose from the-
375 printers available, including any configured network printers.-
376-
377 Typically, QPrintDialog objects are constructed with a QPrinter-
378 object, and executed using the exec() function.-
379-
380 \snippet code/src_gui_dialogs_qabstractprintdialog.cpp 0-
381-
382 If the dialog is accepted by the user, the QPrinter object is-
383 correctly configured for printing.-
384-
385 \table-
386 \row-
387 \li \inlineimage plastique-printdialog.png-
388 \li \inlineimage plastique-printdialog-properties.png-
389 \endtable-
390-
391 The printer dialog (shown above in Plastique style) enables access to common-
392 printing properties. On X11 platforms that use the CUPS printing system, the-
393 settings for each available printer can be modified via the dialog's-
394 \uicontrol{Properties} push button.-
395-
396 On Windows and \macos, the native print dialog is used, which means that-
397 some QWidget and QDialog properties set on the dialog won't be respected.-
398 The native print dialog on \macos does not support setting printer options,-
399 i.e. setOptions() and setOption() have no effect.-
400-
401 In Qt 4.4, it was possible to use the static functions to show a sheet on-
402 \macos. This is no longer supported in Qt 4.5. If you want this-
403 functionality, use QPrintDialog::open().-
404-
405 \sa QPageSetupDialog, QPrinter-
406*/-
407-
408/*!-
409 \fn QPrintDialog::QPrintDialog(QPrinter *printer, QWidget *parent)-
410-
411 Constructs a new modal printer dialog for the given \a printer-
412 with the given \a parent.-
413*/-
414-
415/*!-
416 \fn QPrintDialog::~QPrintDialog()-
417-
418 Destroys the print dialog.-
419*/-
420-
421/*!-
422 \fn int QPrintDialog::exec()-
423 \reimp-
424*/-
425-
426/*!-
427 \since 4.4-
428-
429 Set a list of widgets as \a tabs to be shown on the print dialog, if supported.-
430-
431 Currently this option is only supported on X11.-
432-
433 Setting the option tabs will transfer their ownership to the print dialog.-
434*/-
435void QAbstractPrintDialog::setOptionTabs(const QList<QWidget*> &tabs)-
436{-
437 Q_D(QAbstractPrintDialog);-
438 d->setTabs(tabs);-
439}
never executed: end of block
0
440-
441/*!-
442-
443 \fn void QPrintDialog::accepted(QPrinter *printer)-
444-
445 This signal is emitted when the user accepts the values set in the print dialog.-
446 The \a printer parameter includes the printer that the settings were applied to.-
447*/-
448-
449/*!-
450 \fn QPrinter *QPrintDialog::printer()-
451-
452 Returns the printer that this printer dialog operates-
453 on. This can be useful when using the QPrintDialog::open() method.-
454*/-
455-
456/*!-
457 Closes the dialog and sets its result code to \a result. If this dialog-
458 is shown with exec(), done() causes the local event loop to finish,-
459 and exec() to return \a result.-
460-
461 \note This function does not apply to the Native Print Dialog on the Mac-
462 \macos and Windows platforms, because the dialog is required to be modal-
463 and only the user can close it.-
464-
465 \sa QDialog::done()-
466*/-
467void QPrintDialog::done(int result)-
468{-
469 Q_D(QPrintDialog);-
470 QDialog::done(result);-
471 if (result == Accepted)
result == AcceptedDescription
TRUEnever evaluated
FALSEnever evaluated
0
472 emit accepted(printer());
never executed: accepted(printer());
0
473 if (d->receiverToDisconnectOnClose) {
d->receiverToDisconnectOnCloseDescription
TRUEnever evaluated
FALSEnever evaluated
0
474 disconnect(this, SIGNAL(accepted(QPrinter*)),-
475 d->receiverToDisconnectOnClose, d->memberToDisconnectOnClose);-
476 d->receiverToDisconnectOnClose = 0;-
477 }
never executed: end of block
0
478 d->memberToDisconnectOnClose.clear();-
479}
never executed: end of block
0
480-
481/*!-
482 \since 4.5-
483 \overload-
484-
485 Opens the dialog and connects its accepted() signal to the slot specified-
486 by \a receiver and \a member.-
487-
488 The signal will be disconnected from the slot when the dialog is closed.-
489*/-
490void QPrintDialog::open(QObject *receiver, const char *member)-
491{-
492 Q_D(QPrintDialog);-
493 connect(this, SIGNAL(accepted(QPrinter*)), receiver, member);-
494 d->receiverToDisconnectOnClose = receiver;-
495 d->memberToDisconnectOnClose = member;-
496 QDialog::open();-
497}
never executed: end of block
0
498-
499QT_END_NAMESPACE-
500-
501#endif // QT_NO_PRINTDIALOG-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9