fix(search-iface):解决部分搜索插件搜索结果中含有换行符时UI显示异常的问题

This commit is contained in:
iaom 2023-12-20 15:51:38 +08:00
parent 4b513cf00f
commit 9ff607afe1
7 changed files with 20 additions and 7 deletions

View File

@ -69,7 +69,7 @@ QVariant SearchResultModel::data(const QModelIndex &index, int role) const
return m_items.at(index.row()).name; return m_items.at(index.row()).name;
} }
case Qt::ToolTipRole: { case Qt::ToolTipRole: {
return m_items.at(index.row()).name; return m_items.at(index.row()).toolTip;
} }
default: default:
return QVariant(); return QVariant();

View File

@ -192,6 +192,7 @@ void AppSearchPlugin::run()
SearchPluginIface::ResultInfo ri; SearchPluginIface::ResultInfo ri;
ri.name = data.value(SearchProperty::SearchResultProperty::ApplicationLocalName).toString(); ri.name = data.value(SearchProperty::SearchResultProperty::ApplicationLocalName).toString();
ri.toolTip = ri.name;
ri.icon = IconLoader::loadIconXdg(data.value(SearchProperty::SearchResultProperty::ApplicationIconName).toString(), QIcon(":/res/icons/unknown.svg")); ri.icon = IconLoader::loadIconXdg(data.value(SearchProperty::SearchResultProperty::ApplicationIconName).toString(), QIcon(":/res/icons/unknown.svg"));
SearchPluginIface::DescriptionInfo description; SearchPluginIface::DescriptionInfo description;
description.key = QString(tr("Application Description:")); description.key = QString(tr("Application Description:"));

View File

@ -65,7 +65,8 @@ bool SearchManager::creatResultInfo(SearchPluginIface::ResultInfo &ri, const QSt
return false; return false;
} }
ri.icon = FileUtils::getFileIcon(QUrl::fromLocalFile(path).toString(), false); ri.icon = FileUtils::getFileIcon(QUrl::fromLocalFile(path).toString(), false);
ri.name = info.fileName(); ri.name = info.fileName().replace("\r", " ").replace("\n", " ");
ri.toolTip = info.fileName();
ri.description = QVector<SearchPluginIface::DescriptionInfo>() \ ri.description = QVector<SearchPluginIface::DescriptionInfo>() \
<< SearchPluginIface::DescriptionInfo{tr("Path:"), path} \ << SearchPluginIface::DescriptionInfo{tr("Path:"), path} \
<< SearchPluginIface::DescriptionInfo{tr("Modified time:"), info.lastModified().toString("yyyy/MM/dd hh:mm:ss")}; << SearchPluginIface::DescriptionInfo{tr("Modified time:"), info.lastModified().toString("yyyy/MM/dd hh:mm:ss")};

View File

@ -233,9 +233,11 @@ void NoteSearch::run() {
} }
dbusArgs.endArray(); dbusArgs.endArray();
qDebug() << str; qDebug() << str;
QString name = str.length() > 2? str.at(1) : "";
SearchPluginIface::ResultInfo ri( SearchPluginIface::ResultInfo ri(
IconLoader::loadIconQt("kylin-notebook", QIcon(":/res/icons/desktop.png")), IconLoader::loadIconQt("kylin-notebook", QIcon(":/res/icons/desktop.png")),
str.at(1), name.replace("\r", " ").replace("\n", " "),
name,
QVector<SearchPluginIface::DescriptionInfo>() << SearchPluginIface::DescriptionInfo { QVector<SearchPluginIface::DescriptionInfo>() << SearchPluginIface::DescriptionInfo {
key : QString(tr("Note Description:")), key : QString(tr("Note Description:")),
value : str.at(0) value : str.at(0)

View File

@ -20,7 +20,10 @@
#ifndef SEARCHPLUGINIFACE_H #ifndef SEARCHPLUGINIFACE_H
#define SEARCHPLUGINIFACE_H #define SEARCHPLUGINIFACE_H
#define SearchPluginIface_iid "org.ukui.ukui-search.plugin-iface.SearchPluginInterface" #define SearchPluginIface_iid "org.ukui.ukui-search.plugin-iface.SearchPluginInterface"
#define SEARCH_PLUGIN_IFACE_VERSION "1.1.0" /**
* changelog:1.2.0 toolTip
*/
#define SEARCH_PLUGIN_IFACE_VERSION "1.2.0"
#include <QString> #include <QString>
#include <QIcon> #include <QIcon>
@ -58,14 +61,19 @@ public:
{ {
QIcon icon; QIcon icon;
QString name; QString name;
QString toolTip;
QVector<DescriptionInfo> description; QVector<DescriptionInfo> description;
QString actionKey; QString actionKey;
int type; int type;
ResultInfo(const QIcon &iconToSet = QIcon(), const QString &nameToSet = QString(), ResultInfo(const QIcon &iconToSet = QIcon(),
const QString &nameToSet = QString(),
const QString &toolTipToSet = QString(),
const QVector<DescriptionInfo> &descriptionToSet = QVector<DescriptionInfo>(), const QVector<DescriptionInfo> &descriptionToSet = QVector<DescriptionInfo>(),
const QString &actionKeyToSet = QString(), const int &typeToSet = 0) { const QString &actionKeyToSet = QString(),
const int &typeToSet = 0) {
icon = iconToSet; icon = iconToSet;
name = nameToSet; name = nameToSet;
toolTip = toolTipToSet;
description = descriptionToSet; description = descriptionToSet;
actionKey = actionKeyToSet; actionKey = actionKeyToSet;
type = typeToSet; type = typeToSet;

View File

@ -459,7 +459,7 @@ void SettingsMatch::createResultInfo(SearchPluginIface::ResultInfo &resultInfo,
resultInfo.name.prepend("--"); resultInfo.name.prepend("--");
resultInfo.name.prepend(ql.language() == QLocale::English ? topInfo.at(0) : topInfo.at(1)); resultInfo.name.prepend(ql.language() == QLocale::English ? topInfo.at(0) : topInfo.at(1));
} }
resultInfo.toolTip = resultInfo.name;
resultInfo.icon = FileUtils::getSettingIcon(); resultInfo.icon = FileUtils::getSettingIcon();
resultInfo.actionKey = path.section("/", 1, 1); resultInfo.actionKey = path.section("/", 1, 1);
} }

View File

@ -50,6 +50,7 @@ void UkuiSearch::WebSearchPlugin::KeywordSearch(QString keyword, DataQueue<UkuiS
{ {
m_keyWord = keyword; m_keyWord = keyword;
ResultInfo resultInfo; ResultInfo resultInfo;
resultInfo.name = m_keyWord.replace("\r", " ").replace("\n", " ");
resultInfo.name = m_keyWord; resultInfo.name = m_keyWord;
resultInfo.type = 0; resultInfo.type = 0;