diff options
Diffstat (limited to 'src/widgets')
27 files changed, 153 insertions, 90 deletions
diff --git a/src/widgets/dialogs/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp index 3bcd6f7c4b..defc0539c9 100644 --- a/src/widgets/dialogs/qfiledialog.cpp +++ b/src/widgets/dialogs/qfiledialog.cpp @@ -2689,7 +2689,7 @@ void QFileDialogPrivate::saveSettings() settings.beginGroup(QLatin1String("FileDialog")); if (usingWidgets()) { - settings.setValue(QLatin1String("sidebarWidth"), qFileDialogUi->splitter->sizes().first()); + settings.setValue(QLatin1String("sidebarWidth"), qFileDialogUi->splitter->sizes().constFirst()); settings.setValue(QLatin1String("shortcuts"), QUrl::toStringList(qFileDialogUi->sidebar->urls())); settings.setValue(QLatin1String("treeViewHeader"), qFileDialogUi->treeView->header()->saveState()); } @@ -3001,9 +3001,9 @@ void QFileDialogPrivate::createWidgets() q->selectNameFilter(options->initiallySelectedNameFilter()); q->setDefaultSuffix(options->defaultSuffix()); q->setHistory(options->history()); - if (options->initiallySelectedFiles().count() == 1) - q->selectFile(options->initiallySelectedFiles().first().fileName()); const auto initiallySelectedFiles = options->initiallySelectedFiles(); + if (initiallySelectedFiles.size() == 1) + q->selectFile(initiallySelectedFiles.first().fileName()); for (const QUrl &url : initiallySelectedFiles) q->selectUrl(url); lineEdit()->selectAll(); @@ -4095,7 +4095,7 @@ QStringList QFSCompleter::splitPath(const QString &path) const parts.removeFirst(); currentLocationList.removeLast(); } - if (!currentLocationList.isEmpty() && currentLocationList.last().isEmpty()) + if (!currentLocationList.isEmpty() && currentLocationList.constLast().isEmpty()) currentLocationList.removeLast(); return currentLocationList + parts; } diff --git a/src/widgets/dialogs/qfileinfogatherer.cpp b/src/widgets/dialogs/qfileinfogatherer.cpp index 48ae5f1fc4..b20db8fc7c 100644 --- a/src/widgets/dialogs/qfileinfogatherer.cpp +++ b/src/widgets/dialogs/qfileinfogatherer.cpp @@ -217,9 +217,9 @@ void QFileInfoGatherer::run() condition.wait(&mutex); if (abort.load()) return; - const QString thisPath = path.front(); + const QString thisPath = qAsConst(path).front(); path.pop_front(); - const QStringList thisList = files.front(); + const QStringList thisList = qAsConst(files).front(); files.pop_front(); locker.unlock(); diff --git a/src/widgets/dialogs/qfilesystemmodel.cpp b/src/widgets/dialogs/qfilesystemmodel.cpp index bfa40317eb..c72761f2ae 100644 --- a/src/widgets/dialogs/qfilesystemmodel.cpp +++ b/src/widgets/dialogs/qfilesystemmodel.cpp @@ -374,7 +374,7 @@ QFileSystemModelPrivate::QFileSystemNode *QFileSystemModelPrivate::node(const QS QModelIndex index = QModelIndex(); // start with "My Computer" #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) if (absolutePath.startsWith(QLatin1String("//"))) { // UNC path - QString host = QLatin1String("\\\\") + pathElements.first(); + QString host = QLatin1String("\\\\") + pathElements.constFirst(); if (absolutePath == QDir::fromNativeSeparators(host)) absolutePath.append(QLatin1Char('/')); if (longPath.endsWith(QLatin1Char('/')) && !absolutePath.endsWith(QLatin1Char('/'))) diff --git a/src/widgets/dialogs/qsidebar.cpp b/src/widgets/dialogs/qsidebar.cpp index 2e884e238d..1b1eb6472e 100644 --- a/src/widgets/dialogs/qsidebar.cpp +++ b/src/widgets/dialogs/qsidebar.cpp @@ -127,7 +127,7 @@ QMimeData *QUrlModel::mimeData(const QModelIndexList &indexes) const */ bool QUrlModel::canDrop(QDragEnterEvent *event) { - if (!event->mimeData()->formats().contains(mimeTypes().first())) + if (!event->mimeData()->formats().contains(mimeTypes().constFirst())) return false; const QList<QUrl> list = event->mimeData()->urls(); @@ -145,7 +145,7 @@ bool QUrlModel::canDrop(QDragEnterEvent *event) bool QUrlModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) { - if (!data->formats().contains(mimeTypes().first())) + if (!data->formats().contains(mimeTypes().constFirst())) return false; Q_UNUSED(action); Q_UNUSED(column); diff --git a/src/widgets/dialogs/qwizard.cpp b/src/widgets/dialogs/qwizard.cpp index aa10f65389..53f947354c 100644 --- a/src/widgets/dialogs/qwizard.cpp +++ b/src/widgets/dialogs/qwizard.cpp @@ -850,9 +850,9 @@ void QWizardPrivate::switchToPage(int newId, Direction direction) q->cleanupPage(oldId); initialized.remove(oldId); } - Q_ASSERT(history.last() == oldId); + Q_ASSERT(history.constLast() == oldId); history.removeLast(); - Q_ASSERT(history.last() == newId); + Q_ASSERT(history.constLast() == newId); } } diff --git a/src/widgets/doc/qtwidgets.qdocconf b/src/widgets/doc/qtwidgets.qdocconf index 8160396ca2..75bbb99579 100644 --- a/src/widgets/doc/qtwidgets.qdocconf +++ b/src/widgets/doc/qtwidgets.qdocconf @@ -26,7 +26,7 @@ qhp.QtWidgets.subprojects.classes.sortPages = true tagfile = ../../../doc/qtwidgets/qtwidgets.tags -depends += qtcore qtgui qtdoc qtsql qtdesigner qtquick qmake qtsvg +depends += qtcore qtgui qtdoc qtsql qtdesigner qtquick qmake qtplatformheaders qtsvg headerdirs += .. diff --git a/src/widgets/itemviews/qtableview.cpp b/src/widgets/itemviews/qtableview.cpp index 714f09e893..e045d60fc8 100644 --- a/src/widgets/itemviews/qtableview.cpp +++ b/src/widgets/itemviews/qtableview.cpp @@ -2016,8 +2016,8 @@ QRegion QTableView::visualRegionForSelection(const QItemSelection &selection) co if (viewportRect.intersects(rangeRect)) selectionRegion += rangeRect; if (d->hasSpans()) { - foreach (QSpanCollection::Span *s, - d->spans.spansInRect(range.left(), range.top(), range.width(), range.height())) { + const auto spansInRect = d->spans.spansInRect(range.left(), range.top(), range.width(), range.height()); + for (QSpanCollection::Span *s : spansInRect) { if (range.contains(s->top(), s->left(), range.parent())) { const QRect &visualSpanRect = d->visualSpanRect(*s); if (viewportRect.intersects(visualSpanRect)) diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index ebdbdbd3e6..2d23bb61a2 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -424,6 +424,7 @@ QWidget *QApplicationPrivate::hidden_focus_widget = 0; // will get keyboard inpu QWidget *QApplicationPrivate::active_window = 0; // toplevel with keyboard focus #ifndef QT_NO_WHEELEVENT int QApplicationPrivate::wheel_scroll_lines; // number of lines to scroll +QWidget *QApplicationPrivate::wheel_widget = Q_NULLPTR; #endif bool qt_in_tab_key_event = false; int qt_antialiasing_threshold = -1; @@ -786,7 +787,7 @@ void QApplicationPrivate::initializeWidgetFontHash() QWidget *QApplication::activePopupWidget() { return QApplicationPrivate::popupWidgets && !QApplicationPrivate::popupWidgets->isEmpty() ? - QApplicationPrivate::popupWidgets->last() : 0; + QApplicationPrivate::popupWidgets->constLast() : nullptr; } @@ -1718,9 +1719,11 @@ QString QApplicationPrivate::desktopStyleKey() // first valid one. if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) { const QStringList availableKeys = QStyleFactory::keys(); - foreach (const QString &style, theme->themeHint(QPlatformTheme::StyleNames).toStringList()) + const auto styles = theme->themeHint(QPlatformTheme::StyleNames).toStringList(); + for (const QString &style : styles) { if (availableKeys.contains(style, Qt::CaseInsensitive)) return style; + } } return QString(); } @@ -2225,10 +2228,13 @@ QWidget *qt_tlw_for_window(QWindow *wnd) else break; } - if (wnd) - foreach (QWidget *tlw, qApp->topLevelWidgets()) + if (wnd) { + const auto tlws = qApp->topLevelWidgets(); + for (QWidget *tlw : tlws) { if (tlw->windowHandle() == wnd) return tlw; + } + } return 0; } @@ -2391,7 +2397,7 @@ void QApplicationPrivate::dispatchEnterLeave(QWidget* enter, QWidget* leave, con const QPoint globalPos = qIsInf(globalPosF.x()) ? QPoint(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX) : globalPosF.toPoint(); - const QPoint windowPos = enterList.back()->window()->mapFromGlobal(globalPos); + const QPoint windowPos = qAsConst(enterList).back()->window()->mapFromGlobal(globalPos); for (auto it = enterList.crbegin(), end = enterList.crend(); it != end; ++it) { auto *w = *it; if (!QApplication::activeModalWidget() || QApplicationPrivate::tryModalHelper(w, 0)) { @@ -3302,7 +3308,6 @@ bool QApplication::notify(QObject *receiver, QEvent *e) case QEvent::Wheel: { QWidget* w = static_cast<QWidget *>(receiver); - QWheelEvent* wheel = static_cast<QWheelEvent*>(e); // QTBUG-40656, QTBUG-42731: ignore wheel events when a popup (QComboBox) is open. if (const QWidget *popup = QApplication::activePopupWidget()) { @@ -3310,27 +3315,61 @@ bool QApplication::notify(QObject *receiver, QEvent *e) return true; } - QPoint relpos = wheel->pos(); - bool eventAccepted = wheel->isAccepted(); + QWheelEvent* wheel = static_cast<QWheelEvent*>(e); + const bool spontaneous = wheel->spontaneous(); + const Qt::ScrollPhase phase = wheel->phase(); - if (e->spontaneous() && wheel->phase() == Qt::ScrollUpdate) - QApplicationPrivate::giveFocusAccordingToFocusPolicy(w, e, relpos); + if (phase == Qt::NoScrollPhase || phase == Qt::ScrollBegin + || (phase == Qt::ScrollUpdate && !QApplicationPrivate::wheel_widget)) { + + if (spontaneous && phase == Qt::ScrollBegin) + QApplicationPrivate::wheel_widget = Q_NULLPTR; + + const QPoint &relpos = wheel->pos(); + + if (spontaneous && (phase == Qt::NoScrollPhase || phase == Qt::ScrollUpdate)) + QApplicationPrivate::giveFocusAccordingToFocusPolicy(w, e, relpos); - while (w) { QWheelEvent we(relpos, wheel->globalPos(), wheel->pixelDelta(), wheel->angleDelta(), wheel->delta(), wheel->orientation(), wheel->buttons(), - wheel->modifiers(), wheel->phase(), wheel->source()); - we.spont = wheel->spontaneous(); - res = d->notify_helper(w, w == receiver ? wheel : &we); - eventAccepted = ((w == receiver) ? wheel : &we)->isAccepted(); - e->spont = false; - if ((res && eventAccepted) - || w->isWindow() || w->testAttribute(Qt::WA_NoMousePropagation)) - break; + wheel->modifiers(), phase, wheel->source()); + bool eventAccepted; + while (w) { + we.spont = spontaneous && w == receiver; + we.ignore(); + res = d->notify_helper(w, &we); + eventAccepted = we.isAccepted(); + if (res && eventAccepted) { + if (spontaneous && phase != Qt::NoScrollPhase) + QApplicationPrivate::wheel_widget = w; + break; + } + if (w->isWindow() || w->testAttribute(Qt::WA_NoMousePropagation)) + break; - relpos += w->pos(); - w = w->parentWidget(); + we.p += w->pos(); + w = w->parentWidget(); + } + wheel->setAccepted(eventAccepted); + } else if (QApplicationPrivate::wheel_widget) { + if (!spontaneous) { + // wheel_widget may forward the wheel event to a delegate widget, + // either directly or indirectly (e.g. QAbstractScrollArea will + // forward to its QScrollBars through viewportEvent()). In that + // case, the event will not be spontaneous but synthesized, so + // we can send it straigth to the receiver. + d->notify_helper(w, wheel); + } else { + const QPoint &relpos = QApplicationPrivate::wheel_widget->mapFromGlobal(wheel->globalPos()); + QWheelEvent we(relpos, wheel->globalPos(), wheel->pixelDelta(), wheel->angleDelta(), wheel->delta(), wheel->orientation(), wheel->buttons(), + wheel->modifiers(), wheel->phase(), wheel->source()); + we.spont = true; + we.ignore(); + d->notify_helper(QApplicationPrivate::wheel_widget, &we); + wheel->setAccepted(we.isAccepted()); + if (phase == Qt::ScrollEnd) + QApplicationPrivate::wheel_widget = Q_NULLPTR; + } } - wheel->setAccepted(eventAccepted); } break; #endif @@ -3795,7 +3834,7 @@ void QApplicationPrivate::closePopup(QWidget *popup) } else { // A popup was closed, so the previous popup gets the focus. - QWidget* aw = QApplicationPrivate::popupWidgets->last(); + QWidget* aw = QApplicationPrivate::popupWidgets->constLast(); if (QWidget *fw = aw->focusWidget()) fw->setFocus(Qt::PopupFocusReason); @@ -3942,7 +3981,8 @@ void QApplication::alert(QWidget *widget, int duration) if (QWindow *window= QApplicationPrivate::windowForWidget(widget)) window->alert(duration); } else { - foreach (QWidget *topLevel, topLevelWidgets()) + const auto topLevels = topLevelWidgets(); + for (QWidget *topLevel : topLevels) QApplication::alert(topLevel, duration); } } diff --git a/src/widgets/kernel/qapplication_p.h b/src/widgets/kernel/qapplication_p.h index b884b32016..0482f83a8a 100644 --- a/src/widgets/kernel/qapplication_p.h +++ b/src/widgets/kernel/qapplication_p.h @@ -208,6 +208,7 @@ public: static QWidget *active_window; #ifndef QT_NO_WHEELEVENT static int wheel_scroll_lines; + static QWidget *wheel_widget; #endif static int enabledAnimations; // Combination of QPlatformTheme::UiEffect diff --git a/src/widgets/kernel/qgesturemanager.cpp b/src/widgets/kernel/qgesturemanager.cpp index 4c85be33f5..9a3e9291bf 100644 --- a/src/widgets/kernel/qgesturemanager.cpp +++ b/src/widgets/kernel/qgesturemanager.cpp @@ -219,7 +219,8 @@ QGesture *QGestureManager::getState(QObject *object, QGestureRecognizer *recogni } // check if the QGesture for this recognizer has already been created - foreach (QGesture *state, m_objectGestures.value(QGestureManager::ObjectGesture(object, type))) { + const auto states = m_objectGestures.value(QGestureManager::ObjectGesture(object, type)); + for (QGesture *state : states) { if (m_gestureToRecognizer.value(state) == recognizer) return state; } @@ -684,7 +685,8 @@ void QGestureManager::deliverEvents(const QSet<QGesture *> &gestures, QApplication::sendEvent(receiver, &event); bool eventAccepted = event.isAccepted(); - foreach(QGesture *gesture, event.gestures()) { + const auto eventGestures = event.gestures(); + for (QGesture *gesture : eventGestures) { if (eventAccepted || event.isAccepted(gesture)) { QWidget *w = event.m_targetWidgets.value(gesture->gestureType(), 0); Q_ASSERT(w); @@ -710,7 +712,8 @@ void QGestureManager::deliverEvents(const QSet<QGesture *> &gestures, QGestureEvent event(it.value()); QApplication::sendEvent(it.key(), &event); bool eventAccepted = event.isAccepted(); - foreach (QGesture *gesture, event.gestures()) { + const auto eventGestures = event.gestures(); + for (QGesture *gesture : eventGestures) { if (gesture->state() == Qt::GestureStarted && (eventAccepted || event.isAccepted(gesture))) { QWidget *w = event.m_targetWidgets.value(gesture->gestureType(), 0); diff --git a/src/widgets/kernel/qwhatsthis.cpp b/src/widgets/kernel/qwhatsthis.cpp index b69ca54159..66b622911a 100644 --- a/src/widgets/kernel/qwhatsthis.cpp +++ b/src/widgets/kernel/qwhatsthis.cpp @@ -375,11 +375,9 @@ class QWhatsThisPrivate : public QObject void QWhatsThisPrivate::notifyToplevels(QEvent *e) { - QWidgetList toplevels = QApplication::topLevelWidgets(); - for (int i = 0; i < toplevels.count(); ++i) { - QWidget *w = toplevels.at(i); + const QWidgetList toplevels = QApplication::topLevelWidgets(); + for (auto *w : toplevels) QApplication::sendEvent(w, e); - } } QWhatsThisPrivate *QWhatsThisPrivate::instance = 0; diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 7e2e02b58e..ec5a68eeef 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -1417,7 +1417,8 @@ void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyO win = topData()->window; } - foreach (const QByteArray &propertyName, q->dynamicPropertyNames()) { + const auto dynamicPropertyNames = q->dynamicPropertyNames(); + for (const QByteArray &propertyName : dynamicPropertyNames) { if (!qstrncmp(propertyName, "_q_platform_", 12)) win->setProperty(propertyName, q->property(propertyName)); } @@ -11984,7 +11985,9 @@ QWidget *QWidgetPrivate::widgetInNavigationDirection(Direction direction) QWidget *targetWidget = 0; int shortestDistance = INT_MAX; - foreach(QWidget *targetCandidate, QApplication::allWidgets()) { + + const auto targetCandidates = QApplication::allWidgets(); + for (QWidget *targetCandidate : targetCandidates) { const QRect targetCandidateRect = targetCandidate->rect().translated(targetCandidate->mapToGlobal(QPoint())); @@ -12689,7 +12692,7 @@ QWidget *QWidget::keyboardGrabber() does not allow an application to interrupt what the user is currently doing in another application. - \sa isActiveWindow(), window(), show() + \sa isActiveWindow(), window(), show(), QWindowsWindowFunctions::setWindowActivationBehavior() */ void QWidget::activateWindow() { diff --git a/src/widgets/styles/qwindowsxpstyle.cpp b/src/widgets/styles/qwindowsxpstyle.cpp index cda7dff509..c33e4167c1 100644 --- a/src/widgets/styles/qwindowsxpstyle.cpp +++ b/src/widgets/styles/qwindowsxpstyle.cpp @@ -406,10 +406,12 @@ HWND QWindowsXPStylePrivate::winId(const QWidget *widget) return hwnd; // Find top level with native window (there might be dialogs that do not have one). - foreach (const QWidget *toplevel, QApplication::topLevelWidgets()) + const auto topLevels = QApplication::topLevelWidgets(); + for (const QWidget *toplevel : topLevels) { if (toplevel->windowHandle() && toplevel->windowHandle()->handle()) if (const HWND topLevelHwnd = QApplicationPrivate::getHWNDForWidget(toplevel)) return topLevelHwnd; + } if (QDesktopWidget *desktop = qApp->desktop()) if (const HWND desktopHwnd = QApplicationPrivate::getHWNDForWidget(desktop)) diff --git a/src/widgets/util/qcompleter.cpp b/src/widgets/util/qcompleter.cpp index 9c61a3a263..9f167f5924 100644 --- a/src/widgets/util/qcompleter.cpp +++ b/src/widgets/util/qcompleter.cpp @@ -755,9 +755,9 @@ void QUnsortedModelEngine::filterOnDemand(int n) const QAbstractItemModel *model = c->proxy->sourceModel(); int lastRow = model->rowCount(curParent) - 1; QIndexMapper im(curMatch.indices.last() + 1, lastRow); - int lastIndex = buildIndices(curParts.last(), curParent, n, im, &curMatch); + int lastIndex = buildIndices(curParts.constLast(), curParent, n, im, &curMatch); curMatch.partial = (lastRow != lastIndex); - saveInCache(curParts.last(), curParent, curMatch); + saveInCache(curParts.constLast(), curParent, curMatch); } QMatchData QUnsortedModelEngine::filter(const QString& part, const QModelIndex& parent, int n) diff --git a/src/widgets/util/qflickgesture.cpp b/src/widgets/util/qflickgesture.cpp index 3d1971db8e..933db1711b 100644 --- a/src/widgets/util/qflickgesture.cpp +++ b/src/widgets/util/qflickgesture.cpp @@ -581,7 +581,8 @@ QGestureRecognizer::Result QFlickGestureRecognizer::recognize(QGesture *state, // Check for an active scroller at globalPos if (inputType == QScroller::InputPress) { - foreach (QScroller *as, QScroller::activeScrollers()) { + const auto activeScrollers = QScroller::activeScrollers(); + for (QScroller *as : activeScrollers) { if (as != scroller) { QRegion scrollerRegion; @@ -589,11 +590,13 @@ QGestureRecognizer::Result QFlickGestureRecognizer::recognize(QGesture *state, scrollerRegion = QRect(w->mapToGlobal(QPoint(0, 0)), w->size()); #ifndef QT_NO_GRAPHICSVIEW } else if (QGraphicsObject *go = qobject_cast<QGraphicsObject *>(as->target())) { - if (go->scene()) { + if (const auto *scene = go->scene()) { const auto goBoundingRectMappedToScene = go->mapToScene(go->boundingRect()); - foreach (QGraphicsView *gv, go->scene()->views()) + const auto views = scene->views(); + for (QGraphicsView *gv : views) { scrollerRegion |= gv->mapFromScene(goBoundingRectMappedToScene) .translated(gv->mapToGlobal(QPoint(0, 0))); + } } #endif } diff --git a/src/widgets/util/qscroller.cpp b/src/widgets/util/qscroller.cpp index 2d6bcf72c6..02e3c2b82a 100644 --- a/src/widgets/util/qscroller.cpp +++ b/src/widgets/util/qscroller.cpp @@ -575,8 +575,11 @@ QPointF QScroller::pixelPerMeter() const if (QGraphicsObject *go = qobject_cast<QGraphicsObject *>(d->target)) { QTransform viewtr; //TODO: the first view isn't really correct - maybe use an additional field in the prepare event? - if (go->scene() && !go->scene()->views().isEmpty()) - viewtr = go->scene()->views().first()->viewportTransform(); + if (const auto *scene = go->scene()) { + const auto views = scene->views(); + if (!views.isEmpty()) + viewtr = views.first()->viewportTransform(); + } QTransform tr = go->deviceTransform(viewtr); if (tr.isScaling()) { QPointF p0 = tr.map(QPointF(0, 0)); @@ -1121,12 +1124,15 @@ void QScrollerPrivate::pushSegment(ScrollType type, qreal deltaTime, qreal stopP return; ScrollSegment s; - if (orientation == Qt::Horizontal && !xSegments.isEmpty()) - s.startTime = xSegments.last().startTime + xSegments.last().deltaTime * xSegments.last().stopProgress; - else if (orientation == Qt::Vertical && !ySegments.isEmpty()) - s.startTime = ySegments.last().startTime + ySegments.last().deltaTime * ySegments.last().stopProgress; - else + if (orientation == Qt::Horizontal && !xSegments.isEmpty()) { + const auto &lastX = xSegments.constLast(); + s.startTime = lastX.startTime + lastX.deltaTime * lastX.stopProgress; + } else if (orientation == Qt::Vertical && !ySegments.isEmpty()) { + const auto &lastY = ySegments.constLast(); + s.startTime = lastY.startTime + lastY.deltaTime * lastY.stopProgress; + } else { s.startTime = monotonicTimer.elapsed(); + } s.startPos = startPos; s.deltaPos = deltaPos; @@ -1463,8 +1469,11 @@ bool QScrollerPrivate::prepareScrolling(const QPointF &position) #ifndef QT_NO_GRAPHICSVIEW if (QGraphicsObject *go = qobject_cast<QGraphicsObject *>(target)) { //TODO: the first view isn't really correct - maybe use an additional field in the prepare event? - if (go->scene() && !go->scene()->views().isEmpty()) - setDpiFromWidget(go->scene()->views().first()); + if (const auto *scene = go->scene()) { + const auto views = scene->views(); + if (!views.isEmpty()) + setDpiFromWidget(views.first()); + } } #endif diff --git a/src/widgets/util/qundostack.cpp b/src/widgets/util/qundostack.cpp index 6643b4429c..6f733f99d5 100644 --- a/src/widgets/util/qundostack.cpp +++ b/src/widgets/util/qundostack.cpp @@ -588,9 +588,9 @@ void QUndoStack::push(QUndoCommand *cmd) QUndoCommand *cur = 0; if (macro) { - QUndoCommand *macro_cmd = d->macro_stack.last(); + QUndoCommand *macro_cmd = d->macro_stack.constLast(); if (!macro_cmd->d->child_list.isEmpty()) - cur = macro_cmd->d->child_list.last(); + cur = macro_cmd->d->child_list.constLast(); } else { if (d->index > 0) cur = d->command_list.at(d->index - 1); @@ -616,7 +616,7 @@ void QUndoStack::push(QUndoCommand *cmd) } } else { if (macro) { - d->macro_stack.last()->d->child_list.append(cmd); + d->macro_stack.constLast()->d->child_list.append(cmd); } else { d->command_list.append(cmd); d->checkUndoLimit(); @@ -963,7 +963,7 @@ void QUndoStack::beginMacro(const QString &text) d->clean_index = -1; // we've deleted the clean state d->command_list.append(cmd); } else { - d->macro_stack.last()->d->child_list.append(cmd); + d->macro_stack.constLast()->d->child_list.append(cmd); } d->macro_stack.append(cmd); diff --git a/src/widgets/widgets/qdialogbuttonbox.cpp b/src/widgets/widgets/qdialogbuttonbox.cpp index 6fc8cb5e26..2b68c308ec 100644 --- a/src/widgets/widgets/qdialogbuttonbox.cpp +++ b/src/widgets/widgets/qdialogbuttonbox.cpp @@ -964,7 +964,8 @@ bool QDialogButtonBox::event(QEvent *event) break; } - foreach (QPushButton *pb, (dialog ? dialog : this)->findChildren<QPushButton *>()) { + const auto pbs = (dialog ? dialog : this)->findChildren<QPushButton *>(); + for (QPushButton *pb : pbs) { if (pb->isDefault() && pb != firstAcceptButton) { hasDefault = true; break; diff --git a/src/widgets/widgets/qdockarealayout.cpp b/src/widgets/widgets/qdockarealayout.cpp index 29089311c6..c14fd5a942 100644 --- a/src/widgets/widgets/qdockarealayout.cpp +++ b/src/widgets/widgets/qdockarealayout.cpp @@ -3096,7 +3096,7 @@ void QDockAreaLayout::addDockWidget(QInternal::DockPosition pos, QDockWidget *do void QDockAreaLayout::tabifyDockWidget(QDockWidget *first, QDockWidget *second) { - QList<int> path = indexOf(first); + const QList<int> path = indexOf(first); if (path.isEmpty()) return; @@ -3133,7 +3133,7 @@ void QDockAreaLayout::resizeDocks(const QList<QDockWidget *> &docks, while (path.size() > 1) { QDockAreaLayoutInfo *info = this->info(path); if (!info->tabbed && info->o == o) { - info->item_list[path.last()].size = size; + info->item_list[path.constLast()].size = size; int totalSize = 0; foreach (const QDockAreaLayoutItem &item, info->item_list) { if (!item.skip()) { @@ -3147,7 +3147,7 @@ void QDockAreaLayout::resizeDocks(const QList<QDockWidget *> &docks, path.removeLast(); } - const int dockNum = path.first(); + const int dockNum = path.constFirst(); Q_ASSERT(dockNum < QInternal::DockCount); QRect &r = this->docks[dockNum].rect; QSize s = r.size(); diff --git a/src/widgets/widgets/qlineedit_p.cpp b/src/widgets/widgets/qlineedit_p.cpp index 8410568cc1..b646e82209 100644 --- a/src/widgets/widgets/qlineedit_p.cpp +++ b/src/widgets/widgets/qlineedit_p.cpp @@ -427,7 +427,7 @@ QIcon QLineEditPrivate::clearButtonIcon() const void QLineEditPrivate::setClearButtonEnabled(bool enabled) { - foreach (const SideWidgetEntry &e, trailingSideWidgets) { + for (const SideWidgetEntry &e : trailingSideWidgets) { if (e.flags & SideWidgetClearButton) { e.action->setEnabled(enabled); break; @@ -443,13 +443,13 @@ void QLineEditPrivate::positionSideWidgets() const QSize iconSize = QLineEditPrivate::iconSize(); const int delta = QLineEditIconButton::IconMargin + iconSize.width(); QRect widgetGeometry(QPoint(QLineEditIconButton::IconMargin, (contentRect.height() - iconSize.height()) / 2), iconSize); - foreach (const SideWidgetEntry &e, leftSideWidgetList()) { + for (const SideWidgetEntry &e : leftSideWidgetList()) { e.widget->setGeometry(widgetGeometry); if (e.action->isVisible()) widgetGeometry.moveLeft(widgetGeometry.left() + delta); } widgetGeometry.moveLeft(contentRect.width() - iconSize.width() - QLineEditIconButton::IconMargin); - foreach (const SideWidgetEntry &e, rightSideWidgetList()) { + for (const SideWidgetEntry &e : rightSideWidgetList()) { e.widget->setGeometry(widgetGeometry); if (e.action->isVisible()) widgetGeometry.moveLeft(widgetGeometry.left() - delta); diff --git a/src/widgets/widgets/qmainwindowlayout.cpp b/src/widgets/widgets/qmainwindowlayout.cpp index ae87ea526d..63a6c718bc 100644 --- a/src/widgets/widgets/qmainwindowlayout.cpp +++ b/src/widgets/widgets/qmainwindowlayout.cpp @@ -1163,7 +1163,7 @@ void QMainWindowLayout::insertToolBar(QToolBar *before, QToolBar *toolbar) // copy the toolbar also in the saved state savedState.toolBarAreaLayout.insertItem(before, item); } - if (!currentGapPos.isEmpty() && currentGapPos.first() == 0) { + if (!currentGapPos.isEmpty() && currentGapPos.constFirst() == 0) { currentGapPos = layoutState.toolBarAreaLayout.currentGapIndex(); if (!currentGapPos.isEmpty()) { currentGapPos.prepend(0); @@ -1501,7 +1501,7 @@ void QMainWindowLayout::splitDockWidget(QDockWidget *after, Qt::DockWidgetArea QMainWindowLayout::dockWidgetArea(QWidget *widget) const { - QList<int> pathToWidget = layoutState.dockAreaLayout.indexOf(widget); + const QList<int> pathToWidget = layoutState.dockAreaLayout.indexOf(widget); if (pathToWidget.isEmpty()) return Qt::NoDockWidgetArea; return toDockWidgetArea(pathToWidget.first()); @@ -1783,7 +1783,7 @@ QLayoutItem *QMainWindowLayout::takeAt(int index) } #ifndef QT_NO_TOOLBAR - if (!currentGapPos.isEmpty() && currentGapPos.first() == 0) { + if (!currentGapPos.isEmpty() && currentGapPos.constFirst() == 0) { currentGapPos = layoutState.toolBarAreaLayout.currentGapIndex(); if (!currentGapPos.isEmpty()) { currentGapPos.prepend(0); @@ -2057,7 +2057,7 @@ void QMainWindowLayout::animationFinished(QWidget *widget) if (parentInfo->tabbed) { // merge the two tab widgets - int idx = path.last(); + int idx = path.constLast(); Q_ASSERT(parentInfo->item_list[idx].widgetItem->widget() == dwgw); delete parentInfo->item_list[idx].widgetItem; parentInfo->item_list.removeAt(idx); @@ -2283,7 +2283,7 @@ QLayoutItem *QMainWindowLayout::unplug(QWidget *widget, bool group) #ifndef QT_NO_DOCKWIDGET if (QDockWidget *dw = qobject_cast<QDockWidget*>(widget)) { - Q_ASSERT(path.first() == 1); + Q_ASSERT(path.constFirst() == 1); bool actualGroup = false; #ifndef QT_NO_TABBAR if (group && (dockOptions & QMainWindow::GroupedDragging) && path.size() > 3) { @@ -2386,7 +2386,7 @@ void QMainWindowLayout::hover(QLayoutItem *widgetItem, const QPoint &mousePos) } } } - foreach (QWidget *w, candidates) { + for (QWidget *w : candidates) { QWindow *handle1 = widget->windowHandle(); QWindow *handle2 = w->windowHandle(); if (handle1 && handle2 && handle1->screen() != handle2->screen()) diff --git a/src/widgets/widgets/qmdiarea.cpp b/src/widgets/widgets/qmdiarea.cpp index 2b734b603f..b42ebe7e48 100644 --- a/src/widgets/widgets/qmdiarea.cpp +++ b/src/widgets/widgets/qmdiarea.cpp @@ -516,7 +516,7 @@ QVector<QRect> MinOverlapPlacer::findMaxOverlappers(const QRect &domain, const Q if (overlap >= maxOverlap || maxOverlap == -1) { if (overlap > maxOverlap) { maxOverlap = overlap; - result.resize(0); + result.clear(); } result << srcRect; } diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp index 514cb1a8c9..1b9e31968a 100644 --- a/src/widgets/widgets/qmenu.cpp +++ b/src/widgets/widgets/qmenu.cpp @@ -117,7 +117,7 @@ public: { Q_D(QTornOffMenu); // make the torn-off menu a sibling of p (instead of a child) - QWidget *parentWidget = d->causedStack.isEmpty() ? p : d->causedStack.last(); + QWidget *parentWidget = d->causedStack.isEmpty() ? p : d->causedStack.constLast(); if (parentWidget->parentWidget()) parentWidget = parentWidget->parentWidget(); setParent(parentWidget, Qt::Window | Qt::Tool); @@ -1270,14 +1270,17 @@ void QMenuPrivate::_q_platformMenuAboutToShow() Q_Q(QMenu); #ifdef Q_OS_OSX - if (platformMenu) - Q_FOREACH (QAction *action, q->actions()) + if (platformMenu) { + const auto actions = q->actions(); + for (QAction *action : actions) { if (QWidget *widget = widgetItems.value(action)) if (widget->parent() == q) { QPlatformMenuItem *menuItem = platformMenu->menuItemForTag(reinterpret_cast<quintptr>(action)); moveWidgetToPlatformItem(widget, menuItem); platformMenu->syncMenuItem(menuItem); } + } + } #endif emit q->aboutToShow(); diff --git a/src/widgets/widgets/qmenubar.cpp b/src/widgets/widgets/qmenubar.cpp index f15ce06e23..261ff0bca3 100644 --- a/src/widgets/widgets/qmenubar.cpp +++ b/src/widgets/widgets/qmenubar.cpp @@ -200,7 +200,7 @@ void QMenuBarPrivate::updateGeometries() if(itemsDirty) { for(int j = 0; j < shortcutIndexMap.size(); ++j) q->releaseShortcut(shortcutIndexMap.value(j)); - shortcutIndexMap.resize(0); // faster than clear + shortcutIndexMap.clear(); const int actionsCount = actions.count(); shortcutIndexMap.reserve(actionsCount); for (int i = 0; i < actionsCount; i++) diff --git a/src/widgets/widgets/qtabbar.cpp b/src/widgets/widgets/qtabbar.cpp index cf485974f6..ba3fc2fcd7 100644 --- a/src/widgets/widgets/qtabbar.cpp +++ b/src/widgets/widgets/qtabbar.cpp @@ -590,7 +590,7 @@ QRect QTabBarPrivate::normalizedScrollRect(int index) } bool tearTopVisible = index != 0 && topEdge != -scrollOffset; - bool tearBottomVisible = index != tabList.size() - 1 && bottomEdge != tabList.last().rect.bottom() + 1 - scrollOffset; + bool tearBottomVisible = index != tabList.size() - 1 && bottomEdge != tabList.constLast().rect.bottom() + 1 - scrollOffset; if (tearTopVisible && !tearLeftRect.isNull()) topEdge = tearLeftRect.bottom() + 1; if (tearBottomVisible && !tearRightRect.isNull()) @@ -621,7 +621,7 @@ QRect QTabBarPrivate::normalizedScrollRect(int index) } bool tearLeftVisible = index != 0 && leftEdge != -scrollOffset; - bool tearRightVisible = index != tabList.size() - 1 && rightEdge != tabList.last().rect.right() + 1 - scrollOffset; + bool tearRightVisible = index != tabList.size() - 1 && rightEdge != tabList.constLast().rect.right() + 1 - scrollOffset; if (tearLeftVisible && !tearLeftRect.isNull()) leftEdge = tearLeftRect.right() + 1; if (tearRightVisible && !tearRightRect.isNull()) @@ -642,7 +642,7 @@ void QTabBarPrivate::makeVisible(int index) const bool horiz = !verticalTabs(shape); const int tabStart = horiz ? tabRect.left() : tabRect.top(); const int tabEnd = horiz ? tabRect.right() : tabRect.bottom(); - const int lastTabEnd = horiz ? tabList.last().rect.right() : tabList.last().rect.bottom(); + const int lastTabEnd = horiz ? tabList.constLast().rect.right() : tabList.constLast().rect.bottom(); const QRect scrollRect = normalizedScrollRect(index); const int scrolledTabBarStart = qMax(1, scrollRect.left() + scrollOffset); const int scrolledTabBarEnd = qMin(lastTabEnd - 1, scrollRect.right() + scrollOffset); diff --git a/src/widgets/widgets/qtextbrowser.cpp b/src/widgets/widgets/qtextbrowser.cpp index d8a7b27d60..db66d39089 100644 --- a/src/widgets/widgets/qtextbrowser.cpp +++ b/src/widgets/widgets/qtextbrowser.cpp @@ -1141,7 +1141,7 @@ void QTextBrowser::clearHistory() d->forwardStack.clear(); if (!d->stack.isEmpty()) { QTextBrowserPrivate::HistoryEntry historyEntry = d->stack.top(); - d->stack.resize(0); + d->stack.clear(); d->stack.push(historyEntry); d->home = historyEntry.url; } diff --git a/src/widgets/widgets/qtoolbararealayout.cpp b/src/widgets/widgets/qtoolbararealayout.cpp index 2e79b502ea..05564bb6b1 100644 --- a/src/widgets/widgets/qtoolbararealayout.cpp +++ b/src/widgets/widgets/qtoolbararealayout.cpp @@ -347,7 +347,7 @@ void QToolBarAreaLayoutInfo::removeToolBar(QToolBar *toolBar) void QToolBarAreaLayoutInfo::insertToolBarBreak(QToolBar *before) { if (before == 0) { - if (!lines.isEmpty() && lines.last().toolBarItems.isEmpty()) + if (!lines.isEmpty() && lines.constLast().toolBarItems.isEmpty()) return; lines.append(QToolBarAreaLayoutLine(o)); return; |