Fix Item::suggestedRect() when the parentContainer() wasn't root
This commit is contained in:
@@ -1189,9 +1189,16 @@ QRect ItemContainer::suggestedDropRect(QSize minSize, const Item *relativeTo, Lo
|
||||
const int count = sizes.count();
|
||||
|
||||
if (relativeTo && count == 1) {
|
||||
// If it's the only item then the result is that it's relative to the whole layout
|
||||
// So simplify our code
|
||||
relativeTo = nullptr;
|
||||
|
||||
// When the container only has one item we can do some simplifications
|
||||
|
||||
if (isRoot()) {
|
||||
// Means the result is relative to the whole window
|
||||
relativeTo = nullptr;
|
||||
} else {
|
||||
// Do it relative to this container instead
|
||||
return parentContainer()->suggestedDropRect(minSize, this, loc);
|
||||
}
|
||||
}
|
||||
|
||||
if (relativeTo) {
|
||||
|
||||
@@ -185,6 +185,7 @@ private Q_SLOTS:
|
||||
void tst_ensureEnoughSize();
|
||||
void tst_turnIntoPlaceholder();
|
||||
void tst_suggestedRect();
|
||||
void tst_suggestedRect2();
|
||||
void tst_insertAnotherRoot();
|
||||
void tst_misc1();
|
||||
void tst_misc2();
|
||||
@@ -829,6 +830,23 @@ void TestMultiSplitter::tst_suggestedRect()
|
||||
QVERIFY(serializeDeserializeTest(root));
|
||||
}
|
||||
|
||||
void TestMultiSplitter::tst_suggestedRect2()
|
||||
{
|
||||
// Tests a bug where the inner drop locations didn't work when there was a nested container
|
||||
// Like container >> container >> Item
|
||||
|
||||
auto root1 = createRoot();
|
||||
auto root2 = createRoot();
|
||||
|
||||
const QSize minSize(100, 100);
|
||||
Item *item = createItem();
|
||||
|
||||
root2->insertItem(item, Location_OnRight);
|
||||
root1->insertItem(root2.get(), Location_OnRight);
|
||||
|
||||
QVERIFY(item->parentContainer()->suggestedDropRect(minSize, item, Location_OnRight).isValid());
|
||||
}
|
||||
|
||||
void TestMultiSplitter::tst_insertAnotherRoot()
|
||||
{
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user