feat: 新增流量波动图窗口,展示活动接口最近 5 分钟网速趋势
- C++ 后端增加 SpeedSample 采样结构与每接口环形缓冲(MAX_HISTORY_SAMPLES=300, 即 5 分钟/1Hz),通过 speedHistoryDownload/speedHistoryUpload 暴露为 QVariantList of QPointF 供 QML 绘制;接口切换/消失时同步清理历史避免泄漏 - 新增 package/components/TrafficChartWindow.qml:纯 QML Canvas 绘制下载/上传 双折线,无外部依赖;支持 hover 辅助线、置顶图钉、空状态兜底 - networkview.qml 右键菜单增加"流量波动图"入口,弹出屏幕居中独立窗口
This commit is contained in:
@@ -11,6 +11,9 @@
|
||||
#include <QTimer>
|
||||
#include <QVariantList>
|
||||
#include <QMap>
|
||||
#include <QHash>
|
||||
#include <QPointF>
|
||||
#include <QDateTime>
|
||||
|
||||
DS_BEGIN_NAMESPACE
|
||||
|
||||
@@ -26,6 +29,15 @@ struct NetworkInterface {
|
||||
qint64 txDropped; // 发送丢弃数
|
||||
};
|
||||
|
||||
// 单个速度采样点:用于趋势图的环形缓冲
|
||||
// timestamp: 自 epoch 的秒级时间戳,作为 X 轴定位
|
||||
// downloadSpeed / uploadSpeed: 当时的瞬时速度(字节/秒),作为两条折线的 Y 值
|
||||
struct SpeedSample {
|
||||
qint64 timestamp;
|
||||
double downloadSpeed;
|
||||
double uploadSpeed;
|
||||
};
|
||||
|
||||
class NetworkMonitorApplet : public DApplet
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -44,6 +56,11 @@ class NetworkMonitorApplet : public DApplet
|
||||
Q_PROPERTY(QString ipv6Address READ ipv6Address NOTIFY ipv6AddressChanged)
|
||||
// 插件版本号,从 dde-shell 元数据读取,版本唯一源为 CMakeLists.txt project(VERSION)
|
||||
Q_PROPERTY(QString version READ version CONSTANT)
|
||||
// 当前活动接口的下行速度历史采样点(QPointF 列表:x=时间戳秒, y=速度 bytes/sec)
|
||||
// 用于趋势图绘制下载折线,每次 calculateSpeed 追加一个点并发射 speedHistoryChanged
|
||||
Q_PROPERTY(QVariantList speedHistoryDownload READ speedHistoryDownload NOTIFY speedHistoryChanged)
|
||||
// 当前活动接口的上行速度历史采样点,结构同 speedHistoryDownload
|
||||
Q_PROPERTY(QVariantList speedHistoryUpload READ speedHistoryUpload NOTIFY speedHistoryChanged)
|
||||
|
||||
public:
|
||||
explicit NetworkMonitorApplet(QObject *parent = nullptr);
|
||||
@@ -62,6 +79,10 @@ public:
|
||||
QString activeInterface() const;
|
||||
QString ipAddress() const;
|
||||
QString ipv6Address() const;
|
||||
// 返回当前活动接口的下行速度历史(QPointF 列表),供 QML 趋势图绘制
|
||||
QVariantList speedHistoryDownload() const;
|
||||
// 返回当前活动接口的上行速度历史(QPointF 列表),供 QML 趋势图绘制
|
||||
QVariantList speedHistoryUpload() const;
|
||||
// 返回插件版本号,从 dde-shell 插件元数据(metadata.json)读取
|
||||
QString version() const;
|
||||
|
||||
@@ -77,6 +98,7 @@ signals:
|
||||
void activeInterfaceChanged();
|
||||
void ipAddressChanged();
|
||||
void ipv6AddressChanged();
|
||||
void speedHistoryChanged();
|
||||
|
||||
private:
|
||||
void readNetworkStats();
|
||||
@@ -109,6 +131,12 @@ private:
|
||||
|
||||
bool m_ready;
|
||||
bool m_firstUpdate;
|
||||
|
||||
// 速度历史环形缓冲:每个接口独立维护一份,key 为接口名
|
||||
// 设计原因:接口切换时趋势图不出现跳变,切回时仍能看到该接口历史
|
||||
QHash<QString, QVector<SpeedSample>> m_speedHistory;
|
||||
// 每个接口最多保留的采样点数:5 分钟 × 60 秒 = 300
|
||||
static constexpr int MAX_HISTORY_SAMPLES = 300;
|
||||
};
|
||||
|
||||
DS_END_NAMESPACE
|
||||
Reference in New Issue
Block a user