dialogs/qabstractprintdialog.cpp

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

Generated by Squish Coco Non-Commercial