diff --git a/ApiServer/main.cpp b/ApiServer/main.cpp index 0f35afa..ae351e2 100644 --- a/ApiServer/main.cpp +++ b/ApiServer/main.cpp @@ -21,7 +21,7 @@ void start() { int main(int argc, char* argv[]) { - qSetMessagePattern("%{time yyyy-MM-dd hh:mm:ss.zzz} : %{pid} : %{category} : %{type} : %{line} : %{function} : %{message}"); + qSetMessagePattern("%{time yyyy-MM-dd hh:mm:ss.zzz} : %{threadid} : %{category} : %{type} : %{line} : %{function} : %{message}"); QLoggingCategory::setFilterRules("QCloudMusicApi.debug=false"); QCoreApplication a(argc, argv); start(); diff --git a/QCloudMusicApi/definevaluehelper.h b/QCloudMusicApi/definevaluehelper.h new file mode 100644 index 0000000..bc0083c --- /dev/null +++ b/QCloudMusicApi/definevaluehelper.h @@ -0,0 +1,69 @@ +#ifndef DEFINEVALUEHELPER_H +#define DEFINEVALUEHELPER_H + +#define READ_NAME(valueName) valueName + +#define WRITE_NAME(valueName) \ + set_##valueName + +#define INIT_NAME(valueName) \ + init_##valueName + +#define NOTIFY_NAME(valueName) \ + valueName##Changed + +#define DEFINE_VALUE(type, valueName, defaultValue) \ +Q_PROPERTY(type valueName READ READ_NAME(valueName) WRITE WRITE_NAME(valueName) NOTIFY NOTIFY_NAME(valueName)) \ +public: \ + type READ_NAME(valueName)() const { return m_##valueName; } \ + void WRITE_NAME(valueName)(type valueName) { \ + if(valueName == m_##valueName) { \ + return; \ + } \ + m_##valueName = valueName; \ + emit NOTIFY_NAME(valueName)(); \ + } \ +Q_SIGNALS: \ + void NOTIFY_NAME(valueName)(); \ +private: \ + type m_##valueName = defaultValue; + + +#define DEFINE_VALUEADD(type, valueName, defaultValue) \ +Q_PROPERTY(type valueName READ READ_NAME(valueName) WRITE WRITE_NAME(valueName) NOTIFY NOTIFY_NAME(valueName)) \ +public: \ + type READ_NAME(valueName)() const { return m_##valueName; } \ + void WRITE_NAME(valueName)(type valueName) { \ + if(valueName == 0) { \ + return; \ + } \ + m_##valueName += valueName; \ + emit NOTIFY_NAME(valueName)(); \ + }; \ + void INIT_NAME(valueName)(type valueName){ \ + if(valueName == m_##valueName) { \ + return; \ + } \ + m_##valueName = valueName;\ + emit NOTIFY_NAME(valueName)(); \ + };\ +Q_SIGNALS: \ + void NOTIFY_NAME(valueName)(); \ +private: \ + type m_##valueName = defaultValue; + + +#define DEFINE_VALUE_FORCE(type, valueName, defaultValue) \ +Q_PROPERTY(type valueName READ READ_NAME(valueName) WRITE WRITE_NAME(valueName) NOTIFY NOTIFY_NAME(valueName)) \ +public: \ + type READ_NAME(valueName)() const { return m_##valueName; } \ + void WRITE_NAME(valueName)(type valueName) { \ + m_##valueName = valueName; \ + emit NOTIFY_NAME(valueName)(); \ + } \ +Q_SIGNALS: \ + void NOTIFY_NAME(valueName)(); \ +private: \ + type m_##valueName = defaultValue; + +#endif // DEFINEVALUEHELPER_H diff --git a/QCloudMusicApi/global.h b/QCloudMusicApi/global.h index f8363ee..9396d54 100644 --- a/QCloudMusicApi/global.h +++ b/QCloudMusicApi/global.h @@ -20,34 +20,6 @@ # define QCLOUDMUSICAPI_EXPORT #endif - -//读函数名 -#define READ_NAME(valueName) valueName - -//写函数名 -#define WRITE_NAME(valueName) \ -set_##valueName - -//变化函数名 -#define NOTIFY_NAME(valueName) \ - valueName##Changed - -//定义变量 -#define DEFINE_VALUE(type, valueName, defaultValue) \ - Q_PROPERTY(type valueName READ READ_NAME(valueName) WRITE WRITE_NAME(valueName) NOTIFY NOTIFY_NAME(valueName)) \ - public: \ - type READ_NAME(valueName)() const { return m_##valueName; } \ - void WRITE_NAME(valueName)(type valueName) { \ - if(valueName == m_##valueName) { \ - return; \ - } \ - m_##valueName = valueName; \ - emit NOTIFY_NAME(valueName)(); \ -} \ - Q_SIGNALS: \ - void NOTIFY_NAME(valueName)(); \ - private: \ - type m_##valueName = defaultValue; \ - public: \ +#include "definevaluehelper.h" #endif // GLOBAL_H diff --git a/Test/main.cpp b/Test/main.cpp index ee212fd..0296bfa 100644 --- a/Test/main.cpp +++ b/Test/main.cpp @@ -6,7 +6,7 @@ int main(int argc, char *argv[]) { - qSetMessagePattern("%{time yyyy-MM-dd hh:mm:ss.zzz} : %{pid} : %{category} : %{type} : %{line} : %{function} : %{message}"); + qSetMessagePattern("%{time yyyy-MM-dd hh:mm:ss.zzz} : %{threadid} : %{category} : %{type} : %{line} : %{function} : %{message}"); ServiceLocator::init(); QApplication a(argc, argv);