mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-11 00:24:47 -07:00
* 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
37 lines
798 B
C++
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
|