Skip to content

Commit 1d97dd1

Browse files
GongHeng2017deepin-bot[bot]
authored andcommitted
Feat: add HeaderInfoTableWidget for displaying device information
Add a custom table widget with rounded border and alternating row colors for displaying device information as key-value pairs. - Add HeaderInfoDelegate for custom text color handling in selection - Add HeaderInfoTableWidget with rounded border painting and vertical divider - Support dynamic height adjustment based on content - Use DPalette for consistent theming with active/inactive states Log: add feature for cpu info show. Task: https://pms.uniontech.com/task-view-387697.html
1 parent 8e86c3e commit 1d97dd1

13 files changed

Lines changed: 438 additions & 22 deletions

deepin-devicemanager/src/DeviceManager/DeviceManager.cpp

Lines changed: 11 additions & 3 deletions
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

@@ -1935,8 +1935,6 @@ void DeviceManager::overviewToTxt(QTextStream &out)
19351935
out << "\n";
19361936
}
19371937

1938-
1939-
19401938
void DeviceManager::overviewToHtml(QFile &html)
19411939
{
19421940
qCDebug(appLog) << "Exporting overview to html";
@@ -2179,6 +2177,16 @@ void DeviceManager::setCpuFrequencyIsCur(const bool &flag)
21792177
}
21802178
}
21812179

