Skip to content

Commit

Permalink
Fix crash in TWidgetHelper::show/hideChildren.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Nov 1, 2021
1 parent d9953c2 commit 402b73f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
24 changes: 24 additions & 0 deletions ui/rp_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,30 @@
#include <QtGui/QtEvents>

namespace Ui {
namespace {

[[nodiscard]] std::vector<QPointer<QWidget>> GetChildWidgets(
not_null<QWidget*> widget) {
const auto &children = widget->children();
auto result = std::vector<QPointer<QWidget>>();
result.reserve(children.size());
for (const auto child : children) {
if (child && child->isWidgetType()) {
result.push_back(static_cast<QWidget*>(child));
}
}
return result;
}

} // namespace

void ToggleChildrenVisibility(not_null<QWidget*> widget, bool visible) {
for (const auto &child : GetChildWidgets(widget)) {
if (child) {
child->setVisible(visible);
}
}
}

void ResizeFitChild(
not_null<RpWidget*> parent,
Expand Down
18 changes: 8 additions & 10 deletions ui/rp_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
#include <QtCore/QPointer>
#include <QtGui/QtEvents>

namespace Ui {

void ToggleChildrenVisibility(not_null<QWidget*> widget, bool visible);

} // namespace Ui

class TWidget;

template <typename Base>
Expand All @@ -30,18 +36,10 @@ class TWidgetHelper : public Base {
}

void hideChildren() {
for (auto child : Base::children()) {
if (child->isWidgetType()) {
static_cast<QWidget*>(child)->hide();
}
}
Ui::ToggleChildrenVisibility(this, false);
}
void showChildren() {
for (auto child : Base::children()) {
if (child->isWidgetType()) {
static_cast<QWidget*>(child)->show();
}
}
Ui::ToggleChildrenVisibility(this, true);
}

void moveToLeft(int x, int y, int outerw = 0) {
Expand Down

0 comments on commit 402b73f

Please sign in to comment.