fix: disable copy/cut and block undo/redo in DPasswordEdit#753
fix: disable copy/cut and block undo/redo in DPasswordEdit#75318202781743 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Sorry @18202781743, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
c87f354 to
174b178
Compare
bf32ffa to
d265184
Compare
cfe4608 to
2fe777e
Compare
deepin pr auto review★ 总体评分:70分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 diff --git a/src/widgets/dpasswordedit.cpp b/src/widgets/dpasswordedit.cpp
--- a/src/widgets/dpasswordedit.cpp
+++ b/src/widgets/dpasswordedit.cpp
@@ -140,49 +140,51 @@ bool DPasswordEdit::eventFilter(QObject* watcher, QEvent* event)
}
}
#endif
if (watcher == lineEdit() && event->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
if (keyEvent->matches(QKeySequence::Undo)
|| keyEvent->matches(QKeySequence::Redo)) {
return true;
}
}
if (watcher == lineEdit() && event->type() == QEvent::ContextMenu) {
QMenu *menu = lineEdit()->createStandardContextMenu();
if (!menu)
return DLineEdit::eventFilter(watcher, event);
+ menu->setAttribute(Qt::WA_DeleteOnClose);
+
for (QAction *action : menu->actions()) {
const auto &text = action->text();
if (text.startsWith(QLineEdit::tr("&Undo"))
|| text.startsWith(QLineEdit::tr("&Redo"))) {
action->setEnabled(false);
}
if (text.startsWith(QLineEdit::tr("Cu&t")) && !cutEnabled()) {
action->setEnabled(false);
}
if (text.startsWith(QLineEdit::tr("&Copy")) && !copyEnabled()) {
action->setEnabled(false);
}
if (text.startsWith(QLineEdit::tr("&Paste")) && !pasteEnabled()) {
action->setEnabled(false);
}
}
menu->popup(static_cast<QContextMenuEvent *>(event)->globalPos());
event->accept();
lineEdit()->setFocus();
return true;
}
return DLineEdit::eventFilter(watcher, event);
} |
|
需要兼容qt5和qt6,qt5上没设置objectName,无法区分,只能通过text来区分, |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 18202781743, BLumia, robertkill The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Default-disable copy/cut for security, intercept undo/redo shortcuts and context menu actions to prevent password leakage. DPasswordEdit构造时默认禁用复制、剪切功能,拦截撤消、重做快捷键及右键菜单项,防止密码信息泄露。 Log: DPasswordEdit禁用复制粘贴及撤销重做,防止密码泄露 PMS: TASK-392179 Influence: DPasswordEdit密文明文均禁止复制粘贴和撤销重做,提升密码输入安全性。
2fe777e to
202b913
Compare
DPasswordEdit构造时默认禁用复制、剪切功能,并拦截撤消、重做快捷键,防止密码信息泄露。
Log: DPasswordEdit禁用复制粘贴及撤销重做快捷操作
PMS: TASK-392179