124 lines
3.3 KiB
Python
124 lines
3.3 KiB
Python
|
|
"""
|
||
|
|
需求列表项组件
|
||
|
|
"""
|
||
|
|
from PyQt5.QtWidgets import QWidget, QHBoxLayout, QVBoxLayout, QLabel, QCheckBox
|
||
|
|
from PyQt5.QtCore import Qt
|
||
|
|
|
||
|
|
|
||
|
|
class RequirementItemWidget(QWidget):
|
||
|
|
"""需求列表项组件"""
|
||
|
|
|
||
|
|
def __init__(self, requirement, parent=None):
|
||
|
|
"""
|
||
|
|
初始化需求列表项
|
||
|
|
|
||
|
|
Args:
|
||
|
|
requirement: 需求对象
|
||
|
|
parent: 父组件
|
||
|
|
"""
|
||
|
|
super().__init__(parent)
|
||
|
|
self.requirement = requirement
|
||
|
|
self._setup_ui()
|
||
|
|
|
||
|
|
def _setup_ui(self):
|
||
|
|
"""设置UI"""
|
||
|
|
layout = QHBoxLayout(self)
|
||
|
|
layout.setContentsMargins(10, 10, 10, 10)
|
||
|
|
layout.setSpacing(10)
|
||
|
|
|
||
|
|
# 复选框
|
||
|
|
checkbox = QCheckBox()
|
||
|
|
checkbox.setChecked(self.requirement.checked)
|
||
|
|
checkbox.stateChanged.connect(
|
||
|
|
lambda state: setattr(self.requirement, 'checked', state == Qt.Checked)
|
||
|
|
)
|
||
|
|
layout.addWidget(checkbox)
|
||
|
|
|
||
|
|
# 内容区域
|
||
|
|
content_layout = QVBoxLayout()
|
||
|
|
content_layout.setSpacing(5)
|
||
|
|
|
||
|
|
# 标题行
|
||
|
|
title_layout = QHBoxLayout()
|
||
|
|
title_layout.setSpacing(10)
|
||
|
|
|
||
|
|
# 需求标题
|
||
|
|
title_label = QLabel(f"{self.requirement.req_id} {self.requirement.title}")
|
||
|
|
title_label.setStyleSheet("""
|
||
|
|
font-weight: bold;
|
||
|
|
color: #60a5fa;
|
||
|
|
""")
|
||
|
|
title_layout.addWidget(title_label)
|
||
|
|
|
||
|
|
title_layout.addStretch()
|
||
|
|
|
||
|
|
# 置信度标签
|
||
|
|
confidence_label = self._create_confidence_label()
|
||
|
|
title_layout.addWidget(confidence_label)
|
||
|
|
|
||
|
|
# 优先级标签
|
||
|
|
priority_label = self._create_priority_label()
|
||
|
|
title_layout.addWidget(priority_label)
|
||
|
|
|
||
|
|
content_layout.addLayout(title_layout)
|
||
|
|
|
||
|
|
# 需求描述
|
||
|
|
desc_label = QLabel(self.requirement.description)
|
||
|
|
desc_label.setStyleSheet("""
|
||
|
|
color: #94a3b8;
|
||
|
|
font-size: 12px;
|
||
|
|
""")
|
||
|
|
desc_label.setWordWrap(True)
|
||
|
|
content_layout.addWidget(desc_label)
|
||
|
|
|
||
|
|
layout.addLayout(content_layout)
|
||
|
|
|
||
|
|
# 设置整体样式
|
||
|
|
self.setStyleSheet("""
|
||
|
|
QWidget {
|
||
|
|
background: rgba(51, 65, 85, 0.3);
|
||
|
|
border: 1px solid rgba(59, 130, 246, 0.15);
|
||
|
|
border-radius: 6px;
|
||
|
|
}
|
||
|
|
""")
|
||
|
|
|
||
|
|
def _create_confidence_label(self) -> QLabel:
|
||
|
|
"""创建置信度标签"""
|
||
|
|
confidence = self.requirement.confidence
|
||
|
|
|
||
|
|
if confidence >= 90:
|
||
|
|
color = "#10b981"
|
||
|
|
elif confidence >= 70:
|
||
|
|
color = "#f59e0b"
|
||
|
|
else:
|
||
|
|
color = "#ef4444"
|
||
|
|
|
||
|
|
label = QLabel(f"{confidence}%")
|
||
|
|
label.setStyleSheet(f"""
|
||
|
|
background: {color}33;
|
||
|
|
color: {color};
|
||
|
|
border: 1px solid {color};
|
||
|
|
border-radius: 4px;
|
||
|
|
padding: 2px 6px;
|
||
|
|
font-size: 11px;
|
||
|
|
""")
|
||
|
|
|
||
|
|
return label
|
||
|
|
|
||
|
|
def _create_priority_label(self) -> QLabel:
|
||
|
|
"""创建优先级标签"""
|
||
|
|
priority = self.requirement.priority
|
||
|
|
color = "#f59e0b" if priority == "高" else "#3b82f6"
|
||
|
|
|
||
|
|
label = QLabel(f"{priority}优先级")
|
||
|
|
label.setStyleSheet(f"""
|
||
|
|
background: {color}33;
|
||
|
|
color: {color};
|
||
|
|
border: 1px solid {color};
|
||
|
|
border-radius: 4px;
|
||
|
|
padding: 2px 6px;
|
||
|
|
font-size: 11px;
|
||
|
|
""")
|
||
|
|
|
||
|
|
return label
|