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;
}
case Qt::ToolTipRole: {
return m_items.at(index.row()).name;
return m_items.at(index.row()).toolTip;
}
default:
return QVariant();

View File

@ -192,6 +192,7 @@ void AppSearchPlugin::run()
SearchPluginIface::ResultInfo ri;
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"));
SearchPluginIface::DescriptionInfo description;
description.key = QString(tr("Application Description:"));

View File

@ -65,7 +65,8 @@ bool SearchManager::creatResultInfo(SearchPluginIface::ResultInfo &ri, const QSt
return 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>() \
<< SearchPluginIface::DescriptionInfo{tr("Path:"), path} \
<< 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();
qDebug() << str;
QString name = str.length() > 2? str.at(1) : "";
SearchPluginIface::ResultInfo ri(
IconLoader::loadIconQt("kylin-notebook", QIcon(":/res/icons/desktop.png")),
str.at(1),
name.replace("\r", " ").replace("\n", " "),
name,
QVector<SearchPluginIface::DescriptionInfo>() << SearchPluginIface::DescriptionInfo {
key : QString(tr("Note Description:")),
value : str.at(0)

View File

@ -20,7 +20,10 @@
#ifndef SEARCHPLUGINIFACE_H
#define SEARCHPLUGINIFACE_H
#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 <QIcon>
@ -58,14 +61,19 @@ public:
{
QIcon icon;
QString name;
QString toolTip;
QVector<DescriptionInfo> description;
QString actionKey;
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 QString &actionKeyToSet = QString(), const int &typeToSet = 0) {
const QString &actionKeyToSet = QString(),
const int &typeToSet = 0) {
icon = iconToSet;
name = nameToSet;
toolTip = toolTipToSet;
description = descriptionToSet;
actionKey = actionKeyToSet;
type = typeToSet;

View File

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

View File

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