summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@theqtcompany.com>2014-10-31 14:20:03 +0100
committerEike Ziller <eike.ziller@theqtcompany.com>2014-11-04 07:57:08 +0100
commitcd5e00034d7cc9bd11d26f4cbde91e2db2c12383 (patch)
tree56dfa1d2719f9afbb28af01d44d836cbe4c9ebf7
parentd6a7287fb40121951d3d93296eed011c2b598832 (diff)
downloadqt-creator-cd5e00034d7cc9bd11d26f4cbde91e2db2c12383.tar.gz
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: Robert Loehning <robert.loehning@digia.com> Reviewed-by: Christian Stenger <christian.stenger@digia.com>
-rw-r--r--src/plugins/help/helpwidget.cpp41
-rw-r--r--src/plugins/help/helpwidget.h6
-rw-r--r--src/plugins/help/openpagesmanager.cpp9
-rw-r--r--src/plugins/help/openpagesmanager.h3
-rw-r--r--src/plugins/help/searchwidget.cpp33
-rw-r--r--src/plugins/help/searchwidget.h5
-rwxr-xr-xtests/system/suite_HELP/tst_HELP04/test.py2
7 files changed, 51 insertions, 48 deletions
diff --git a/src/plugins/help/helpwidget.cpp b/src/plugins/help/helpwidget.cpp
index dfe6790233..a0b87e39c2 100644
--- a/src/plugins/help/helpwidget.cpp
+++ b/src/plugins/help/helpwidget.cpp
@@ -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
diff --git a/src/plugins/help/helpwidget.h b/src/plugins/help/helpwidget.h
index daafb849ab..addb95dc80 100644
--- a/src/plugins/help/helpwidget.h
+++ b/src/plugins/help/helpwidget.h
@@ -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
diff --git a/src/plugins/help/openpagesmanager.cpp b/src/plugins/help/openpagesmanager.cpp
index 1d4f98aa88..751f78bb1e 100644
--- a/src/plugins/help/openpagesmanager.cpp
+++ b/src/plugins/help/openpagesmanager.cpp
@@ -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);
diff --git a/src/plugins/help/openpagesmanager.h b/src/plugins/help/openpagesmanager.h
index b5f0eb56a4..2e8d481bd8 100644
--- a/src/plugins/help/openpagesmanager.h
+++ b/src/plugins/help/openpagesmanager.h
@@ -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);
diff --git a/src/plugins/help/searchwidget.cpp b/src/plugins/help/searchwidget.cpp
index 706d113848..a0e428e0aa 100644
--- a/src/plugins/help/searchwidget.cpp
+++ b/src/plugins/help/searchwidget.cpp
@@ -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()
diff --git a/src/plugins/help/searchwidget.h b/src/plugins/help/searchwidget.h
index 58cc403687..802efc957a 100644
--- a/src/plugins/help/searchwidget.h
+++ b/src/plugins/help/searchwidget.h
@@ -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;
diff --git a/tests/system/suite_HELP/tst_HELP04/test.py b/tests/system/suite_HELP/tst_HELP04/test.py
index 0996d9bebb..ea3145d2e3 100755
--- a/tests/system/suite_HELP/tst_HELP04/test.py
+++ b/tests/system/suite_HELP/tst_HELP04/test.py
@@ -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)