KDStateMachineEditor API Documentation 2.1
Loading...
Searching...
No Matches
objecthelper.h
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#ifndef KDSME_UTIL_OBJECTHELPER_H
17#define KDSME_UTIL_OBJECTHELPER_H
18
19#include "kdsme_core_export.h"
20
21#include <QObject>
22#include <QMetaEnum>
23#include <QList>
24
25#include <algorithm>
26
27QT_BEGIN_NAMESPACE
28class QPointF;
29QT_END_NAMESPACE
30
31namespace KDSME {
32
33namespace ObjectHelper {
34
36
44
45KDSME_CORE_EXPORT const char *enumToString(const QMetaObject *metaObject, const char *name, int value);
46KDSME_CORE_EXPORT int stringToEnum(const QMetaObject *metaObject, const char *name, const char *key);
47
51
59KDSME_CORE_EXPORT bool descendantOf(const QObject *ascendant, const QObject *object);
60
66KDSME_CORE_EXPORT int depth(const QObject *root, const QObject *object);
67
73template<class FilterType, class ItemType>
83
89template<class C, class P>
90C filter(const C &source, const P &predicate)
91{
92 C d = source;
93 // filter elements
94 d.erase(std::remove_if(std::begin(d), std::end(d), predicate), std::end(d));
95 return d;
96}
97
105template<typename T>
106T *findParentOfType(QObject *object)
107{
108 if (!object) {
109 return nullptr;
110 }
111 if (qobject_cast<T *>(object)) {
112 return static_cast<T *>(object);
113 }
114 return findParentOfType<T>(object->parent());
115}
116
117}
118
119}
120
121#endif
KDSME_CORE_EXPORT QString toString(const QPointF &point)
KDSME_CORE_EXPORT QString displayString(const QObject *object, DisplayOption option=NoStrip)
KDSME_CORE_EXPORT int depth(const QObject *root, const QObject *object)
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)
C filter(const C &source, const P &predicate)
KDSME_CORE_EXPORT bool descendantOf(const QObject *ascendant, const QObject *object)
T * findParentOfType(QObject *object)
KDSME_CORE_EXPORT QString addressToString(const void *p)
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