From 2e7f11246e8b5bd0952c3b498da04ae4fc14f264 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Sat, 8 Aug 2020 02:14:58 +0200 Subject: [PATCH] QLayout: make its indexOf functions take pointer-to-const Try to fix an API mistake there: there is no reason why these functions should take pointers to non-const widgets, as that actually preventing reasonable code (e.g. finding out the index of "this" inside a const method of a QWidget subclass). Unfortunately, indexOf(QWidget*) is also virtual, meaning that changing its signature is an API break. Hopefully, there are only few users that override this method (Woboq says 0). [ChangeLog][Potentially Source-Incompatible Changes] The QLayout::indexOf(QWidget *) virtual function has changed signature, becoming QLayout::indexOf(const QWidget *). This is source incompatible, although the fix (for the few users that do override indexOf() in their layouts) is straightforward. Change-Id: Id2183f5ecd9dc7e2a37c7355266e8494ef7929f2 Reviewed-by: Richard Moe Gustavsen --- src/widgets/kernel/qlayout.cpp | 6 +++--- src/widgets/kernel/qlayout.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/widgets/kernel/qlayout.cpp b/src/widgets/kernel/qlayout.cpp index bbc7e793c4..431c93596a 100644 --- a/src/widgets/kernel/qlayout.cpp +++ b/src/widgets/kernel/qlayout.cpp @@ -1177,9 +1177,9 @@ QLayoutItem *QLayout::replaceWidget(QWidget *from, QWidget *to, Qt::FindChildOpt Returns the index of \a widget, or -1 if \a widget is not found. - The default implementation iterates over all items using itemAt() + The default implementation iterates over all items using itemAt(). */ -int QLayout::indexOf(QWidget *widget) const +int QLayout::indexOf(const QWidget *widget) const { int i = 0; QLayoutItem *item = itemAt(i); @@ -1199,7 +1199,7 @@ int QLayout::indexOf(QWidget *widget) const Returns the index of \a layoutItem, or -1 if \a layoutItem is not found. */ -int QLayout::indexOf(QLayoutItem *layoutItem) const +int QLayout::indexOf(const QLayoutItem *layoutItem) const { int i = 0; QLayoutItem *item = itemAt(i); diff --git a/src/widgets/kernel/qlayout.h b/src/widgets/kernel/qlayout.h index ff04c4d334..2748ebab9f 100644 --- a/src/widgets/kernel/qlayout.h +++ b/src/widgets/kernel/qlayout.h @@ -117,8 +117,8 @@ public: virtual void setGeometry(const QRect&) override; virtual QLayoutItem *itemAt(int index) const = 0; virtual QLayoutItem *takeAt(int index) = 0; - virtual int indexOf(QWidget *) const; - QT6_VIRTUAL int indexOf(QLayoutItem *) const; + virtual int indexOf(const QWidget *) const; + virtual int indexOf(const QLayoutItem *) const; virtual int count() const = 0; bool isEmpty() const override; QSizePolicy::ControlTypes controlTypes() const override;