From 70e4cb06510f2dcb44693988fe7557bdc161b47f Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Wed, 2 Oct 2019 10:25:35 +0200 Subject: [PATCH] preview: clarify a bit the search code. Found no way to highlight anchors, still an issue (filed QTBUG-78927) --- src/qtgui/preview_w.cpp | 37 ++++++++++++++++++++----------------- src/qtgui/preview_w.h | 3 +-- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/qtgui/preview_w.cpp b/src/qtgui/preview_w.cpp index 77e8fa88..7581a68f 100644 --- a/src/qtgui/preview_w.cpp +++ b/src/qtgui/preview_w.cpp @@ -131,8 +131,6 @@ void Preview::init() "RCL.SEARCH.GUI.PREVIEW"); // signals and slots connections - connect(searchTextCMB, SIGNAL(activated(int)), - this, SLOT(searchTextFromIndex(int))); connect(searchTextCMB, SIGNAL(editTextChanged(const QString&)), this, SLOT(searchTextChanged(const QString&))); connect(nextPB, SIGNAL(clicked()), this, SLOT(nextPressed())); @@ -259,25 +257,30 @@ bool Preview::eventFilter(QObject *target, QEvent *event) void Preview::searchTextChanged(const QString & text) { - LOGDEB1("Search line text changed. text: '" << qs2utf8s(text) << "'\n"); - m_searchTextFromIndex = -1; - if (text.isEmpty()) { - m_dynSearchActive = false; - clearPB->setEnabled(false); + LOGDEB("Preview::searchTextChanged:(" << qs2utf8s(text) << ") current: ("<< + qs2utf8s(searchTextCMB->currentText()) << ") currentindex " << + searchTextCMB->currentIndex() << "\n"); + if (!searchTextCMB->itemText(searchTextCMB->currentIndex()).compare(text)) { + // Then we assume that the text was set by selecting in the + // combobox There does not seem to be another way to + // discriminate select and hand edit. Note that the + // activated() signal is called *after* the editTextChanged() + // one, so it is useless. + m_searchTextFromIndex = searchTextCMB->currentIndex(); + doSearch("", false, false); } else { - m_dynSearchActive = true; - clearPB->setEnabled(true); - doSearch(text, false, false); + m_searchTextFromIndex = -1; + if (text.isEmpty()) { + m_dynSearchActive = false; + clearPB->setEnabled(false); + } else { + m_dynSearchActive = true; + clearPB->setEnabled(true); + doSearch(text, false, false); + } } } -void Preview::searchTextFromIndex(int idx) -{ - LOGDEB1("search line from index " << idx << "\n"); - m_searchTextFromIndex = idx; -} - - void Preview::emitSaveDocToFile() { PreviewTextEdit *ce = currentEditor(); diff --git a/src/qtgui/preview_w.h b/src/qtgui/preview_w.h index f31283af..f9dc70fd 100644 --- a/src/qtgui/preview_w.h +++ b/src/qtgui/preview_w.h @@ -137,7 +137,6 @@ public: public slots: // Search stuff virtual void searchTextChanged(const QString& text); - virtual void searchTextFromIndex(int); virtual void doSearch(const QString& str, bool next, bool reverse, bool wo = false); virtual void nextPressed(); @@ -173,7 +172,7 @@ private: bool m_dynSearchActive{false}; // Index value the search text comes from. -1 if text was edited - int m_searchTextFromIndex{-1}; + int m_searchTextFromIndex{0}; bool m_canBeep{true}; bool m_loading{false};