GrabBag/AppUtils/UICommon/Inc/DetectLogHelper.h

112 lines
3.0 KiB
C
Raw Permalink Normal View History

#ifndef DETECTLOGHELPER_H
#define DETECTLOGHELPER_H
#include <QObject>
#include <QListView>
#include <QStringListModel>
#include <QDateTime>
/**
* @brief
*
* QListView
* - "x2", "x3"
* -
* -
* - 线
*
* 使
* 1. mainwindow.h : DetectLogHelper* m_logHelper;
* 2. : m_logHelper = new DetectLogHelper(ui->detect_log, this);
* 3. : m_logHelper->appendLog("消息");
* 4. : m_logHelper->clearLog();
*/
class DetectLogHelper : public QObject
{
Q_OBJECT
public:
/**
* @brief
* @param listView QListView ui->detect_log
* @param parent
*/
explicit DetectLogHelper(QListView* listView, QObject *parent = nullptr);
~DetectLogHelper();
/**
* @brief 线线
* @param message
*/
void appendLog(const QString& message);
/**
* @brief 线线
*/
void clearLog();
/**
* @brief
* @param format "hh:mm:ss"
*/
void setTimestampFormat(const QString& format);
/**
* @brief
* @param show true
*/
void setShowTimestamp(bool show);
/**
* @brief
* @param enable true
*/
void setDeduplicationEnabled(bool enable);
/**
* @brief QStringListModel
* @return QStringListModel
*/
QStringListModel* model() const;
signals:
/**
* @brief 使线
*/
void logUpdateRequested(const QString& message);
/**
* @brief 使线
*/
void logClearRequested();
private slots:
/**
* @brief UI线程中更新日志
*/
void updateLogInUI(const QString& message);
/**
* @brief UI线程中清空日志
*/
void clearLogInUI();
private:
QListView* m_listView;
QStringListModel* m_logModel;
// 日志去重相关
QString m_lastLogMessage; // 最后一条日志消息(不含时间戳)
int m_lastLogCount; // 最后一条日志的重复次数
// 配置项
QString m_timestampFormat; // 时间戳格式
bool m_showTimestamp; // 是否显示时间戳
bool m_deduplicationEnabled; // 是否启用去重
// 初始化信号槽连接
void initConnections();
};
#endif // DETECTLOGHELPER_H