TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
ttksuperenum.cpp
Go to the documentation of this file.
1 #include "ttksuperenum.h"
2 
3 #include <QStringList>
4 
5 TTKSuperEnum::TTKSuperEnum(const QString &value)
6  : m_enumValue()
7 {
8  int enumValue = 0;
9  const QStringList &enums = value.split(',');
10 
11  for(QString data : qAsConst(enums))
12  {
13  const int pos = data.indexOf('=');
14  if(pos != TTKSuperEnum::Null)
15  {
16  enumValue = data.right(data.length() - pos - 1).trimmed().toInt();
17  data = data.left(pos);
18  }
19 
20  m_enumValue[enumValue] = data.trimmed();
21  enumValue++;
22  }
23 }
24 
25 QString TTKSuperEnum::keyToString(int value) const
26 {
27  if(TTKSuperEnum::Null == value)
28  {
29  return "Null";
30  }
31 
32  const auto &it = m_enumValue.find(value);
33  return it != m_enumValue.end() ? it->second : "Invalid";
34 }
35 
36 int TTKSuperEnum::stringToKey(const QString &name) const
37 {
38  if("Null" == name)
39  {
40  return TTKSuperEnum::Null;
41  }
42 
43  for(auto &&item : qAsConst(m_enumValue))
44  {
45  if(item.second == name)
46  {
47  return item.first;
48  }
49  }
50  return TTKSuperEnum::Null;
51 }
static constexpr int Null
Definition: ttksuperenum.h:31
QString keyToString(int value) const
#define qAsConst
Definition: ttkqtglobal.h:53
const char * name
Definition: http_parser.c:458
TTKSuperEnum(const QString &value)
Definition: ttksuperenum.cpp:5
std::unordered_map< int, QString > m_enumValue
Definition: ttksuperenum.h:49
int stringToKey(const QString &name) const