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

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