| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- #pragma once
- #include <QObject>
- #include <QObject>
- #include <QHash>
- #include <QVariant>
- #include <QMutex>
- #include <QMutexLocker>
- #include <QReadWriteLock>
- #include <mutex>
- #include <QSettings>
- #include "json/json.h"
- #define READ_INI_STR(key, default_value) (settings.contains(key) ? settings.value(key).toString() : default_value)
- #define READ_INI_INT(key, default_value) (settings.contains(key) ? settings.value(key).toInt() : default_value)
- enum SignalDataType
- {
- CourseData = 0,
- HttpLogList = 1,
- };
- typedef struct tag_SaveJsonLog
- {
- std::string m_jsonRequest; //记录发送的json
- std::string m_jsonResponse; //记录返回的json
- bool m_bStatus;
- std::string m_nAPIID;
- bool m_serverData;
- tag_SaveJsonLog(std::string strRequest, std::string strResponse, std::string nAPIID, bool bStatus,bool bserverData=false)
- {
- m_jsonRequest = strRequest;
- m_jsonResponse = strResponse;
- m_nAPIID = nAPIID;
- m_bStatus = bStatus;
- m_serverData =bserverData;
- }
- }LogJson;
- class DataManager : public QObject
- {
- Q_OBJECT
- public:
- // 获取单例实例
- static DataManager& instance();
- // 清空所有数据
- static void destroyInstance();
- //公用操作函数
- //utf8与string互相转换
- static std::string string_To_UTF8(const std::string& str);
- static std::string UTF8_to_string(const std::string& str);
-
- //json格式化
- static bool JsonToStyled(const std::string& str, std::string& strRetrun);
- static bool JsonToStyled(Json::Value& jValue, std::string& strRetrun);
- //HTTP日志
- void AddHttpLog(LogJson& pNewLog);
- //清空HTTP日志
- void ClearHttpLog();
- QList<LogJson>* GetLogJson() {
- return &m_vectorLogJson;
- };
- void InitTestFileData();
- QString getTestFileData(){return strAllDataFile;};
- signals:
- // 数据改变信号
- void dataChanged(const int key);
- private:
- explicit DataManager(QObject* parent = nullptr);
- ~DataManager() = default;
- // 禁止拷贝和赋值
- DataManager(const DataManager&) = delete;
- DataManager& operator=(const DataManager&) = delete;
- static DataManager* g_GlobalSingle;
- static std::mutex m_Mutex;
- // 数据存储
- QList<LogJson> m_vectorLogJson;
- // 读写锁,保证线程安全
- mutable QReadWriteLock m_lock;
- QString strAllDataFile;
- };
|