📄 enum.h
字号:
#ifndef OOENUM_H#define OOENUM_H#include "myexport.h"#include <QStringList>#include <QTextStream>#include <QMap>typedef QMap<QString, int> NameMap;//start/** @short An object-oriented enumerator class which uses strings instead of compiler symbols, and provides bidirectional mapping between QStrings and int values. No compiler symbols are introduced. */class UTILS_EXPORT Enum {public: Enum(int enumval = 0); virtual ~Enum(); /** Converts from the int value to a String */ virtual QString toString() const; /** Converts from a string to the internal enum value. returns false if an invalid string is passed in. */ virtual bool fromString(QString str) =0; virtual operator int() const ; bool operator=(int other); bool operator=(QString other); bool operator==(const Enum& other) const { return m_Val == other.m_Val; } virtual QStringList names() const = 0;protected: //end /** Adds symbols to the map with enum values starting at 0 @param nameMap - the map containing strings to numbers @param nameList - a string list of names to add to the map @param initialized - if true, do nothing (to avoid repeat-redundant calls - if false, set to true after initializing. */ static NameMap& initMap(NameMap& nameMap, QStringList nameList, bool & initialized, int startIndex = 0); //start int m_Val;};/* optional */QTextStream& operator<<(QTextStream& ts, const Enum& pref);//end#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -