Skip to content

Commit

Permalink
Add Group::close()
Browse files Browse the repository at this point in the history
Convenience to close all groups at once.
Part of issue #513
  • Loading branch information
iamsergio committed Jul 5, 2024
1 parent cec9ef9 commit bb11431
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
* v2.2.0 (unreleased)
- qtquick: Add support for MainWindowOption_HasCentralWidget
- Add Config::setDockWidgetTabIndexOverrideFunc() (#165)

* v2.1.1 (unreleased)
-
Expand Down
12 changes: 12 additions & 0 deletions src/core/Group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,18 @@ LayoutingGuest *Group::asLayoutingGuest() const
return d;
}

bool Group::close() const
{
bool allAccepted = true;

const DockWidget::List docks = dockWidgets();
for (DockWidget *dock : docks) {
allAccepted = allAccepted && dock->close();
}

return allAccepted;
}

Group::Private::Private(Group *qq, int userType, FrameOptions options)
: q(qq)
, m_userType(userType)
Expand Down
4 changes: 4 additions & 0 deletions src/core/Group.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ class DOCKS_EXPORT Group : public Controller, public FocusScope

LayoutingGuest *asLayoutingGuest() const;

/// Convenience that just calls close() on all its dock widgets
/// Returns whether all dock widgets accepted the close
bool close() const;

/// Returns the group that's in the specified item
static Core::Group *fromItem(const Core::Item *);

Expand Down
25 changes: 25 additions & 0 deletions tests/tst_docks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3104,6 +3104,29 @@ KDDW_QCORO_TASK tst_dockWidgetTabIndexOverride()
KDDW_TEST_RETURN(true);
}

KDDW_QCORO_TASK tst_closeGroup()
{
// Tests closing a whole group via Group::close()
EnsureTopLevelsDeleted e;

auto m =
createMainWindow(Size(500, 500), MainWindowOption_None);
auto dock1 = createDockWidget("1", Platform::instance()->tests_createView({ true }));
auto dock2 = createDockWidget("2", Platform::instance()->tests_createView({ true }));
m->addDockWidget(dock1, Location_OnTop);
dock1->addDockWidgetAsTab(dock2);

CHECK(dock1->isOpen());
CHECK(dock2->isOpen());

auto group = dock1->d->group();
CHECK(group->close());
CHECK(!dock1->isOpen());
CHECK(!dock2->isOpen());

KDDW_TEST_RETURN(true);
}

KDDW_QCORO_TASK tst_restoreWithCentralFrameWithTabs()
{
EnsureTopLevelsDeleted e;
Expand Down Expand Up @@ -6421,6 +6444,8 @@ static const auto s_tests = std::vector<KDDWTest>
TEST(tst_mainWindowToggle),
TEST(tst_startDragging),
#if !defined(KDDW_FRONTEND_FLUTTER)
TEST(tst_closeGroup),
TEST(tst_dockWidgetTabIndexOverride),
TEST(tst_dockWidgetTabIndexOverride),
TEST(tst_restoreWithCentralFrameWithTabs),
TEST(tst_preferredInitialSize),
Expand Down

0 comments on commit bb11431

Please sign in to comment.