fix:Sets polyphonic and English questions when searching
This commit is contained in:
parent
0d2785eb49
commit
c76c501c18
|
@ -33,7 +33,6 @@ SettingsMatch::SettingsMatch(QObject *parent) : QObject(parent)
|
|||
*/
|
||||
QStringList SettingsMatch::startMatchApp(const QString &source){
|
||||
m_sourceText=source;
|
||||
// qDebug()<<m_sourceText;
|
||||
QStringList settingList=matching();
|
||||
return settingList;
|
||||
}
|
||||
|
@ -43,9 +42,8 @@ QStringList SettingsMatch::startMatchApp(const QString &source){
|
|||
* 将xml文件内容读到内存
|
||||
*/
|
||||
void SettingsMatch::xmlElement(){
|
||||
QString pinyinIndex;
|
||||
QString ChineseIndex;
|
||||
|
||||
QString EnglishIndex;
|
||||
QFile file(QString::fromLocal8Bit("/usr/share/ukui-control-center/shell/res/search.xml"));
|
||||
if (!file.open(QIODevice::ReadOnly)){
|
||||
return;
|
||||
|
@ -60,36 +58,27 @@ void SettingsMatch::xmlElement(){
|
|||
QDomElement element=node.toElement();
|
||||
QString key=element.attribute("name");;
|
||||
m_chine_searchResult=m_chine_searchList.value(key);
|
||||
m_pinyin_searchResult=m_pinyin_searchList.value(key);
|
||||
m_English_searchResult=m_English_searchList.value(key);
|
||||
QDomNodeList list=element.childNodes();
|
||||
for(int i=0;i<list.count();++i){
|
||||
QDomNode n=list.at(i);
|
||||
|
||||
if(n.nodeName()==QString::fromLocal8Bit("pinyinPlugin")){
|
||||
pinyinIndex=n.toElement().text();
|
||||
}
|
||||
if(n.nodeName()==QString::fromLocal8Bit("pinyinfunc")){
|
||||
pinyinIndex+=QString::fromLocal8Bit("/")+n.toElement().text();
|
||||
m_pinyin_searchResult.append(pinyinIndex);
|
||||
}
|
||||
|
||||
if(n.nodeName()==QString::fromLocal8Bit("ChinesePlugin")){
|
||||
ChineseIndex=n.toElement().text();
|
||||
}
|
||||
if(n.nodeName()==QString::fromLocal8Bit("ChineseFunc")){
|
||||
ChineseIndex+=QString::fromLocal8Bit("/")+n.toElement().text();
|
||||
|
||||
m_chine_searchResult.append(ChineseIndex);
|
||||
m_chine_searchResult.append(ChineseIndex);
|
||||
}
|
||||
if(n.nodeName()==QString::fromLocal8Bit("EnglishFunc")){
|
||||
EnglishIndex=QString::fromLocal8Bit("/")+n.toElement().text();
|
||||
m_English_searchResult.append(EnglishIndex);
|
||||
}
|
||||
}
|
||||
m_pinyin_searchList.insert(key,m_pinyin_searchResult);
|
||||
m_chine_searchList.insert(key,m_chine_searchResult);
|
||||
|
||||
m_English_searchList.insert(key,m_English_searchResult);
|
||||
node=node.nextSibling();
|
||||
}
|
||||
file.close();
|
||||
// qDebug()<<pinyin_searchlist;
|
||||
// qDebug()<<chine_searchlist;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -101,35 +90,61 @@ QStringList SettingsMatch::matching(){
|
|||
QStringList returnresult;
|
||||
QStringList regmatch;
|
||||
QString key;
|
||||
QStringList pinyinlist;
|
||||
QMap<QString, QStringList>::const_iterator i;
|
||||
for(i=m_chine_searchList.constBegin();i!=m_chine_searchList.constEnd();++i){
|
||||
regmatch=*i;
|
||||
key=i.key();
|
||||
// qDebug()<<key;
|
||||
for(int t=0; t<regmatch.size();t++)
|
||||
{
|
||||
if(m_sourceText=="/")
|
||||
continue;
|
||||
QString str =regmatch.at(t);
|
||||
if(str.contains(m_sourceText))
|
||||
QLocale ql;
|
||||
if(ql.language()==QLocale::Chinese){
|
||||
for(i=m_chine_searchList.constBegin();i!=m_chine_searchList.constEnd();++i){
|
||||
regmatch=*i;
|
||||
key=i.key();
|
||||
for(int t=0; t<regmatch.size();t++)
|
||||
{
|
||||
str=key+"/"+str;
|
||||
returnresult.append(str);//中文名
|
||||
continue;
|
||||
if(m_sourceText=="/")
|
||||
continue;
|
||||
QString str =regmatch.at(t);
|
||||
pinyinlist=FileUtils::findMultiToneWords(str);
|
||||
if(str.contains(m_sourceText))
|
||||
{
|
||||
str=key+"/"+str;
|
||||
returnresult.append(str);//中文名
|
||||
continue;
|
||||
}
|
||||
for(int i = 0;i<pinyinlist.size()/2;i++){
|
||||
str =regmatch.at(t);
|
||||
QString shouzimu=pinyinlist.at(2*i+1); // 中文转首字母
|
||||
if(shouzimu.contains(m_sourceText,Qt::CaseInsensitive)){
|
||||
str=key+"/"+str;
|
||||
returnresult.append(str);
|
||||
break;
|
||||
}
|
||||
if(m_sourceText.size()<2)
|
||||
break;
|
||||
QString pinyin=pinyinlist.at(2*i);// 中文转拼音
|
||||
if(pinyin.contains(m_sourceText,Qt::CaseInsensitive)){
|
||||
str=key+"/"+str;
|
||||
returnresult.append(str);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
if(ql.language()==QLocale::English){
|
||||
for(i=m_English_searchList.constBegin();i!=m_English_searchList.constEnd();++i){
|
||||
regmatch=*i;
|
||||
key=i.key();
|
||||
for(int t=0; t<regmatch.size();t++)
|
||||
{
|
||||
if(m_sourceText=="/")
|
||||
continue;
|
||||
QString str =regmatch.at(t);
|
||||
if(str.contains(m_sourceText,Qt::CaseInsensitive)){
|
||||
str=key+"/"+str;
|
||||
returnresult.append(str);
|
||||
}
|
||||
}
|
||||
QString shouzimu=FileUtils::findMultiToneWords(str).at(1);// 中文转首字母
|
||||
if(shouzimu.contains(m_sourceText,Qt::CaseInsensitive)){
|
||||
str=key+"/"+str;
|
||||
returnresult.append(str);
|
||||
continue;
|
||||
}
|
||||
QString pinyin=FileUtils::findMultiToneWords(str).at(0);// 中文转拼音
|
||||
if(pinyin.contains(m_sourceText,Qt::CaseInsensitive)){
|
||||
str=key+"/"+str;
|
||||
returnresult.append(str);
|
||||
}
|
||||
}
|
||||
}
|
||||
// qDebug()<<returnresult;
|
||||
return returnresult;
|
||||
}
|
||||
|
|
|
@ -42,10 +42,10 @@ private:
|
|||
QStringList matching();
|
||||
|
||||
private:
|
||||
QMap<QString,QStringList> m_pinyin_searchList;
|
||||
QMap<QString,QStringList> m_chine_searchList;
|
||||
QStringList m_pinyin_searchResult;
|
||||
QMap<QString,QStringList> m_English_searchList;
|
||||
QStringList m_chine_searchResult;
|
||||
QStringList m_English_searchResult;
|
||||
QString m_sourceText;
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue