107 lines
3.6 KiB
Diff
107 lines
3.6 KiB
Diff
From fb79eb15820419ee346148abd7ce1a52d83becaf Mon Sep 17 00:00:00 2001
|
|
From: liuxinhao <liuxinhao@kylinsec.com.cn>
|
|
Date: Wed, 10 Aug 2022 14:42:05 +0800
|
|
Subject: [PATCH 1/2] fix(search): when the relevant setting interface cannot
|
|
be searched, a prompt will be added
|
|
MIME-Version: 1.0
|
|
Content-Type: text/plain; charset=UTF-8
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
- 当未能搜索到相关设置界面时加入提示。修改跳转逻辑,不通过补全直接输入并回车也可以触发跳转功能
|
|
|
|
Closes #I5H192
|
|
---
|
|
src/search-edit/search-edit.cpp | 30 +++++++++++++++++++++--
|
|
translations/kiran-control-panel.zh_CN.ts | 13 ++++++++++
|
|
2 files changed, 41 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/src/search-edit/search-edit.cpp b/src/search-edit/search-edit.cpp
|
|
index a4b9d9e..5ffcfb6 100644
|
|
--- a/src/search-edit/search-edit.cpp
|
|
+++ b/src/search-edit/search-edit.cpp
|
|
@@ -21,12 +21,14 @@
|
|
#include <QApplication>
|
|
#include <QCompleter>
|
|
#include <QEvent>
|
|
+#include <QTimer>
|
|
#include <QKeyEvent>
|
|
#include <QHBoxLayout>
|
|
#include <QLabel>
|
|
#include <QListView>
|
|
#include <QSpacerItem>
|
|
#include <QStandardItemModel>
|
|
+#include <kiran-message-box.h>
|
|
|
|
SearchEdit::SearchEdit(QWidget *parent)
|
|
: KiranSearchBox(parent)
|
|
@@ -53,17 +55,41 @@ void SearchEdit::init()
|
|
m_completer->installEventFilter(this);
|
|
|
|
setCompleter(m_completer);
|
|
-
|
|
// clang-format off
|
|
connect(m_completer, QOverload<const QModelIndex &>::of(&QCompleter::activated), [this](const QModelIndex &index) {
|
|
if( !index.isValid() )
|
|
+ {
|
|
return ;
|
|
-
|
|
+ }
|
|
QString categoryID,subItemID;
|
|
auto filterModel = m_completer->completionModel();
|
|
categoryID = filterModel->data(index,SearchModel::roleCategoryID).toString();
|
|
subItemID = filterModel->data(index,SearchModel::roleSubItemID).toString();
|
|
emit requestJumpTo(categoryID,subItemID);
|
|
+ QTimer::singleShot(0,this,&QLineEdit::clear);
|
|
+ });
|
|
+ connect(this,&QLineEdit::returnPressed,[this](){
|
|
+ QString searchkey = text();
|
|
+ if( searchkey.isEmpty() )
|
|
+ {
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ auto items = m_searchModel->findItems(searchkey);
|
|
+ if( items.isEmpty() )
|
|
+ {
|
|
+ auto clickedButton = KiranMessageBox::message(this,tr("Info"),tr("Failed to find related items, please re-enter!"),KiranMessageBox::Ok|KiranMessageBox::No);
|
|
+ if( clickedButton == KiranMessageBox::Ok )
|
|
+ clear();
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ auto item = items.at(0);
|
|
+ auto categoryID = item->data(SearchModel::roleCategoryID).toString();
|
|
+ auto subItemID = item->data(SearchModel::roleSubItemID).toString();
|
|
+ clear();
|
|
+
|
|
+ emit requestJumpTo(categoryID,subItemID);
|
|
});
|
|
// clang-format on
|
|
}
|
|
\ No newline at end of file
|
|
diff --git a/translations/kiran-control-panel.zh_CN.ts b/translations/kiran-control-panel.zh_CN.ts
|
|
index 4da29a1..8e4a4a0 100644
|
|
--- a/translations/kiran-control-panel.zh_CN.ts
|
|
+++ b/translations/kiran-control-panel.zh_CN.ts
|
|
@@ -30,4 +30,17 @@
|
|
<translation>控制面板</translation>
|
|
</message>
|
|
</context>
|
|
+<context>
|
|
+ <name>SearchEdit</name>
|
|
+ <message>
|
|
+ <location filename="../src/search-edit/search-edit.cpp" line="81"/>
|
|
+ <source>Info</source>
|
|
+ <translation>提示</translation>
|
|
+ </message>
|
|
+ <message>
|
|
+ <location filename="../src/search-edit/search-edit.cpp" line="81"/>
|
|
+ <source>Failed to find related items, please re-enter!</source>
|
|
+ <translation>未能搜索到相关项,请重新输入!</translation>
|
|
+ </message>
|
|
+</context>
|
|
</TS>
|
|
--
|
|
2.33.0
|
|
|