chore: 格式化ElaWidgetTools代码

This commit is contained in:
sleepwithoutbz
2025-09-20 01:39:00 +08:00
parent d2fded145d
commit 4ab391f8a1
394 changed files with 10913 additions and 15860 deletions

View File

@@ -5,69 +5,53 @@
#include <QFile>
#include <QMutex>
#ifndef QT_NO_DEBUG
#include <iostream>
#include <iostream>
#endif
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <QTextStream>
#include <QTextStream>
#endif
#include "ElaLog.h"
Q_GLOBAL_STATIC(QMutex, messageLogMutex)
Q_GLOBAL_STATIC(QString, logFileNameTime)
ElaLogPrivate::ElaLogPrivate(QObject* parent)
: QObject{parent}
{
}
ElaLogPrivate::ElaLogPrivate(QObject *parent) : QObject{parent} {}
ElaLogPrivate::~ElaLogPrivate()
{
}
ElaLogPrivate::~ElaLogPrivate() {}
void ElaLogPrivate::_messageLogHander(QtMsgType type, const QMessageLogContext& ctx, const QString& msg)
{
if (type > QtCriticalMsg)
{
void ElaLogPrivate::_messageLogHander(QtMsgType type, const QMessageLogContext &ctx, const QString &msg) {
if (type > QtCriticalMsg) {
return;
}
QString logInfo;
QString logTime = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
switch (type)
{
case QtDebugMsg:
{
switch (type) {
case QtDebugMsg: {
logInfo = QString("[信息-%1](函数: %2 , 行数: %3) -> %4").arg(logTime, ctx.function, QString::number(ctx.line), msg);
break;
}
case QtWarningMsg:
{
case QtWarningMsg: {
logInfo = QString("[警告-%1](函数: %2 , 行数: %3) -> %4").arg(logTime, ctx.function, QString::number(ctx.line), msg);
break;
}
case QtCriticalMsg:
{
case QtCriticalMsg: {
logInfo = QString("[错误-%1](函数: %2 , 行数: %3) -> %4").arg(logTime, ctx.function, QString::number(ctx.line), msg);
break;
}
default:
{
default: {
qCritical("发生致命错误!");
break;
}
}
qDebug() << logInfo;
ElaLog* log = ElaLog::getInstance();
ElaLog *log = ElaLog::getInstance();
Q_EMIT log->logMessage(logInfo);
messageLogMutex->lock();
QFile logfile;
if (log->getIsLogFileNameWithTime())
{
if (log->getIsLogFileNameWithTime()) {
logfile.setFileName(log->getLogSavePath() + "\\" + log->getLogFileName() + *logFileNameTime + ".txt");
}
else
{
} else {
logfile.setFileName(log->getLogSavePath() + "\\" + log->getLogFileName() + ".txt");
}
if (logfile.open(QIODevice::WriteOnly | QIODevice::Append))
{
if (logfile.open(QIODevice::WriteOnly | QIODevice::Append)) {
QTextStream logFileStream(&logfile);
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
logFileStream << logInfo << Qt::endl;
@@ -79,23 +63,17 @@ void ElaLogPrivate::_messageLogHander(QtMsgType type, const QMessageLogContext&
messageLogMutex->unlock();
}
void ElaLogPrivate::_clearLogFile()
{
if (_pIsLogFileNameWithTime)
{
void ElaLogPrivate::_clearLogFile() {
if (_pIsLogFileNameWithTime) {
QString logTime = QDateTime::currentDateTime().toString("yyyy-MM-dd hh-mm-ss");
logTime.prepend("_");
logTime.replace(" ", "_");
logFileNameTime->clear();
logFileNameTime->append(logTime);
}
else
{
} else {
QFile file(_pLogSavePath + "\\" + _pLogFileName + ".txt");
if (file.exists())
{
if (file.open(QIODevice::WriteOnly | QIODevice::Text | QFile::Truncate))
{
if (file.exists()) {
if (file.open(QIODevice::WriteOnly | QIODevice::Text | QFile::Truncate)) {
file.close();
}
}