-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refeator: 抽出definevaluehelper; 修改日志格式
- Loading branch information
Showing
4 changed files
with
72 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters