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>
This commit is contained in:
parent
1ab91b7bdb
commit
2c96f51771
@ -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) {
|
||||
|
@ -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;
|
||||
|
@ -1224,7 +1224,7 @@ bool QMainWindowLayoutState::restoreState(QDataStream &_stream,
|
||||
if (info == nullptr) {
|
||||
continue;
|
||||
}
|
||||
info->item_list.append(QDockAreaLayoutItem(new QDockWidgetItem(w)));
|
||||
info->add(w);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user