Skip to content

Commit 6c51615

Browse files
committed
feat: improve PageMultiInfo CPU header info display and device generation
- Update PageMultiInfo to use scroll area container layout for CPU header detail widgets - Add/adjust accessor usage for header info in CPU page - Refactor scroll area content resizing and visibility behavior - Update DeviceGenerator logic and declarations (internal feature updates) - Keep UI behavior consistent with latest header info widget layout Log: add feature for cpu info show. Task: https://pms.uniontech.com/task-view-387697.html
1 parent 8f355a2 commit 6c51615

4 files changed

Lines changed: 146 additions & 16 deletions

File tree

deepin-devicemanager/src/GenerateDevice/DeviceGenerator.cpp

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: GPL-3.0-or-later
44

@@ -204,6 +204,10 @@ void DeviceGenerator::generatorCpuDevice()
204204
device->setCpuInfo(*it, lshw, dmidecode, coreNum, logicalNum);
205205
DeviceManager::instance()->addCpuDevice(device);
206206
}
207+
208+
// 计算并设置CPU头部信息(当前没有多个物理CPU的环境,所以只能编码单物理CPU的逻辑)
209+
if (lsCpu.size() > 0)
210+
calAndSetCpuHeaderInfo(lsCpu.at(0), coreNum, logicalNum);
207211
}
208212

209213
void DeviceGenerator::generatorBiosDevice()
@@ -1256,6 +1260,67 @@ QString DeviceGenerator::uniqueID(const QMap<QString, QString> &mapInfo)
12561260
return "";
12571261
}
12581262

1263+
void DeviceGenerator::calAndSetCpuHeaderInfo(const QMap<QString, QString> &firstProcessorInfo,
1264+
int coreNum, int logicalNum)
1265+
{
1266+
QList<QList<QPair<QString, QString>>> cpuHeaderInfo;
1267+
QList<QPair<QString, QString>> singleCpuHeaderInfo;
1268+
1269+
if (firstProcessorInfo.contains("model name")) {
1270+
QPair<QString, QString> modelName(tr("Model Name"), firstProcessorInfo.value("model name"));
1271+
singleCpuHeaderInfo.push_back(modelName);
1272+
}
1273+
if (firstProcessorInfo.contains("vendor_id")) {
1274+
QPair<QString, QString> vendorID(tr("Vendor ID"), firstProcessorInfo.value("vendor_id"));
1275+
singleCpuHeaderInfo.push_back(vendorID);
1276+
}
1277+
if (firstProcessorInfo.contains("Architecture")) {
1278+
QPair<QString, QString> arch(tr("Architecture"), firstProcessorInfo.value("Architecture"));
1279+
singleCpuHeaderInfo.push_back(arch);
1280+
}
1281+
if (coreNum > 0) {
1282+
QPair<QString, QString> coreCount(tr("Core(s)"), QString::number(coreNum));
1283+
singleCpuHeaderInfo.push_back(coreCount);
1284+
QPair<QString, QString> threadPerCore(tr("Thread(s)"), QString::number(logicalNum / coreNum));
1285+
singleCpuHeaderInfo.push_back(threadPerCore);
1286+
}
1287+
if (firstProcessorInfo.contains("L1d cache")) {
1288+
QString strL1dCache = firstProcessorInfo.value("L1d cache");
1289+
QString strTotalL1dCache = Common::formatTotalCache(strL1dCache, coreNum);
1290+
if (!strTotalL1dCache.isEmpty()) {
1291+
QPair<QString, QString> totalL1dCache(tr("L1d cache"), strTotalL1dCache);
1292+
singleCpuHeaderInfo.push_back(totalL1dCache);
1293+
}
1294+
}
1295+
if (firstProcessorInfo.contains("L1i cache")) {
1296+
QString strL1iCache = firstProcessorInfo.value("L1i cache");
1297+
QString strTotalL1iCache = Common::formatTotalCache(strL1iCache, coreNum);
1298+
if (!strTotalL1iCache.isEmpty()) {
1299+
QPair<QString, QString> totalL1iCache(tr("L1i cache"), strTotalL1iCache);
1300+
singleCpuHeaderInfo.push_back(totalL1iCache);
1301+
}
1302+
}
1303+
if (firstProcessorInfo.contains("L2 cache")) {
1304+
QString strL2Cache = firstProcessorInfo.value("L2 cache");
1305+
QString strTotalL2Cache = Common::formatTotalCache(strL2Cache, coreNum);
1306+
if (!strTotalL2Cache.isEmpty()) {
1307+
QPair<QString, QString> totalL2Cache(tr("L2 cache"), strTotalL2Cache);
1308+
singleCpuHeaderInfo.push_back(totalL2Cache);
1309+
}
1310+
}
1311+
if (firstProcessorInfo.contains("L3 cache")) {
1312+
QString strL3Cache = firstProcessorInfo.value("L3 cache");
1313+
QString strTotalL3Cache = Common::formatTotalCache(strL3Cache, 1);
1314+
if (!strTotalL3Cache.isEmpty()) {
1315+
QPair<QString, QString> totalL3Cache(tr("L3 cache"), strTotalL3Cache);
1316+
singleCpuHeaderInfo.push_back(totalL3Cache);
1317+
}
1318+
}
1319+
1320+
cpuHeaderInfo.push_back(singleCpuHeaderInfo);
1321+
DeviceManager::instance()->setCpuHeaderInfo(cpuHeaderInfo);
1322+
}
1323+
12591324
void DeviceGenerator::generatorInfoFromToml(DeviceType deviceType)
12601325
{
12611326
DeviceManager::instance()->tomlDeviceSet(deviceType);

deepin-devicemanager/src/GenerateDevice/DeviceGenerator.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// Copyright (C) 2019 ~ 2020 Uniontech Software Technology Co.,Ltd.
2-
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2019 - 2026 UnionTech Software Technology Co., Ltd.
32
//
43
// SPDX-License-Identifier: GPL-3.0-or-later
54

@@ -338,6 +337,10 @@ class DeviceGenerator : public QObject
338337

339338
protected:
340339
QStringList m_ListBusID;
340+
341+
private:
342+
void calAndSetCpuHeaderInfo(const QMap<QString, QString> &firstProcessorInfo,
343+
int coreNum, int logicalNum);
341344
};
342345