2180+
void DeviceManager::setCpuHeaderInfo(const QList<QList<QPair<QString, QString> > > &info)
2181+
{
2182+
m_ListCpuHeaderInfo = info;
2183+
}
2184+
2185+
void DeviceManager::getCpuHeaderInfo(QList<QList<QPair<QString, QString> > > &info) const
2186+
{
2187+
info = m_ListCpuHeaderInfo;
2188+
}
2189+
21822190
bool DeviceManager::validateKeyboardVidPid(const QString &vid, const QString &pid, QString &normalizedVid, QString &normalizedPid)
21832191
{
21842192
qCDebug(appLog) << "Validating keyboard VID:" << vid << "PID:" << pid;

deepin-devicemanager/src/DeviceManager/DeviceManager.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

@@ -632,6 +631,9 @@ class DeviceManager : public QObject
632631
*/
633632
void setCpuFrequencyIsCur(const bool &flag);
634633

634+
void setCpuHeaderInfo(const QList<QList<QPair<QString, QString>>> &info);
635+
void getCpuHeaderInfo(QList<QList<QPair<QString, QString>>> &info) const;
636+
635637
/**
636638
* @brief validateKeyboardVidPid:校验有效的vid和pid
637639
* @param vid
@@ -680,6 +682,7 @@ class DeviceManager : public QObject
680682

681683
static int m_CurrentXlsRow; //<! xlsx表格当前行
682684
QStringList m_networkDriver; //网络驱动
685+
QList<QList<QPair<QString, QString>>> m_ListCpuHeaderInfo; // 所有物理CPU个体的头部信息
683686
};
684687

685688
#endif // DEVICEMANAGER_H

deepin-devicemanager/src/GenerateDevice/DeviceGenerator.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,10 @@ void DeviceGenerator::generatorCpuDevice()
241241
device->setCpuInfo(*it, lshw, dmidecode, coreNum, logicalNum);
242242
DeviceManager::instance()->addCpuDevice(device);
243243
}
244+
245+
// 计算并设置CPU头部信息(当前没有多个物理CPU的环境,所以只能编码单物理CPU的逻辑)
246+
if (lsCpu.size() > 0)
247+
calAndSetCpuHeaderInfo(lsCpu.at(0), coreNum, logicalNum);
244248
}
245249

246250
void DeviceGenerator::generatorBiosDevice()
@@ -1512,6 +1516,67 @@ QString DeviceGenerator::uniqueID(const QMap<QString, QString> &mapInfo)
15121516
return "";
15131517
}
15141518

1519+
void DeviceGenerator::calAndSetCpuHeaderInfo(const QMap<QString, QString> &firstProcessorInfo,
1520+
int coreNum, int logicalNum)
1521+
{
1522+
QList<QList<QPair<QString, QString>>> cpuHeaderInfo;
1523+
QList<QPair<QString, QString>> singleCpuHeaderInfo;
1524+
1525+
if (firstProcessorInfo.contains("model name")) {
1526+
QPair<QString, QString> modelName(tr("Model Name"), firstProcessorInfo.value("model name"));
1527+
singleCpuHeaderInfo.push_back(modelName);
1528+
}
1529+
if (firstProcessorInfo.contains("vendor_id")) {
1530+
QPair<QString, QString> vendorID(tr("Vendor ID"), firstProcessorInfo.value("vendor_id"));
1531+
singleCpuHeaderInfo.push_back(vendorID);
1532+
}
1533+
if (firstProcessorInfo.contains("Architecture")) {
1534+
QPair<QString, QString> arch(tr("Architecture"), firstProcessorInfo.value("Architecture"));
1535+
singleCpuHeaderInfo.push_back(arch);
1536+
}
1537+
if (coreNum > 0) {
1538+
QPair<QString, QString> coreCount(tr("Core(s)"), QString::number(coreNum));
1539+
singleCpuHeaderInfo.push_back(coreCount);
1540+
QPair<QString, QString> threadPerCore(tr("Thread(s)"), QString::number(logicalNum / coreNum));
1541+
singleCpuHeaderInfo.push_back(threadPerCore);
1542+
}
1543+
if (firstProcessorInfo.contains("L1d cache")) {
1544+
QString strL1dCache = firstProcessorInfo.value("L1d cache");
1545+
QString strTotalL1dCache = Common::formatTotalCache(strL1dCache, coreNum);
1546+
if (!strTotalL1dCache.isEmpty()) {
1547+
QPair<QString, QString> totalL1dCache(tr("L1d cache"), strTotalL1dCache);
1548+
singleCpuHeaderInfo.push_back(totalL1dCache);
1549+
}
1550+
}
1551+
if (firstProcessorInfo.contains("L1i cache")) {
1552+
QString strL1iCache = firstProcessorInfo.value("L1i cache");
1553+
QString strTotalL1iCache = Common::formatTotalCache(strL1iCache, coreNum);
1554+
if (!strTotalL1iCache.isEmpty()) {
1555+
QPair<QString, QString> totalL1iCache(tr("L1i cache"), strTotalL1iCache);
1556+
singleCpuHeaderInfo.push_back(totalL1iCache);
1557+
}
1558+
}
1559+
if (firstProcessorInfo.contains("L2 cache")) {
1560+
QString strL2Cache = firstProcessorInfo.value("L2 cache");
1561+
QString strTotalL2Cache = Common::formatTotalCache(strL2Cache, coreNum);
1562+
if (!strTotalL2Cache.isEmpty()) {
1563+
QPair<QString, QString> totalL2Cache(tr("L2 cache"), strTotalL2Cache);
1564+
singleCpuHeaderInfo.push_back(totalL2Cache);
1565+
}
1566+
}
1567+
if (firstProcessorInfo.contains("L3 cache")) {
1568+
QString strL3Cache = firstProcessorInfo.value("L3 cache");
1569+
QString strTotalL3Cache = Common::formatTotalCache(strL3Cache, 1);
1570+
if (!strTotalL3Cache.isEmpty()) {
1571+
QPair<QString, QString> totalL3Cache(tr("L3 cache"), strTotalL3Cache);
1572+
singleCpuHeaderInfo.push_back(totalL3Cache);
1573+
}
1574+
}
1575+
1576+
cpuHeaderInfo.push_back(singleCpuHeaderInfo);
1577+
DeviceManager::instance()->setCpuHeaderInfo(cpuHeaderInfo);
1578+
}
1579+
15151580
void DeviceGenerator::generatorInfoFromToml(DeviceType deviceType)
15161581
{
15171582
qCDebug(appLog) << "Generator info from toml";

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/MainWindow.cpp

Lines changed: 2 additions & 2 deletions
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

@@ -50,7 +50,7 @@ DWIDGET_USE_NAMESPACE
5050
using namespace DDLog;
5151
// 主界面需要的一些宏定义
5252
#define INIT_WIDTH 1000 // 窗口的初始化宽度
53-
#define INIT_HEIGHT 720 // 窗口的初始化高度
53+
#define INIT_HEIGHT 802 // 窗口的初始化高度
5454
#define MIN_WIDTH 680 // 窗口的最小宽度
5555
#define MIN_HEIGHT 300 // 窗口的最小高度
5656

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
{
@@ -64,6 +69,11 @@ PageMultiInfo::~PageMultiInfo()
6469
{
6570
qCDebug(appLog) << "PageMultiInfo destructor start";
6671
// 清空指针
72+
if (mp_HeaderInfoWidget) {
73+
delete mp_HeaderInfoWidget;
74+
mp_HeaderInfoWidget = nullptr;
75+
mp_HeaderInfoContainer = nullptr;
76+
}
6777
if (mp_Table) {
6878
qCDebug(appLog) << "Deleting table";
6979
delete mp_Table;
@@ -89,6 +99,26 @@ void PageMultiInfo::updateInfo(const QList<DeviceBaseInfo *> &lst)
8999
qCWarning(appLog) << "Empty device list provided";
90100
return;
91101
}
102+
103+
// 当前为CPU页面,显示头部信息视图
104+
DeviceCpu *cpuInfo = dynamic_cast<DeviceCpu *>(lst.at(0));
105+
if (cpuInfo) {
106+
QList<QList<QPair<QString, QString>>> headerInfo;
107+
DeviceManager::instance()->getCpuHeaderInfo(headerInfo);
108+
clearLayout(mp_HeaderInfoWidgetLay);
109+
for (int i = 0; i < headerInfo.size(); ++i) {
110+
HeaderInfoTableWidget *headerWidget = new HeaderInfoTableWidget(mp_HeaderInfoWidget);
111+
headerWidget->updateData(headerInfo.at(i));
112+
mp_HeaderInfoWidgetLay->addWidget(headerWidget);
113+
}
114+
mp_HeaderInfoWidget->setMaximumHeight(kHeaderInfoDefaultHeight);
115+
mp_HeaderInfoWidget->resize(this->width(), kHeaderInfoDefaultHeight);
116+
mp_HeaderInfoWidget->setVisible(true);
117+
} else {
118+
mp_HeaderInfoWidget->setVisible(false);
119+
mp_HeaderInfoWidget->setMaximumHeight(0);
120+
}
121+
92122
m_deviceList.clear();
93123
m_menuControlList.clear();
94124

@@ -285,23 +315,35 @@ void PageMultiInfo::initWidgets()
285315
{
286316
qCDebug(appLog) << "PageMultiInfo::initWidgets";
287317
// 初始化界面布局
288-
QVBoxLayout *hLayout = new QVBoxLayout();
318+
QVBoxLayout *vLayout = new QVBoxLayout();
289319
QHBoxLayout *labelLayout = new QHBoxLayout();
290320
labelLayout->addSpacing(10);
291321
labelLayout->addWidget(mp_Label);
292322

293323
// Label 距离上下控件的距离LABEL_MARGIN
294-
hLayout->addSpacing(LABEL_MARGIN);
295-
hLayout->addLayout(labelLayout);
296-
hLayout->addSpacing(LABEL_MARGIN);
324+
vLayout->addSpacing(LABEL_MARGIN);
325+
vLayout->addLayout(labelLayout);
326+
vLayout->addSpacing(LABEL_MARGIN);
327+
328+
// 添加头部信息视图
329+
mp_HeaderInfoWidget->setWidget(mp_HeaderInfoContainer);
330+
mp_HeaderInfoWidget->setWidgetResizable(true);
331+
mp_HeaderInfoWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
332+
mp_HeaderInfoWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
333+
mp_HeaderInfoWidget->setFrameShape(QFrame::NoFrame);
334+
mp_HeaderInfoWidget->setMaximumHeight(kHeaderInfoDefaultHeight);
335+
mp_HeaderInfoWidget->setMinimumHeight(0);
336+
mp_HeaderInfoWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
337+
mp_HeaderInfoWidgetLay->setContentsMargins(0, 0, 0, 0);
338+
mp_HeaderInfoWidget->setVisible(false);
339+
vLayout->addWidget(mp_HeaderInfoWidget, 1); // stretch=1,允许随窗口缩放
297340

298341
mp_Table->setFixedHeight(TABLE_HEIGHT);
342+
vLayout->addWidget(mp_Table);
343+
vLayout->addWidget(mp_Detail);
344+
vLayout->setContentsMargins(10, 10, 10, 0);
299345

300-
hLayout->addWidget(mp_Table);
301-
hLayout->addWidget(mp_Detail);
302-
hLayout->setContentsMargins(10, 10, 10, 0);
303-
304-
setLayout(hLayout);
346+
setLayout(vLayout);
305347
}
306348

307349
void PageMultiInfo::getTableListInfo(const QList<DeviceBaseInfo *> &lst, QList<QStringList> &deviceList, QList<QStringList> &menuControlList)
@@ -341,3 +383,16 @@ void PageMultiInfo::getTableListInfo(const QList<DeviceBaseInfo *> &lst, QList<Q
341383
}
342384
qCDebug(appLog) << "PageMultiInfo::getTableListInfo end";
343385
}
386+
387+
void PageMultiInfo::clearLayout(QLayout *layout)
388+
{
389+
QLayoutItem *item;
390+
while ((item = layout->takeAt(0)) != nullptr) {
391+
// 如果布局项包含控件,删除该控件
392+
if (QWidget *widget = item->widget()) {
393+
widget->deleteLater(); // 安全删除,避免事件冲突
394+
}
395+
// 删除布局项本身(注意:如果 item 是子布局,需递归处理,本例仅处理直接控件)
396+
delete item;
397+
}
398+
}

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; //<! 保存设备列表
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
2+
//
3+
// SPDX-License-Identifier: GPL-3.0-or-later
4+
5+
#include <DApplication>
6+
#include <DPaletteHelper>
7+
#include <DPalette>
8+
9+
#include "headerinfotableDelegate.h"
10+
11+
DWIDGET_USE_NAMESPACE
12+
13+
HeaderInfoDelegate::HeaderInfoDelegate(QObject *parent)
14+
: QStyledItemDelegate(parent)
15+
{
16+
}
17+
18+
void HeaderInfoDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
19+
{
20+
QStyleOptionViewItem opt(option);
21+
initStyleOption(&opt, index);
22+
23+
QWidget *wnd = DApplication::activeWindow();
24+
DPalette::ColorGroup cg = wnd ? DPalette::Active : DPalette::Inactive;
25+
auto palette = DPaletteHelper::instance()->palette(option.widget);
26+
27+
if (opt.state & QStyle::State_Selected) {
28+
QColor highlightColor = palette.color(cg, DPalette::HighlightedText);
29+
opt.palette.setColor(QPalette::Text, highlightColor);
30+
opt.palette.setColor(QPalette::WindowText, highlightColor);
31+
} else {
32+
QColor normalColor = palette.color(cg, DPalette::Text);
33+
opt.palette.setColor(QPalette::Text, normalColor);
34+
opt.palette.setColor(QPalette::WindowText, normalColor);
35+
}
36+
37+
QStyledItemDelegate::paint(painter, opt, index);
38+
}

0 commit comments

Comments
 (0)