refactor: 删除interfaceStats死代码
删除未使用的 Q_PROPERTY interfaceStats、interfaceStats() 实现、 statsChanged 信号、QML 属性绑定。#14 随之解决(interfaceStats 整体删除,不再有不完整输出)。
This commit is contained in:
@@ -59,14 +59,16 @@
|
||||
~~`networkview.qml` 和 `NetworkPopup.qml` 中重复颜色定义、`isPhysicalIf`、`formatSpeed`、`formatTotal` 等,`formatSpeed` 还在 `TrafficChartWindow.qml` 中第三份拷贝。~~
|
||||
已新建 `package/components/NetCommon.qml` 聚合所有公共颜色与函数。3 个文件删除重复定义改为引用 `common.xxx`,净删除 91 行重复代码。`downloadValueColor` 由属性绑定改为函数(调用方传速度值)。
|
||||
|
||||
**12. 死代码:`interfaceStats` 属性未被使用**
|
||||
`networkview.qml:43` 绑定了 `interfaceStats` 属性,但从未在任何 UI 中读取。C++ 侧的 `interfaceStats()` 函数和 `Q_PROPERTY` 也是死代码。且其 `QStringList` 用 `|` 分隔符编码结构化数据的方式本身也很脆弱。
|
||||
**12. ~~死代码:`interfaceStats` 属性未被使用~~ ✅ 已修复**
|
||||
~~`networkview.qml` 绑定了 `interfaceStats` 属性但从未读取,C++ 侧的 `interfaceStats()` 函数和 `Q_PROPERTY` 也是死代码。~~
|
||||
已删除 `Q_PROPERTY`、`interfaceStats()` 实现、`statsChanged` 信号、QML 属性绑定。
|
||||
|
||||
**13. 死代码:`refresh()` Q_INVOKABLE 从未被 QML 调用**
|
||||
注释(networkview.qml:276)说明此前 QML 调 `applet.refresh()` 导致问题后已移除调用,但 C++ 侧的 `Q_INVOKABLE void refresh()` 仍保留。若确无外部调用方,可删除或标注保留原因。
|
||||
|
||||
**14. `interfaceStats` 暴露的数据不完整**
|
||||
`NetworkInterface` 结构体解析了 `rxErrors`/`txErrors`/`rxDropped`/`txDropped`,但 `interfaceStats()` 输出时丢弃了这些字段。若未来要展示丢包/错误率,需补全。
|
||||
**14. ~~`interfaceStats` 暴露的数据不完整~~ ✅ 随 #12 一并解决**
|
||||
~~`NetworkInterface` 结构体解析了 `rxErrors`/`txErrors`/`rxDropped`/`txDropped`,但 `interfaceStats()` 输出时丢弃了这些字段。~~
|
||||
`interfaceStats()` 已随 #12 整体删除,不再有不完整的输出。结构体字段保留供未来使用。
|
||||
|
||||
**15. README.md 和 AGENTS.md 严重过时**
|
||||
- 项目结构只列 `AboutWindow.qml`,实际有 5 个组件(缺 `NetworkPopup`、`SettingsWindow`、`TextColorPicker`、`TrafficChartWindow`)
|
||||
|
||||
@@ -40,7 +40,6 @@ AppletItem {
|
||||
// 活动接口的 IPv6 全球地址,由 C++ 后端 detectIpAddress 持续更新
|
||||
readonly property string ipv6Address: applet ? (applet.ipv6Address || "") : ""
|
||||
readonly property var networkInterfaces: applet ? (applet.networkInterfaces || []) : []
|
||||
readonly property var interfaceStats: applet ? (applet.interfaceStats || []) : []
|
||||
|
||||
// 公共颜色与格式化函数:集中定义于 components/NetCommon.qml(随 import "components" 引入),
|
||||
// 与 NetworkPopup、TrafficChartWindow 共享同一份实现,消除跨组件重复定义
|
||||
|
||||
@@ -103,23 +103,6 @@ QStringList NetworkMonitorApplet::networkInterfaces() const
|
||||
return m_interfaceList;
|
||||
}
|
||||
|
||||
QStringList NetworkMonitorApplet::interfaceStats() const
|
||||
{
|
||||
QStringList stats;
|
||||
for (const QString &name : m_interfaceList) {
|
||||
if (m_interfaces.contains(name)) {
|
||||
const NetworkInterface &iface = m_interfaces[name];
|
||||
stats << QString("%1|%2|%3|%4|%5")
|
||||
.arg(iface.name)
|
||||
.arg(iface.rxBytes)
|
||||
.arg(iface.txBytes)
|
||||
.arg(iface.rxPackets)
|
||||
.arg(iface.txPackets);
|
||||
}
|
||||
}
|
||||
return stats;
|
||||
}
|
||||
|
||||
bool NetworkMonitorApplet::ready() const
|
||||
{
|
||||
return m_ready;
|
||||
@@ -360,7 +343,6 @@ void NetworkMonitorApplet::readNetworkStats()
|
||||
}
|
||||
|
||||
calculateSpeed();
|
||||
emit statsChanged();
|
||||
// 每次刷新都检测 IP,以应对 DHCP 续约等 IP 变更场景
|
||||
detectIpAddress();
|
||||
}
|
||||
|
||||
@@ -49,7 +49,6 @@ class NetworkMonitorApplet : public DApplet
|
||||
Q_PROPERTY(double totalDownload READ totalDownload NOTIFY totalChanged)
|
||||
Q_PROPERTY(double totalUpload READ totalUpload NOTIFY totalChanged)
|
||||
Q_PROPERTY(QStringList networkInterfaces READ networkInterfaces NOTIFY interfacesChanged)
|
||||
Q_PROPERTY(QStringList interfaceStats READ interfaceStats NOTIFY statsChanged)
|
||||
Q_PROPERTY(bool ready READ ready NOTIFY readyChanged)
|
||||
// 当前活动接口,用户在弹窗或设置窗口选择后持久化到 ~/.config/jnetapplet/settings.ini,
|
||||
// 下次启动自动恢复;若保存的接口已不存在则回退到自动选择
|
||||
@@ -81,7 +80,6 @@ public:
|
||||
double totalDownload() const;
|
||||
double totalUpload() const;
|
||||
QStringList networkInterfaces() const;
|
||||
QStringList interfaceStats() const;
|
||||
bool ready() const;
|
||||
QString activeInterface() const;
|
||||
QString ipAddress() const;
|
||||
@@ -104,7 +102,6 @@ signals:
|
||||
void speedChanged();
|
||||
void totalChanged();
|
||||
void interfacesChanged();
|
||||
void statsChanged();
|
||||
void readyChanged();
|
||||
void activeInterfaceChanged();
|
||||
void ipAddressChanged();
|
||||
|
||||
Reference in New Issue
Block a user