Qt 4.8
Public Functions | Static Public Functions | Private Functions | Properties | List of all members
QPrinterInfo Class Reference

The QPrinterInfo class gives access to information about existing printers. More...

#include <qprinterinfo.h>

Public Functions

bool isDefault () const
 Returns whether this printer is the default printer. More...
 
bool isNull () const
 Returns whether this QPrinterInfo object holds a printer definition. More...
 
QPrinterInfooperator= (const QPrinterInfo &other)
 Sets the QPrinterInfo object to be equal to other. More...
 
QString printerName () const
 Returns the name of the printer. More...
 
 QPrinterInfo ()
 Constructs an empty QPrinterInfo object. More...
 
 QPrinterInfo (const QPrinterInfo &other)
 Constructs a copy of other. More...
 
 QPrinterInfo (const QPrinter &printer)
 Constructs a QPrinterInfo object from printer. More...
 
QList< QPrinter::PaperSizesupportedPaperSizes () const
 Returns a list of supported paper sizes by the printer. More...
 
 ~QPrinterInfo ()
 Destroys the QPrinterInfo object. More...
 

Static Public Functions

static QList< QPrinterInfoavailablePrinters ()
 Returns a list of available printers on the system. More...
 
static QPrinterInfo defaultPrinter ()
 Returns the default printer on the system. More...
 

Private Functions

 QPrinterInfo (const QString &name)
 

Properties

QScopedPointer< QPrinterInfoPrivate, QPrinterInfoPrivateDeleterd_ptr
 

Detailed Description

The QPrinterInfo class gives access to information about existing printers.

Use the static functions to generate a list of QPrinterInfo objects. Each QPrinterInfo object in the list represents a single printer and can be queried for name, supported paper sizes, and whether or not it is the default printer.

Since
4.4

Definition at line 58 of file qprinterinfo.h.

Constructors and Destructors

◆ QPrinterInfo() [1/4]

QPrinterInfo::QPrinterInfo ( )

Constructs an empty QPrinterInfo object.

See also
isNull()

Definition at line 85 of file qprinterinfo.cpp.

87 {
88 }
static QPrinterInfoPrivate shared_null
QScopedPointer< QPrinterInfoPrivate, QPrinterInfoPrivateDeleter > d_ptr
Definition: qprinterinfo.h:81

◆ QPrinterInfo() [2/4]

QPrinterInfo::QPrinterInfo ( const QPrinterInfo other)

Constructs a copy of other.

Since
4.8

Definition at line 98 of file qprinterinfo.cpp.

99  : d_ptr(new QPrinterInfoPrivate(*other.d_ptr))
100 {
101 }
QScopedPointer< QPrinterInfoPrivate, QPrinterInfoPrivateDeleter > d_ptr
Definition: qprinterinfo.h:81

◆ QPrinterInfo() [3/4]

QPrinterInfo::QPrinterInfo ( const QPrinter printer)

Constructs a QPrinterInfo object from printer.

Definition at line 106 of file qprinterinfo.cpp.

108 {
109  foreach (const QPrinterInfo &printerInfo, availablePrinters()) {
110  if (printerInfo.printerName() == printer.printerName()) {
111  d_ptr.reset(new QPrinterInfoPrivate(*printerInfo.d_ptr));
112  break;
113  }
114  }
115 }
void reset(T *other=0)
Deletes the existing object it is pointing to if any, and sets its pointer to other.
The QPrinterInfo class gives access to information about existing printers.
Definition: qprinterinfo.h:58
QString printerName() const
Returns the name of the printer.
static QPrinterInfoPrivate shared_null
QScopedPointer< QPrinterInfoPrivate, QPrinterInfoPrivateDeleter > d_ptr
Definition: qprinterinfo.h:81
static QList< QPrinterInfo > availablePrinters()
Returns a list of available printers on the system.
QString printerName() const
Returns the printer name.
Definition: qprinter.cpp:834

◆ ~QPrinterInfo()

QPrinterInfo::~QPrinterInfo ( )

Destroys the QPrinterInfo object.

References to the values in the object become invalid.

Definition at line 129 of file qprinterinfo.cpp.

130 {
131 }

◆ QPrinterInfo() [4/4]

QPrinterInfo::QPrinterInfo ( const QString name)
private
Warning
This function is not part of the public interface.

Definition at line 120 of file qprinterinfo.cpp.

121  : d_ptr(new QPrinterInfoPrivate(name))
122 {
123 }
QScopedPointer< QPrinterInfoPrivate, QPrinterInfoPrivateDeleter > d_ptr
Definition: qprinterinfo.h:81

Functions

◆ availablePrinters()

QList< QPrinterInfo > QPrinterInfo::availablePrinters ( )
static

Returns a list of available printers on the system.

Definition at line 53 of file qprinterinfo_mac.cpp.

Referenced by defaultPrinter(), QPrinter::QPrinter(), QPrinterInfo(), qt_getLprPrinters(), and QPrinter::setPrinterName().

54 {
55  QList<QPrinterInfo> printers;
56 
57  QCFType<CFArrayRef> array;
58  if (PMServerCreatePrinterList(kPMServerLocal, &array) == noErr) {
59  CFIndex count = CFArrayGetCount(array);
60  for (int i = 0; i < count; ++i) {
61  PMPrinter printer = static_cast<PMPrinter>(const_cast<void *>(CFArrayGetValueAtIndex(array, i)));
62  QString printerName = QCFString::toQString(PMPrinterGetName(printer));
63 
64  QPrinterInfo printerInfo(printerName);
65  if (PMPrinterIsDefault(printer))
66  printerInfo.d_ptr->isDefault = true;
67  printers.append(printerInfo);
68  }
69  }
70 
71  return printers;
72 }
static QString toQString(CFStringRef cfstr)
Definition: qcore_mac.cpp:47
The QString class provides a Unicode character string.
Definition: qstring.h:83
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
The QPrinterInfo class gives access to information about existing printers.
Definition: qprinterinfo.h:58
QString printerName() const
Returns the name of the printer.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ defaultPrinter()

