Cockatrice
2026-01-14-Development-2.11.0-beta.46
A cross-platform 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
QLayoutItem *it;
24
while
((it = l->takeAt(0)) !=
nullptr
) {
25
if
(QWidget *w = it->widget())
26
w->deleteLater();
27
if
(QLayout *sub = it->layout())
28
clearLayoutRec
(sub);
29
delete
it;
30
}
31
}
32
}
// namespace QtUtils
33
34
#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.14.0