File: searchwidget.cpp

package info (click to toggle)
ukui-control-center 3.22.1.29-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 42,420 kB
  • sloc: cpp: 77,963; xml: 2,408; sh: 30; makefile: 4
file content (675 lines) | stat: -rw-r--r-- 27,611 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
/*
 * Copyright (C) 2023, KylinSoft Co., Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 *
**/
#include "searchwidget.h"
#include "pinyin.h"
#include "homepagewidget.h"

#include <QDebug>
#include <QKeyEvent>
#include <QLineEdit>
#include <QListWidget>
#include <QPushButton>
#include <QXmlStreamReader>
#include <QCompleter>
#include <QRegularExpression>
#include <mainwindow.h>
#include "utils/modulefactory.h"

extern "C" {
#include <glib.h>
}

const QStringList filterPathList = { "/Display/Auto Brightness"};

const QStringList yangtzeFilterPathList = {"/Shortcut/Add", "/Shortcut/Customize Shortcut",
                                          "/Display/Color Temperature And Eye Care", "/Display/Eye protection mode"};

const QStringList nileFilterPathList = {"/Display/Night Mode"};

const QStringList tabletFilterPathList = {"/Display/Color Temperature And Eye Care", "/Display/Eye protection mode"};

SearchWidget::SearchWidget(QWidget *parent)
    : KSearchLineEdit(parent)
    , m_xmlExplain("")
    , m_bIsChinese(false)
    , m_searchValue("")
    , m_bIstextEdited(false)
{
    initExcludeSearch();
    m_model = new QStandardItemModel(this);
    m_completer = this->completer();
    this->completer()->setModel(m_model);
    QAbstractItemView *popup = m_completer->popup();
    this->reloadStyle();
    this->setClearButtonEnabled(true);
    m_completer->popup()->setAttribute(Qt::WA_InputMethodEnabled);
    m_completer->setFilterMode(Qt::MatchContains);//设置QCompleter支持匹配字符搜索
    m_completer->setCaseSensitivity(Qt::CaseInsensitive);//这个属性可设置进行匹配时的大小写敏感性
    m_completer->setCompletionRole(Qt::UserRole); //设置ItemDataRole
    m_completer->setWrapAround(false);

    connect(this, &QLineEdit::textEdited, this, [ = ] {
        if (text() != "") {
            m_bIstextEdited = true;
        } else {
            m_bIstextEdited = false;
        }
    });

    connect(this, &QLineEdit::textChanged, this, [ = ] {
        QString retValue = text();

        if (popup->model()->rowCount() == 0) {
            UkccCommon::buriedSettings(QString("SearchWidget"), nullptr, QString("No search results"), retValue);
            if (m_model->data(m_model->index(m_model->rowCount() - 1, 0)) != tr("No search results"))
                m_model->appendRow(new QStandardItem(tr("No search results")));
            m_model->setData(m_model->index(m_model->rowCount() - 1, 0), text(), Qt::UserRole);
            m_completer->setCompletionRole(Qt::UserRole);

        } else {
            if (!m_bIsChinese)
                m_completer->setCompletionRole(Qt::DisplayRole);
            if (m_model->data(m_model->index(m_model->rowCount() - 1, 0)) == tr("No search results")) {
                UkccCommon::buriedSettings(QString("SearchWidget"), nullptr, QString("No search results"), retValue);
                while (m_model->data(m_model->index(m_model->rowCount() - 1, 0)) == tr("No search results")) {
                    m_model->clearItemData(m_model->index(m_model->rowCount() - 1, 0));
                    m_model->removeRow(m_model->rowCount() - 1);
                }
                if (popup->model()->rowCount() == 0) {
                    m_model->appendRow(new QStandardItem(tr("No search results")));
                    m_model->setData(m_model->index(m_model->rowCount() - 1, 0), text(), Qt::UserRole);
                    m_completer->setCompletionRole(Qt::UserRole);
                }
            }
        }

        if (m_bIstextEdited) {
            m_bIstextEdited = false;
            return ;
        }

        //避免输入单个字符,直接匹配到第一个完整字符(导致不能匹配正确的字符)
        if ("" == retValue || m_searchValue.contains(retValue, Qt::CaseInsensitive)) {
            m_searchValue = retValue;
            return ;
        }

        retValue = transPinyinToChinese(text());

        //拼音转化没找到,再搜索字符包含关联字符
        if (retValue == text()) {
            retValue = containTxtData(retValue);
        }

        m_searchValue = retValue;

        this->setText(retValue);
    });

    connect(this, &QLineEdit::returnPressed, this, [ = ] {

        if (!text().isEmpty()) {
            //enter defalt set first
            if (!jumpContentPathWidget(text())) {
                const QString &currentCompletion = this->completer()->currentCompletion();
                qDebug() << Q_FUNC_INFO << " [SearchWidget] currentCompletion : " << currentCompletion;

                //中文遍历一遍,若没有匹配再遍历将拼音转化为中文再遍历
                //解决输入拼音时,有配置数据后,直接回车无法进入第一个匹配数据页面的问题
                if (!jumpContentPathWidget(currentCompletion)) {
                    jumpContentPathWidget(transPinyinToChinese(currentCompletion));
                }
            }
        }
    });
#if QT_VERSION <= QT_VERSION_CHECK(5, 12, 0)
    connect(m_completer, static_cast<void(QCompleter::*)(const QString &)>(&QCompleter::activated),
            [=](const QString &text) {
#else
    //鼠标点击后直接页面跳转(https://doc.qt.io/qt-5/qcompleter.html#activated-1)
    connect(m_completer, QOverload<const QString &>::of(&QCompleter::activated),
            [=](const QString &text) {
#endif
        Q_UNUSED(text);
        Q_EMIT returnPressed();
    });
}

SearchWidget::~SearchWidget() {

}

bool SearchWidget::jumpContentPathWidget(QString path) {
    qDebug() << Q_FUNC_INFO << path;
    bool bResult = false;

    if (m_EnterNewPagelist.count() > 0) {
        SearchBoxStruct data = getModuleBtnString(path);
        if (data.translateContent != "" && data.fullPagePath != "") {
            for (int i = 0; i < m_EnterNewPagelist.count(); i++) {
                if (m_EnterNewPagelist[i].translateContent == data.fullPagePath) {//getModuleBtnString解析SearchBoxStruct.fullPagePath,满足此处判断
#if DEBUG_XML_SWITCH
                    qDebug() << " [SearchWidget] m_EnterNewPagelist[i].translateContent : " << m_EnterNewPagelist[i].translateContent << " , fullPagePath : " << m_EnterNewPagelist[i].fullPagePath << " , actualModuleName: " << m_EnterNewPagelist[i].actualModuleName;
                    qDebug() << " [SearchWidget] data.translateContent : " << data.translateContent << " , data.fullPagePath : " << data.fullPagePath << " , data.actualModuleName: " << data.actualModuleName;
#endif
                    //the data.actualModuleName had translate to All lowercase
                    qDebug() <<" actulaModuleName is:" << data.translateContent << " " << m_EnterNewPagelist[i].fullPagePath << m_EnterNewPagelist[i].fullPagePath.section('/', 1, 1);
                    Q_EMIT notifyModuleSearch(data.translateContent, m_EnterNewPagelist[i].fullPagePath.section('/', 1, 1), data.fullPagePath);//fullPagePath need delete moduleName
                    bResult = true;

                    // 埋点搜索插件
                    UkccCommon::buriedSettings(QString("SearchWidget"), nullptr, QString("search"), m_EnterNewPagelist[i].fullPagePath);

                    break;
                }
            }
        } else {
            qWarning() << "[SearchWidget] translateContent : " << data.translateContent << " , fullPagePath : " << data.fullPagePath;
        }
    } else {
        qWarning() << " [SearchWidget] QList is nullptr.";
    }

    return bResult;
}

void SearchWidget::loadxml() {
    if (!m_EnterNewPagelist.isEmpty()) {
        m_EnterNewPagelist.clear();
        searchItemList.clear();
        searchMap.clear();
    }

    if (!m_inputList.isEmpty()) {
        m_inputList.clear();
    }

    if (m_model->rowCount() > 0) {
        QStandardItem *item = nullptr;
        for (int i = 0; i < m_model->rowCount(); i++) {
            item = m_model->takeItem(i);
            delete item;
            item = nullptr;
        }
        m_model->clear();
    }

    //添加一项空数据,为了防止使用setText输入错误数据时直接跳转到list中正确的第一个页面
    m_searchBoxStruct.fullPagePath = "";
    m_searchBoxStruct.actualModuleName = "";
    m_searchBoxStruct.translateContent = "";
    m_searchBoxStruct.childPageName = "";
    m_EnterNewPagelist.append(m_searchBoxStruct);
    m_inputList.append(SearchDataStruct());
    m_model->appendRow(new QStandardItem(""));

    auto isChineseFunc = [](const QString &str)->bool {
        QRegularExpression rex_expression(R"(^[^a-zA-Z]+$)");
        return rex_expression.match(str).hasMatch();
    };

    QJsonArray searchItems;
    QJsonObject rootobj;

    for (const QString i : m_xmlFilePath) {

        QString xmlPath = i.arg(m_lang);
        QFile file(xmlPath);

        if (!file.exists()) {
            qWarning() << " [SearchWidget] File not exist";
            continue;
        }

        if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
            qWarning() << " [SearchWidget] File open failed";
            continue;
        }

        QXmlStreamReader xmlRead(&file);
        QStringRef dataName;
        QXmlStreamReader::TokenType type = QXmlStreamReader::Invalid;

        //遍历XML文件,读取每一行的xml数据都会
        //先进入StartElement读取出<>中的内容;
        //再进入Characters读取出中间数据部分;
        //最后进入时进入EndElement读取出</>中的内容
        while (!xmlRead.atEnd()) {
            type = xmlRead.readNext();

            switch (type) {
            case QXmlStreamReader::StartElement:
                m_xmlExplain = xmlRead.name().toString();
                break;
            case QXmlStreamReader::Characters:
                if (!xmlRead.isWhitespace()) {
                    if (m_xmlExplain == XML_Source) { // get xml source date

                        m_searchBoxStruct.translateContent = xmlRead.text().toString();

                    } else if (m_xmlExplain == XML_Title) {
                        if (xmlRead.text().toString() != "") // translation not nullptr can set it
                            m_searchBoxStruct.translateContent = xmlRead.text().toString();
                    } else if (m_xmlExplain == XML_Numerusform) {
                        if (xmlRead.text().toString() != "") // translation not nullptr can set it
                            m_searchBoxStruct.translateContent = xmlRead.text().toString();
                    } else if (m_xmlExplain == XML_Explain_Path) {
                        m_searchBoxStruct.fullPagePath = xmlRead.text().toString();

                        // openkylin yangtze 过滤掉的搜索项
                        if (UkccCommon::isOpenkylin() && yangtzeFilterPathList.contains(m_searchBoxStruct.fullPagePath)) {
                            continue;
                        }

                        // openkylin Nile 过滤掉的搜索项
                        if (UkccCommon::isOpenkylinNile() && nileFilterPathList.contains(m_searchBoxStruct.fullPagePath)) {
                            continue;
                        }

                        // xc 平板 过滤掉的搜索项
                        if (!UkccCommon::isOpenkylinNile() && !UkccCommon::isOpenkylin() && tabletFilterPathList.contains(m_searchBoxStruct.fullPagePath)) {
                            continue;
                        }

#ifndef MAVIS
                        // 非mavis搜索词过滤
                        if (filterPathList.contains(m_searchBoxStruct.fullPagePath)) {
                            continue;
                        }
#endif

                        // follow path module name to get actual module name  ->  Left module dispaly can support
                        // mulLanguages
                        m_searchBoxStruct.actualModuleName =
                                getModulesName(m_searchBoxStruct.fullPagePath.section('/', 1, 1));

                        // 插件不存在,跳过该插件的搜索项
                        if ( m_searchBoxStruct.actualModuleName.isEmpty())
                            continue;

                        if (!isChineseFunc(m_searchBoxStruct.translateContent)) {
                            if (!m_TxtList.contains(m_searchBoxStruct.translateContent)) {
                                m_TxtList.append(m_searchBoxStruct.translateContent);
                            }
                        }

                        if ((!g_file_test("/usr/sbin/ksc-defender", G_FILE_TEST_EXISTS) && m_searchBoxStruct.fullPagePath.contains("securitycenter",Qt::CaseInsensitive))
                                || (!UkccCommon::isCommunity() && m_searchBoxStruct.fullPagePath.contains("update")) ) {
                            break;
                        }
#ifndef __sw_64__
                        if(m_searchBoxStruct.fullPagePath.contains("Change valid",Qt::CaseInsensitive)) {
                            break;
                        }
#endif
                        m_EnterNewPagelist.append(m_searchBoxStruct);
                        searchItemList.append(m_searchBoxStruct);

                        // Add search result content
                        if (!m_bIsChinese) {
                            if ("" == m_searchBoxStruct.childPageName) {
                                m_model->appendRow(new QStandardItem(
                                        QString("%1 --> %2")
                                                .arg(m_searchBoxStruct.actualModuleName)
                                                .arg(m_searchBoxStruct.translateContent)));
                            } else {
                                m_model->appendRow(new QStandardItem(
                                        QString("%1 --> %2 / %3")
                                                .arg(m_searchBoxStruct.actualModuleName)
                                                .arg(m_searchBoxStruct.childPageName)
                                                .arg(m_searchBoxStruct.translateContent)));
                            }
                        } else {
                            appendChineseData(m_searchBoxStruct);
                        }
                        QJsonObject bodyJson;
                        QString pluginName = m_searchBoxStruct.fullPagePath.section('/', 1, 1);
                        bodyJson.insert("plugin", pluginName);
                        bodyJson.insert("plugin" + m_lang, m_searchBoxStruct.actualModuleName);
                        bodyJson.insert("subEnglish", m_searchBoxStruct.fullPagePath.section('/', 2, 2));
                        bodyJson.insert("sub" + m_lang, m_searchBoxStruct.translateContent);
                        bodyJson.insert("superordinate", ModulesFactory::getModuleNamebyName(pluginName));
                        searchItems.append(bodyJson);
                        clearSearchData();
                    } else {
                        // donthing
                    }
                } else {
                    // qDebug() << "  QXmlStreamReader::Characters with whitespaces.";
                }
                break;
            case QXmlStreamReader::EndElement:
#if DEBUG_XML_SWITCH
                qDebug() << " [SearchWidget] -::EndElement: " << xmlRead.name();
#endif
                // if (m_xmlExplain != "") {
                //     m_xmlExplain = "";
                // }
                break;
            default:
                break;
            }
        }

        m_xmlExplain = "";
        clearSearchData();
        qDebug() << " [SearchWidget] m_EnterNewPagelist.count : " << m_EnterNewPagelist.count();

        file.close();
    }
    rootobj.insert("ukcc", searchItems);
    searchMap = rootobj.toVariantMap();
}

//Follow display content to Analysis SearchBoxStruct data
SearchWidget::SearchBoxStruct SearchWidget::getModuleBtnString(QString value) {
    SearchBoxStruct data;

    data.translateContent = value.section('-', 0, 1).remove('-').trimmed();
    //follow actual module name to get path module name
    data.actualModuleName = getModulesName(data.translateContent, false);
    data.fullPagePath = value.section('>', 1, -1).remove('>').trimmed();

    if (data.fullPagePath.contains('/', Qt::CaseInsensitive)) {
        data.fullPagePath = data.fullPagePath.section('/', 0, 0).remove('/').trimmed();
    }

#if DEBUG_XML_SWITCH
    qDebug() << Q_FUNC_INFO << " [SearchWidget] data.translateContent : " << data.translateContent << "   ,  data.fullPagePath : " << data.fullPagePath;
#endif

    return data;
}

QVariantMap SearchWidget::getSearchItems() {
    return searchMap;
}

void SearchWidget::updateSearchItem(QString plugin_name, bool show,
                                    SearchWidget::SearchBoxStruct *data) {
    if (show && data == nullptr) {
        return;
    }
    if (data != nullptr) {
        searchItemList.append(*data);
    }
    for (int index = 0; index < searchItemList.size() && data == nullptr;) {
        QString pluginName = searchItemList.at(index).actualModuleName;
        if (pluginName.contains(plugin_name)) {
            searchItemList.removeAt(index);
        } else {
            ++index;
        }
    }
    QJsonArray searchItems;
    QJsonObject rootobj;
    for (auto &searchItem: searchItemList) {
        QJsonObject bodyJson;
        QString pluginName = searchItem.fullPagePath.section('/', 1, 1);
        bodyJson.insert("plugin", pluginName);
        bodyJson.insert("plugin" + m_lang, searchItem.actualModuleName);
        bodyJson.insert("subEnglish", searchItem.fullPagePath.section('/', 2, 2));
        bodyJson.insert("sub" + m_lang, searchItem.translateContent);
        bodyJson.insert("superordinate", ModulesFactory::getModuleNamebyName(pluginName));
        searchItems.append(bodyJson);
    }
    rootobj.insert("ukcc", searchItems);
    QJsonDocument document;
    document.setObject(rootobj);
    QByteArray byteArray = document.toJson(QJsonDocument::Indented);
    QString strJson(byteArray);
    searchMap = rootobj.toVariantMap();
}

//tranlate the path name to tr("name")
QString SearchWidget::getModulesName(QString name, bool state) {
    QString strResult = "";

    for (auto it : m_moduleNameList) {
        if (state) { //true : follow first search second (use pathName translate to actual moduleName)
            if (it.first == name) {
                strResult = it.second;
                break;
            }
        } else { //false : follow second search first (use actual moduleName translate to pathName)
            if (it.second == name) {
                strResult = it.first;
                break;
            }
        }
    }

    return strResult;
}

QString SearchWidget::removeDigital(QString input) {
    if ("" == input)
        return "";

    QString value = "";
    QByteArray ba = input.toLocal8Bit();
    char *data = nullptr;
    data = ba.data();
    while (*data) {
        if (!(*data >= '0' && *data <= '9')) {
            value += *data;
        }
        data++;
    }

    return value;
}

QString SearchWidget::transPinyinToChinese(QString pinyin) {
    QString value = pinyin;

    //遍历"汉字-拼音"列表,将存在的"拼音"转换为"汉字"
    for (auto data : m_inputList) {
        if (value == data.pinyin) {
            value = data.chiese;
            break;
        }
    }

    return value;
}

QString SearchWidget::containTxtData(QString txt) {
    QString value = txt;

    //遍历"汉字-拼音"列表,将存在的"拼音"转换为"汉字"
    for (auto data : m_inputList) {
        if (data.chiese.contains(txt, Qt::CaseInsensitive) ||
               data.pinyin.contains(txt, Qt::CaseInsensitive)) {
            value = data.chiese;
            break;
        }
    }

    return value;
}

void SearchWidget::appendChineseData(SearchWidget::SearchBoxStruct data) {
    if ("" == data.childPageName) {
        //先添加使用appenRow添加Qt::EditRole数据(用于下拉框显示),然后添加Qt::UserRole数据(用于输入框搜索)
        //Qt::EditRole数据用于显示搜索到的结果(汉字)
        //Qt::UserRole数据用于输入框输入的数据(拼音/汉字 均可)
        //即在输入框搜索Qt::UserRole的数据,就会在下拉框显示Qt::EditRole的数据
        m_model->appendRow(new QStandardItem(//icon.value(),
                                             QString("%1 --> %2").arg(data.actualModuleName).arg(data.translateContent)));

        //设置汉字的Qt::UserRole数据
        m_model->setData(m_model->index(m_model->rowCount() - 1, 0),
                         QString("%1 --> %2")
                         .arg(data.actualModuleName)
                         .arg(data.translateContent),
                         Qt::UserRole);

        QString hanziTxt = QString("%1 --> %2").arg(data.actualModuleName).arg(data.translateContent);

        for (auto datas : m_TxtList) {
            for (int i = 0; i < datas.count(); i++) {
                if( data.translateContent == datas){
                    return;
                }
            }
        }

        QString pinyinTxt = QString("%1 --> %2")
                            .arg(removeDigital(Chinese2Pinyin(data.actualModuleName)))
                            .arg(removeDigital(Chinese2Pinyin(data.translateContent)));

        //添加显示的汉字(用于拼音搜索显示)
        m_model->appendRow(new QStandardItem(/*icon.value(),*/ hanziTxt));
        //设置Qt::UserRole搜索的拼音(即搜索拼音会显示上面的汉字)
        m_model->setData(m_model->index(m_model->rowCount() - 1, 0), pinyinTxt, Qt::UserRole);

        SearchDataStruct transdata;
        transdata.chiese = hanziTxt;
        transdata.pinyin = pinyinTxt;
        //存储 汉字和拼音 : 在选择对应的下拉框数据后,会将Qt::UserRole数据设置到输入框(即pinyin)
        //而在输入框发送 DSearchEdit::textChanged 信号时,会遍历m_inputList,根据pinyin获取到对应汉字,再将汉字设置到输入框
        m_inputList.append(transdata);
    } else {
        //先添加使用appenRow添加Qt::EditRole数据(用于下拉框显示),然后添加Qt::UserRole数据(用于输入框搜索)
        //Qt::EditRole数据用于显示搜索到的结果(汉字)
        //Qt::UserRole数据用于输入框输入的数据(拼音/汉字 均可)
        //即在输入框搜索Qt::UserRole的数据,就会在下拉框显示Qt::EditRole的数据
        m_model->appendRow(new QStandardItem(//icon.value(),
                                             QString("%1 --> %2 / %3").arg(data.actualModuleName).arg(data.childPageName).arg(data.translateContent)));

        //设置汉字的Qt::UserRole数据
        m_model->setData(m_model->index(m_model->rowCount() - 1, 0),
                         QString("%1 --> %2 / %3")
                         .arg(data.actualModuleName)
                         .arg(data.childPageName)
                         .arg(data.translateContent),
                         Qt::UserRole);

        QString hanziTxt = QString("%1 --> %2 / %3").arg(data.actualModuleName).arg(data.childPageName).arg(data.translateContent);
        QString pinyinTxt = QString("%1 --> %2 / %3")
                            .arg(removeDigital(Chinese2Pinyin(data.actualModuleName)))
                            .arg(removeDigital(Chinese2Pinyin(data.childPageName)))
                            .arg(removeDigital(Chinese2Pinyin(data.translateContent)));

        m_model->appendRow(new QStandardItem(/*icon.value(),*/ hanziTxt));
        //设置Qt::UserRole搜索的拼音(即搜索拼音会显示上面的汉字)
        m_model->setData(m_model->index(m_model->rowCount() - 1, 0), pinyinTxt, Qt::UserRole);

        SearchDataStruct transdata;
        transdata.chiese = hanziTxt;
        transdata.pinyin = pinyinTxt;
        //存储 汉字和拼音 : 在选择对应的下拉框数据后,会将Qt::UserRole数据设置到输入框(即pinyin)
        //而在输入框发送 DSearchEdit::textChanged 信号时,会遍历m_inputList,根据pinyin获取到对应汉字,再将汉字设置到输入框
        m_inputList.append(transdata);
    }
}

void SearchWidget::clearSearchData() {
    m_searchBoxStruct.translateContent = "";
    m_searchBoxStruct.actualModuleName = "";
    m_searchBoxStruct.childPageName = "";
    m_searchBoxStruct.fullPagePath = "";
}

void SearchWidget::hiddenSearchItem(QString name, bool show)
{
    if (show && m_model->rowCount() == count) {
            return;
    }
    bool exist = false;
    for (int index = 0 ; index < m_model->rowCount() ; index++) {
        if (m_model->item(index)->text().contains(name + " -->")) {
            exist = true;
            break;
        }
    }
    if (!show) {//去掉需隐藏的搜索项
         for (int index = 0 ; index < m_model->rowCount() ; index++) {
             if (m_model->item(index)->text().contains(name + " -->")) {
                 m_model->removeRow(index);
                 index--;
             }
         }
         updateSearchItem(name, show, nullptr);
    } else if (show && exist){
       return;
    } else {//加入需展示的搜索项
        for(SearchBoxStruct tmpStruct : m_EnterNewPagelist) {
            if (tmpStruct.actualModuleName == name) {
                appendChineseData(tmpStruct);
                updateSearchItem(name, show, &tmpStruct);
            }
        }
     }
}

void SearchWidget::initExcludeSearch() {
    if (!UkccCommon::isExistEffect()) {
        mExcludeList << "/Theme/Performance mode" << "/Theme/Transparency";
    }

    if (!UkccCommon::isExitBattery()) {
        mExcludeList << "/Power/Battery saving plan";
    }

    if (UkccCommon::isWayland() || !UkccCommon::isExistEffect()) {
        mExcludeList << "/Display/night mode";
    }
    if (!UkccCommon::isTablet()) {
        mExcludeList << "/UserinfoIntel/Change Tel" << "/Display/Dynamic light";
    }
}

void SearchWidget::setLanguage(QString type) {
    m_lang = type;

    if (type == "zh_CN" || type == "zh_HK" || type == "zh_TW" || type == "bo_CN") {
        m_bIsChinese = true;
        m_completer->setCompletionRole(Qt::UserRole); //设置ItemDataRole
    } else {
        m_completer->setCompletionRole(Qt::DisplayRole);
    }
    QTimer::singleShot(1, this, [=]() {
        QtConcurrent::run([=]() {
            loadxml();
            //记录搜索项总数
           count = m_model->rowCount();
        });
    });
}

//save all modules moduleInteface name and actual moduleName
//moduleName : moduleInteface name  (used to path module to translate searchName)
//searchName : actual module
void SearchWidget::addModulesName(QString moduleName, QString searchName, QString translation) {
    QPair<QString, QString> data;
    data.first = moduleName;
    data.second = searchName;
    m_moduleNameList.append(data);

    if (!translation.isEmpty()) {
        m_xmlFilePath.insert(translation);
    }

}

void SearchWidget::onCompleterActivated(QString value) {
    qDebug() << Q_FUNC_INFO << value;
    Q_EMIT returnPressed();
}