Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions net-view/operation/private/netitemprivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace network {
*/
NetItemPrivate::NetItemPrivate()
: m_item(nullptr)
, m_parent(nullptr)
{
}

Expand Down
19 changes: 11 additions & 8 deletions net-view/window/netview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ NetView::NetView(NetManager *manager)
connect(this, &NetView::activated, this, &NetView::onActivated);

// 支持在触摸屏上滚动
//QScroller::grabGesture(viewport(), QScroller::LeftMouseButtonGesture);
//QScrollerProperties sp;
//sp.setScrollMetric(QScrollerProperties::VerticalOvershootPolicy, QScrollerProperties::OvershootAlwaysOff);
// QScroller::grabGesture(viewport(), QScroller::LeftMouseButtonGesture);
// QScrollerProperties sp;
// sp.setScrollMetric(QScrollerProperties::VerticalOvershootPolicy, QScrollerProperties::OvershootAlwaysOff);
}

NetView::~NetView() = default;
Expand Down Expand Up @@ -143,7 +143,7 @@ void NetView::rowsInserted(const QModelIndex &parent, int start, int end)
NetWirelessOtherItem *otherItem = NetItem::toItem<NetWirelessOtherItem>(item);
if (otherItem) {
updateItemExpand(otherItem);
connect(otherItem, &NetWirelessOtherItem::expandedChanged, this, &NetView::onExpandStatusChanged);
connect(otherItem, &NetWirelessOtherItem::expandedChanged, this, &NetView::onExpandStatusChanged, Qt::UniqueConnection);
}
} break;
case NetType::WirelessMineItem:
Expand All @@ -152,8 +152,8 @@ void NetView::rowsInserted(const QModelIndex &parent, int start, int end)
case NetType::VPNControlItem: {
NetVPNControlItem *vpnControlItem = NetItem::toItem<NetVPNControlItem>(item);
if (vpnControlItem) {
connect(vpnControlItem, &NetVPNControlItem::expandedChanged, this, &NetView::onExpandStatusChanged);
connect(vpnControlItem, &NetVPNControlItem::enabledChanged, this, &NetView::onExpandStatusChanged);
connect(vpnControlItem, &NetVPNControlItem::expandedChanged, this, &NetView::onExpandStatusChanged, Qt::UniqueConnection);
connect(vpnControlItem, &NetVPNControlItem::enabledChanged, this, &NetView::onExpandStatusChanged, Qt::UniqueConnection);
updateItemExpand(vpnControlItem);
}
} break;
Expand All @@ -164,9 +164,9 @@ void NetView::rowsInserted(const QModelIndex &parent, int start, int end)
NetDeviceItem *dev = NetItem::toItem<NetDeviceItem>(item);
if (dev) {
updateItemExpand(dev);
connect(dev, &NetDeviceItem::enabledChanged, this, &NetView::onExpandStatusChanged);
connect(dev, &NetDeviceItem::enabledChanged, this, &NetView::onExpandStatusChanged, Qt::UniqueConnection);
if (dev->itemType() == NetType::WirelessDeviceItem)
connect(NetItem::toItem<NetWirelessDeviceItem>(dev), &NetWirelessDeviceItem::apModeChanged, this, &NetView::onExpandStatusChanged);
connect(NetItem::toItem<NetWirelessDeviceItem>(dev), &NetWirelessDeviceItem::apModeChanged, this, &NetView::onExpandStatusChanged, Qt::UniqueConnection);
}
} break;
default:
Expand Down Expand Up @@ -281,6 +281,9 @@ void NetView::updateItemExpand(NetItem *item)
return;
}
QModelIndex sIndex = m_model->index(item);
if (!sIndex.isValid()) {
return;
}
QModelIndex index = m_proxyModel->mapFromSource(sIndex);
if (isExpanded(index) != expandItem) {
setExpanded(index, expandItem);
Expand Down
7 changes: 7 additions & 0 deletions net-view/window/private/netmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ QModelIndex NetModel::index(const NetItem *object)
if (!parent) {
return QModelIndex();
}
NetItem *ancestor = parent;
while (ancestor && ancestor != m_treeRoot) {
ancestor = ancestor->getParent();
}
if (ancestor != m_treeRoot) {
return QModelIndex();
}

int pos = parent->getChildIndex(object);
assert(pos >= 0);
Expand Down