Skip to content

Commit 9b848a0

Browse files
committed
fix: fix system and app proxy is hide
the system and app proxy must show on the control center PMS: BUG-350619
1 parent 22c5f90 commit 9b848a0

File tree

3 files changed

+51
-6
lines changed

3 files changed

+51
-6
lines changed

dcc-network/operation/netitemmodel.cpp

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
// SPDX-License-Identifier: GPL-3.0-or-later
44
#include "netitemmodel.h"
55

6-
#include "netitem.h"
7-
86
namespace dde {
97
namespace network {
108
enum NetModelRole {
@@ -42,9 +40,28 @@ protected Q_SLOTS:
4240
onAddObject(child);
4341
}
4442

45-
void AboutToRemoveObject(const NetItem *, int pos) { beginRemoveRows(QModelIndex(), pos, pos); }
43+
bool needRemoveNodeItem(const NetItem *childItem) const
44+
{
45+
if (childItem && (childItem->itemType() == NetType::NetItemType::SystemProxyControlItem
46+
|| childItem->itemType() == NetType::NetItemType::AppProxyControlItem)) {
47+
// 对于系统代理和应用代理(应用代理在V25上被裁减了,但是这里还是加上去这个判断,防止以后加上),
48+
// 这里始终显示当前的节点
49+
return false;
50+
}
51+
return true;
52+
}
4653

47-
void removeObject(const NetItem *child) { endRemoveRows(); }
54+
void AboutToRemoveObject(const NetItem *parentItem, int pos)
55+
{
56+
if (needRemoveNodeItem(parentItem->getChild(pos)))
57+
beginRemoveRows(QModelIndex(), pos, pos);
58+
}
59+
60+
void removeObject(const NetItem *child)
61+
{
62+
if (needRemoveNodeItem(child))
63+
endRemoveRows();
64+
}
4865

4966
protected:
5067
NetItem *m_root;
@@ -195,10 +212,32 @@ QHash<int, QByteArray> NetItemModel::roleNames() const
195212
return names;
196213
}
197214

215+
bool NetItemModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
216+
{
217+
QModelIndex childIndex = sourceModel()->index(source_row, 0, source_parent);
218+
NetItem *curItem = static_cast<NetItem *>(childIndex.internalPointer());
219+
if (!curItem) {
220+
return false;
221+
}
222+
// 有的节点出现了两次,所以这里让显示第一次出现的那个节点
223+
if (m_rowMap.contains(curItem->itemType())) {
224+
return (m_rowMap[curItem->itemType()] == source_row);
225+
}
226+
227+
m_rowMap[curItem->itemType()] = source_row;
228+
return true;
229+
}
230+
198231
bool NetItemModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const
199232
{
200233
NetItem *leftItem = static_cast<NetItem *>(source_left.internalPointer());
234+
if (!leftItem)
235+
return false;
236+
201237
NetItem *rightItem = static_cast<NetItem *>(source_right.internalPointer());
238+
if (!rightItem)
239+
return false;
240+
202241
if (leftItem->itemType() != rightItem->itemType())
203242
return leftItem->itemType() < rightItem->itemType();
204243
switch (leftItem->itemType()) {

dcc-network/operation/netitemmodel.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
#include <QSortFilterProxyModel>
88

9+
#include "netitem.h"
10+
911
namespace dde {
1012
namespace network {
1113
class NetItem;
@@ -27,7 +29,11 @@ class NetItemModel : public QSortFilterProxyModel
2729
void rootChanged(NetItem *root);
2830

2931
protected:
32+
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
3033
bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override;
34+
35+
private:
36+
mutable QMap<NetType::NetItemType, int> m_rowMap;
3137
};
3238
} // namespace network
3339
} // namespace dde

dcc-network/qml/PageSystemProxy.qml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ DccObject {
4444
id: devCheck
4545
D.Switch {
4646
checked: netItem.isEnabled
47-
enabled: netItem.enabledable
47+
enabled: true
4848
onClicked: {
4949
dccData.exec(netItem.isEnabled ? NetManager.DisabledDevice : NetManager.EnabledDevice, netItem.id, {})
5050
}
@@ -70,7 +70,7 @@ DccObject {
7070
pageType: DccObject.Editor
7171
page: D.Switch {
7272
checked: root.method !== NetType.None
73-
enabled: netItem.enabledable
73+
enabled: true
7474
onClicked: {
7575
if (checked) {
7676
root.method = netItem.lastMethod

0 commit comments

Comments
 (0)