Skip to content

Commit

Permalink
refeator: 抽出definevaluehelper; 修改日志格式
Browse files Browse the repository at this point in the history
  • Loading branch information
s12mmm3 committed Dec 20, 2024
1 parent 06ef1ec commit 77b405d
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 31 deletions.
2 changes: 1 addition & 1 deletion ApiServer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
69 changes: 69 additions & 0 deletions QCloudMusicApi/definevaluehelper.h
Original file line number Diff line number Diff line change
@@ -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
30 changes: 1 addition & 29 deletions QCloudMusicApi/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion Test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 77b405d

Please sign in to comment.