summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2013-11-08 13:22:36 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-11-10 14:09:55 +0100
commit8462a6933c843eeed2d94d83d4b10f7c946a5475 (patch)
treea01876a5b5fd588a6382aa93677afe539baf2eff /src
parent9af6fd5d8a2d142742ad690286f50c7aac34908c (diff)
Remove a boolean trap in QLayout::replaceWidget
Use some flags instead. Task-number: QTBUG-34668 Change-Id: I9a75253c8eb98164c594bb6bb06c1a16c9609537 Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com> Reviewed-by: J-P Nurmi <jpnurmi@digia.com> Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'src')
-rw-r--r--src/widgets/kernel/qlayout.cpp24
-rw-r--r--src/widgets/kernel/qlayout.h4
2 files changed, 19 insertions, 9 deletions
diff --git a/src/widgets/kernel/qlayout.cpp b/src/widgets/kernel/qlayout.cpp
index f17a6caa3c..eb21a580b1 100644
--- a/src/widgets/kernel/qlayout.cpp
+++ b/src/widgets/kernel/qlayout.cpp
@@ -1112,18 +1112,26 @@ bool QLayout::activate()
\since 5.2
Searches for widget \a from and replaces it with widget \a to if found.
- Returns the layout item that contains the widget \a from on success. Otherwise \c 0 is returned.
- If \a recursive is \c true, sub-layouts are searched for doing the replacement. Notice that the returned item therefore might not belong to this layout, but to a sub-layout.
+ Returns the layout item that contains the widget \a from on success.
+ Otherwise \c 0 is returned. If \a options contains \c Qt::FindChildrenRecursively
+ (the default), sub-layouts are searched for doing the replacement.
+ Any other flag in \a options is ignored.
- The returned layout item is no longer owned by the layout and should be either deleted or inserted to another layout. The widget \a from is no longer managed by the layout and may need to be deleted or hidden. The parent of widget \a from is left unchanged.
+ Notice that the returned item therefore might not belong to this layout,
+ but to a sub-layout.
- This function works for the built-in Qt layouts, but might not work for custom layouts.
+ The returned layout item is no longer owned by the layout and should be
+ either deleted or inserted to another layout. The widget \a from is no
+ longer managed by the layout and may need to be deleted or hidden. The
+ parent of widget \a from is left unchanged.
+
+ This function works for the built-in Qt layouts, but might not work for
+ custom layouts.
\sa indexOf()
*/
-//### Qt 6 make this function virtual
-QLayoutItem* QLayout::replaceWidget(QWidget *from, QWidget *to, bool recursive)
+QLayoutItem *QLayout::replaceWidget(QWidget *from, QWidget *to, Qt::FindChildOptions options)
{
Q_D(QLayout);
if (!from || !to)
@@ -1141,8 +1149,8 @@ QLayoutItem* QLayout::replaceWidget(QWidget *from, QWidget *to, bool recursive)
break;
}
- if (item->layout() && recursive) {
- QLayoutItem *r = item->layout()->replaceWidget(from, to, true);
+ if (item->layout() && (options & Qt::FindChildrenRecursively)) {
+ QLayoutItem *r = item->layout()->replaceWidget(from, to, options);
if (r)
return r;
}
diff --git a/src/widgets/kernel/qlayout.h b/src/widgets/kernel/qlayout.h
index ca5f6d42ea..27d9d34b9c 100644
--- a/src/widgets/kernel/qlayout.h
+++ b/src/widgets/kernel/qlayout.h
@@ -130,7 +130,9 @@ public:
virtual int count() const = 0;
bool isEmpty() const;
QSizePolicy::ControlTypes controlTypes() const;
- QLayoutItem* replaceWidget(QWidget *from, QWidget *to, bool recursive = true);
+
+ // ### Qt 6 make this function virtual
+ QLayoutItem *replaceWidget(QWidget *from, QWidget *to, Qt::FindChildOptions options = Qt::FindChildrenRecursively);
int totalHeightForWidth(int w) const;
QSize totalMinimumSize() const;