diff --git a/tests/tst_docks.cpp b/tests/tst_docks.cpp index cf3a1b64..41f9846c 100644 --- a/tests/tst_docks.cpp +++ b/tests/tst_docks.cpp @@ -335,6 +335,7 @@ private Q_SLOTS: void tst_restoreWithPlaceholder(); void tst_restoreWithNonClosableWidget(); void tst_restoreAfterResize(); + void tst_restoreWithAffinity(); void tst_marginsAfterRestore(); void tst_restoreEmbeddedMainWindow(); void tst_restoreWithDockFactory(); @@ -1596,6 +1597,48 @@ void TestDocks::tst_restoreAfterResize() QCOMPARE(oldWindowSize, m->size()); } +void TestDocks::tst_restoreWithAffinity() +{ + EnsureTopLevelsDeleted e; + + auto m1 = createMainWindow(QSize(500, 500)); + m1->setAffinityName("a1"); + auto m2 = createMainWindow(QSize(500, 500)); + m2->setAffinityName("a2"); + + auto dock1 = createDockWidget("1", new QPushButton("1"), {}, true, "a1"); + m1->addDockWidget(dock1, Location_OnLeft); + + auto dock2 = createDockWidget("2", new QPushButton("2"), {}, true, "a2"); + dock2->setFloating(true); + dock2->show(); + + LayoutSaver saver; + saver.setAffinityNames({"a1"}); + const QByteArray saved1 = saver.serializeLayout(); + + QPointer fw2 = dock2->floatingWindow(); + saver.restoreLayout(saved1); + + // Restoring affinity 1 shouldn't close affinity 2 + QVERIFY(!fw2.isNull()); + QVERIFY(dock2->isVisible()); + + // Close all and restore again + DockRegistry::self()->clear(); + saver.restoreLayout(saved1); + + // dock2 continues closed + QVERIFY(!dock2->isVisible()); + + // dock1 was restored + QVERIFY(dock1->isVisible()); + QVERIFY(!dock1->isFloating()); + QCOMPARE(dock1->window(), m1.get()); + + delete dock2->window(); +} + void TestDocks::tst_marginsAfterRestore() { EnsureTopLevelsDeleted e; diff --git a/tests/utils.cpp b/tests/utils.cpp index e5d5514c..6f5261a0 100644 --- a/tests/utils.cpp +++ b/tests/utils.cpp @@ -82,9 +82,12 @@ std::unique_ptr KDDockWidgets::Tests::createMainWindo return ptr; } -DockWidgetBase *KDDockWidgets::Tests::createDockWidget(const QString &name, QWidget *w, DockWidgetBase::Options options, bool show) +DockWidgetBase *KDDockWidgets::Tests::createDockWidget(const QString &name, QWidget *w, + DockWidgetBase::Options options, bool show, + const QString &affinityName) { auto dock = new DockWidget(name, options); + dock->setAffinityName(affinityName); dock->setWidget(w); dock->setObjectName(name); dock->setGeometry(0, 0, 400, 400); diff --git a/tests/utils.h b/tests/utils.h index c6e47832..9a3d5016 100644 --- a/tests/utils.h +++ b/tests/utils.h @@ -68,7 +68,8 @@ std::unique_ptr createMainWindow(QSize sz = {600, 600 std::unique_ptr createMainWindow(QVector &docks); KDDockWidgets::DockWidgetBase *createDockWidget(const QString &name, QWidget *w, - DockWidgetBase::Options options = {}, bool show = true); + DockWidgetBase::Options options = {}, bool show = true, + const QString &affinityName = {}); KDDockWidgets::DockWidgetBase *createDockWidget(const QString &name, QColor color); class NonClosableWidget : public QWidget