From ed718b00fe1adbe5cdad72bd8eb794fa4473c3fd Mon Sep 17 00:00:00 2001 From: wodim Date: Wed, 30 Aug 2017 12:31:09 +0200 Subject: Clean up properly after the search field in the settings dialog is emptied. --- src/modules/options/OptionsDialog.cpp | 74 +++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 30 deletions(-) diff --git a/src/modules/options/OptionsDialog.cpp b/src/modules/options/OptionsDialog.cpp index 7c126d1f7..6883337aa 100644 --- a/src/modules/options/OptionsDialog.cpp +++ b/src/modules/options/OptionsDialog.cpp @@ -322,6 +322,7 @@ void OptionsDialog::searchLineEditTextChanged(const QString &) bool OptionsDialog::searchInSelectors(KviOptionsWidget * pOptionsWidget, const QStringList & lKeywords) { KviPointerList * selectors = pOptionsWidget->selectors(); + bool bCleaningUp = lKeywords.isEmpty(); bool bFoundSomethingHere = false; if(selectors->count() > 0) { @@ -331,28 +332,38 @@ bool OptionsDialog::searchInSelectors(KviOptionsWidget * pOptionsWidget, const Q QWidget * pWidget = selectors->at(i)->widgetToHighlight(); if(!pWidget) continue; - QString szTmp = pWidget->toolTip(); - szTmp = szTmp.replace(QRegExp("<[^<>]+>"), ""); - szText.append(szTmp); - if(!szText.isEmpty()) + if(bCleaningUp) { - bool bOk = true; - for(int j = 0; j < lKeywords.count(); j++) + QFont font = pWidget->font(); + font.setBold(false); + font.setUnderline(false); + pWidget->setFont(font); + } + else + { + QString szTmp = pWidget->toolTip(); + szTmp = szTmp.replace(QRegExp("<[^<>]+>"), ""); + szText.append(szTmp); + if(!szText.isEmpty()) { - if(szText.indexOf(lKeywords.at(j), 0, Qt::CaseInsensitive) == -1) + bool bOk = true; + for(int j = 0; j < lKeywords.count(); j++) { - bOk = false; - break; + if(szText.indexOf(lKeywords.at(j), 0, Qt::CaseInsensitive) == -1) + { + bOk = false; + break; + } } + if(bOk) + { + bFoundSomethingHere = true; + } + QFont font = pWidget->font(); + font.setBold(bOk); + font.setUnderline(bOk); + pWidget->setFont(font); } - if(bOk) - { - bFoundSomethingHere = true; - } - QFont font = pWidget->font(); - font.setBold(bOk); - font.setUnderline(bOk); - pWidget->setFont(font); } } } @@ -369,6 +380,7 @@ bool OptionsDialog::recursiveSearch(OptionsDialogTreeWidgetItem * pItem, const Q m_pWidgetStack->addWidget(pItem->m_pOptionsWidget); } + bool bCleaningUp = lKeywords.isEmpty(); bool bFoundSomethingHere = false; KviOptionsWidget * pOptionsWidget = pItem->m_pOptionsWidget; QTabWidget * pTab = pOptionsWidget->tabWidget(); @@ -377,12 +389,12 @@ bool OptionsDialog::recursiveSearch(OptionsDialogTreeWidgetItem * pItem, const Q for(int i = 0; i < pTab->count(); i++) { QString szTxt = pTab->tabText(i); - if(KviQString::equalCIN(szTxt, ">>> ", 4)) + if(bCleaningUp || KviQString::equalCIN(szTxt, ">>> ", 4)) { szTxt.replace(">>> ", ""); szTxt.replace(" <<<", ""); } - if(searchInSelectors((KviOptionsWidget *)pTab->widget(i), lKeywords)) + if(searchInSelectors((KviOptionsWidget *)pTab->widget(i), lKeywords) && !bCleaningUp) { bFoundSomethingHere = true; szTxt.insert(0, ">>> "); @@ -393,18 +405,21 @@ bool OptionsDialog::recursiveSearch(OptionsDialogTreeWidgetItem * pItem, const Q } else { - if(searchInSelectors(pOptionsWidget, lKeywords)) + if(searchInSelectors(pOptionsWidget, lKeywords) && !bCleaningUp) bFoundSomethingHere = true; } - QStringList szInstanceKeywords = pItem->m_pInstanceEntry->szKeywords.split(QChar(',')); - // debug all the "search keywords" for each entry in the options tree - // qDebug("OPT %s",pItem->m_pInstanceEntry->szKeywords.toUtf8().data()); + if (!bCleaningUp) + { + QStringList szInstanceKeywords = pItem->m_pInstanceEntry->szKeywords.split(QChar(',')); + // debug all the "search keywords" for each entry in the options tree + // qDebug("OPT %s",pItem->m_pInstanceEntry->szKeywords.toUtf8().data()); - for(int i = 0; i < szInstanceKeywords.count() && !bFoundSomethingHere; i++) - for(int j = 0; j < lKeywords.count() && !bFoundSomethingHere; j++) - if(szInstanceKeywords.at(i).contains(lKeywords.at(j), Qt::CaseInsensitive)) - bFoundSomethingHere = true; + for(int i = 0; i < szInstanceKeywords.count() && !bFoundSomethingHere; i++) + for(int j = 0; j < lKeywords.count() && !bFoundSomethingHere; j++) + if(szInstanceKeywords.at(i).contains(lKeywords.at(j), Qt::CaseInsensitive)) + bFoundSomethingHere = true; + } if(bFoundSomethingHere) { @@ -424,7 +439,7 @@ bool OptionsDialog::recursiveSearch(OptionsDialogTreeWidgetItem * pItem, const Q for(int j = 0; j < ccount; j++) { OptionsDialogTreeWidgetItem * pChild = (OptionsDialogTreeWidgetItem *)pItem->child(j); - bool bRet = recursiveSearch(pChild, lKeywords); + bool bRet = recursiveSearch(pChild, lKeywords) && !bCleaningUp; if(bRet) bFoundSomethingInside = true; } @@ -461,8 +476,7 @@ void OptionsDialog::clearSearch() QTreeWidgetItemIterator it(m_pTreeWidget); while (*it) { - (*it)->setForeground(0, Qt::black); - (*it)->setBackground(0, Qt::transparent); + recursiveSearch(((OptionsDialogTreeWidgetItem *)* it), QStringList()); ++it; } -- cgit v1.3.1-10-gc9f91