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"
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
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
3334using namespace DDLog ;
3435
3536#define LEAST_PAGE_HEIGHT 315 // PageMultiInfo最小高度 当小于这个高度时,上方的表格就要变小
37+ static constexpr int kHeaderInfoDefaultHeight = 362 ; // 滚动区域默认高度
3638
3739PageMultiInfo::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
307349void 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+ }
0 commit comments