diff options
author | Thorbjørn Lund Martsum <tmartsum@gmail.com> | 2012-09-03 06:35:39 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-21 23:17:55 +0200 |
commit | 42d681f9cfc984046a93b9efe19903d46ac68bb1 (patch) | |
tree | 0a93a177458dc661b9ceb200f8fa21250b6b601f /src/widgets/kernel/qformlayout.cpp | |
parent | e327ba191df56f3315a004d7650d5f1080f12acb (diff) |
Add widget replace function to QLayout
Sometimes it is nice to be able to replace a widget in a layout.
Change-Id: I23a6a65e417e94d53bc48639503db1a142bc3f10
Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
Diffstat (limited to 'src/widgets/kernel/qformlayout.cpp')
-rw-r--r-- | src/widgets/kernel/qformlayout.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/widgets/kernel/qformlayout.cpp b/src/widgets/kernel/qformlayout.cpp index fd6482d5af..e1376c754f 100644 --- a/src/widgets/kernel/qformlayout.cpp +++ b/src/widgets/kernel/qformlayout.cpp @@ -246,6 +246,7 @@ public: int hSpacing; int vSpacing; + QLayoutItem* replaceAt(int index, QLayoutItem*) Q_DECL_OVERRIDE; }; QFormLayoutPrivate::QFormLayoutPrivate() @@ -1001,6 +1002,32 @@ QStyle* QFormLayoutPrivate::getStyle() const return QApplication::style(); } +QLayoutItem* QFormLayoutPrivate::replaceAt(int index, QLayoutItem *newitem) +{ + Q_Q(QFormLayout); + if (!newitem) + return 0; + const int storageIndex = storageIndexFromLayoutItem(m_matrix, m_things.value(index)); + if (storageIndex == -1) { + // ### Qt6 - fix warning too when this class becomes public + qWarning("QFormLayoutPrivate::replaceAt: Invalid index %d", index); + return 0; + } + + int row, col; + QFormLayoutPrivate::ItemMatrix::storageIndexToPosition(storageIndex, &row, &col); + Q_ASSERT(m_matrix(row, col)); + + QFormLayoutItem *item = m_matrix(row, col); + Q_ASSERT(item); + + QLayoutItem *olditem = item->item; + item->item = newitem; + + q->invalidate(); + return olditem; +} + /*! \class QFormLayout \since 4.4 |