| 1592 | } |
| 1593 | |
| 1594 | bool ViewManager::createSplitWithExisting(int targetSplitterId, QStringList widgetInfos, int idx, bool horizontalSplit) |
| 1595 | { |
| 1596 | auto targetSplitter = _viewContainer->findSplitter(targetSplitterId); |
| 1597 | if (targetSplitter == nullptr || idx < 0) |
| 1598 | return false; |
| 1599 | |
| 1600 | QVector<QWidget *> linearLayout; |
| 1601 | QList<int> forbiddenSplitters, forbiddenViews; |
| 1602 | |
| 1603 | // specify that top level splitters should not be used as children for created splittter |
| 1604 | for (int i = 0; i < _viewContainer->count(); ++i) { |
| 1605 | forbiddenSplitters.append(_viewContainer->viewSplitterAt(i)->id()); |
| 1606 | } |
| 1607 | |
| 1608 | // specify that parent splitters of the splitter with targetSplitterId id should not be used |
| 1609 | // as children for created splitter |
| 1610 | for (auto splitter = targetSplitter; splitter != targetSplitter->getToplevelSplitter(); splitter = qobject_cast<ViewSplitter *>(splitter->parentWidget())) { |
| 1611 | forbiddenSplitters.append(splitter->id()); |
| 1612 | } |
| 1613 | |
| 1614 | // to make positioning clearer by avoiding situations where |
| 1615 | // e.g. splitter to be created is at index x of targetSplitter |
| 1616 | // and some direct children of targetSplitter are used as |
| 1617 | // children of created splitter, causing the final position |
| 1618 | // of created splitter to may not be at x |
| 1619 | for (int i = 0; i < targetSplitter->count(); ++i) { |
| 1620 | auto w = targetSplitter->widget(i); |
| 1621 | |
| 1622 | if (auto s = qobject_cast<ViewSplitter *>(w)) |
| 1623 | forbiddenSplitters.append(s->id()); |
| 1624 | else |
| 1625 | forbiddenViews.append(qobject_cast<TerminalDisplay *>(w)->id()); |
| 1626 | } |
| 1627 | |
| 1628 | for (auto &info : widgetInfos) { |
| 1629 | auto typeAndId = info.split(QLatin1Char('-')); |
| 1630 | if (typeAndId.size() != 2) |
| 1631 | return false; |
| 1632 | |
| 1633 | int id = typeAndId[1].toInt(); |
| 1634 | QChar type = typeAndId[0][0]; |
| 1635 | |
| 1636 | if (type == QLatin1Char('s') && !forbiddenSplitters.removeOne(id)) { |
| 1637 | if (auto s = _viewContainer->findSplitter(id)) { |
| 1638 | linearLayout.append(s); |
| 1639 | continue; |
| 1640 | } |
| 1641 | } else if (type == QLatin1Char('v') && !forbiddenViews.removeOne(id)) { |
| 1642 | if (auto v = findTerminalDisplay(id)) { |
| 1643 | linearLayout.append(v); |
| 1644 | continue; |
| 1645 | } |
| 1646 | } |
| 1647 | |
| 1648 | return false; |
| 1649 | } |
| 1650 | |
| 1651 | if (linearLayout.count() == 1) { |
nothing calls this directly
no test coverage detected