QtPrintSupport: eradicate all Q_FOREACH loops

Saves more than 2KiB in text size on optimized GCC 4.9 Linux
AMD64 builds, iow: ~0.5% of the total library size.

Change-Id: I84e1dc208da13eefdf1573c9b7ac7c9d76a7f5c7
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
Marc Mutz 2015-12-23 00:15:30 +01:00
parent 2d4295f167
commit b78097b22d
6 changed files with 21 additions and 16 deletions

View File

@ -339,9 +339,9 @@ void QPageSetupWidget::initPageSizes()
QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get();
if (ps) {
QPrintDevice printDevice = ps->createPrintDevice(m_printerName);
foreach (const QPageSize &pageSize, printDevice.supportedPageSizes()) {
const auto pageSizes = printDevice.supportedPageSizes();
for (const QPageSize &pageSize : pageSizes)
m_ui.pageSizeCombo->addItem(pageSize.name(), QVariant::fromValue(pageSize.id()));
}
if (m_ui.pageSizeCombo->count() > 0 && printDevice.supportsCustomPageSizes()) {
m_ui.pageSizeCombo->addItem(tr("Custom"), QVariant::fromValue(QPageSize::Custom));
m_blockSignals = false;

View File

@ -168,7 +168,7 @@ QPageSize QPlatformPrintDevice::supportedPageSize(const QPageSize &pageSize) con
// e.g. Windows defines DMPAPER_11X17 and DMPAPER_TABLOID with names "11x17" and "Tabloid", but both
// map to QPageSize::Tabloid / PPD Key "Tabloid" / ANSI B Tabloid
if (pageSize.id() != QPageSize::Custom) {
foreach (const QPageSize &ps, m_pageSizes) {
for (const QPageSize &ps : m_pageSizes) {
if (ps.id() == pageSize.id() && ps.name() == pageSize.name())
return ps;
}
@ -176,7 +176,7 @@ QPageSize QPlatformPrintDevice::supportedPageSize(const QPageSize &pageSize) con
// Next try match on id only if not custom
if (pageSize.id() != QPageSize::Custom) {
foreach (const QPageSize &ps, m_pageSizes) {
for (const QPageSize &ps : m_pageSizes) {
if (ps.id() == pageSize.id())
return ps;
}
@ -191,7 +191,7 @@ QPageSize QPlatformPrintDevice::supportedPageSize(QPageSize::PageSizeId pageSize
if (!m_havePageSizes)
loadPageSizes();
foreach (const QPageSize &ps, m_pageSizes) {
for (const QPageSize &ps : m_pageSizes) {
if (ps.id() == pageSizeId)
return ps;
}
@ -205,7 +205,7 @@ QPageSize QPlatformPrintDevice::supportedPageSize(const QString &pageName) const
if (!m_havePageSizes)
loadPageSizes();
foreach (const QPageSize &ps, m_pageSizes) {
for (const QPageSize &ps : m_pageSizes) {
if (ps.name() == pageName)
return ps;
}
@ -234,7 +234,7 @@ QPageSize QPlatformPrintDevice::supportedPageSize(const QSizeF &size, QPageSize:
QPageSize QPlatformPrintDevice::supportedPageSizeMatch(const QPageSize &pageSize) const
{
// Try to find a supported page size based on point size
foreach (const QPageSize &ps, m_pageSizes) {
for (const QPageSize &ps : m_pageSizes) {
if (ps.sizePoints() == pageSize.sizePoints())
return ps;
}

View File

@ -1463,7 +1463,9 @@ QVariant QWin32PrintEngine::property(PrintEnginePropertyKey key) const
case PPK_SupportedResolutions: {
QList<QVariant> list;
foreach (int resolution, d->m_printDevice.supportedResolutions())
const auto resolutions = d->m_printDevice.supportedResolutions();
list.reserve(resolutions.size());
for (int resolution : resolutions)
list << resolution;
value = list;
break;
@ -1475,7 +1477,9 @@ QVariant QWin32PrintEngine::property(PrintEnginePropertyKey key) const
case PPK_PaperSources: {
QList<QVariant> out;
foreach (const QPrint::InputSlot inputSlot, d->m_printDevice.supportedInputSlots())
const auto inputSlots = d->m_printDevice.supportedInputSlots();
out.reserve(inputSlots.size());
for (const QPrint::InputSlot inputSlot : inputSlots)
out << QVariant(inputSlot.id == QPrint::CustomInputSlot ? inputSlot.windowsId : int(inputSlot.id));
value = out;
break;

View File

@ -160,7 +160,8 @@ void QPrinterPrivate::changeEngines(QPrinter::OutputFormat format, const QPrinte
initEngines(format, printer);
if (oldPrintEngine) {
foreach (QPrintEngine::PrintEnginePropertyKey key, m_properties) {
const auto properties = m_properties; // take a copy: setProperty() below modifies m_properties
for (const auto &key : properties) {
QVariant prop;
// PPK_NumberOfCopies need special treatmeant since it in most cases
// will return 1, disregarding the actual value that was set

View File

@ -318,7 +318,7 @@ QList<QPrinter::PaperSize> QPrinterInfo::supportedPaperSizes() const
QList<QPrinter::PaperSize> list;
const QList<QPageSize> supportedPageSizes = d->m_printDevice.supportedPageSizes();
list.reserve(supportedPageSizes.size());
foreach (const QPageSize &pageSize, supportedPageSizes)
for (const QPageSize &pageSize : supportedPageSizes)
list.append(QPrinter::PaperSize(pageSize.id()));
return list;
}
@ -340,7 +340,7 @@ QList<QPair<QString, QSizeF> > QPrinterInfo::supportedSizesWithNames() const
QList<QPair<QString, QSizeF> > list;
const QList<QPageSize> supportedPageSizes = d->m_printDevice.supportedPageSizes();
list.reserve(supportedPageSizes.size());
foreach (const QPageSize &pageSize, supportedPageSizes)
for (const QPageSize &pageSize : supportedPageSizes)
list.append(qMakePair(pageSize.name(), pageSize.size(QPageSize::Millimeter)));
return list;
}
@ -382,7 +382,7 @@ QList<QPrinter::DuplexMode> QPrinterInfo::supportedDuplexModes() const
QList<QPrinter::DuplexMode> list;
const QList<QPrint::DuplexMode> supportedDuplexModes = d->m_printDevice.supportedDuplexModes();
list.reserve(supportedDuplexModes.size());
foreach (QPrint::DuplexMode mode, supportedDuplexModes)
for (QPrint::DuplexMode mode : supportedDuplexModes)
list << QPrinter::DuplexMode(mode);
return list;
}
@ -424,7 +424,7 @@ QList<QPrinterInfo> QPrinterInfo::availablePrinters()
if (ps) {
const QStringList availablePrintDeviceIds = ps->availablePrintDeviceIds();
list.reserve(availablePrintDeviceIds.size());
foreach (const QString &id, availablePrintDeviceIds)
for (const QString &id : availablePrintDeviceIds)
list.append(QPrinterInfo(id));
}
return list;

View File

@ -223,8 +223,8 @@ void QPrintPreviewWidgetPrivate::_q_fit(bool doFitting)
if (doFitting && fitting) {
QRect viewRect = graphicsView->viewport()->rect();
if (zoomMode == QPrintPreviewWidget::FitInView) {
QList<QGraphicsItem*> containedItems = graphicsView->items(viewRect, Qt::ContainsItemBoundingRect);
foreach(QGraphicsItem* item, containedItems) {
const QList<QGraphicsItem*> containedItems = graphicsView->items(viewRect, Qt::ContainsItemBoundingRect);
for (QGraphicsItem* item : containedItems) {
PageItem* pg = static_cast<PageItem*>(item);
if (pg->pageNumber() == curPage)
return;