Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qprinterinfo.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qprinterinfo.h"
5#include "qprinterinfo_p.h"
6#include "qprintdevice_p.h"
7
8#ifndef QT_NO_PRINTER
9
10#include <QtCore/qdebug.h>
11
12#include <qpa/qplatformprintplugin.h>
13#include <qpa/qplatformprintersupport.h>
14
16
18
20{
21public:
22 static inline void cleanup(QPrinterInfoPrivate *d)
23 {
24 if (d != &*shared_null)
25 delete d;
26 }
27};
28
37
41
65 : d_ptr(shared_null)
66{
67}
68
73 : d_ptr((other.d_ptr.data() == shared_null) ? &*shared_null : new QPrinterInfoPrivate(*other.d_ptr))
74{
75}
76
81 : d_ptr(shared_null)
82{
84 if (ps) {
85 QPrinterInfo pi(printer.printerName());
86 if (pi.d_ptr.data() == shared_null)
87 d_ptr.reset(shared_null);
88 else
89 d_ptr.reset(new QPrinterInfoPrivate(*pi.d_ptr));
90 }
91}
92
97 : d_ptr(new QPrinterInfoPrivate(name))
98{
99}
100
108
113{
114 Q_ASSERT(d_ptr);
115 if (other.d_ptr.data() == shared_null)
116 d_ptr.reset(shared_null);
117 else
118 d_ptr.reset(new QPrinterInfoPrivate(*other.d_ptr));
119 return *this;
120}
121
131{
132 const Q_D(QPrinterInfo);
133 return d->m_printDevice.id();
134}
135
143{
144 const Q_D(QPrinterInfo);
145 return d->m_printDevice.name();
146}
147
154{
155 const Q_D(QPrinterInfo);
156 return d->m_printDevice.location();
157}
158
165{
166 const Q_D(QPrinterInfo);
167 return d->m_printDevice.makeAndModel();
168}
169
177{
178 Q_D(const QPrinterInfo);
179 return d == shared_null || !d->m_printDevice.isValid();
180}
181
186{
187 Q_D(const QPrinterInfo);
188 return d->m_printDevice.isDefault();
189}
190
197{
198 Q_D(const QPrinterInfo);
199 return d->m_printDevice.isRemote();
200}
201
211{
212 Q_D(const QPrinterInfo);
213 return QPrinter::PrinterState(d->m_printDevice.state());
214}
215
222QList<QPageSize> QPrinterInfo::supportedPageSizes() const
223{
224 Q_D(const QPrinterInfo);
225 return d->m_printDevice.supportedPageSizes();
226}
227
235{
236 Q_D(const QPrinterInfo);
237 return d->m_printDevice.defaultPageSize();
238}
239
247{
248 Q_D(const QPrinterInfo);
249 return d->m_printDevice.supportsCustomPageSizes();
250}
251
261{
262 Q_D(const QPrinterInfo);
263 return QPageSize(d->m_printDevice.minimumPhysicalPageSize(), QString(), QPageSize::ExactMatch);
264}
265
275{
276 Q_D(const QPrinterInfo);
277 return QPageSize(d->m_printDevice.maximumPhysicalPageSize(), QString(), QPageSize::ExactMatch);
278}
279
287{
288 Q_D(const QPrinterInfo);
289 return d->m_printDevice.supportedResolutions();
290}
291
299{
300 Q_D(const QPrinterInfo);
301 return QPrinter::DuplexMode(d->m_printDevice.defaultDuplexMode());
302}
303
310QList<QPrinter::DuplexMode> QPrinterInfo::supportedDuplexModes() const
311{
312 Q_D(const QPrinterInfo);
313 QList<QPrinter::DuplexMode> list;
314 const auto supportedDuplexModes = d->m_printDevice.supportedDuplexModes();
318 return list;
319}
320
328{
329 Q_D(const QPrinterInfo);
330 return QPrinter::ColorMode(d->m_printDevice.defaultColorMode());
331}
332
339QList<QPrinter::ColorMode> QPrinterInfo::supportedColorModes() const
340{
341 Q_D(const QPrinterInfo);
342 QList<QPrinter::ColorMode> list;
343 const auto supportedColorModes = d->m_printDevice.supportedColorModes();
347 return list;
348}
349
369
381{
382 QList<QPrinterInfo> list;
384 if (ps) {
385 const QStringList availablePrintDeviceIds = ps->availablePrintDeviceIds();
386 list.reserve(availablePrintDeviceIds.size());
387 for (const QString &id : availablePrintDeviceIds)
389 }
390 return list;
391}
392
405
427
438{
440}
441
442# ifndef QT_NO_DEBUG_STREAM
444{
445 QDebugStateSaver saver(debug);
446 debug.nospace();
447 debug << "QPrinterInfo(";
448 if (p.isNull())
449 debug << "null";
450 else
451 p.d_ptr->m_printDevice.format(debug);
452 debug << ')';
453 return debug;
454}
455# endif // !QT_NO_DEBUG_STREAM
456
458
459#endif // QT_NO_PRINTER
\inmodule QtCore
\inmodule QtCore
void reserve(qsizetype size)
Definition qlist.h:753
void append(parameter_type t)
Definition qlist.h:458
\inmodule QtGui
Definition qpagesize.h:22
static QPlatformPrinterSupport * get()
The QPlatformPrinterSupport class provides an abstraction for print support.
virtual QString defaultPrintDeviceId() const
virtual QPrintDevice createPrintDevice(const QString &id)
virtual QStringList availablePrintDeviceIds() const
static void cleanup(QPrinterInfoPrivate *d)
QPrinterInfoPrivate(const QString &id=QString())
QPrintDevice m_printDevice
The QPrinterInfo class gives access to information about existing printers.
QPrinter::DuplexMode defaultDuplexMode() const
Returns the default duplex mode of this printer.
static QList< QPrinterInfo > availablePrinters()
Returns a list of QPrinterInfo objects for all the available printers on this system.
QPrinter::ColorMode defaultColorMode() const
Returns the default color mode of this printer.
QPageSize maximumPhysicalPageSize() const
Returns the maximum physical page size supported by this printer.
QPrinterInfo & operator=(const QPrinterInfo &other)
Sets the QPrinterInfo object to be equal to other.
QString location() const
Returns the human-readable location of the printer.
QPageSize defaultPageSize() const
Returns the current default Page Size for this printer.
~QPrinterInfo()
Destroys the QPrinterInfo object.
QList< QPageSize > supportedPageSizes() const
Returns a list of Page Sizes supported by this printer.
QString description() const
Returns the human-readable description of the printer.
QList< QPrinter::DuplexMode > supportedDuplexModes() const
Returns a list of duplex modes supported by this printer.
bool isNull() const
Returns whether this QPrinterInfo object holds a printer definition.
bool supportsCustomPageSizes() const
Returns whether this printer supports custom page sizes.
static QString defaultPrinterName()
Returns the current default printer name.
bool isRemote() const
Returns whether this printer is a remote network printer.
bool isDefault() const
Returns whether this printer is currently the default printer.
QString makeAndModel() const
Returns the human-readable make and model of the printer.
QPrinter::PrinterState state() const
Returns the current state of this printer.
QList< QPrinter::ColorMode > supportedColorModes() const
Returns the supported color modes of this printer.
QString printerName() const
Returns the name of the printer.
static QStringList availablePrinterNames()
Returns a list of all the available Printer Names on this system.
QPageSize minimumPhysicalPageSize() const
Returns the minimum physical page size supported by this printer.
static QPrinterInfo defaultPrinter()
Returns the default printer on the system.
QPrinterInfo()
Constructs an empty QPrinterInfo object.
QList< int > supportedResolutions() const
Returns a list of resolutions supported by this printer.
static QPrinterInfo printerInfo(const QString &printerName)
Returns the printer printerName.
\reentrant
Definition qprinter.h:28
ColorMode
This enum type is used to indicate whether QPrinter should print in color or not.
Definition qprinter.h:42
PrinterState
\value Idle \value Active \value Aborted \value Error
Definition qprinter.h:64
QString printerName() const
Returns the printer name.
Definition qprinter.cpp:621
void reset(T *other=nullptr) noexcept(noexcept(Cleanup::cleanup(std::declval< T * >())))
Deletes the existing object it is pointing to (if any), and sets its pointer to other.
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
ColorMode
Definition qprint_p.h:72
DuplexMode
Definition qprint_p.h:64
Combined button and popup list for selecting options.
QList< QString > QStringList
Constructs a string list that contains the given string, str.
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
GLenum mode
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLuint name
GLfloat GLfloat p
[1]
QDebug operator<<(QDebug debug, const QPrinterInfo &p)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
QList< int > list
[14]
QSharedPointer< T > other(t)
[5]