Skip to content

Commit

Permalink
Add a test for FloatingWindow placeholders
Browse files Browse the repository at this point in the history
They currently lose if there's a competing main window placeholder.
Test is currently failing.

For issue #513 and #280
  • Loading branch information
iamsergio committed Jul 10, 2024
1 parent fd09338 commit 77fffd6
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/core/Position.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ void Position::removePlaceholder(Core::Item *placeholder)
m_placeholders.end());
}

int Position::placeholderCount() const
{
return m_placeholders.size();
}

void Position::deserialize(const LayoutSaver::Position &lp)
{
m_lastFloatingGeometry = lp.lastFloatingGeometry;
Expand Down
9 changes: 9 additions & 0 deletions src/core/Position_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class DOCKS_EXPORT_FOR_UNIT_TESTS Position
bool m_wasFloating = false;

///@brief Adds the last layout item where the dock widget was (or is)
/// This is called at the moment the dock widget is added into any layout
void addPlaceholderItem(Core::Item *placeholder);

bool containsPlaceholder(Core::Item *) const;
Expand All @@ -85,6 +86,14 @@ class DOCKS_EXPORT_FOR_UNIT_TESTS Position
///@brief removes the Item @p placeholder
void removePlaceholder(Core::Item *placeholder);

/// The amount of placeholders we know about
/// this will be either:
/// 0 - if dock widget hasn't been docked
/// 1 - if it has been docked
/// 2 - if it has been docked to main window and to a floating window
/// We don't support memorizing more than 1 main window or more than 1 floating window
int placeholderCount() const;

void saveTabIndex(int tabIndex, bool isFloating)
{
m_tabIndex = tabIndex;
Expand Down
38 changes: 38 additions & 0 deletions tests/tst_docks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3127,6 +3127,43 @@ KDDW_QCORO_TASK tst_closeGroup()
KDDW_TEST_RETURN(true);
}

KDDW_QCORO_TASK tst_placeholderInFloatingWindow()
{
// Tests that placeholders in floating windows get priority
// over main window placeholders if the last state was floating

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 }));

// Make dock1 have a placeholder in the main window:
m->addDockWidget(dock1, Location_OnTop);
dock2->setFloating(true);
CHECK(dock1->hasPreviousDockedLocation());
auto lastPos1 = dock1->d->lastPosition();
CHECK(lastPos1->isValid());
CHECK(lastPos1->placeholderCount() == 1);

// float it, then nest it with dock2 (floating)
dock1->setFloating(true);
CHECK(lastPos1->placeholderCount() == 2);

dock2->addDockWidgetToContainingWindow(dock1, Location_OnTop);
CHECK(lastPos1->placeholderCount() == 2);

dock1->close();
dock1->show();

CHECK(lastPos1->placeholderCount() == 2);
// CHECK(!dock1->isInMainWindow());
// Platform::instance()->tests_wait(10000000);

KDDW_TEST_RETURN(true);
}

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

0 comments on commit 77fffd6

Please sign in to comment.