343346
#endif // DEVICEGENERATOR_H

deepin-devicemanager/src/Page/PageMultiInfo.cpp

Lines changed: 66 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: GPL-3.0-or-later
44

55
// 项目自身文件
66
#include "PageMultiInfo.h"
7+
#include "headerinfotablewidget.h"
78
#include "PageTableHeader.h"
89
#include "PageDetail.h"
910
#include "MacroDefinition.h"
@@ -12,6 +13,7 @@
1213
#include "DevicePrint.h"
1314
#include "DeviceInput.h"
1415
#include "DeviceNetwork.h"
16+
#include "DeviceCpu.h"
1517
#include "DDLog.h"
1618
#include "commonfunction.h"
1719

@@ -22,7 +24,6 @@
2224
#include <DMessageManager>
2325

2426
// Qt库文件
25-
#include <QVBoxLayout>
2627
#include <QAction>
2728
#include <QIcon>
2829
#include <QLoggingCategory>
@@ -33,10 +34,14 @@ DWIDGET_USE_NAMESPACE
3334
using namespace DDLog;
3435

3536
#define LEAST_PAGE_HEIGHT 315 // PageMultiInfo最小高度 当小于这个高度时,上方的表格就要变小
37+
static constexpr int kHeaderInfoDefaultHeight = 362; // 滚动区域默认高度
3638