QPrinterInfo QPrinterInfo::defaultPrinter ( )
static

Returns the default printer on the system.

The return value should be checked using isNull() before being used, in case there is no default printer.

See also
isNull()

Definition at line 74 of file qprinterinfo_mac.cpp.

Referenced by QPdfBaseEnginePrivate::closePrintDevice(), QPrinter::QPrinter(), and qt_getLprPrinters().

75 {
77  foreach (const QPrinterInfo &printerInfo, printers) {
78  if (printerInfo.isDefault())
79  return printerInfo;
80  }
81 
82  return printers.value(0);
83 }
T value(int i) const
Returns the value at index position i in the list.
Definition: qlist.h:661
bool isDefault() const
Returns whether this printer is the default printer.
The QPrinterInfo class gives access to information about existing printers.
Definition: qprinterinfo.h:58
static QList< QPrinterInfo > availablePrinters()
Returns a list of available printers on the system.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ isDefault()

bool QPrinterInfo::isDefault ( ) const

Returns whether this printer is the default printer.

Definition at line 174 of file qprinterinfo.cpp.

Referenced by defaultPrinter(), and qt_getLprPrinters().

175 {
176  const Q_D(QPrinterInfo);
177  return d->isDefault;
178 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinterInfo class gives access to information about existing printers.
Definition: qprinterinfo.h:58

◆ isNull()

bool QPrinterInfo::isNull ( ) const

Returns whether this QPrinterInfo object holds a printer definition.

An empty QPrinterInfo object could result for example from calling defaultPrinter() when there are no printers on the system.

Definition at line 165 of file qprinterinfo.cpp.

Referenced by QPdfBaseEnginePrivate::closePrintDevice(), QPrinter::QPrinter(), and supportedPaperSizes().

166 {
167  const Q_D(QPrinterInfo);
169 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinterInfo class gives access to information about existing printers.
Definition: qprinterinfo.h:58
static QPrinterInfoPrivate shared_null

◆ operator=()

QPrinterInfo & QPrinterInfo::operator= ( const QPrinterInfo other)

Sets the QPrinterInfo object to be equal to other.

Since
4.8

Definition at line 141 of file qprinterinfo.cpp.

142 {
143  Q_ASSERT(d_ptr);
144  d_ptr.reset(new QPrinterInfoPrivate(*other.d_ptr));
145  return *this;
146 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void reset(T *other=0)
Deletes the existing object it is pointing to if any, and sets its pointer to other.
QScopedPointer< QPrinterInfoPrivate, QPrinterInfoPrivateDeleter > d_ptr
Definition: qprinterinfo.h:81

◆ printerName()

QString QPrinterInfo::printerName ( ) const

Returns the name of the printer.

See also
QPrinter::setPrinterName()

Definition at line 153 of file qprinterinfo.cpp.

Referenced by availablePrinters(), QPdfBaseEnginePrivate::closePrintDevice(), QPrinter::QPrinter(), and QPrinterInfo().

154 {
155  const Q_D(QPrinterInfo);
156  return d->name;
157 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPrinterInfo class gives access to information about existing printers.
Definition: qprinterinfo.h:58

◆ supportedPaperSizes()

QList< QPrinter::PaperSize > QPrinterInfo::supportedPaperSizes ( ) const

Returns a list of supported paper sizes by the printer.

Since
4.4

Not all printer drivers support this query, so the list may be empty. On Mac OS X 10.3, this function always returns an empty list.

Definition at line 85 of file qprinterinfo_mac.cpp.

Referenced by qt_getLprPrinters().

86 {
87  const Q_D(QPrinterInfo);
88 
89  QList<QPrinter::PaperSize> paperSizes;
90  if (isNull())
91  return paperSizes;
92 
93  PMPrinter cfPrn = PMPrinterCreateFromPrinterID(QCFString::toCFStringRef(d->name));
94  if (!cfPrn)
95  return paperSizes;
96 
97  CFArrayRef array;
98  if (PMPrinterGetPaperList(cfPrn, &array) != noErr) {
99  PMRelease(cfPrn);
100  return paperSizes;
101  }
102 
103  int count = CFArrayGetCount(array);
104  for (int i = 0; i < count; ++i) {
105  PMPaper paper = static_cast<PMPaper>(const_cast<void *>(CFArrayGetValueAtIndex(array, i)));
106  double width, height;
107  if (PMPaperGetWidth(paper, &width) == noErr && PMPaperGetHeight(paper, &height) == noErr) {
108  QSizeF size(width * 0.3527, height * 0.3527);
109  paperSizes.append(qSizeFTopaperSize(size));
110  }
111  }
112 
113  PMRelease(cfPrn);
114 
115  return paperSizes;
116 }
double d
Definition: qnumeric_p.h:62
QPrinter::PaperSize qSizeFTopaperSize(const QSizeF &size)
Definition: qprinter.cpp:2629
static CFStringRef toCFStringRef(const QString &str)
Definition: qcore_mac.cpp:69
#define Q_D(Class)
Definition: qglobal.h:2482
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
The QPrinterInfo class gives access to information about existing printers.
Definition: qprinterinfo.h:58
bool isNull() const
Returns whether this QPrinterInfo object holds a printer definition.
const struct __CFArray * CFArrayRef
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

Properties

◆ d_ptr

Definition at line 81 of file qprinterinfo.h.

Referenced by availablePrinters(), operator=(), QPrinterInfo(), and qt_getLprPrinters().


The documentation for this class was generated from the following files: