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.5 Change-Id: Ib2ccd7557a21a43b68f184fe4575018f2a97004b Reviewed-by: David Faure <david.faure@kdab.com> (cherry picked from commit 2c96f517714eb67a9af821141a90eed68b8714ed) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
65f59d96c7
commit
de5925b159
@ -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)
|
QLayoutItem *QDockAreaLayoutInfo::plug(const QList<int> &path)
|
||||||
{
|
{
|
||||||
Q_ASSERT(!path.isEmpty());
|
Q_ASSERT(!path.isEmpty());
|
||||||
@ -1148,8 +1156,6 @@ bool QDockAreaLayoutInfo::insertGap(const QList<int> &path, QLayoutItem *dockWid
|
|||||||
index = -index - 1;
|
index = -index - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// dump(qDebug() << "insertGap() before:" << index << tabIndex, *this, QString());
|
|
||||||
|
|
||||||
if (path.size() > 1) {
|
if (path.size() > 1) {
|
||||||
QDockAreaLayoutItem &item = item_list[index];
|
QDockAreaLayoutItem &item = item_list[index];
|
||||||
|
|
||||||
@ -1778,6 +1784,26 @@ QLayoutItem *QDockAreaLayoutInfo::takeAt(int *x, int index)
|
|||||||
return nullptr;
|
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()
|
void QDockAreaLayoutInfo::deleteAllLayoutItems()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < item_list.size(); ++i) {
|
for (int i = 0; i < item_list.size(); ++i) {
|
||||||
@ -1971,6 +1997,7 @@ bool QDockAreaLayoutInfo::restoreState(QDataStream &stream, QList<QDockWidget*>
|
|||||||
if (testing) {
|
if (testing) {
|
||||||
//was it is not really added to the layout, we need to delete the object here
|
//was it is not really added to the layout, we need to delete the object here
|
||||||
delete item.widgetItem;
|
delete item.widgetItem;
|
||||||
|
item.widgetItem = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (nextMarker == SequenceMarker) {
|
} else if (nextMarker == SequenceMarker) {
|
||||||
|
@ -109,6 +109,7 @@ public:
|
|||||||
QList<int> gapIndex(const QPoint &pos, bool nestingEnabled,
|
QList<int> gapIndex(const QPoint &pos, bool nestingEnabled,
|
||||||
TabMode tabMode) const;
|
TabMode tabMode) const;
|
||||||
void remove(const QList<int> &path);
|
void remove(const QList<int> &path);
|
||||||
|
void remove(QWidget *widget);
|
||||||
void unnest(int index);
|
void unnest(int index);
|
||||||
void split(int index, Qt::Orientation orientation, QLayoutItem *dockWidgetItem);
|
void split(int index, Qt::Orientation orientation, QLayoutItem *dockWidgetItem);
|
||||||
#if QT_CONFIG(tabbar)
|
#if QT_CONFIG(tabbar)
|
||||||
@ -156,6 +157,7 @@ public:
|
|||||||
|
|
||||||
QLayoutItem *itemAt(int *x, int index) const;
|
QLayoutItem *itemAt(int *x, int index) const;
|
||||||
QLayoutItem *takeAt(int *x, int index);
|
QLayoutItem *takeAt(int *x, int index);
|
||||||
|
void add(QWidget *widget);
|
||||||
void deleteAllLayoutItems();
|
void deleteAllLayoutItems();
|
||||||
|
|
||||||
QMainWindowLayout *mainWindowLayout() const;
|
QMainWindowLayout *mainWindowLayout() const;
|
||||||
|
@ -1224,7 +1224,7 @@ bool QMainWindowLayoutState::restoreState(QDataStream &_stream,
|
|||||||
if (info == nullptr) {
|
if (info == nullptr) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
info->item_list.append(QDockAreaLayoutItem(new QDockWidgetItem(w)));
|
info->add(w);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user