From ece0c0a5e7e0b18beb58ccd868bde54c7be64f78 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Fri, 22 Nov 2019 14:46:58 +0100 Subject: Tidy nullptr usage Move away from using 0 as pointer literal. Done using clang-tidy. This is not complete as run-clang-tidy can't handle all of qtbase in one go. Change-Id: I1076a21f32aac0dab078af6f175f7508145eece0 Reviewed-by: Friedemann Kleint Reviewed-by: Lars Knoll --- src/widgets/widgets/qdockwidget.cpp | 80 ++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 40 deletions(-) (limited to 'src/widgets/widgets/qdockwidget.cpp') diff --git a/src/widgets/widgets/qdockwidget.cpp b/src/widgets/widgets/qdockwidget.cpp index bcbd3dd2d4..299e5da8d3 100644 --- a/src/widgets/widgets/qdockwidget.cpp +++ b/src/widgets/widgets/qdockwidget.cpp @@ -197,7 +197,7 @@ QSize QDockWidgetTitleButton::sizeHint() const { ensurePolished(); - int size = 2*style()->pixelMetric(QStyle::PM_DockWidgetTitleBarButtonMargin, 0, this); + int size = 2*style()->pixelMetric(QStyle::PM_DockWidgetTitleBarButtonMargin, nullptr, this); if (!icon().isNull()) { const QSize sz = icon().actualSize(dockButtonIconSize()); size += qMax(sz.width(), sz.height()); @@ -226,7 +226,7 @@ void QDockWidgetTitleButton::paintEvent(QPaintEvent *) opt.init(this); opt.state |= QStyle::State_AutoRaise; - if (style()->styleHint(QStyle::SH_DockWidget_ButtonsHaveFrame, 0, this)) + if (style()->styleHint(QStyle::SH_DockWidget_ButtonsHaveFrame, nullptr, this)) { if (isEnabled() && underMouse() && !isChecked() && !isDown()) opt.state |= QStyle::State_Raised; @@ -311,12 +311,12 @@ QLayoutItem *QDockWidgetLayout::itemAt(int index) const int cnt = 0; for (int i = 0; i < item_list.count(); ++i) { QLayoutItem *item = item_list.at(i); - if (item == 0) + if (item == nullptr) continue; if (index == cnt++) return item; } - return 0; + return nullptr; } QLayoutItem *QDockWidgetLayout::takeAt(int index) @@ -324,7 +324,7 @@ QLayoutItem *QDockWidgetLayout::takeAt(int index) int j = 0; for (int i = 0; i < item_list.count(); ++i) { QLayoutItem *item = item_list.at(i); - if (item == 0) + if (item == nullptr) continue; if (index == j) { item_list[i] = 0; @@ -333,7 +333,7 @@ QLayoutItem *QDockWidgetLayout::takeAt(int index) } ++j; } - return 0; + return nullptr; } int QDockWidgetLayout::count() const @@ -362,7 +362,7 @@ QSize QDockWidgetLayout::sizeFromContent(const QSize &content, bool floating) co const bool nativeDeco = nativeWindowDeco(floating); int fw = floating && !nativeDeco - ? w->style()->pixelMetric(QStyle::PM_DockWidgetFrameWidth, 0, w) + ? w->style()->pixelMetric(QStyle::PM_DockWidgetFrameWidth, nullptr, w) : 0; const int th = titleHeight(); @@ -394,7 +394,7 @@ QSize QDockWidgetLayout::sizeFromContent(const QSize &content, bool floating) co uint explicitMin = 0; uint explicitMax = 0; - if (w->d_func()->extra != 0) { + if (w->d_func()->extra != nullptr) { explicitMin = w->d_func()->extra->explicitMinSize; explicitMax = w->d_func()->extra->explicitMaxSize; } @@ -448,7 +448,7 @@ QSize QDockWidgetLayout::minimumSize() const QWidget *QDockWidgetLayout::widgetForRole(Role r) const { QLayoutItem *item = item_list.at(r); - return item == 0 ? 0 : item->widget(); + return item == nullptr ? nullptr : item->widget(); } QLayoutItem *QDockWidgetLayout::itemForRole(Role r) const @@ -459,12 +459,12 @@ QLayoutItem *QDockWidgetLayout::itemForRole(Role r) const void QDockWidgetLayout::setWidgetForRole(Role r, QWidget *w) { QWidget *old = widgetForRole(r); - if (old != 0) { + if (old != nullptr) { old->hide(); removeWidget(old); } - if (w != 0) { + if (w != nullptr) { addChildWidget(w); item_list[r] = new QWidgetItemV2(w); w->show(); @@ -505,8 +505,8 @@ int QDockWidgetLayout::minimumTitleWidth() const int titleHeight = this->titleHeight(); - int mw = q->style()->pixelMetric(QStyle::PM_DockWidgetTitleMargin, 0, q); - int fw = q->style()->pixelMetric(QStyle::PM_DockWidgetFrameWidth, 0, q); + int mw = q->style()->pixelMetric(QStyle::PM_DockWidgetTitleMargin, nullptr, q); + int fw = q->style()->pixelMetric(QStyle::PM_DockWidgetFrameWidth, nullptr, q); return pick(verticalTitleBar, closeSize) + pick(verticalTitleBar, floatSize) @@ -531,7 +531,7 @@ int QDockWidgetLayout::titleHeight() const perp(verticalTitleBar, floatSize)); QFontMetrics titleFontMetrics = q->fontMetrics(); - int mw = q->style()->pixelMetric(QStyle::PM_DockWidgetTitleMargin, 0, q); + int mw = q->style()->pixelMetric(QStyle::PM_DockWidgetTitleMargin, nullptr, q); return qMax(buttonHeight + 2, titleFontMetrics.height() + 2*mw); } @@ -543,7 +543,7 @@ void QDockWidgetLayout::setGeometry(const QRect &geometry) bool nativeDeco = nativeWindowDeco(); int fw = q->isFloating() && !nativeDeco - ? q->style()->pixelMetric(QStyle::PM_DockWidgetFrameWidth, 0, q) + ? q->style()->pixelMetric(QStyle::PM_DockWidgetFrameWidth, nullptr, q) : 0; if (nativeDeco) { @@ -730,7 +730,7 @@ void QDockWidgetPrivate::updateButtons() QStyleOptionDockWidget opt; q->initStyleOption(&opt); - bool customTitleBar = dwLayout->widgetForRole(QDockWidgetLayout::TitleBar) != 0; + bool customTitleBar = dwLayout->widgetForRole(QDockWidgetLayout::TitleBar) != nullptr; bool nativeDeco = dwLayout->nativeWindowDeco(); bool hideButtons = nativeDeco || customTitleBar; @@ -777,18 +777,18 @@ void QDockWidgetPrivate::initDrag(const QPoint &pos, bool nca) { Q_Q(QDockWidget); - if (state != 0) + if (state != nullptr) return; QMainWindowLayout *layout = qt_mainwindow_layout_from_dock(q); - Q_ASSERT(layout != 0); - if (layout->pluggingWidget != 0) // the main window is animating a docking operation + Q_ASSERT(layout != nullptr); + if (layout->pluggingWidget != nullptr) // the main window is animating a docking operation return; state = new QDockWidgetPrivate::DragState; state->pressPos = pos; state->dragging = false; - state->widgetItem = 0; + state->widgetItem = nullptr; state->ownWidgetItem = false; state->nca = nca; state->ctrlDrag = false; @@ -804,14 +804,14 @@ void QDockWidgetPrivate::startDrag(bool group) { Q_Q(QDockWidget); - if (state == 0 || state->dragging) + if (state == nullptr || state->dragging) return; QMainWindowLayout *layout = qt_mainwindow_layout_from_dock(q); - Q_ASSERT(layout != 0); + Q_ASSERT(layout != nullptr); state->widgetItem = layout->unplug(q, group); - if (state->widgetItem == 0) { + if (state->widgetItem == nullptr) { /* I have a QMainWindow parent, but I was never inserted with QMainWindow::addDockWidget, so the QMainWindowLayout has no widget item for me. :( I have to create it myself, and then @@ -838,7 +838,7 @@ void QDockWidgetPrivate::startDrag(bool group) void QDockWidgetPrivate::endDrag(bool abort) { Q_Q(QDockWidget); - Q_ASSERT(state != 0); + Q_ASSERT(state != nullptr); q->releaseMouse(); @@ -881,7 +881,7 @@ void QDockWidgetPrivate::endDrag(bool abort) } } delete state; - state = 0; + state = nullptr; } void QDockWidgetPrivate::setResizerActive(bool active) @@ -900,7 +900,7 @@ bool QDockWidgetPrivate::isAnimating() const Q_Q(const QDockWidget); QMainWindowLayout *mainWinLayout = qt_mainwindow_layout_from_dock(q); - if (mainWinLayout == 0) + if (mainWinLayout == nullptr) return false; return (const void*)mainWinLayout->pluggingWidget == (const void*)q; @@ -925,7 +925,7 @@ bool QDockWidgetPrivate::mousePressEvent(QMouseEvent *event) // is not (but allow moving if the window is floating) (!hasFeature(this, QDockWidget::DockWidgetMovable) && !q->isFloating()) || (qobject_cast(parent) == 0 && !floatingTab) || - isAnimating() || state != 0) { + isAnimating() || state != nullptr) { return false; } @@ -972,7 +972,7 @@ bool QDockWidgetPrivate::mouseMoveEvent(QMouseEvent *event) QMainWindowLayout *mwlayout = qt_mainwindow_layout_from_dock(q); if (!dwlayout->nativeWindowDeco()) { if (!state->dragging - && mwlayout->pluggingWidget == 0 + && mwlayout->pluggingWidget == nullptr && (event->pos() - state->pressPos).manhattanLength() > QApplication::startDragDistance()) { startDrag(); @@ -1019,7 +1019,7 @@ void QDockWidgetPrivate::nonClientAreaMouseEvent(QMouseEvent *event) { Q_Q(QDockWidget); - int fw = q->style()->pixelMetric(QStyle::PM_DockWidgetFrameWidth, 0, q); + int fw = q->style()->pixelMetric(QStyle::PM_DockWidgetFrameWidth, nullptr, q); QWidget *tl = q->topLevelWidget(); QRect geo = tl->geometry(); @@ -1035,21 +1035,21 @@ void QDockWidgetPrivate::nonClientAreaMouseEvent(QMouseEvent *event) case QEvent::NonClientAreaMouseButtonPress: if (!titleRect.contains(event->globalPos())) break; - if (state != 0) + if (state != nullptr) break; if (qobject_cast(parent) == 0 && qobject_cast(parent) == 0) break; if (isAnimating()) break; initDrag(event->pos(), true); - if (state == 0) + if (state == nullptr) break; state->ctrlDrag = (event->modifiers() & Qt::ControlModifier) || (!hasFeature(this, QDockWidget::DockWidgetMovable) && q->isFloating()); startDrag(); break; case QEvent::NonClientAreaMouseMove: - if (state == 0 || !state->dragging) + if (state == nullptr || !state->dragging) break; #ifndef Q_OS_MAC @@ -1085,7 +1085,7 @@ void QDockWidgetPrivate::moveEvent(QMoveEvent *event) { Q_Q(QDockWidget); - if (state == 0 || !state->dragging || !state->nca) + if (state == nullptr || !state->dragging || !state->nca) return; if (!q->isWindow() && qobject_cast(parent) == 0) @@ -1098,7 +1098,7 @@ void QDockWidgetPrivate::moveEvent(QMoveEvent *event) return; QMainWindowLayout *layout = qt_mainwindow_layout_from_dock(q); - Q_ASSERT(layout != 0); + Q_ASSERT(layout != nullptr); QPoint globalMousePos = event->pos() + state->pressPos; layout->hover(state->widgetItem, globalMousePos); @@ -1384,7 +1384,7 @@ void QDockWidget::setFloating(bool floating) Q_D(QDockWidget); // the initial click of a double-click may have started a drag... - if (d->state != 0) + if (d->state != nullptr) d->endDrag(true); QRect r = d->undockedGeometry; @@ -1479,7 +1479,7 @@ void QDockWidget::paintEvent(QPaintEvent *event) QDockWidgetLayout *layout = qobject_cast(this->layout()); - bool customTitleBar = layout->widgetForRole(QDockWidgetLayout::TitleBar) != 0; + bool customTitleBar = layout->widgetForRole(QDockWidgetLayout::TitleBar) != nullptr; bool nativeDeco = layout->nativeWindowDeco(); if (!nativeDeco && !customTitleBar) { @@ -1516,7 +1516,7 @@ bool QDockWidget::event(QEvent *event) switch (event->type()) { #ifndef QT_NO_ACTION case QEvent::Hide: - if (layout != 0) + if (layout != nullptr) layout->keepSize(this); d->toggleViewAction->setChecked(false); emit visibilityChanged(false); @@ -1542,12 +1542,12 @@ bool QDockWidget::event(QEvent *event) break; case QEvent::ZOrderChange: { bool onTop = false; - if (win != 0) { + if (win != nullptr) { const QObjectList &siblings = win->children(); onTop = siblings.count() > 0 && siblings.last() == (QObject*)this; } #if QT_CONFIG(tabbar) - if (!isFloating() && layout != 0 && onTop) + if (!isFloating() && layout != nullptr && onTop) layout->raise(this); #endif break; @@ -1591,7 +1591,7 @@ bool QDockWidget::event(QEvent *event) break; case QEvent::Resize: // if the mainwindow is plugging us, we don't want to update undocked geometry - if (isFloating() && layout != 0 && layout->pluggingWidget != this) + if (isFloating() && layout != nullptr && layout->pluggingWidget != this) d->undockedGeometry = geometry(); // Usually the window won't get resized while it's being moved, but it can happen, -- cgit v1.2.3