// // Created by Krad on 2021/11/19. // #ifndef GUI_USEROPERATIONLOG_H #define GUI_USEROPERATIONLOG_H #include #include #include #define USER_OPERATIONS()\ ADD_OPERATION(Login)\ ADD_OPERATION(Logout)\ ADD_OPERATION(ChangePassword)\ ADD_OPERATION(ChangeUserName)\ ADD_OPERATION(AddPatient)\ ADD_OPERATION(ChangePatientInfo)\ ADD_OPERATION(DeletePatient)\ ADD_OPERATION(SelectPatient)\ ADD_OPERATION(StartRefresh)\ ADD_OPERATION(Stop)\ ADD_OPERATION(StartPreview)\ ADD_OPERATION(StartScan)\ ADD_OPERATION(ConfirmError)\ #define LOG_USER_OPERATION(...)\ UserOperationLog::Default()->log(__VA_ARGS__); enum UserOperation{ #define ADD_OPERATION(name) name,\ USER_OPERATIONS() #undef ADD_OPERATION }; class UserOperationLog { public: UserOperationLog(){} ~UserOperationLog(){ if (logFile.isOpen()) { logFile.flush(); logFile.close(); } } void init(); static UserOperationLog* Default(){ static UserOperationLog d; return &d; } static void cleanHistoryLog(); static QStringList getHistoryLogFiles(); void log(UserOperation operation, bool processing = false); void reloadFile(); QString currentLogFile(){ return currentFileName; } static void loadLogFromFile(QString filePath, QStringList& result); private: QString currentFileName; QFile logFile; QTextStream out; }; #endif //GUI_USEROPERATIONLOG_H