Cockatrice/libcockatrice_utility/libcockatrice/utility/qt_utils.h
DawnFire42 aadee34238
style: Add braces to all control flow statements (#6887)
* style: Add braces to all control flow statements

  Standardize code style by adding explicit braces to all single-statement
  control flow blocks (if, else, for, while) across the entire codebase.

  Also documents the InsertBraces clang-format option (requires v15+) for
  future automated enforcement.

* InsertBraces-check-enabled
2026-05-16 19:19:53 +02:00

37 lines
798 B
C++

#ifndef COCKATRICE_QT_UTILS_H
#define COCKATRICE_QT_UTILS_H
#include <QObject>
namespace QtUtils
{
template <typename T> T *findParentOfType(const QObject *obj)
{
const QObject *p = obj ? obj->parent() : nullptr;
while (p) {
if (auto casted = qobject_cast<T *>(const_cast<QObject *>(p))) {
return casted;
}
p = p->parent();
}
return nullptr;
}
static inline void clearLayoutRec(QLayout *l)
{
if (!l) {
return;
}
QLayoutItem *it;
while ((it = l->takeAt(0)) != nullptr) {
if (QWidget *w = it->widget()) {
w->deleteLater();
}
if (QLayout *sub = it->layout()) {
clearLayoutRec(sub);
}
delete it;
}
}
} // namespace QtUtils
#endif // COCKATRICE_QT_UTILS_H