forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -432,7 +432,7 @@ int HelpWidget::currentIndex() const
|
|||||||
return m_viewerStack->currentIndex();
|
return m_viewerStack->currentIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HelpWidget::addViewer(HelpViewer *viewer, bool highlightSearchTerms)
|
void HelpWidget::addViewer(HelpViewer *viewer)
|
||||||
{
|
{
|
||||||
m_viewerStack->addWidget(viewer);
|
m_viewerStack->addWidget(viewer);
|
||||||
viewer->setFocus(Qt::OtherFocusReason);
|
viewer->setFocus(Qt::OtherFocusReason);
|
||||||
@@ -456,8 +456,7 @@ void HelpWidget::addViewer(HelpViewer *viewer, bool highlightSearchTerms)
|
|||||||
if (m_style == ExternalWindow)
|
if (m_style == ExternalWindow)
|
||||||
connect(viewer, SIGNAL(titleChanged()), this, SLOT(updateWindowTitle()));
|
connect(viewer, SIGNAL(titleChanged()), this, SLOT(updateWindowTitle()));
|
||||||
|
|
||||||
if (highlightSearchTerms)
|
connect(viewer, &HelpViewer::loadFinished, this, &HelpWidget::highlightSearchTerms);
|
||||||
connect(viewer, &HelpViewer::loadFinished, this, &HelpWidget::highlightSearchTerms);
|
|
||||||
|
|
||||||
updateCloseButton();
|
updateCloseButton();
|
||||||
}
|
}
|
||||||
@@ -523,14 +522,14 @@ void HelpWidget::setSource(const QUrl &url)
|
|||||||
viewer->setFocus(Qt::OtherFocusReason);
|
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)
|
if (newPage)
|
||||||
OpenPagesManager::instance().createPageFromSearch(url);
|
OpenPagesManager::instance().createPage(url);
|
||||||
else {
|
else {
|
||||||
HelpViewer* viewer = currentViewer();
|
HelpViewer* viewer = currentViewer();
|
||||||
QTC_ASSERT(viewer, return);
|
QTC_ASSERT(viewer, return);
|
||||||
connect(viewer, &HelpViewer::loadFinished, this, &HelpWidget::highlightSearchTerms);
|
|
||||||
viewer->setSource(url);
|
viewer->setSource(url);
|
||||||
viewer->setFocus(Qt::OtherFocusReason);
|
viewer->setFocus(Qt::OtherFocusReason);
|
||||||
}
|
}
|
||||||
@@ -655,29 +654,13 @@ void HelpWidget::print(HelpViewer *viewer)
|
|||||||
|
|
||||||
void HelpWidget::highlightSearchTerms()
|
void HelpWidget::highlightSearchTerms()
|
||||||
{
|
{
|
||||||
if (HelpViewer *viewer = qobject_cast<HelpViewer *>(sender())) {
|
if (m_searchTerms.isEmpty())
|
||||||
QHelpSearchEngine *searchEngine =
|
return;
|
||||||
LocalHelpManager::helpEngine().searchEngine();
|
HelpViewer *viewer = qobject_cast<HelpViewer *>(sender());
|
||||||
QList<QHelpSearchQuery> queryList = searchEngine->query();
|
QTC_ASSERT(viewer, return);
|
||||||
|
foreach (const QString& term, m_searchTerms)
|
||||||
QStringList terms;
|
viewer->findText(term, 0, false, true);
|
||||||
foreach (const QHelpSearchQuery &query, queryList) {
|
m_searchTerms.clear();
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // Internal
|
} // Internal
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ public:
|
|||||||
HelpViewer *currentViewer() const;
|
HelpViewer *currentViewer() const;
|
||||||
void setCurrentViewer(HelpViewer *viewer);
|
void setCurrentViewer(HelpViewer *viewer);
|
||||||
int currentIndex() const;
|
int currentIndex() const;
|
||||||
void addViewer(HelpViewer *viewer, bool highlightSearchTerms = false);
|
void addViewer(HelpViewer *viewer);
|
||||||
void removeViewerAt(int index);
|
void removeViewerAt(int index);
|
||||||
|
|
||||||
void setViewerFont(const QFont &font);
|
void setViewerFont(const QFont &font);
|
||||||
@@ -81,7 +81,7 @@ public:
|
|||||||
HelpViewer *viewerAt(int index) const;
|
HelpViewer *viewerAt(int index) const;
|
||||||
|
|
||||||
void open(const QUrl &url, bool newPage = false);
|
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,
|
void showTopicChooser(const QMap<QString, QUrl> &links, const QString &key,
|
||||||
bool newPage = false);
|
bool newPage = false);
|
||||||
void activateSideBarItem(const QString &id);
|
void activateSideBarItem(const QString &id);
|
||||||
@@ -148,6 +148,8 @@ private:
|
|||||||
QAction *m_bookmarkAction;
|
QAction *m_bookmarkAction;
|
||||||
QAction *m_searchAction;
|
QAction *m_searchAction;
|
||||||
QAction *m_openPagesAction;
|
QAction *m_openPagesAction;
|
||||||
|
|
||||||
|
QStringList m_searchTerms;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // Internal
|
} // Internal
|
||||||
|
|||||||
@@ -187,12 +187,7 @@ HelpViewer *OpenPagesManager::createPage()
|
|||||||
return createPage(QUrl(Help::Constants::AboutBlank));
|
return createPage(QUrl(Help::Constants::AboutBlank));
|
||||||
}
|
}
|
||||||
|
|
||||||
HelpViewer *OpenPagesManager::createPageFromSearch(const QUrl &url)
|
HelpViewer *OpenPagesManager::createPage(const QUrl &url)
|
||||||
{
|
|
||||||
return createPage(url, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
HelpViewer *OpenPagesManager::createPage(const QUrl &url, bool fromSearch)
|
|
||||||
{
|
{
|
||||||
if (url.isValid() && HelpViewer::launchWithExternalApp(url))
|
if (url.isValid() && HelpViewer::launchWithExternalApp(url))
|
||||||
return 0;
|
return 0;
|
||||||
@@ -201,7 +196,7 @@ HelpViewer *OpenPagesManager::createPage(const QUrl &url, bool fromSearch)
|
|||||||
|
|
||||||
const int index = m_model->rowCount() - 1;
|
const int index = m_model->rowCount() - 1;
|
||||||
HelpViewer * const page = m_model->pageAt(index);
|
HelpViewer * const page = m_model->pageAt(index);
|
||||||
CentralWidget::instance()->addViewer(page, fromSearch);
|
CentralWidget::instance()->addViewer(page);
|
||||||
|
|
||||||
emit pagesChanged();
|
emit pagesChanged();
|
||||||
setCurrentPage(index);
|
setCurrentPage(index);
|
||||||
|
|||||||
@@ -66,8 +66,7 @@ public:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
HelpViewer *createPage();
|
HelpViewer *createPage();
|
||||||
HelpViewer *createPageFromSearch(const QUrl &url);
|
HelpViewer *createPage(const QUrl &url);
|
||||||
HelpViewer *createPage(const QUrl &url, bool fromSearch = false);
|
|
||||||
|
|
||||||
void setCurrentPage(int index);
|
void setCurrentPage(int index);
|
||||||
void setCurrentPage(const QModelIndex &index);
|
void setCurrentPage(const QModelIndex &index);
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ void SearchWidget::showEvent(QShowEvent *event)
|
|||||||
connect(queryWidget, SIGNAL(search()), this, SLOT(search()));
|
connect(queryWidget, SIGNAL(search()), this, SLOT(search()));
|
||||||
connect(resultWidget, &QHelpSearchResultWidget::requestShowLink, this,
|
connect(resultWidget, &QHelpSearchResultWidget::requestShowLink, this,
|
||||||
[this](const QUrl &url) {
|
[this](const QUrl &url) {
|
||||||
emit linkActivated(url, false/*newPage*/);
|
emit linkActivated(url, currentSearchTerms(), false/*newPage*/);
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(searchEngine, SIGNAL(searchingStarted()), this,
|
connect(searchEngine, SIGNAL(searchingStarted()), this,
|
||||||
@@ -232,7 +232,7 @@ bool SearchWidget::eventFilter(QObject *o, QEvent *e)
|
|||||||
bool controlPressed = me->modifiers() & Qt::ControlModifier;
|
bool controlPressed = me->modifiers() & Qt::ControlModifier;
|
||||||
if ((me->button() == Qt::LeftButton && controlPressed)
|
if ((me->button() == Qt::LeftButton && controlPressed)
|
||||||
|| (me->button() == Qt::MidButton)) {
|
|| (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()));
|
QAction *usedAction = menu.exec(mapToGlobal(contextMenuEvent->pos()));
|
||||||
if (usedAction == openLink)
|
if (usedAction == openLink)
|
||||||
emit linkActivated(link, false/*newPage*/);
|
emit linkActivated(link, currentSearchTerms(), false/*newPage*/);
|
||||||
else if (usedAction == openLinkInNewTab)
|
else if (usedAction == openLinkInNewTab)
|
||||||
emit linkActivated(link, true/*newPage*/);
|
emit linkActivated(link, currentSearchTerms(), true/*newPage*/);
|
||||||
else if (usedAction == copyAnchorAction)
|
else if (usedAction == copyAnchorAction)
|
||||||
QApplication::clipboard()->setText(link.toString());
|
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
|
// #pragma mark -- SearchSideBarItem
|
||||||
|
|
||||||
SearchSideBarItem::SearchSideBarItem()
|
SearchSideBarItem::SearchSideBarItem()
|
||||||
: SideBarItem(new SearchWidget, QLatin1String(Constants::HELP_SEARCH))
|
: SideBarItem(new SearchWidget, QLatin1String(Constants::HELP_SEARCH))
|
||||||
{
|
{
|
||||||
widget()->setWindowTitle(tr(Constants::SB_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()
|
QList<QToolButton *> SearchSideBarItem::createToolBarWidgets()
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ public:
|
|||||||
QList<QToolButton *> createToolBarWidgets();
|
QList<QToolButton *> createToolBarWidgets();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void linkActivated(const QUrl &url, bool newPage);
|
void linkActivated(const QUrl &url, const QStringList &searchTerms, bool newPage);
|
||||||
};
|
};
|
||||||
|
|
||||||
class SearchWidget : public QWidget
|
class SearchWidget : public QWidget
|
||||||
@@ -77,7 +77,7 @@ public slots:
|
|||||||
void reindexDocumentation();
|
void reindexDocumentation();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void linkActivated(const QUrl &link, bool newPage);
|
void linkActivated(const QUrl &link, const QStringList &searchTerms, bool newPage);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void showEvent(QShowEvent *event);
|
void showEvent(QShowEvent *event);
|
||||||
@@ -94,6 +94,7 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
bool eventFilter(QObject* o, QEvent *e);
|
bool eventFilter(QObject* o, QEvent *e);
|
||||||
void contextMenuEvent(QContextMenuEvent *contextMenuEvent);
|
void contextMenuEvent(QContextMenuEvent *contextMenuEvent);
|
||||||
|
QStringList currentSearchTerms() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int zoomCount;
|
int zoomCount;
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ def getHighlightsInHtml(htmlCode):
|
|||||||
|
|
||||||
def verifySelection(expected):
|
def verifySelection(expected):
|
||||||
selText = str(__getSelectedText__())
|
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
|
# verify if search keyword is found in results
|
||||||
test.verify(expected.lower() in selText.lower(),
|
test.verify(expected.lower() in selText.lower(),
|
||||||
"'%s' search result can be found" % expected)
|
"'%s' search result can be found" % expected)
|
||||||
|
|||||||
Reference in New Issue
Block a user