Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qprintdevice.cpp
Go to the documentation of this file.
1// Copyright (C) 2014 John Layt <jlayt@kde.org>
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
7
8#include <private/qdebug_p.h>
9
11
12#ifndef QT_NO_PRINTER
13
14QPrintDevice::QPrintDevice()
15 : d(new QPlatformPrintDevice())
16{
17}
18
19QPrintDevice::QPrintDevice(const QString &id)
20 : d(new QPlatformPrintDevice(id))
21{
22}
23
24QPrintDevice::QPrintDevice(QPlatformPrintDevice *dd)
25 : d(dd)
26{
27}
28
29QPrintDevice::QPrintDevice(const QPrintDevice &other)
30 : d(other.d)
31{
32}
33
34QPrintDevice::~QPrintDevice()
35{
36}
37
38QPrintDevice &QPrintDevice::operator=(const QPrintDevice &other)
39{
40 d = other.d;
41 return *this;
42}
43
44bool QPrintDevice::operator==(const QPrintDevice &other) const
45{
46 if (d && other.d)
47 return d->id() == other.d->id();
48 return d == other.d;
49}
50
51QString QPrintDevice::id() const
52{
53 return isValid() ? d->id() : QString();
54}
55
56QString QPrintDevice::name() const
57{
58 return isValid() ? d->name() : QString();
59}
60
61QString QPrintDevice::location() const
62{
63 return isValid() ? d->location() : QString();
64}
65
66QString QPrintDevice::makeAndModel() const
67{
68 return isValid() ? d->makeAndModel() : QString();
69}
70
71bool QPrintDevice::isValid() const
72{
73 return d && d->isValid();
74}
75
76bool QPrintDevice::isDefault() const
77{
78 return isValid() && d->isDefault();
79}
80
81bool QPrintDevice::isRemote() const
82{
83 return isValid() && d->isRemote();
84}
85
86QPrint::DeviceState QPrintDevice::state() const
87{
88 return isValid() ? d->state() : QPrint::Error;
89}
90
91bool QPrintDevice::isValidPageLayout(const QPageLayout &layout, int resolution) const
92{
93 return isValid() && d->isValidPageLayout(layout, resolution);
94}
95
96bool QPrintDevice::supportsMultipleCopies() const
97{
98 return isValid() && d->supportsMultipleCopies();
99}
100
101bool QPrintDevice::supportsCollateCopies() const
102{
103 return isValid() && d->supportsCollateCopies();
104}
105
106QPageSize QPrintDevice::defaultPageSize() const
107{
108 return isValid() ? d->defaultPageSize() : QPageSize();
109}
110
111QList<QPageSize> QPrintDevice::supportedPageSizes() const
112{
113 return isValid() ? d->supportedPageSizes() : QList<QPageSize>();
114}
115
116QPageSize QPrintDevice::supportedPageSize(const QPageSize &pageSize) const
117{
118 return isValid() ? d->supportedPageSize(pageSize) : QPageSize();
119}
120
121QPageSize QPrintDevice::supportedPageSize(QPageSize::PageSizeId pageSizeId) const
122{
123 return isValid() ? d->supportedPageSize(pageSizeId) : QPageSize();
124}
125
126QPageSize QPrintDevice::supportedPageSize(const QString &pageName) const
127{
128 return isValid() ? d->supportedPageSize(pageName) : QPageSize();
129}
130
131QPageSize QPrintDevice::supportedPageSize(const QSize &pointSize) const
132{
133 return isValid() ? d->supportedPageSize(pointSize) : QPageSize();
134}
135
136QPageSize QPrintDevice::supportedPageSize(const QSizeF &size, QPageSize::Unit units) const
137{
138 return isValid() ? d->supportedPageSize(size, units) : QPageSize();
139}
140
141bool QPrintDevice::supportsCustomPageSizes() const
142{
143 return isValid() && d->supportsCustomPageSizes();
144}
145
146QSize QPrintDevice::minimumPhysicalPageSize() const
147{
148 return isValid() ? d->minimumPhysicalPageSize() : QSize();
149}
150
151QSize QPrintDevice::maximumPhysicalPageSize() const
152{
153 return isValid() ? d->maximumPhysicalPageSize() : QSize();
154}
155
156QMarginsF QPrintDevice::printableMargins(const QPageSize &pageSize,
157 QPageLayout::Orientation orientation,
158 int resolution) const
159{
160 return isValid() ? d->printableMargins(pageSize, orientation, resolution) : QMarginsF();
161}
162
163int QPrintDevice::defaultResolution() const
164{
165 return isValid() ? d->defaultResolution() : 0;
166}
167
168QList<int> QPrintDevice::supportedResolutions() const
169{
170 return isValid() ? d->supportedResolutions() : QList<int>();
171}
172
173QPrint::InputSlot QPrintDevice::defaultInputSlot() const
174{
175 return isValid() ? d->defaultInputSlot() : QPrint::InputSlot();
176}
177
178QList<QPrint::InputSlot> QPrintDevice::supportedInputSlots() const
179{
180 return isValid() ? d->supportedInputSlots() : QList<QPrint::InputSlot>{};
181}
182
183QPrint::OutputBin QPrintDevice::defaultOutputBin() const
184{
185 return isValid() ? d->defaultOutputBin() : QPrint::OutputBin();
186}
187
188QList<QPrint::OutputBin> QPrintDevice::supportedOutputBins() const
189{
190 return isValid() ? d->supportedOutputBins() : QList<QPrint::OutputBin>{};
191}
192
193QPrint::DuplexMode QPrintDevice::defaultDuplexMode() const
194{
195 return isValid() ? d->defaultDuplexMode() : QPrint::DuplexNone;
196}
197
198QList<QPrint::DuplexMode> QPrintDevice::supportedDuplexModes() const
199{
200 return isValid() ? d->supportedDuplexModes() : QList<QPrint::DuplexMode>{};
201}
202
203QPrint::ColorMode QPrintDevice::defaultColorMode() const
204{
205 return isValid() ? d->defaultColorMode() : QPrint::GrayScale;
206}
207
208QList<QPrint::ColorMode> QPrintDevice::supportedColorModes() const
209{
210 return isValid() ? d->supportedColorModes() : QList<QPrint::ColorMode>{};
211}
212
213QVariant QPrintDevice::property(PrintDevicePropertyKey key) const
214{
215 return isValid() ? d->property(key) : QVariant();
216}
217
218bool QPrintDevice::setProperty(PrintDevicePropertyKey key, const QVariant &value)
219{
220 return isValid() ? d->setProperty(key, value) : false;
221}
222
223bool QPrintDevice::isFeatureAvailable(PrintDevicePropertyKey key, const QVariant &params) const
224{
225 return isValid() ? d->isFeatureAvailable(key, params) : false;
226}
227
228#if QT_CONFIG(mimetype)
229QList<QMimeType> QPrintDevice::supportedMimeTypes() const
230{
231 return isValid() ? d->supportedMimeTypes() : QList<QMimeType>();
232}
233#endif // mimetype
234
235# ifndef QT_NO_DEBUG_STREAM
236void QPrintDevice::format(QDebug debug) const
237{
238 QDebugStateSaver saver(debug);
239 debug.noquote();
240 debug.nospace();
241 if (isValid()) {
242 const QString deviceId = id();
243 const QString deviceName = name();
244 debug << "id=\"" << deviceId << "\", state=" << state();
245 if (!deviceName.isEmpty() && deviceName != deviceId)
246 debug << ", name=\"" << deviceName << '"';
247 if (!location().isEmpty())
248 debug << ", location=\"" << location() << '"';
249 debug << ", makeAndModel=\"" << makeAndModel() << '"';
250 if (isDefault())
251 debug << ", default";
252 if (isRemote())
253 debug << ", remote";
254 debug << ", defaultPageSize=" << defaultPageSize();
255 if (supportsCustomPageSizes())
256 debug << ", supportsCustomPageSizes";
257 debug << ", physicalPageSize=(";
258 QtDebugUtils::formatQSize(debug, minimumPhysicalPageSize());
259 debug << ")..(";
260 QtDebugUtils::formatQSize(debug, maximumPhysicalPageSize());
261 debug << "), defaultResolution=" << defaultResolution()
262 << ", defaultDuplexMode=" << defaultDuplexMode()
263 << ", defaultColorMode="<< defaultColorMode();
264# if QT_CONFIG(mimetype)
265 const QList<QMimeType> mimeTypes = supportedMimeTypes();
266 if (!mimeTypes.isEmpty()) {
267 debug << ", supportedMimeTypes=(";
268 for (const auto &mimeType : mimeTypes)
269 debug << " \"" << mimeType.name() << '"';
270 debug << ')';
271 }
272# endif // mimetype
273 } else {
274 debug << "null";
275 }
276}
277
278QDebug operator<<(QDebug debug, const QPrintDevice &p)
279{
280 QDebugStateSaver saver(debug);
281 debug.nospace();
282 debug << "QPrintDevice(";
283 p.format(debug);
284 debug << ')';
285 return debug;
286}
287# endif // QT_NO_DEBUG_STREAM
288#endif // QT_NO_PRINTER
289
290QT_END_NAMESPACE