Merged
Conversation
Synchronize source files from linuxdeepin/dtkwidget. Source-pull-request: linuxdeepin/dtkwidget#684
Contributor
Author
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: deepin-ci-robot 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 |
Contributor
Author
deepin pr auto review我对这段代码进行审查,发现了一些可以改进的地方:
void DSearchEditPrivate::init()
{
D_Q(DSearchEdit);
label = new QLabel;
// 创建搜索按钮的辅助函数
auto createSearchIconButton = [q]() -> DIconButton* {
DIconButton *iconbtn = new DIconButton(DStyle::SP_IndicatorSearch, q); // 指定父对象
iconbtn->setFlat(true);
iconbtn->setFocusPolicy(Qt::NoFocus);
iconbtn->setAttribute(Qt::WA_TransparentForMouseEvents);
iconbtn->setAccessibleName("DSearchEditIconButton");
iconbtn->setIconSize(QSize(20, 20));
return iconbtn;
};
auto iconbtn = createSearchIconButton();
placeHolder = qApp->translate("DSearchEdit", "Search");
action = new QWidgetAction(q);
action->setObjectName("_d_search_leftAction");
auto iconAction = createSearchIconButton();
action->setDefaultWidget(iconAction);
q->lineEdit()->addAction(action, QLineEdit::LeadingPosition);
action->defaultWidget()->setVisible(false);
// ... 其余代码保持不变 ...
}
void DSearchEditPrivate::_q_toEditMode(bool focus)
{
D_Q(DSearchEdit);
// 缓存默认控件的引用
auto defaultWidget = action->defaultWidget();
auto iconWidget = q->findChild<QLabel*>("DSearchEditIcon");
auto lineEdit = q->lineEdit();
if (animation) {
// ... 其余代码保持不变,但使用缓存的引用 ...
} else {
if (focus || !lineEdit->text().isEmpty()) {
defaultWidget->setVisible(true);
iconWidget->setVisible(false);
lineEdit->setPlaceholderText(placeholderText);
} else {
defaultWidget->setVisible(false);
iconWidget->setVisible(true);
lineEdit->setPlaceholderText(QString());
}
}
}
这些改进可以提高代码的可维护性、性能和安全性,同时保持原有功能不变。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Synchronize source files from linuxdeepin/dtkwidget.
Source-pull-request: linuxdeepin/dtkwidget#684