Skip to content

Commit

Permalink
Merge branch 'master' into feat/cross-platform
Browse files Browse the repository at this point in the history
  • Loading branch information
Candinya committed May 20, 2024
2 parents 4944416 + f7dfe7b commit 7dec489
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 18 deletions.
27 changes: 21 additions & 6 deletions configs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Configs::Configs()
QSettings settings;

// 初始化配置
logLevel = settings.value("LogLevel", 2).toInt(); // 回报 Warn 和 Critical 的日志
logLevel = settings.value("LogLevel", ConfigLogLevelWarning).toInt(); // 回报 Warn 和 Critical 的日志

settings.beginGroup("Trace");
traceMaxHops = settings.value("MaxHops", 30).toInt(); // 最大发出 30 跳路由追踪
Expand All @@ -23,6 +23,10 @@ Configs::Configs()
autoOpenMap = settings.value("OpenMap", true).toBool(); // 解析或追踪时自动打开地图
autoStartTrace = settings.value("StartTrace", false).toBool(); // 解析完成后自动开始追踪
settings.endGroup();

settings.beginGroup("Resolve");
resolveDoubleClickAction = settings.value("DoubleClickAction", ConfigResolveDoubleClickActionStartTrace).toInt();
settings.endGroup();
}

void Configs::Save() {
Expand All @@ -48,18 +52,18 @@ void Configs::Save() {
settings.setValue("OpenMap", autoOpenMap );
settings.setValue("StartTrace", autoStartTrace);
settings.endGroup();

settings.beginGroup("Resolve");
settings.setValue("DoubleClickAction", resolveDoubleClickAction);
settings.endGroup();
}

int Configs::GetLogLevel() {
return logLevel;
}

void Configs::SetLogLevel(int newLogLevel) {
// Debug 0
// Info 1
// Warn 2
// Critical 3
if (0 <= newLogLevel && newLogLevel <= 3) {
if (ConfigLogLevelDebug <= newLogLevel && newLogLevel <= ConfigLogLevelCritical) {
// 有效的
logLevel = newLogLevel;
} // 否则是无效的
Expand Down Expand Up @@ -113,5 +117,16 @@ void Configs::SetAutoStartTrace(bool newAutoStartTrace) {
autoStartTrace = newAutoStartTrace;
}

int Configs::GetResolveDoubleClickAction() {
return resolveDoubleClickAction;
}

void Configs::SetResolveDoubleClickAction(int newResolveDoubleClickAction) {
if (ConfigResolveDoubleClickActionStartTrace <= resolveDoubleClickAction && resolveDoubleClickAction <= ConfigResolveDoubleClickActionOpenMap) {
// 有效的
resolveDoubleClickAction = newResolveDoubleClickAction;
} // 否则是无效的
}


Configs * gCfg;
22 changes: 20 additions & 2 deletions configs.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,30 @@ const int DEF_TRACE_MAX_HOPs = 100; // trace 最大跳站
const unsigned long DEF_TRACE_TIMEOUT_MAX = 10000; // trace 最大超时时间
const unsigned long DEF_TRACE_THREAD_INTERVAL_MAX = 3000; // 每个线程的最大启动延迟

// 一些预定义的枚举
enum ConfigLogLevel {
ConfigLogLevelDebug,
ConfigLogLevelInfo,
ConfigLogLevelWarning,
ConfigLogLevelCritical
};
enum ConfigResolveDoubleClickAction {
ConfigResolveDoubleClickActionStartTrace,
ConfigResolveDoubleClickActionOpenMap
};


class Configs
{
public:
Configs();

void Save();

int GetLogLevel();
int GetLogLevel();
void SetLogLevel(int);

int GetTraceMaxHops();
int GetTraceMaxHops();
void SetTraceMaxHops(int);

unsigned long GetTraceTimeout();
Expand All @@ -33,6 +46,9 @@ class Configs
bool GetAutoStartTrace();
void SetAutoStartTrace(bool);

int GetResolveDoubleClickAction();
void SetResolveDoubleClickAction(int);

private:
int logLevel;

Expand All @@ -43,6 +59,8 @@ class Configs
bool autoOpenMap;
bool autoStartTrace;

int resolveDoubleClickAction;

};

extern Configs * gCfg;
Expand Down
8 changes: 4 additions & 4 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ void customMessageHandler(QtMsgType type, const QMessageLogContext &context, con
switch (type) {
case QtDebugMsg:
level = QString("Debug");
printToLogsTable = gCfg->GetLogLevel() <= 0;
printToLogsTable = gCfg->GetLogLevel() <= ConfigLogLevelDebug;
break;
case QtInfoMsg:
level = QString("Info");
printToLogsTable = gCfg->GetLogLevel() <= 1;
printToLogsTable = gCfg->GetLogLevel() <= ConfigLogLevelInfo;
break;
case QtWarningMsg:
level = QString("Warning");
printToLogsTable = gCfg->GetLogLevel() <= 2;
printToLogsTable = gCfg->GetLogLevel() <= ConfigLogLevelWarning;
break;
case QtCriticalMsg:
level = QString("Critical");
printToLogsTable = gCfg->GetLogLevel() <= 3;
printToLogsTable = gCfg->GetLogLevel() <= ConfigLogLevelCritical;
break;
case QtFatalMsg:
// 特殊处理: Fatal 是完全无法恢复、需要立刻停止级别的错误,所以不应该进入正常处理流程,而应该尽快结束程序。
Expand Down
18 changes: 14 additions & 4 deletions nyatrace_configs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,24 @@ void NyaTraceConfigs::initializeCurrentValue() {
ui->spinTraceThreadInterval->setValue( gCfg->GetTraceThreadInterval());
ui->checkAutoOpenMap->setChecked( gCfg->GetAutoOpenMap() );
ui->checkAutoStartTrace->setChecked( gCfg->GetAutoStartTrace() );
ui->radioResolveDoubleClickActionStartTrace->setChecked(gCfg->GetResolveDoubleClickAction() == ConfigResolveDoubleClickActionStartTrace);
ui->radioResolveDoubleClickActionOpenMap->setChecked( gCfg->GetResolveDoubleClickAction() == ConfigResolveDoubleClickActionOpenMap );
}

void NyaTraceConfigs::setLogLevelValue(int logLevel) {
// 根据日志等级映射
QString targetLogLevel;
switch(logLevel) {
case 0:
case ConfigLogLevelDebug:
targetLogLevel = "Debug";
break;
case 1:
case ConfigLogLevelInfo:
targetLogLevel = "Info";
break;
case 2:
case ConfigLogLevelWarning:
targetLogLevel = "Warning";
break;
case 3:
case ConfigLogLevelCritical:
targetLogLevel = "Critical";
break;
default:
Expand Down Expand Up @@ -104,6 +106,13 @@ void NyaTraceConfigs::Apply() {
unsigned long newTraceThreadInterval = ui->spinTraceThreadInterval->value();
bool newAutoOpenMap = ui->checkAutoOpenMap->isChecked();
bool newAutoStartTrace = ui->checkAutoStartTrace->isChecked();
int newResolveDoubleClickAction = ConfigResolveDoubleClickActionStartTrace;

if (ui->radioResolveDoubleClickActionStartTrace->isChecked()) {
newResolveDoubleClickAction = ConfigResolveDoubleClickActionStartTrace;
} else if (ui->radioResolveDoubleClickActionOpenMap->isChecked()) {
newResolveDoubleClickAction = ConfigResolveDoubleClickActionOpenMap;
}

// 应用设置
qDebug() << "[GUI Configs]"
Expand All @@ -122,6 +131,7 @@ void NyaTraceConfigs::Apply() {
gCfg->SetTraceThreadInterval(newTraceThreadInterval);
gCfg->SetAutoOpenMap( newAutoOpenMap );
gCfg->SetAutoStartTrace( newAutoStartTrace );
gCfg->SetResolveDoubleClickAction(newResolveDoubleClickAction);
}

void NyaTraceConfigs::on_btnApply_clicked()
Expand Down
61 changes: 60 additions & 1 deletion nyatrace_configs.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>400</width>
<height>320</height>
<height>400</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -105,6 +105,65 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupResolve">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>解析</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<layout class="QHBoxLayout" name="layoutResolveDoubleClickAction">
<item>
<widget class="QLabel" name="labelDoubleClickAction">
<property name="text">
<string>双击解析记录的动作</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0,1">
<property name="spacing">
<number>6</number>
</property>
<item>
<widget class="QRadioButton" name="radioResolveDoubleClickActionStartTrace">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>开始追踪</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioResolveDoubleClickActionOpenMap">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>打开地图</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupTrace">
<property name="sizePolicy">
Expand Down
9 changes: 8 additions & 1 deletion nyatrace_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,14 @@ void NyaTraceGUI::on_resolveTable_doubleClicked(const QModelIndex &index)
// 不需要再指定 index ,因为在单击的时候已经确定好了是哪一个
Q_UNUSED(index);

StartTracing();
switch (gCfg->GetResolveDoubleClickAction()) {
case ConfigResolveDoubleClickActionStartTrace:
StartTracing();
break;
case ConfigResolveDoubleClickActionOpenMap:
OpenMap();
break;
}
}


Expand Down

0 comments on commit 7dec489

Please sign in to comment.