Commit cd5e0003 authored by Eike Ziller's avatar Eike Ziller
Browse files

Help: Fix highlighting of search terms.



It was using the wrong search help engine to get the search terms.
Instead let the search widget itself figure out the search terms, and
pass it directly on to the help widget when activating links.

Change-Id: Ib72220eafca69e92894fe7584b1e4dfd9a42cc7e
Task-number: QTCREATORBUG-13239
Reviewed-by: default avatarRobert Loehning <robert.loehning@digia.com>
Reviewed-by: default avatarChristian Stenger <christian.stenger@digia.com>
parent d6a7287f
......@@ -432,7 +432,7 @@ int HelpWidget::currentIndex() const
return m_viewerStack->currentIndex();
}
void HelpWidget::addViewer(HelpViewer *viewer, bool highlightSearchTerms)
void HelpWidget::addViewer(HelpViewer *viewer)
{
m_viewerStack->addWidget(viewer);
viewer->setFocus(Qt::OtherFocusReason);
......@@ -456,8 +456,7 @@ void HelpWidget::addViewer(HelpViewer *viewer, bool highlightSearchTerms)
if (m_style == ExternalWindow)
connect(viewer, SIGNAL(titleChanged()), this, SLOT(updateWindowTitle()));
if (highlightSearchTerms)
connect(viewer, &HelpViewer::loadFinished, this, &HelpWidget::highlightSearchTerms);
connect(viewer, &HelpViewer::loadFinished, this, &HelpWidget::highlightSearchTerms);
updateCloseButton();
}
......@@ -523,14 +522,14 @@ void HelpWidget::setSource(const QUrl &url)
viewer->setFocus(Qt::OtherFocusReason);
}
void HelpWidget::openFromSearch(const QUrl &url, bool newPage)
void HelpWidget::openFromSearch(const QUrl &url, const QStringList &searchTerms, bool newPage)
{
m_searchTerms = searchTerms;
if (newPage)
OpenPagesManager::instance().createPageFromSearch(url);
OpenPagesManager::instance().createPage(url);
else {
HelpViewer* viewer = currentViewer();
QTC_ASSERT(viewer, return);
connect(viewer, &HelpViewer::loadFinished, this, &HelpWidget::highlightSearchTerms);
viewer->setSource(url);
viewer->setFocus(Qt::OtherFocusReason);
}
......@@ -655,29 +654,13 @@ void HelpWidget::print(HelpViewer *viewer)
void HelpWidget::highlightSearchTerms()
{
if (HelpViewer *viewer = qobject_cast<HelpViewer *>(sender())) {
QHelpSearchEngine *searchEngine =
LocalHelpManager::helpEngine().searchEngine();
QList<QHelpSearchQuery> queryList = searchEngine->query();
QStringList terms;
foreach (const QHelpSearchQuery &query, queryList) {
switch (query.fieldName) {
default: break;
case QHelpSearchQuery::ALL: {
case QHelpSearchQuery::PHRASE:
case QHelpSearchQuery::DEFAULT:
case QHelpSearchQuery::ATLEAST:
foreach (QString term, query.wordList)
terms.append(term.remove(QLatin1Char('"')));
}
}
}
foreach (const QString& term, terms)
viewer->findText(term, 0, false, true);
disconnect(viewer, &HelpViewer::loadFinished, this, &HelpWidget::highlightSearchTerms);
}
if (m_searchTerms.isEmpty())
return;
HelpViewer *viewer = qobject_cast<HelpViewer *>(sender());
QTC_ASSERT(viewer, return);
foreach (const QString& term, m_searchTerms)
viewer->findText(term, 0, false, true);
m_searchTerms.clear();
}
} // Internal
......
......@@ -71,7 +71,7 @@ public:
HelpViewer *currentViewer() const;
void setCurrentViewer(HelpViewer *viewer);
int currentIndex() const;
void addViewer(HelpViewer *viewer, bool highlightSearchTerms = false);
void addViewer(HelpViewer *viewer);
void removeViewerAt(int index);
void setViewerFont(const QFont &font);
......@@ -81,7 +81,7 @@ public:
HelpViewer *viewerAt(int index) const;
void open(const QUrl &url, bool newPage = false);
void openFromSearch(const QUrl &url, bool newPage = false);
void openFromSearch(const QUrl &url, const QStringList &searchTerms, bool newPage = false);
void showTopicChooser(const QMap<QString, QUrl> &links, const QString &key,
bool newPage = false);
void activateSideBarItem(const QString &id);
......@@ -148,6 +148,8 @@ private:
QAction *m_bookmarkAction;
QAction *m_searchAction;
QAction *m_openPagesAction;
QStringList m_searchTerms;
};
} // Internal
......
......@@ -187,12 +187,7 @@ HelpViewer *OpenPagesManager::createPage()
return createPage(QUrl(Help::Constants::AboutBlank));
}
HelpViewer *OpenPagesManager::createPageFromSearch(const QUrl &url)
{
return createPage(url, true);
}
HelpViewer *OpenPagesManager::createPage(const QUrl &url, bool fromSearch)
HelpViewer *OpenPagesManager::createPage(const QUrl &url)
{
if (url.isValid() && HelpViewer::launchWithExternalApp(url))
return 0;
......@@ -201,7 +196,7 @@ HelpViewer *OpenPagesManager::createPage(const QUrl &url, bool fromSearch)
const int index = m_model->rowCount() - 1;
HelpViewer * const page = m_model->pageAt(index);
CentralWidget::instance()->addViewer(page, fromSearch);
CentralWidget::instance()->addViewer(page);
emit pagesChanged();
setCurrentPage(index);
......
......@@ -66,8 +66,7 @@ public:
public slots:
HelpViewer *createPage();
HelpViewer *createPageFromSearch(const QUrl &url);
HelpViewer *createPage(const QUrl &url, bool fromSearch = false);
HelpViewer *createPage(const QUrl &url);
void setCurrentPage(int index);
void setCurrentPage(const QModelIndex &index);
......
......@@ -137,7 +137,7 @@ void SearchWidget::showEvent(QShowEvent *event)
connect(queryWidget, SIGNAL(search()), this, SLOT(search()));
connect(resultWidget, &QHelpSearchResultWidget::requestShowLink, this,
[this](const QUrl &url) {
emit linkActivated(url, false/*newPage*/);
emit linkActivated(url, currentSearchTerms(), false/*newPage*/);
});
connect(searchEngine, SIGNAL(searchingStarted()), this,
......@@ -232,7 +232,7 @@ bool SearchWidget::eventFilter(QObject *o, QEvent *e)
bool controlPressed = me->modifiers() & Qt::ControlModifier;
if ((me->button() == Qt::LeftButton && controlPressed)
|| (me->button() == Qt::MidButton)) {
emit linkActivated(link, true/*newPage*/);
emit linkActivated(link, currentSearchTerms(), true/*newPage*/);
}
}
}
......@@ -269,20 +269,43 @@ void SearchWidget::contextMenuEvent(QContextMenuEvent *contextMenuEvent)
QAction *usedAction = menu.exec(mapToGlobal(contextMenuEvent->pos()));
if (usedAction == openLink)
emit linkActivated(link, false/*newPage*/);
emit linkActivated(link, currentSearchTerms(), false/*newPage*/);
else if (usedAction == openLinkInNewTab)
emit linkActivated(link, true/*newPage*/);
emit linkActivated(link, currentSearchTerms(), true/*newPage*/);
else if (usedAction == copyAnchorAction)
QApplication::clipboard()->setText(link.toString());
}
QStringList SearchWidget::currentSearchTerms() const
{
QList<QHelpSearchQuery> queryList = searchEngine->query();
QStringList terms;
foreach (const QHelpSearchQuery &query, queryList) {
switch (query.fieldName) {
case QHelpSearchQuery::ALL:
case QHelpSearchQuery::PHRASE:
case QHelpSearchQuery::DEFAULT:
case QHelpSearchQuery::ATLEAST: {
foreach (QString term, query.wordList)
terms.append(term.remove(QLatin1Char('"')));
}
break;
default:
break;
}
}
return terms;
}
// #pragma mark -- SearchSideBarItem
SearchSideBarItem::SearchSideBarItem()
: SideBarItem(new SearchWidget, QLatin1String(Constants::HELP_SEARCH))
{
widget()->setWindowTitle(tr(Constants::SB_SEARCH));
connect(widget(), SIGNAL(linkActivated(QUrl,bool)), this, SIGNAL(linkActivated(QUrl,bool)));
connect(widget(), SIGNAL(linkActivated(QUrl,QStringList,bool)),
this, SIGNAL(linkActivated(QUrl,QStringList,bool)));
}
QList<QToolButton *> SearchSideBarItem::createToolBarWidgets()
......
......@@ -57,7 +57,7 @@ public:
QList<QToolButton *> createToolBarWidgets();
signals:
void linkActivated(const QUrl &url, bool newPage);
void linkActivated(const QUrl &url, const QStringList &searchTerms, bool newPage);
};
class SearchWidget : public QWidget
......@@ -77,7 +77,7 @@ public slots:
void reindexDocumentation();
signals:
void linkActivated(const QUrl &link, bool newPage);
void linkActivated(const QUrl &link, const QStringList &searchTerms, bool newPage);
protected:
void showEvent(QShowEvent *event);
......@@ -94,6 +94,7 @@ private slots:
private:
bool eventFilter(QObject* o, QEvent *e);
void contextMenuEvent(QContextMenuEvent *contextMenuEvent);
QStringList currentSearchTerms() const;
private:
int zoomCount;
......
......@@ -72,7 +72,7 @@ def getHighlightsInHtml(htmlCode):
def verifySelection(expected):
selText = str(__getSelectedText__())
if test.xverify(selText, "Verify that there is a selection"): # QTCREATORBUG-13239
if test.verify(selText, "Verify that there is a selection"):
# verify if search keyword is found in results
test.verify(expected.lower() in selText.lower(),
"'%s' search result can be found" % expected)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment