KDDockWidgets API Documentation 2.1
Loading...
Searching...
No Matches
ViewGuard.cpp
Go to the documentation of this file.
1/*
2 This file is part of KDDockWidgets.
3
4 SPDX-FileCopyrightText: 2019 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
5 Author: Waqar Ahmed <waqar.ahmed@kdab.com>
6
7 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
8
9 Contact KDAB at <info@kdab.com> for commercial licensing options.
10*/
11
12#include "ViewGuard.h"
13#include "View.h"
14#include "core/View_p.h"
15
16using namespace KDDockWidgets;
17using namespace KDDockWidgets::Core;
18
20{
21 setView(view);
22}
23
25{
26 setView(other.view());
27}
28
33
34ViewGuard::operator bool() const
35{
36 return !isNull();
37}
38
40{
41 return v == nullptr;
42}
43
45{
46 return v;
47}
48
50{
51 return v;
52}
53
55{
56 v = nullptr;
57 m_onDestroy.disconnect();
58}
59
61{
62 return v;
63}
64
66{
67 setView(view);
68 return *this;
69}
70
72{
73 if (this == &other)
74 return *this;
75
76 setView(other.view());
77 return *this;
78}
79
80void ViewGuard::setView(View *view)
81{
82 if (view == v)
83 return;
84
85 if (view && view->inDtor()) {
86 // We don't care about views that are already being in DTOR. They count as already deleted
87 // for what's ViewGuard concerned. This is rare anyway, would need to require some
88 // reentrancy.
89 view = nullptr;
90 }
91
92 clear();
93 v = view;
94
95 if (v) {
96 m_onDestroy = v->d->beingDestroyed.connect([this] { v = nullptr; });
97 }
98}
This class provides a weak reference to a view i.e., it becomes null automatically once a View is des...
Definition ViewGuard.h:27
ViewGuard & operator=(View *)
Definition ViewGuard.cpp:65
bool inDtor() const
Returns whether the DTOR is currently running. freed() might be true while inDtor false,...
Class to abstract QAction, so code still works with QtQuick and Flutter.

© Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/
KDDockWidgets
Advanced Dock Widget Framework for Qt
https://www.kdab.com/development-resources/qt-tools/kddockwidgets/
Generated by doxygen 1.9.8