Skip to content

Commit

Permalink
Merge branch '2.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
iamsergio committed Apr 15, 2024
2 parents 0dbf66a + fe17c73 commit 7176dae
Show file tree
Hide file tree
Showing 6 changed files with 781 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/core/layouting/Item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,21 @@ int ItemBoxContainer::numSideBySide_recursive(Qt::Orientation o) const
return num;
}

bool ItemBoxContainer::percentagesAreSane() const
{
const Item::List visibleChildren = this->visibleChildren();
const Vector<double> percentages = d->childPercentages();
const double totalPercentage = std::accumulate(percentages.begin(), percentages.end(), 0.0);
const double expectedPercentage = visibleChildren.isEmpty() ? 0.0 : 1.0;
if (!fuzzyCompare(totalPercentage, expectedPercentage)) {
root()->dumpLayout();
KDDW_ERROR("Percentages don't add up", totalPercentage, percentages, ( void * )this);
return false;
}

return true;
}

bool ItemBoxContainer::checkSanity()
{
d->m_checkSanityScheduled = false;
Expand Down Expand Up @@ -1280,15 +1295,11 @@ bool ItemBoxContainer::checkSanity()
return false;
}

const Vector<double> percentages = d->childPercentages();
const double totalPercentage = std::accumulate(percentages.begin(), percentages.end(), 0.0);
const double expectedPercentage = visibleChildren.isEmpty() ? 0.0 : 1.0;
if (!fuzzyCompare(totalPercentage, expectedPercentage)) {
root()->dumpLayout();
KDDW_ERROR("Percentages don't add up", totalPercentage, percentages, ( void * )this);
if (!percentagesAreSane()) {
// Percentages might be broken due to buggy old layouts. Try to fix them:
const_cast<ItemBoxContainer *>(this)->d->updateSeparators_recursive();
KDDW_ERROR("percentages={}", d->childPercentages());
return false;
if (!percentagesAreSane())
return false;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/core/layouting/Item_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ class DOCKS_EXPORT ItemBoxContainer : public ItemContainer
Size minSize() const override;
Size maxSizeHint() const override;
Size availableSize() const;
bool percentagesAreSane() const;
Q_REQUIRED_RESULT bool checkSanity() override;
void dumpLayout(int level = 0, bool printSeparators = true) override;
void setSize_recursive(
Expand Down
4 changes: 4 additions & 0 deletions tests/anonymize_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ main(List<String> args) {
return;
}

/// Skip internals
if (["-persistentCentralDockWidget", "_kddw_internal_dummy", "_kddw_internal_dummy2"].contains(name))
continue;

contents = contents.replaceAll(name, "dockwidget_tests_$i");
i++;
}
Expand Down
Loading

0 comments on commit 7176dae

Please sign in to comment.