~ubuntu-branches/ubuntu/wily/qtbase-opensource-src/wily

« back to all changes in this revision

Viewing changes to src/printsupport/kernel/qprinterinfo.cpp

  • Committer: Package Import Robot
  • Author(s): Timo Jyrinki
  • Date: 2013-02-05 12:46:17 UTC
  • Revision ID: package-import@ubuntu.com-20130205124617-c8jouts182j002fx
Tags: upstream-5.0.1+dfsg
ImportĀ upstreamĀ versionĀ 5.0.1+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/legal
 
5
**
 
6
** This file is part of the documentation of the Qt Toolkit.
 
7
**
 
8
** $QT_BEGIN_LICENSE:FDL$
 
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 Free Documentation License Usage
 
18
** Alternatively, this file may be used under the terms of the GNU Free
 
19
** Documentation License version 1.3 as published by the Free Software
 
20
** Foundation and appearing in the file included in the packaging of
 
21
** this file.  Please review the following information to ensure
 
22
** the GNU Free Documentation License version 1.3 requirements
 
23
** will be met: http://www.gnu.org/copyleft/fdl.html.
 
24
** $QT_END_LICENSE$
 
25
**
 
26
****************************************************************************/
 
27
 
 
28
#include "qprinterinfo.h"
 
29
#include "qprinterinfo_p.h"
 
30
 
 
31
#ifndef QT_NO_PRINTER
 
32
 
 
33
#include <qpa/qplatformprintplugin.h>
 
34
#include <qpa/qplatformprintersupport.h>
 
35
 
 
36
QT_BEGIN_NAMESPACE
 
37
 
 
38
QPrinterInfoPrivate QPrinterInfoPrivate::shared_null;
 
39
 
 
40
 
 
41
/*!
 
42
    \class QPrinterInfo
 
43
 
 
44
    \brief The QPrinterInfo class gives access to information about
 
45
    existing printers.
 
46
 
 
47
    \ingroup printing
 
48
    \inmodule QtPrintSupport
 
49
 
 
50
    Use the static functions to generate a list of QPrinterInfo
 
51
    objects. Each QPrinterInfo object in the list represents a single
 
52
    printer and can be queried for name, supported paper sizes, and
 
53
    whether or not it is the default printer.
 
54
 
 
55
    \since 4.4
 
56
*/
 
57
 
 
58
/*!
 
59
    \fn QList<QPrinterInfo> QPrinterInfo::availablePrinters()
 
60
 
 
61
    Returns a list of available printers on the system.
 
62
*/
 
63
 
 
64
/*!
 
65
    \fn QPrinterInfo QPrinterInfo::defaultPrinter()
 
66
 
 
67
    Returns the default printer on the system.
 
68
 
 
69
    The return value should be checked using isNull() before being
 
70
    used, in case there is no default printer.
 
71
 
 
72
    On some systems it is possible for there to be available printers
 
73
    but none of them set to be the default printer.
 
74
 
 
75
    \sa isNull()
 
76
    \sa isDefault()
 
77
    \sa availablePrinters()
 
78
*/
 
79
 
 
80
/*!
 
81
    Constructs an empty QPrinterInfo object.
 
82
 
 
83
    \sa isNull()
 
84
*/
 
85
QPrinterInfo::QPrinterInfo()
 
86
    : d_ptr(&QPrinterInfoPrivate::shared_null)
 
87
{
 
88
}
 
89
 
 
90
/*!
 
91
    Constructs a copy of \a other.
 
92
*/
 
93
QPrinterInfo::QPrinterInfo(const QPrinterInfo &other)
 
94
    : d_ptr(new QPrinterInfoPrivate(*other.d_ptr))
 
95
{
 
96
}
 
97
 
 
98
/*!
 
99
    Constructs a QPrinterInfo object from \a printer.
 
100
*/
 
101
QPrinterInfo::QPrinterInfo(const QPrinter &printer)
 
102
    : d_ptr(&QPrinterInfoPrivate::shared_null)
 
103
{
 
104
    QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get();
 
105
    if (ps) {
 
106
        QPrinterInfo pi = ps->printerInfo(printer.printerName());
 
107
        d_ptr.reset(new QPrinterInfoPrivate(*pi.d_ptr));
 
108
    }
 
109
}
 
110
 
 
111
/*!
 
112
    \internal
 
113
*/
 
114
QPrinterInfo::QPrinterInfo(const QString &name)
 
115
    : d_ptr(new QPrinterInfoPrivate(name))
 
116
{
 
117
}
 
118
 
 
119
/*!
 
120
    Destroys the QPrinterInfo object. References to the values in the
 
121
    object become invalid.
 
122
*/
 
123
QPrinterInfo::~QPrinterInfo()
 
