This commit is contained in:
Sergio Martins
2020-04-06 21:57:34 +01:00
parent 164ccd5cd7
commit 94b47893d6
2 changed files with 34 additions and 4 deletions

View File

@@ -218,15 +218,23 @@ int Item::pos(Qt::Orientation o) const
void Item::insertItem(Item *item, Location loc, SizingOption sizingOption)
{
Q_ASSERT(item != this);
const bool locIsSide1 = locationIsSide1(loc);
if (sizingOption == SizingOption::Calculate)
item->setGeometry(m_parent->suggestedDropRect(item->minSize(), this, loc));
if (m_parent->hasOrientationFor(loc)) {
int indexInParent = m_parent->indexOfChild(this);
const bool locIsSide1 = locationIsSide1(loc);
int indexInParent = m_parent->indexOfVisibleChild(this);
if (!locIsSide1)
indexInParent++;
const Qt::Orientation orientation = orientationForLocation(loc);
if (orientation != m_parent->orientation()) {
Q_ASSERT(m_parent->visibleChildren().size() == 1);
// This is the case where the container only has one item, so it's both vertical and horizontal
// Now its orientation gets defined
m_parent->m_orientation = orientation;
}
m_parent->insertItem(item, indexInParent);
} else {
ItemContainer *container = m_parent->convertChildToContainer(this);

View File

@@ -53,6 +53,8 @@ private Q_SLOTS:
void tst_createRoot();
void tst_insertOne();
void tst_insertThreeSideBySide();
void tst_insertTwoHorizontal();
void tst_insertTwoVertical();
void tst_insertOnWidgetItem1();
void tst_insertOnWidgetItem2();
void tst_insertOnWidgetItem1DifferentOrientation();
@@ -114,6 +116,27 @@ void TestMultiSplitter::tst_insertThreeSideBySide()
QCOMPARE(root->numChildren(), 3);
}
void TestMultiSplitter::tst_insertTwoHorizontal()
{
auto root = createRoot();
auto item1 = createItem("1");
auto item2 = createItem("2");
root->insertItem(item1, Location_OnLeft);
item1->insertItem(item2, Location_OnRight);
root->dumpLayout();
QVERIFY(root->checkSanity());
}
void TestMultiSplitter::tst_insertTwoVertical()
{
auto root = createRoot();
auto item1 = createItem("1");
auto item2 = createItem("2");
root->insertItem(item1, Location_OnTop);
item1->insertItem(item2, Location_OnBottom);
QVERIFY(root->checkSanity());
}
void TestMultiSplitter::tst_insertOnWidgetItem1()
{
// We insert into a widget item instead of in a container. It will insert in the container still
@@ -643,7 +666,6 @@ void TestMultiSplitter::tst_suggestedRect()
QCOMPARE(topRect.topRight(), item2->geometry().topRight());
QCOMPARE(bottomRect.bottomLeft(), item2->geometry().bottomLeft());
QCOMPARE(bottomRect.bottomRight(), item2->geometry().bottomRight());
}
QTEST_MAIN(TestMultiSplitter)