mirror of
https://github.com/clementine-player/Clementine
synced 2025-02-06 06:03:23 +01:00
Add pretty printer for Qt enums.
This commit is contained in:
parent
0212a1fa91
commit
66cc5d432e
@ -35,6 +35,7 @@
|
||||
#include <QXmlStreamReader>
|
||||
#include <QtDebug>
|
||||
#include <QtGlobal>
|
||||
#include <QMetaEnum>
|
||||
|
||||
#if defined(Q_OS_UNIX)
|
||||
# include <sys/statvfs.h>
|
||||
@ -395,6 +396,17 @@ void ConsumeCurrentElement(QXmlStreamReader* reader) {
|
||||
}
|
||||
}
|
||||
|
||||
const char* EnumToString(const QMetaObject& meta, const char* name, int value) {
|
||||
int index = meta.indexOfEnumerator(name);
|
||||
if (index == -1)
|
||||
return "[UnknownEnum]";
|
||||
QMetaEnum metaenum = meta.enumerator(index);
|
||||
const char* result = metaenum.valueToKey(value);
|
||||
if (result == 0)
|
||||
return "[UnknownEnumValue]";
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace Utilities
|
||||
|
||||
|
||||
|
@ -30,6 +30,7 @@
|
||||
class QIODevice;
|
||||
class QMouseEvent;
|
||||
class QXmlStreamReader;
|
||||
class QMetaObject;
|
||||
|
||||
namespace Utilities {
|
||||
QString PrettyTime(int seconds);
|
||||
@ -81,6 +82,11 @@ namespace Utilities {
|
||||
// file - whichever came first.
|
||||
void ConsumeCurrentElement(QXmlStreamReader* reader);
|
||||
|
||||
// Shortcut for getting a Qt-aware enum value as a string.
|
||||
// Pass in the QMetaObject of the class that owns the enum, the string name of
|
||||
// the enum and a valid value from that enum.
|
||||
const char* EnumToString(const QMetaObject& meta, const char* name, int value);
|
||||
|
||||
|
||||
enum ConfigPath {
|
||||
Path_Root,
|
||||
|
Loading…
x
Reference in New Issue
Block a user