3739
PageMultiInfo::PageMultiInfo(QWidget *parent)
3840
: PageInfo(parent)
3941
, mp_Label(new DLabel(this))
42+
, mp_HeaderInfoWidget(new DScrollArea(this))
43+
, mp_HeaderInfoContainer(new DWidget(mp_HeaderInfoWidget))
44+
, mp_HeaderInfoWidgetLay(new QVBoxLayout(mp_HeaderInfoContainer))
4045
, mp_Table(new PageTableHeader(this))
4146
, mp_Detail(new PageDetail(this))
4247
{
@@ -62,6 +67,11 @@ PageMultiInfo::PageMultiInfo(QWidget *parent)
6267
PageMultiInfo::~PageMultiInfo()
6368
{
6469
// 清空指针
70+
if (mp_HeaderInfoWidget) {
71+
delete mp_HeaderInfoWidget;
72+
mp_HeaderInfoWidget = nullptr;
73+
mp_HeaderInfoContainer = nullptr;
74+
}
6575
if (mp_Table) {
6676
delete mp_Table;
6777
mp_Table = nullptr;
@@ -81,6 +91,26 @@ void PageMultiInfo::updateInfo(const QList<DeviceBaseInfo *> &lst)
8191

8292
if (lst.size() < 1)
8393
return;
94+
95+
// 当前为CPU页面,显示头部信息视图
96+
DeviceCpu *cpuInfo = dynamic_cast<DeviceCpu *>(lst.at(0));
97+
if (cpuInfo) {
98+
QList<QList<QPair<QString, QString>>> headerInfo;
99+
DeviceManager::instance()->getCpuHeaderInfo(headerInfo);
100+
clearLayout(mp_HeaderInfoWidgetLay);
101+
for (int i = 0; i < headerInfo.size(); ++i) {
102+
HeaderInfoTableWidget *headerWidget = new HeaderInfoTableWidget(mp_HeaderInfoWidget);
103+
headerWidget->updateData(headerInfo.at(i));
104+
mp_HeaderInfoWidgetLay->addWidget(headerWidget);
105+
}
106+
mp_HeaderInfoWidget->setMaximumHeight(kHeaderInfoDefaultHeight);
107+
mp_HeaderInfoWidget->resize(this->width(), kHeaderInfoDefaultHeight);
108+
mp_HeaderInfoWidget->setVisible(true);
109+
} else {
110+
mp_HeaderInfoWidget->setVisible(false);
111+
mp_HeaderInfoWidget->setMaximumHeight(0);
112+
}
113+
84114
m_deviceList.clear();
85115
m_menuControlList.clear();
86116

@@ -242,23 +272,35 @@ void PageMultiInfo::slotCheckPrinterStatus(int row, bool &isPrinter, bool &isIns
242272
void PageMultiInfo::initWidgets()
243273
{
244274
// 初始化界面布局
245-
QVBoxLayout *hLayout = new QVBoxLayout();
275+
QVBoxLayout *vLayout = new QVBoxLayout();
246276
QHBoxLayout *labelLayout = new QHBoxLayout();
247277
labelLayout->addSpacing(10);
248278
labelLayout->addWidget(mp_Label);
249279

250280
// Label 距离上下控件的距离LABEL_MARGIN
251-
hLayout->addSpacing(LABEL_MARGIN);
252-
hLayout->addLayout(labelLayout);
253-
hLayout->addSpacing(LABEL_MARGIN);
281+
vLayout->addSpacing(LABEL_MARGIN);
282+
vLayout->addLayout(labelLayout);
283+
vLayout->addSpacing(LABEL_MARGIN);
284+
285+
// 添加头部信息视图
286+
mp_HeaderInfoWidget->setWidget(mp_HeaderInfoContainer);
287+
mp_HeaderInfoWidget->setWidgetResizable(true);
288+
mp_HeaderInfoWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
289+
mp_HeaderInfoWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
290+
mp_HeaderInfoWidget->setFrameShape(QFrame::NoFrame);
291+
mp_HeaderInfoWidget->setMaximumHeight(kHeaderInfoDefaultHeight);
292+
mp_HeaderInfoWidget->setMinimumHeight(0);
293+
mp_HeaderInfoWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
294+
mp_HeaderInfoWidgetLay->setContentsMargins(0, 0, 0, 0);
295+
mp_HeaderInfoWidget->setVisible(false);
296+
vLayout->addWidget(mp_HeaderInfoWidget, 1); // stretch=1,允许随窗口缩放
254297

255298
mp_Table->setFixedHeight(TABLE_HEIGHT);
299+
vLayout->addWidget(mp_Table);
300+
vLayout->addWidget(mp_Detail);
301+
vLayout->setContentsMargins(10, 10, 10, 0);
256302

257-
hLayout->addWidget(mp_Table);
258-
hLayout->addWidget(mp_Detail);
259-
hLayout->setContentsMargins(10, 10, 10, 0);
260-
261-
setLayout(hLayout);
303+
setLayout(vLayout);
262304
}
263305

264306
void PageMultiInfo::getTableListInfo(const QList<DeviceBaseInfo *> &lst, QList<QStringList> &deviceList, QList<QStringList> &menuControlList)
@@ -295,3 +337,16 @@ void PageMultiInfo::getTableListInfo(const QList<DeviceBaseInfo *> &lst, QList<Q
295337
menuControlList.append(menuControl);
296338
}
297339
}
340+
341+
void PageMultiInfo::clearLayout(QLayout *layout)
342+
{
343+
QLayoutItem *item;
344+
while ((item = layout->takeAt(0)) != nullptr) {
345+
// 如果布局项包含控件,删除该控件
346+
if (QWidget *widget = item->widget()) {
347+
widget->deleteLater(); // 安全删除,避免事件冲突
348+
}
349+
// 删除布局项本身(注意:如果 item 是子布局,需递归处理,本例仅处理直接控件)
350+
delete item;
351+
}
352+
}

deepin-devicemanager/src/Page/PageMultiInfo.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
// Copyright (C) 2019 ~ 2020 Uniontech Software Technology Co.,Ltd.
2-
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2019 - 2026 UnionTech Software Technology Co., Ltd.
32
//
43
// SPDX-License-Identifier: GPL-3.0-or-later
54

65
#ifndef DEVICEPAGE_H
76
#define DEVICEPAGE_H
87

98
#include <QObject>
9+
#include <QVBoxLayout>
1010
#include <DWidget>
1111
#include <DLabel>
12+
#include <DScrollArea>
1213

1314
#include "PageInfo.h"
1415

@@ -122,8 +123,14 @@ private slots:
122123
*/
123124
void getTableListInfo(const QList<DeviceBaseInfo *> &lst, QList<QStringList>& deviceList, QList<QStringList>& menuList);
124125

126+
// 清空布局中的所有 Widget
127+
void clearLayout(QLayout *layout);
128+
125129
private:
126130
DLabel *mp_Label;
131+
DScrollArea *mp_HeaderInfoWidget;
132+
DWidget *mp_HeaderInfoContainer;
133+
QVBoxLayout *mp_HeaderInfoWidgetLay;
127134
PageTableHeader *mp_Table; //<! 上面的表格
128135
PageDetail *mp_Detail; //<! 下面的详细内容
129136
QList<DeviceBaseInfo *> m_lstDevice; //<! 保存设备列表

0 commit comments

Comments
 (0)