KDStateMachineEditor API Documentation 2.1
Loading...
Searching...
No Matches
element.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: 2014 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 "element.h"
17#include "element_p.h"
18
19#include "elementutil.h"
20#include "state.h"
21
22#include "objecthelper.h"
23#include "layoututils.h"
24
25#include "debug.h"
26#include <QEvent>
27
28using namespace KDSME;
29
30Element::Element(QObject *parent)
31 : QObject(parent)
32 , d(new Private)
33{
34}
35
39
41{
42 return ElementType;
43}
44
45Element::Flags Element::flags() const
46{
47 return d->m_flags;
48}
49
50void Element::setFlags(Element::Flags flags)
51{
52 if (d->m_flags == flags)
53 return;
54 d->m_flags = flags;
55 Q_EMIT flagsChanged(flags);
56}
57
58QString Element::label() const
59{
60 return d->m_label;
61}
62
63void Element::setLabel(const QString &label)
64{
65 if (d->m_label == label)
66 return;
67
68 d->m_label = label;
69 Q_EMIT labelChanged(label);
70}
71
72quintptr Element::internalId() const
73{
74 return d->m_id;
75}
76
77void Element::setInternalId(quintptr id)
78{
79 d->m_id = id;
80}
81
83{
84 return reinterpret_cast<void *>(d->m_id);
85}
86
88{
89 d->m_id = reinterpret_cast<quintptr>(ptr);
90}
91
92QPointF Element::pos() const
93{
94 return d->m_pos;
95}
96
97void Element::setPos(const QPointF &pos) // clazy:exclude=function-args-by-value
98{
99 if (d->m_pos == pos)
100 return;
101
102 d->m_pos = pos;
103 Q_EMIT posChanged(pos);
104}
105
106qreal Element::width() const
107{
108 return d->m_width;
109}
110
111void Element::setWidth(qreal width)
112{
113 if (d->m_width == width)
114 return;
115
116 d->m_width = width;
117 Q_EMIT widthChanged(width);
118}
119
120qreal Element::height() const
121{
122 return d->m_height;
123}
124
125void Element::setHeight(qreal height)
126{
127 if (d->m_height == height)
128 return;
129
130 d->m_height = height;
131 Q_EMIT heightChanged(height);
132}
133
134QPointF Element::absolutePos() const
135{
136 QPointF point;
137 const Element *current = this;
138 do {
139 point += current->pos();
140 current = current->parentElement();
141 } while (current);
142 return point;
143}
144
146{
147 return d->m_visible;
148}
149
150void Element::setVisible(bool visible)
151{
152 if (d->m_visible == visible)
153 return;
154
155 d->m_visible = visible;
156 Q_EMIT visibleChanged(d->m_visible);
157}
158
160{
161 return d->m_selected;
162}
163
164void Element::setSelected(bool selected)
165{
166 if (d->m_selected == selected)
167 return;
168
169 d->m_selected = selected;
170 Q_EMIT selectedChanged(d->m_selected);
171}
172
174{
175 QSizeF size;
176 switch (type()) {
178 size = QSizeF(32, 32);
179 break;
182 break;
184 size = boundingRect().size().expandedTo(LayoutUtils::sizeForLabel(label()));
185 break;
187 size = QSizeF(32, 32);
188 break;
194 break;
195 }
196 return size;
197}
198
200{
201 const QRectF rect(pos().x(), pos().y(), width(), height());
202 return rect;
203}
204
206{
207 return qobject_cast<Element *>(parent());
208}
209
211{
212 setParent(static_cast<QObject *>(parent));
213}
214
215QList<Element *> Element::childElements() const
216{
217 return ObjectHelper::copy_if_type<Element *>(children());
218}
219
221{
223 if (label().isEmpty()) {
224 return str;
225 }
226 return QStringLiteral("%1 [Label: %2]").arg(str).arg(label()); // clazy:exclude=qstring-arg
227}
228
230{
231 return ObjectHelper::enumToString(&staticMetaObject, "Type", type);
232}
233
235{
236 const int value = ObjectHelper::stringToEnum(&staticMetaObject, "Type", type);
237 return static_cast<Element::Type>(value);
238}
239
240void Element::setParent(QObject *object)
241{
242 const auto *oldElementParent = parentElement();
243 const auto newElementParent = qobject_cast<Element *>(object);
244 if (oldElementParent != newElementParent) {
245 Q_EMIT parentChanged(newElementParent);
246 }
247
248 QObject::setParent(object);
249}
250
251#include "moc_element.cpp"
void visibleChanged(bool visible)
bool isSelected() const
Definition element.cpp:159
void heightChanged(qreal height)
void posChanged(const QPointF &pos)
qreal width
Definition element.h:43
void setPos(const QPointF &pos)
Definition element.cpp:97
QPointF absolutePos() const
Definition element.cpp:134
void flagsChanged(KDSME::Element::Flags flags)
QList< Element * > childElements() const
Definition element.cpp:215
void setSelected(bool selected)
Definition element.cpp:164
qreal height
Definition element.h:44
bool selected
Whether this item is marked as selected.
Definition element.h:48
void setLabel(const QString &label)
Definition element.cpp:63
void setVisible(bool visible)
Definition element.cpp:150
bool isVisible() const
Definition element.cpp:145
void * internalPointer() const
Definition element.cpp:82
static Q_INVOKABLE KDSME::Element::Type stringToType(const char *type)
Definition element.cpp:234
static Q_INVOKABLE const char * typeToString(KDSME::Element::Type type)
Definition element.cpp:229
QPointF pos
The position of the element from the top-left corner.
Definition element.h:42
void setParentElement(Element *parent)
Definition element.cpp:210
void setWidth(qreal width)
Definition element.cpp:111
void setParent(QObject *object)
Definition element.cpp:240
void selectedChanged(bool selected)
void setInternalPointer(void *ptr)
Definition element.cpp:87
void parentChanged(KDSME::Element *parent)
bool visible
Whether this item is visible in the scene.
Definition element.h:46
quintptr internalId() const
Definition element.cpp:72
Element(QObject *parent=nullptr)
Definition element.cpp:30
void labelChanged(const QString &label)
void setInternalId(quintptr id)
Definition element.cpp:77
virtual QString toDisplayString() const
Definition element.cpp:220
QSizeF preferredSize() const
Definition element.cpp:173
virtual QRectF boundingRect() const
Definition element.cpp:199
QString label
Definition element.h:40
@ TimeoutTransitionType
Definition element.h:58
@ SignalTransitionType
Definition element.h:57
void widthChanged(qreal width)
void setFlags(Flags flags)
Definition element.cpp:50
Flags flags
Definition element.h:39
KDSME::Element * parent
Definition element.h:37
void setHeight(qreal height)
Definition element.cpp:125
Element * parentElement() const
Definition element.cpp:205
static QSizeF sizeForLabel(const QString &label)
KDSME_CORE_EXPORT QString className(const QObject *object, DisplayOption option=NoStrip)
KDSME_CORE_EXPORT int stringToEnum(const QMetaObject *metaObject, const char *name, const char *key)
KDSME_CORE_EXPORT const char * enumToString(const QMetaObject *metaObject, const char *name, int value)
QList< FilterType > copy_if_type(const QList< ItemType > &list)

© 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