提交 34df2528 编写于 作者: 之一Yo's avatar 之一Yo

修复移除导航菜单项的问题

上级 92b0ca45
# coding:utf-8 # coding:utf-8
from typing import Dict, List from typing import Dict, List
from itertools import groupby
from PyQt5.QtCore import Qt, QObject, pyqtSignal from PyQt5.QtCore import Qt, QObject, pyqtSignal
from PyQt5.QtWidgets import QWidget, QStackedWidget from PyQt5.QtWidgets import QWidget, QStackedWidget
...@@ -52,6 +53,7 @@ class StackedHistory: ...@@ -52,6 +53,7 @@ class StackedHistory:
return return
self.history[1:] = [i for i in self.history[1:] if i != routeKey] self.history[1:] = [i for i in self.history[1:] if i != routeKey]
self.history = [k for k, g in groupby(self.history)]
self.goToTop() self.goToTop()
def top(self): def top(self):
...@@ -119,6 +121,7 @@ class Router(QObject): ...@@ -119,6 +121,7 @@ class Router(QObject):
def remove(self, routeKey: str): def remove(self, routeKey: str):
""" remove history """ """ remove history """
self.history = [i for i in self.history if i.routeKey != routeKey] self.history = [i for i in self.history if i.routeKey != routeKey]
self.history = [list(g)[0] for k, g in groupby(self.history, lambda i: i.routeKey)]
self.emptyChanged.emit(not bool(self.history)) self.emptyChanged.emit(not bool(self.history))
for stacked, history in self.stackHistories.items(): for stacked, history in self.stackHistories.items():
......
...@@ -357,6 +357,16 @@ class NavigationPanel(QFrame): ...@@ -357,6 +357,16 @@ class NavigationPanel(QFrame):
if item.parentRouteKey is not None: if item.parentRouteKey is not None:
self.widget(item.parentRouteKey).removeChild(item.widget) self.widget(item.parentRouteKey).removeChild(item.widget)
if isinstance(item.widget, NavigationTreeWidgetBase):
for child in item.widget.findChildren(NavigationWidget, options=Qt.FindChildrenRecursively):
key = child.property('routeKey')
if key is None:
continue
self.items.pop(key)
child.deleteLater()
self.history.remove(key)
item.widget.deleteLater() item.widget.deleteLater()
self.history.remove(routeKey) self.history.remove(routeKey)
......
...@@ -8,7 +8,7 @@ from PyQt5.QtWidgets import QWidget, QVBoxLayout ...@@ -8,7 +8,7 @@ from PyQt5.QtWidgets import QWidget, QVBoxLayout
from ...common.config import isDarkTheme from ...common.config import isDarkTheme
from ...common.style_sheet import themeColor from ...common.style_sheet import themeColor
from ...common.icon import drawIcon from ...common.icon import drawIcon, toQIcon
from ...common.icon import FluentIcon as FIF from ...common.icon import FluentIcon as FIF
...@@ -90,7 +90,7 @@ class NavigationPushButton(NavigationWidget): ...@@ -90,7 +90,7 @@ class NavigationPushButton(NavigationWidget):
""" """
super().__init__(isSelectable=isSelectable, parent=parent) super().__init__(isSelectable=isSelectable, parent=parent)
self.icon = icon self._icon = icon
self._text = text self._text = text
self.setStyleSheet( self.setStyleSheet(
...@@ -99,6 +99,17 @@ class NavigationPushButton(NavigationWidget): ...@@ -99,6 +99,17 @@ class NavigationPushButton(NavigationWidget):
def text(self): def text(self):
return self._text return self._text
def setText(self, text: str):
self._text = text
self.update()
def icon(self):
return toQIcon(self._icon)
def setIcon(self, icon: Union[str, QIcon, FIF]):
self._icon = icon
self.update()
def _margins(self): def _margins(self):
return QMargins(0, 0, 0, 0) return QMargins(0, 0, 0, 0)
...@@ -133,7 +144,7 @@ class NavigationPushButton(NavigationWidget): ...@@ -133,7 +144,7 @@ class NavigationPushButton(NavigationWidget):
painter.setBrush(QColor(c, c, c, 10)) painter.setBrush(QColor(c, c, c, 10))
painter.drawRoundedRect(self.rect(), 5, 5) painter.drawRoundedRect(self.rect(), 5, 5)
drawIcon(self.icon, painter, QRectF(11.5+pl, 10, 16, 16)) drawIcon(self._icon, painter, QRectF(11.5+pl, 10, 16, 16))
# draw text # draw text
if self.isCompacted: if self.isCompacted:
...@@ -295,6 +306,10 @@ class NavigationTreeWidgetBase(NavigationWidget): ...@@ -295,6 +306,10 @@ class NavigationTreeWidgetBase(NavigationWidget):
""" """
raise NotImplementedError raise NotImplementedError
def childItems(self) -> list:
""" return child items """
raise NotImplementedError
class NavigationTreeWidget(NavigationTreeWidgetBase): class NavigationTreeWidget(NavigationTreeWidgetBase):
""" Navigation tree widget """ """ Navigation tree widget """
...@@ -346,6 +361,9 @@ class NavigationTreeWidget(NavigationTreeWidgetBase): ...@@ -346,6 +361,9 @@ class NavigationTreeWidget(NavigationTreeWidgetBase):
self.treeChildren.remove(child) self.treeChildren.remove(child)
self.vBoxLayout.removeWidget(child) self.vBoxLayout.removeWidget(child)
def childItems(self) -> list:
return self.treeChildren
def setExpanded(self, isExpanded: bool, ani=False): def setExpanded(self, isExpanded: bool, ani=False):
""" set the expanded status """ """ set the expanded status """
if isExpanded == self.isExpanded: if isExpanded == self.isExpanded:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册