mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
Util. function for class name
This commit is contained in:
committed by
Mat Sutcliffe
parent
5987e58043
commit
c1622951b3
@@ -9,8 +9,9 @@
|
||||
#include "metadatautils.h"
|
||||
|
||||
#include <QMetaType>
|
||||
#include <QTextStream>
|
||||
#include <QMetaObject>
|
||||
#include <QTextStream>
|
||||
#include <QObject>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
@@ -43,6 +44,27 @@ namespace BlackMisc
|
||||
return meta;
|
||||
}
|
||||
|
||||
QString className(const QObject *object)
|
||||
{
|
||||
if (!object) { return "nullptr"; }
|
||||
return object->metaObject()->className();
|
||||
}
|
||||
|
||||
QString classNameShort(const QObject *object)
|
||||
{
|
||||
if (!object) { return "nullptr"; }
|
||||
const QString fn = object->metaObject()->className();
|
||||
if (fn.contains("::"))
|
||||
{
|
||||
const int index = fn.lastIndexOf("::");
|
||||
if (fn.length() > index + 3)
|
||||
{
|
||||
return fn.mid(index + 2);
|
||||
}
|
||||
}
|
||||
return fn;
|
||||
}
|
||||
|
||||
#ifdef Q_CC_MSVC
|
||||
#include <crtdbg.h>
|
||||
|
||||
|
||||
@@ -13,11 +13,12 @@
|
||||
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <QString>
|
||||
#include <stddef.h>
|
||||
|
||||
class QMetaType;
|
||||
class QTextStream;
|
||||
class QObject;
|
||||
struct QMetaObject;
|
||||
|
||||
//! Metadata util functions
|
||||
@@ -36,6 +37,12 @@ namespace BlackMisc
|
||||
//! Real heap size of an object
|
||||
BLACKMISC_EXPORT size_t heapSizeOf(const QMetaObject &objectType);
|
||||
|
||||
//! Class name as from QMetaObject::className with namespace
|
||||
BLACKMISC_EXPORT QString className(const QObject *object);
|
||||
|
||||
//! Class name as from QMetaObject::className without namespace
|
||||
BLACKMISC_EXPORT QString classNameShort(const QObject *object);
|
||||
|
||||
} // ns
|
||||
|
||||
#endif // guard
|
||||
|
||||
Reference in New Issue
Block a user