mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-20 20:40:29 +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 "metadatautils.h"
|
||||||
|
|
||||||
#include <QMetaType>
|
#include <QMetaType>
|
||||||
#include <QTextStream>
|
|
||||||
#include <QMetaObject>
|
#include <QMetaObject>
|
||||||
|
#include <QTextStream>
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
{
|
{
|
||||||
@@ -43,6 +44,27 @@ namespace BlackMisc
|
|||||||
return meta;
|
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
|
#ifdef Q_CC_MSVC
|
||||||
#include <crtdbg.h>
|
#include <crtdbg.h>
|
||||||
|
|
||||||
|
|||||||
@@ -13,11 +13,12 @@
|
|||||||
|
|
||||||
#include "blackmisc/blackmiscexport.h"
|
#include "blackmisc/blackmiscexport.h"
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
class QMetaType;
|
class QMetaType;
|
||||||
class QTextStream;
|
class QTextStream;
|
||||||
|
class QObject;
|
||||||
struct QMetaObject;
|
struct QMetaObject;
|
||||||
|
|
||||||
//! Metadata util functions
|
//! Metadata util functions
|
||||||
@@ -36,6 +37,12 @@ namespace BlackMisc
|
|||||||
//! Real heap size of an object
|
//! Real heap size of an object
|
||||||
BLACKMISC_EXPORT size_t heapSizeOf(const QMetaObject &objectType);
|
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
|
} // ns
|
||||||
|
|
||||||
#endif // guard
|
#endif // guard
|
||||||
|
|||||||
Reference in New Issue
Block a user