QtPrintSupport: Move plugin access of QPrinterInfo internals to base
Move all plugin methods requiring access to QPrinterInfo internals into the plugin base class, and remove the plugin classes as friends from QPrinterInfo. Change-Id: Ic527efc681e198abf19e038dd77c36bb8017d049 Reviewed-by: Teemu Katajisto <teemu.katajisto@digia.com> Reviewed-by: John Layt <jlayt@kde.org>bb10
parent
2922f85e70
commit
271b484b00
|
|
@ -128,14 +128,13 @@ QPrinterInfo QCocoaPrinterSupport::printerInfoFromPMPrinter(const PMPrinter &pri
|
|||
if (!printer)
|
||||
return QPrinterInfo();
|
||||
|
||||
QPrinterInfo pi = QPrinterInfo(QCFString::toQString(PMPrinterGetID(printer)));
|
||||
QString name = QCFString::toQString(PMPrinterGetID(printer));
|
||||
QString description = QCFString::toQString(PMPrinterGetName(printer));
|
||||
QString location = QCFString::toQString(PMPrinterGetLocation(printer));
|
||||
CFStringRef cfMakeAndModel;
|
||||
PMPrinterGetMakeAndModelName(printer, &cfMakeAndModel);
|
||||
QString makeAndModel = QCFString::toQString(cfMakeAndModel);
|
||||
bool isDefault = PMPrinterIsDefault(printer);
|
||||
|
||||
pi.d_func()->description = QCFString::toQString(PMPrinterGetName(printer));
|
||||
pi.d_func()->location = QCFString::toQString(PMPrinterGetLocation(printer));
|
||||
CFStringRef makeAndModel;
|
||||
PMPrinterGetMakeAndModelName(printer, &makeAndModel);
|
||||
pi.d_func()->makeAndModel = QCFString::toQString(makeAndModel);
|
||||
pi.d_func()->isDefault = PMPrinterIsDefault(printer);
|
||||
|
||||
return pi;
|
||||
return createPrinterInfo(name, description, location, makeAndModel, isDefault, 0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,29 +71,17 @@ QPaintEngine *QCupsPrinterSupport::createPaintEngine(QPrintEngine *engine, QPrin
|
|||
|
||||
QList<QPrinter::PaperSize> QCupsPrinterSupport::supportedPaperSizes(const QPrinterInfo &printerInfo) const
|
||||
{
|
||||
return QCUPSSupport::getCupsPrinterPaperSizes(printerInfoCupsPrinterIndex(printerInfo));
|
||||
return QCUPSSupport::getCupsPrinterPaperSizes(printerIndex(printerInfo));
|
||||
}
|
||||
|
||||
QList<QPrinterInfo> QCupsPrinterSupport::availablePrinters()
|
||||
{
|
||||
QList<QPrinterInfo> printers;
|
||||
foreach (const QCUPSSupport::Printer &p, QCUPSSupport::availableUnixPrinters()) {
|
||||
QPrinterInfo printer(p.name);
|
||||
printer.d_func()->isDefault = p.isDefault;
|
||||
setPrinterInfoCupsPrinterIndex(&printer, p.cupsPrinterIndex);
|
||||
QPrinterInfo printer = createPrinterInfo(p.name, QString(), QString(), QString(), p.isDefault, p.cupsPrinterIndex);
|
||||
printers.append(printer);
|
||||
}
|
||||
return printers;
|
||||
}
|
||||
|
||||
int QCupsPrinterSupport::printerInfoCupsPrinterIndex(const QPrinterInfo &p)
|
||||
{
|
||||
return p.isNull() ? -1 : p.d_func()->cupsPrinterIndex;
|
||||
}
|
||||
|
||||
void QCupsPrinterSupport::setPrinterInfoCupsPrinterIndex(QPrinterInfo *p, int index)
|
||||
{
|
||||
p->d_func()->cupsPrinterIndex = index;
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -60,8 +60,6 @@ public:
|
|||
virtual QList<QPrinterInfo> availablePrinters();
|
||||
|
||||
private:
|
||||
static int printerInfoCupsPrinterIndex(const QPrinterInfo &p);
|
||||
static void setPrinterInfoCupsPrinterIndex(QPrinterInfo *p, int index);
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -64,10 +64,8 @@ QWindowsPrinterSupport::QWindowsPrinterSupport()
|
|||
QWin32PrintEngine::queryDefaultPrinter(defaultPrinterName, program, port);
|
||||
for (uint i = 0; i < returned; ++i) {
|
||||
QString printerName(QString::fromWCharArray(infoList[i].pPrinterName));
|
||||
|
||||
QPrinterInfo printerInfo(printerName);
|
||||
if (printerInfo.printerName() == defaultPrinterName)
|
||||
printerInfo.d_ptr->isDefault = true;
|
||||
bool isDefault = (printerName == defaultPrinterName);
|
||||
QPrinterInfo printerInfo = createPrinterInfo(printerName, QString(), QString(), QString(), isDefault, i);
|
||||
mPrinterList.append(printerInfo);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,8 +79,10 @@ public:
|
|||
static QSizeF convertPaperSizeToQSizeF(QPrinter::PaperSize paperSize);
|
||||
|
||||
protected:
|
||||
static void setPrinterInfoDefault(QPrinterInfo *p, bool isDefault);
|
||||
static bool printerInfoIsDefault(const QPrinterInfo &p);
|
||||
static int printerIndex(const QPrinterInfo &printer);
|
||||
static QPrinterInfo createPrinterInfo(const QString &name, const QString &description,
|
||||
const QString &location, const QString &makeAndModel,
|
||||
bool isDefault, int index);
|
||||
};
|
||||
|
||||
#endif // QT_NO_PRINTER
|
||||
|
|
|
|||
|
|
@ -107,14 +107,22 @@ QPrinterInfo QPlatformPrinterSupport::printerInfo(const QString &printerName)
|
|||
return QPrinterInfo();
|
||||
}
|
||||
|
||||
void QPlatformPrinterSupport::setPrinterInfoDefault(QPrinterInfo *p, bool isDefault)
|
||||
int QPlatformPrinterSupport::printerIndex(const QPrinterInfo &printer)
|
||||
{
|
||||
p->d_func()->isDefault = isDefault;
|
||||
return printer.d_func()->index;
|
||||
}
|
||||
|
||||
bool QPlatformPrinterSupport::printerInfoIsDefault(const QPrinterInfo &p)
|
||||
QPrinterInfo QPlatformPrinterSupport::createPrinterInfo(const QString &name, const QString &description,
|
||||
const QString &location, const QString &makeAndModel,
|
||||
bool isDefault, int index)
|
||||
{
|
||||
return p.d_func()->isDefault;
|
||||
QPrinterInfo printer(name);
|
||||
printer.d_func()->description = description;
|
||||
printer.d_func()->location = location;
|
||||
printer.d_func()->makeAndModel = makeAndModel;
|
||||
printer.d_func()->isDefault = isDefault;
|
||||
printer.d_func()->index = index;
|
||||
return printer;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -83,9 +83,6 @@ private:
|
|||
|
||||
private:
|
||||
friend class QPlatformPrinterSupport;
|
||||
friend class QWindowsPrinterSupport;
|
||||
friend class QCocoaPrinterSupport;
|
||||
friend class QCupsPrinterSupport;
|
||||
Q_DECLARE_PRIVATE(QPrinterInfo)
|
||||
QScopedPointer<QPrinterInfoPrivate, QPrinterInfoPrivateDeleter> d_ptr;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -65,11 +65,7 @@ class QPrinterInfoPrivate
|
|||
{
|
||||
public:
|
||||
QPrinterInfoPrivate(const QString& name = QString()) :
|
||||
name(name), isDefault(false)
|
||||
#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
|
||||
, cupsPrinterIndex(0)
|
||||
#endif
|
||||
, hasPaperSizes(false)
|
||||
name(name), isDefault(false), index(-1), hasPaperSizes(false)
|
||||
{}
|
||||
~QPrinterInfoPrivate()
|
||||
{}
|
||||
|
|
@ -81,10 +77,8 @@ public:
|
|||
QString location;
|
||||
QString makeAndModel;
|
||||
bool isDefault;
|
||||
int index; // Internal printer plugin use only
|
||||
|
||||
#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
|
||||
int cupsPrinterIndex;
|
||||
#endif
|
||||
mutable bool hasPaperSizes;
|
||||
mutable QList<QPrinter::PaperSize> paperSizes;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue