GammaRay  2.3.0
util.h
Go to the documentation of this file.
1 /*
2  util.h
3 
4  This file is part of GammaRay, the Qt application inspection and
5  manipulation tool.
6 
7  Copyright (C) 2010-2015 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
8  Author: Volker Krause <volker.krause@kdab.com>
9 
10  Licensees holding valid commercial KDAB GammaRay licenses may use this file in
11  accordance with GammaRay Commercial 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  This program is free software; you can redistribute it and/or modify
16  it under the terms of the GNU General Public License as published by
17  the Free Software Foundation, either version 2 of the License, or
18  (at your option) any later version.
19 
20  This program is distributed in the hope that it will be useful,
21  but WITHOUT ANY WARRANTY; without even the implied warranty of
22  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  GNU General Public License for more details.
24 
25  You should have received a copy of the GNU General Public License
26  along with this program. If not, see <http://www.gnu.org/licenses/>.
27 */
39 #ifndef GAMMARAY_UTIL_H
40 #define GAMMARAY_UTIL_H
41 
42 #include "gammaray_core_export.h"
43 
44 #include <QString>
45 #include <QVariant>
46 
47 class QRect;
48 class QPainter;
49 class QObject;
50 
51 namespace GammaRay {
52 
56 namespace Util {
57 
65  GAMMARAY_CORE_EXPORT QString displayString(const QObject *object);
66 
72  GAMMARAY_CORE_EXPORT QString shortDisplayString(const QObject *object);
73 
81  GAMMARAY_CORE_EXPORT QString addressToString(const void *p);
82 
93  GAMMARAY_CORE_EXPORT QString enumToString(const QVariant &value,
94  const char *typeName = 0,
95  const QObject *object = 0);
96 
101  template <typename T>
102  inline QString enumToString(T value, const char *typeName = 0, const QObject *object = 0)
103  {
104  return enumToString(QVariant::fromValue<T>(value), typeName, object);
105  }
106 
111  GAMMARAY_CORE_EXPORT QString prettyMethodSignature(const QMetaMethod &method);
112 
120  GAMMARAY_CORE_EXPORT bool descendantOf(const QObject *ascendant, const QObject *object);
121 
129  template <typename T>
130  T *findParentOfType(QObject *object) {
131  if (!object) {
132  return 0;
133  }
134  if (qobject_cast<T*>(object)) {
135  return qobject_cast<T*>(object);
136  }
137  return findParentOfType<T>(object->parent());
138  }
139 
148  GAMMARAY_CORE_EXPORT QVariant iconForObject(const QObject *object);
149 
154  GAMMARAY_CORE_EXPORT QString tooltipForObject(const QObject *object);
155 
161  GAMMARAY_CORE_EXPORT void drawTransparencyPattern(QPainter *painter, const QRect &rect, int squareSize = 8);
162 
173  GAMMARAY_CORE_EXPORT int signalIndexToMethodIndex(const QMetaObject* metaObject, int signalIndex);
174 }
175 
176 }
177 
178 #endif // GAMMARAY_UTIL_H
QString enumToString(const QVariant &value, const char *typeName=0, const QObject *object=0)
QString shortDisplayString(const QObject *object)
int signalIndexToMethodIndex(const QMetaObject *metaObject, int signalIndex)
QString addressToString(const void *p)
Definition: endpoint.h:41
bool descendantOf(const QObject *ascendant, const QObject *object)
QString displayString(const QObject *object)
QString tooltipForObject(const QObject *object)
T * findParentOfType(QObject *object)
Definition: util.h:130
full QObject instance
Definition: enums.h:39
QString prettyMethodSignature(const QMetaMethod &method)
QVariant iconForObject(const QObject *object)
void drawTransparencyPattern(QPainter *painter, const QRect &rect, int squareSize=8)

Klarälvdalens Datakonsult AB (KDAB)
"The Qt Experts"
http://www.kdab.com/
GammaRay
Qt-application inspection and manipulation tool
http://www.kdab.com/kdab-products/gammaray/