Cockatrice
2026-06-01-Development-3.1.0-beta.3
A virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
qt_utils.h
Go to the documentation of this file.
1
#ifndef COCKATRICE_QT_UTILS_H
2
#define COCKATRICE_QT_UTILS_H
3
#include <QObject>
4
5
namespace
QtUtils
6
{
7
template
<
typename
T> T *
findParentOfType
(
const
QObject *obj)
8
{
9
const
QObject *p = obj ? obj->parent() :
nullptr
;
10
while
(p) {
11
if
(
auto
casted = qobject_cast<T *>(
const_cast<
QObject *
>
(p))) {
12
return
casted;
13
}
14
p = p->parent();
15
}
16
return
nullptr
;
17
}
18
19
static
inline
void
clearLayoutRec
(QLayout *l)
20
{
21
if
(!l) {
22
return
;
23
}
24
QLayoutItem *it;
25
while
((it = l->takeAt(0)) !=
nullptr
) {
26
if
(QWidget *w = it->widget()) {
27
w->deleteLater();
28
}
29
if
(QLayout *sub = it->layout()) {
30
clearLayoutRec
(sub);
31
}
32
delete
it;
33
}
34
}
35
}
// namespace QtUtils
36
37
#endif
// COCKATRICE_QT_UTILS_H
QtUtils
Definition
qt_utils.h:6
QtUtils::findParentOfType
T * findParentOfType(const QObject *obj)
Definition
qt_utils.h:7
QtUtils::clearLayoutRec
static void clearLayoutRec(QLayout *l)
Definition
qt_utils.h:19
libcockatrice_utility
libcockatrice
utility
qt_utils.h
Generated by
1.16.1