124
{
 
125
}
 
126
 
 
127
/*!
 
128
    Sets the QPrinterInfo object to be equal to \a other.
 
129
*/
 
130
QPrinterInfo &QPrinterInfo::operator=(const QPrinterInfo &other)
 
131
{
 
132
    Q_ASSERT(d_ptr);
 
133
    d_ptr.reset(new QPrinterInfoPrivate(*other.d_ptr));
 
134
    return *this;
 
135
}
 
136
 
 
137
/*!
 
138
    Returns the name of the printer.
 
139
 
 
140
    This is a unique id to identify the printer and may not be human-readable.
 
141
 
 
142
    \sa QPrinterInfo::description()
 
143
    \sa QPrinter::setPrinterName()
 
144
*/
 
145
QString QPrinterInfo::printerName() const
 
146
{
 
147
    const Q_D(QPrinterInfo);
 
148
    return d->name;
 
149
}
 
150
 
 
151
/*!
 
152
    Returns the human-readable description of the printer.
 
153
 
 
154
    \since 5.0
 
155
    \sa QPrinterInfo::printerName()
 
156
*/
 
157
QString QPrinterInfo::description() const
 
158
{
 
159
    const Q_D(QPrinterInfo);
 
160
    return d->description;
 
161
}
 
162
 
 
163
/*!
 
164
    Returns the human-readable location of the printer.
 
165
 
 
166
    \since 5.0
 
167
*/
 
168
QString QPrinterInfo::location() const
 
169
{
 
170
    const Q_D(QPrinterInfo);
 
171
    return d->location;
 
172
}
 
173
 
 
174
/*!
 
175
    Returns the human-readable make and model of the printer.
 
176
 
 
177
    \since 5.0
 
178
*/
 
179
QString QPrinterInfo::makeAndModel() const
 
180
{
 
181
    const Q_D(QPrinterInfo);
 
182
    return d->makeAndModel;
 
183
}
 
184
 
 
185
/*!
 
186
    Returns whether this QPrinterInfo object holds a printer definition.
 
187
 
 
188
    An empty QPrinterInfo object could result for example from calling
 
189
    defaultPrinter() when there are no printers on the system.
 
190
*/
 
191
bool QPrinterInfo::isNull() const
 
192
{
 
193
    Q_D(const QPrinterInfo);
 
194
    return d == &QPrinterInfoPrivate::shared_null;
 
195
}
 
196
 
 
197
/*!
 
198
    Returns whether this printer is the default printer.
 
199
*/
 
200
bool QPrinterInfo::isDefault() const
 
201
{
 
202
    Q_D(const QPrinterInfo);
 
203
    return d->isDefault;
 
204
}
 
205
 
 
206
/*!
 
207
    Returns a list of supported paper sizes by the printer.
 
208
 
 
209
    Not all printer drivers support this query, so the list may be empty.
 
210
    On Mac OS X 10.3, this function always returns an empty list.
 
211
 
 
212
    \since 4.4
 
213
*/
 
214
 
 
215
QList<QPrinter::PaperSize> QPrinterInfo::supportedPaperSizes() const
 
216
{
 
217
    Q_D(const QPrinterInfo);
 
218
    if (!isNull() && !d->hasPaperSizes) {
 
219
        d->paperSizes = QPlatformPrinterSupportPlugin::get()->supportedPaperSizes(*this);
 
220
        d->hasPaperSizes = true;
 
221
    }
 
222
    return d->paperSizes;
 
223
}
 
224
 
 
225
QList<QPrinterInfo> QPrinterInfo::availablePrinters()
 
226
{
 
227
    QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get();
 
228
    if (!ps)
 
229
        return QList<QPrinterInfo>();
 
230
    return ps->availablePrinters();
 
231
}
 
232
 
 
233
QPrinterInfo QPrinterInfo::defaultPrinter()
 
234
{
 
235
    QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get();
 
236
    if (!ps)
 
237
        return QPrinterInfo();
 
238
    return ps->defaultPrinter();
 
239
}
 
240
 
 
241
/*!
 
242
    Returns the printer \a printerName.
 
243
 
 
244
    The return value should be checked using isNull() before being
 
245
    used, in case the named printer does not exist.
 
246
 
 
247
    \since 5.0
 
248
    \sa isNull()
 
249
*/
 
250
QPrinterInfo QPrinterInfo::printerInfo(const QString &printerName)
 
251
{
 
252
    QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get();
 
253
    if (!ps)
 
254
        return QPrinterInfo();
 
255
    return ps->printerInfo(printerName);
 
256
}
 
257
 
 
258
QT_END_NAMESPACE
 
259
 
 
260
#endif // QT_NO_PRINTER