QtPrintSupport: convert some index-based into C++11 range-for loops

Also reserve a QList in QPrinter::supportedPaperSources().

Change-Id: I94d24b81d7adcad2b28d36efdbef5a8726412f1a
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
This commit is contained in:
Marc Mutz 2015-12-29 11:12:31 +01:00
parent 7ca90e985c
commit 24a96e2a3e
5 changed files with 23 additions and 23 deletions

View File

@ -250,8 +250,8 @@ void QPrintPreviewDialogPrivate::init(QPrinter *_printer)
zoomEditor->setValidator(new ZoomFactorValidator(1, 1000, 1, zoomEditor));
zoomFactor->setLineEdit(zoomEditor);
static const short factorsX2[] = { 25, 50, 100, 200, 250, 300, 400, 800, 1600 };
for (int i = 0; i < int(sizeof(factorsX2) / sizeof(factorsX2[0])); ++i)
zoomFactor->addItem(QPrintPreviewDialog::tr("%1%").arg(factorsX2[i] / 2.0));
for (auto factorX2 : factorsX2)
zoomFactor->addItem(QPrintPreviewDialog::tr("%1%").arg(factorX2 / 2.0));
QObject::connect(zoomFactor->lineEdit(), SIGNAL(editingFinished()),
q, SLOT(_q_zoomFactorChanged()));
QObject::connect(zoomFactor, SIGNAL(currentIndexChanged(int)),

View File

@ -336,8 +336,8 @@ void QAlphaPaintEngine::flushAndInit(bool init)
d->resetState(painter());
// fill in the alpha images
for (int i=0; i<rects.size(); ++i)
d->drawAlphaImage(rects.at(i));
for (const auto &rect : qAsConst(rects))
d->drawAlphaImage(rect);
d->m_alphargn = QRegion();

View File

@ -283,10 +283,10 @@ void QPrintDevice::format(QDebug debug) const
<< ", defaultColorMode="<< defaultColorMode();
# ifndef QT_NO_MIMETYPE
const QList<QMimeType> mimeTypes = supportedMimeTypes();
if (const int mimeTypeCount = mimeTypes.size()) {
if (!mimeTypes.isEmpty()) {
debug << ", supportedMimeTypes=(";
for (int i = 0; i < mimeTypeCount; ++i)
debug << " \"" << mimeTypes.at(i).name() << '"';
for (const auto &mimeType : mimeTypes)
debug << " \"" << mimeType.name() << '"';
debug << ')';
}
# endif // !QT_NO_MIMETYPE

View File

@ -1946,13 +1946,12 @@ int QPrinter::winPageSize() const
QList<int> QPrinter::supportedResolutions() const
{
Q_D(const QPrinter);
QList<QVariant> varlist
const QList<QVariant> varlist
= d->printEngine->property(QPrintEngine::PPK_SupportedResolutions).toList();
QList<int> intlist;
const int numSupportedResolutions = varlist.size();
intlist.reserve(numSupportedResolutions);
for (int i = 0; i < numSupportedResolutions; ++i)
intlist << varlist.at(i).toInt();
intlist.reserve(varlist.size());
for (auto var : varlist)
intlist << var.toInt();
return intlist;
}
@ -2015,10 +2014,11 @@ QList<QPrinter::PaperSource> QPrinter::supportedPaperSources() const
Q_D(const QPrinter);
QVariant v = d->printEngine->property(QPrintEngine::PPK_PaperSources);
QList<QVariant> variant_list = v.toList();
const QList<QVariant> variant_list = v.toList();
QList<QPrinter::PaperSource> int_list;
for (int i=0; i<variant_list.size(); ++i)
int_list << (QPrinter::PaperSource) variant_list.at(i).toInt();
int_list.reserve(variant_list.size());
for (const auto &variant : variant_list)
int_list << QPrinter::PaperSource(variant.toInt());
return int_list;
}

View File

@ -295,9 +295,9 @@ int QPrintPreviewWidgetPrivate::calcCurrentPage()
int maxArea = 0;
int newPage = curPage;
QRect viewRect = graphicsView->viewport()->rect();
QList<QGraphicsItem*> items = graphicsView->items(viewRect);
for (int i=0; i<items.size(); ++i) {
PageItem* pg = static_cast<PageItem*>(items.at(i));
const QList<QGraphicsItem*> items = graphicsView->items(viewRect);
for (auto *item : items) {
PageItem* pg = static_cast<PageItem*>(item);
QRect overlap = graphicsView->mapFromScene(pg->sceneBoundingRect()).boundingRect() & viewRect;
int area = overlap.width() * overlap.height();
if (area > maxArea) {
@ -335,17 +335,17 @@ void QPrintPreviewWidgetPrivate::init()
void QPrintPreviewWidgetPrivate::populateScene()
{
// remove old pages
for (int i = 0; i < pages.size(); i++)
scene->removeItem(pages.at(i));
for (auto *page : qAsConst(pages))
scene->removeItem(page);
qDeleteAll(pages);
pages.clear();
int numPages = pictures.count();
QSize paperSize = printer->pageLayout().fullRectPixels(printer->resolution()).size();
QRect pageRect = printer->pageLayout().paintRectPixels(printer->resolution());
for (int i = 0; i < numPages; i++) {
PageItem* item = new PageItem(i+1, pictures.at(i), paperSize, pageRect);
int page = 1;
for (auto *picture : qAsConst(pictures)) {
PageItem* item = new PageItem(page++, picture, paperSize, pageRect);
scene->addItem(item);
pages.append(item);
}