KDStateMachineEditor API Documentation 2.1
Loading...
Searching...
No Matches
depthchecker.cpp
Go to the documentation of this file.
1/*
2 This file is part of the KDAB State Machine Editor Library.
3
4 SPDX-FileCopyrightText: 2015 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
5 Author: Kevin Funk <kevin.funk@kdab.com>
6
7 SPDX-License-Identifier: LGPL-2.1-only OR LicenseRef-KDAB-KDStateMachineEditor
8
9 Licensees holding valid commercial KDAB State Machine Editor Library
10 licenses may use this file in accordance with the KDAB State Machine Editor
11 Library License Agreement provided with the Software.
12
13 Contact info@kdab.com if any conditions of this licensing are not clear to you.
14*/
15
16#include "depthchecker.h"
17
18using namespace KDSME;
19
20namespace {
21
22int elementDepth(const Element *element)
23{
24 if (!element)
25 return -1;
26
27 int depth = 0;
28 const Element *current = element;
29 while (current) {
30 ++depth;
31 current = current->parentElement();
32 }
33 return depth;
34}
35
36}
37
38struct DepthChecker::Private
39{
40 Private(DepthChecker *q)
41 : q(q)
42 , m_target(nullptr)
43 , m_depth(-1)
44 {
45 }
46
47 void updateDepth();
48
49 DepthChecker *q;
50 Element *m_target;
51 int m_depth;
52};
53
55 : QObject(parent)
56 , d(new Private(this))
57{
58}
59
63
65{
66 return d->m_depth;
67}
68
70{
71 return d->m_target;
72}
73
75{
76 if (d->m_target == target)
77 return;
78
79 if (d->m_target) {
80 // clang-format off
81 disconnect(d->m_target, SIGNAL(parentChanged(Element*)), // clazy:exclude=old-style-connect
82 this, SLOT(updateDepth()));
83 // clang-format on
84 }
85
86 d->m_target = target;
87
88 if (d->m_target) {
89 // clang-format off
90 connect(d->m_target, SIGNAL(parentChanged(Element*)), // clazy:exclude=old-style-connect
91 this, SLOT(updateDepth()));
92 // clang-format on
93 }
94 Q_EMIT targetChanged(d->m_target);
95
96 d->updateDepth();
97}
98
99void DepthChecker::Private::updateDepth()
100{
101 const int depth = elementDepth(m_target);
102 if (m_depth == depth)
103 return;
104
105 m_depth = depth;
106 Q_EMIT q->depthChanged(m_depth);
107}
108
109#include "moc_depthchecker.cpp"
void setTarget(Element *target)
void targetChanged(QObject *target)
DepthChecker(QObject *parent=nullptr)
KDSME::Element * target
Element * parentElement() const
Definition element.cpp:205
KDSME_CORE_EXPORT int depth(const QObject *root, const QObject *object)

© Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/
KDStateMachineEditor
Create Qt State Machine metacode using a graphical user interface
https://github.com/KDAB/KDStateMachineEditor
Generated on Tue Jul 15 2025 15:21:47 for KDStateMachineEditor API Documentation by doxygen 1.9.8