diff options
author | Axel Spoerl <axel.spoerl@qt.io> | 2023-11-15 11:19:11 +0100 |
---|---|---|
committer | Axel Spoerl <axel.spoerl@qt.io> | 2023-11-15 21:52:23 +0100 |
commit | 2c96f517714eb67a9af821141a90eed68b8714ed (patch) | |
tree | b9c7258d2f93f488df84831ac9d0d93a1892bd4a | |
parent | 1ab91b7bdbcced6ea4cc176da1d18e6b789208ae (diff) |
QDockAreaLayout: implement widget based add() and remove()
The item_list of a QDockAreaLayoutInfo has abstraction methods for
reading the item list. Adding to and removing from the item list is
done directly, by using the QList api.
Implement an abstraction, that takes a QWidget *.
The argument may either be a QDockWidgetGroupWindow or a QDockWidget.
Task-number: QTBUG-118578
Task-number: QTBUG-118579
Pick-to: 6.6 6.5
Change-Id: Ib2ccd7557a21a43b68f184fe4575018f2a97004b
Reviewed-by: David Faure <david.faure@kdab.com>
-rw-r--r-- | src/widgets/widgets/qdockarealayout.cpp | 31 | ||||
-rw-r--r-- | src/widgets/widgets/qdockarealayout_p.h | 2 | ||||
-rw-r--r-- | src/widgets/widgets/qmainwindowlayout.cpp | 2 |
3 files changed, 32 insertions, 3 deletions
diff --git a/src/widgets/widgets/qdockarealayout.cpp b/src/widgets/widgets/qdockarealayout.cpp index 27eed4075f..da0e987171 100644 --- a/src/widgets/widgets/qdockarealayout.cpp +++ b/src/widgets/widgets/qdockarealayout.cpp @@ -1018,6 +1018,14 @@ void QDockAreaLayoutInfo::remove(const QList<int> &path) } } +void QDockAreaLayoutInfo::remove(QWidget *widget) +{ + const QList<int> path = indexOf(widget); + if (path.isEmpty()) + return; + remove(path); +} + QLayoutItem *QDockAreaLayoutInfo::plug(const QList<int> &path) { Q_ASSERT(!path.isEmpty()); @@ -1148,8 +1156,6 @@ bool QDockAreaLayoutInfo::insertGap(const QList<int> &path, QLayoutItem *dockWid index = -index - 1; } -// dump(qDebug() << "insertGap() before:" << index << tabIndex, *this, QString()); - if (path.size() > 1) { QDockAreaLayoutItem &item = item_list[index]; @@ -1778,6 +1784,26 @@ QLayoutItem *QDockAreaLayoutInfo::takeAt(int *x, int index) return nullptr; } +// Add a dock widget or dock widget group window to the item list +void QDockAreaLayoutInfo::add(QWidget *widget) +{ + // Do not add twice + if (!indexOf(widget).isEmpty()) + return; + + if (auto *dockWidget = qobject_cast<QDockWidget *>(widget)) { + item_list.append(QDockAreaLayoutItem(new QDockWidgetItem(dockWidget))); + return; + } + + if (auto *groupWindow = qobject_cast<QDockWidgetGroupWindow *>(widget)) { + item_list.append(QDockAreaLayoutItem(new QDockWidgetGroupWindowItem(groupWindow))); + return; + } + + qFatal("Coding error. Add supports only QDockWidget and QDockWidgetGroupWindow"); +} + void QDockAreaLayoutInfo::deleteAllLayoutItems() { for (int i = 0; i < item_list.size(); ++i) { @@ -1971,6 +1997,7 @@ bool QDockAreaLayoutInfo::restoreState(QDataStream &stream, QList<QDockWidget*> if (testing) { //was it is not really added to the layout, we need to delete the object here delete item.widgetItem; + item.widgetItem = nullptr; } } } else if (nextMarker == SequenceMarker) { diff --git a/src/widgets/widgets/qdockarealayout_p.h b/src/widgets/widgets/qdockarealayout_p.h index 7a33b39707..aa39bf9913 100644 --- a/src/widgets/widgets/qdockarealayout_p.h +++ b/src/widgets/widgets/qdockarealayout_p.h @@ -108,6 +108,7 @@ public: QList<int> gapIndex(const QPoint &pos, bool nestingEnabled, TabMode tabMode) const; void remove(const QList<int> &path); + void remove(QWidget *widget); void unnest(int index); void split(int index, Qt::Orientation orientation, QLayoutItem *dockWidgetItem); #if QT_CONFIG(tabbar) @@ -155,6 +156,7 @@ public: QLayoutItem *itemAt(int *x, int index) const; QLayoutItem *takeAt(int *x, int index); + void add(QWidget *widget); void deleteAllLayoutItems(); QMainWindowLayout *mainWindowLayout() const; diff --git a/src/widgets/widgets/qmainwindowlayout.cpp b/src/widgets/widgets/qmainwindowlayout.cpp index 0730e86336..57ee3d0b92 100644 --- a/src/widgets/widgets/qmainwindowlayout.cpp +++ b/src/widgets/widgets/qmainwindowlayout.cpp @@ -1224,7 +1224,7 @@ bool QMainWindowLayoutState::restoreState(QDataStream &_stream, if (info == nullptr) { continue; } - info->item_list.append(QDockAreaLayoutItem(new QDockWidgetItem(w))); + info->add(w); } } } |