Added ItemBoxContainer::tst_numSideBySide_recursive()

This commit is contained in:
Sergio Martins
2022-06-02 13:59:20 +01:00
parent 4727c9c7fc
commit f5622732ce
3 changed files with 65 additions and 0 deletions

View File

@@ -979,6 +979,32 @@ ItemBoxContainer::~ItemBoxContainer()
delete d;
}
int ItemBoxContainer::numSideBySide_recursive(Qt::Orientation o) const
{
int num = 0;
if (d->m_orientation == o) {
// Example: Container is horizontal and we want to know how many layouted horizontally
for (Item *child : m_children) {
if (ItemBoxContainer *container = child->asBoxContainer()) {
num += container->numSideBySide_recursive(o);
} else {
num++;
}
}
} else {
// Example: Container is vertical and we want to know how many layouted horizontally
for (Item *child : m_children) {
if (ItemBoxContainer *container = child->asBoxContainer()) {
num = qMax(num, container->numSideBySide_recursive(o));
} else {
num = qMax(num, 1);
}
}
}
return num;
}
bool ItemBoxContainer::checkSanity()
{
d->m_checkSanityScheduled = false;

View File

@@ -475,6 +475,10 @@ public:
bool isHorizontal() const;
int length() const;
/// @brief Returns the number of items layed out horizontally or vertically
/// But honours nesting
int numSideBySide_recursive(Qt::Orientation) const;
private:
bool hasOrientation() const;
int indexOfVisibleChild(const Item *) const;