From 7aec069a0edee1593e8bdb60995609edc18b2574 Mon Sep 17 00:00:00 2001 From: kh1 Date: Fri, 24 Sep 2010 16:44:59 +0200 Subject: Allow fallback to fulltext search when keyword has not been found (remote). Task-number: QTBUG-12963 Reviewed-by: ck --- doc/src/development/assistant-manual.qdoc | 7 +- tools/assistant/lib/qhelpsearchquerywidget.cpp | 84 ++++++++++++++++------ tools/assistant/lib/qhelpsearchquerywidget.h | 4 ++ .../tools/assistant/helpenginewrapper.cpp | 9 +++ .../assistant/tools/assistant/helpenginewrapper.h | 2 + tools/assistant/tools/assistant/remotecontrol.cpp | 22 +++++- .../assistant/tools/qcollectiongenerator/main.cpp | 11 +++ .../tools/shared/collectionconfiguration.cpp | 14 ++++ .../tools/shared/collectionconfiguration.h | 4 ++ 9 files changed, 132 insertions(+), 25 deletions(-) diff --git a/doc/src/development/assistant-manual.qdoc b/doc/src/development/assistant-manual.qdoc index d25a4b3..677e8d0 100644 --- a/doc/src/development/assistant-manual.qdoc +++ b/doc/src/development/assistant-manual.qdoc @@ -640,7 +640,12 @@ QDesktopServices::DataLocation. The first form is useful for collections that are used in a "mobile" way, e.g. carried around on a USB stick. - + \row + \o \c{} + \o This tag describes the ability to fallback and use the full text + search if a keyword can't be found in the index. This functionality + can be used while remote controlling \QA. To make it available for + remote control set the tag value to \c{true}. \endtable In addition to those \QA specific tags, the tags for generating and registering diff --git a/tools/assistant/lib/qhelpsearchquerywidget.cpp b/tools/assistant/lib/qhelpsearchquerywidget.cpp index 1634a0d..8e8b278 100644 --- a/tools/assistant/lib/qhelpsearchquerywidget.cpp +++ b/tools/assistant/lib/qhelpsearchquerywidget.cpp @@ -215,37 +215,36 @@ private: queryHist->curQuery += addend; const QList &query = - queryHist->queries.at(queryHist->curQuery); + queryHist->queries.at(queryHist->curQuery); foreach (const QHelpSearchQuery &queryPart, query) { - QLineEdit *lineEdit = 0; - switch (queryPart.fieldName) { + if (QLineEdit *lineEdit = lineEditFor(queryPart.fieldName)) + lineEdit->setText(queryPart.wordList.join(" ")); + } + + if (queryHist->curQuery == maxOrMinIndex) + thisButton->setEnabled(false); + otherButton->setEnabled(true); + } + + QLineEdit* lineEditFor(const QHelpSearchQuery::FieldName &fieldName) const + { + switch (fieldName) { case QHelpSearchQuery::DEFAULT: - lineEdit = defaultQuery; - break; + return defaultQuery; case QHelpSearchQuery::ALL: - lineEdit = allQuery; - break; + return allQuery; case QHelpSearchQuery::ATLEAST: - lineEdit = atLeastQuery; - break; + return atLeastQuery; case QHelpSearchQuery::FUZZY: - lineEdit = similarQuery; - break; + return similarQuery; case QHelpSearchQuery::WITHOUT: - lineEdit = withoutQuery; - break; + return withoutQuery; case QHelpSearchQuery::PHRASE: - lineEdit = exactQuery; - break; + return exactQuery; default: Q_ASSERT(0); - } - lineEdit->setText(queryPart.wordList.join(" ")); } - - if (queryHist->curQuery == maxOrMinIndex) - thisButton->setEnabled(false); - otherButton->setEnabled(true); + return 0; } void enableOrDisableToolButtons() @@ -512,8 +511,27 @@ QHelpSearchQueryWidget::~QHelpSearchQueryWidget() } /*! + Expands the search query widget so that the extended search fields are shown. +*/ +void QHelpSearchQueryWidget::expandExtendedSearch() +{ + if (d->simpleSearch) + d->showHideAdvancedSearch(); +} + +/*! + Collapses the search query widget so that only the default search field is + shown. +*/ +void QHelpSearchQueryWidget::collapseExtendedSearch() +{ + if (!d->simpleSearch) + d->showHideAdvancedSearch(); +} + +/*! Returns a list of queries to use in combination with the search engines - search(QList &query) function. + search(QList &queryList) function. */ QList QHelpSearchQueryWidget::query() const { @@ -524,6 +542,28 @@ QList QHelpSearchQueryWidget::query() const } /*! + Sets the QHelpSearchQueryWidget input fields to the values specified by + \a queryList search field name. Please note that one has to call the search + engine's search(QList &queryList) function to perform the + actual search. +*/ +void QHelpSearchQueryWidget::setQuery(const QList &queryList) +{ + QList lineEdits; + lineEdits << d->defaultQuery << d->allQuery << d->atLeastQuery + << d->similarQuery << d->withoutQuery << d->exactQuery; + foreach (QLineEdit *lineEdit, lineEdits) + lineEdit->clear(); + + const QLatin1String space(" "); + foreach (const QHelpSearchQuery &q, queryList) { + if (QLineEdit *lineEdit = d->lineEditFor(q.fieldName)) + lineEdit->setText(lineEdit->text() + q.wordList.join(space) + space); + } + d->searchRequested(); +} + +/*! \reimp */ void QHelpSearchQueryWidget::focusInEvent(QFocusEvent *focusEvent) diff --git a/tools/assistant/lib/qhelpsearchquerywidget.h b/tools/assistant/lib/qhelpsearchquerywidget.h index 2afc4b4..f3c290f 100644 --- a/tools/assistant/lib/qhelpsearchquerywidget.h +++ b/tools/assistant/lib/qhelpsearchquerywidget.h @@ -68,7 +68,11 @@ public: QHelpSearchQueryWidget(QWidget *parent = 0); ~QHelpSearchQueryWidget(); + void expandExtendedSearch(); + void collapseExtendedSearch(); + QList query() const; + void setQuery(const QList &queryList); Q_SIGNALS: void search(); diff --git a/tools/assistant/tools/assistant/helpenginewrapper.cpp b/tools/assistant/tools/assistant/helpenginewrapper.cpp index 8a5bb9c..ba54dd6 100644 --- a/tools/assistant/tools/assistant/helpenginewrapper.cpp +++ b/tools/assistant/tools/assistant/helpenginewrapper.cpp @@ -693,6 +693,7 @@ void HelpEngineWrapper::setBrowserWritingSystem(QFontDatabase::WritingSystem sys void HelpEngineWrapper::handleCurrentFilterChanged(const QString &filter) { + TRACE_OBJ const QString &filterToReport = filter == Unfiltered ? TrUnfiltered : filter; emit currentFilterChanged(filterToReport); @@ -700,14 +701,22 @@ void HelpEngineWrapper::handleCurrentFilterChanged(const QString &filter) bool HelpEngineWrapper::showTabs() const { + TRACE_OBJ return d->m_helpEngine->customValue(ShowTabsKey, false).toBool(); } void HelpEngineWrapper::setShowTabs(bool show) { + TRACE_OBJ d->m_helpEngine->setCustomValue(ShowTabsKey, show); } +bool HelpEngineWrapper::fullTextSearchFallbackEnabled() const +{ + TRACE_OBJ + return CollectionConfiguration::fullTextSearchFallbackEnabled(*d->m_helpEngine); +} + // -- TimeoutForwarder TimeoutForwarder::TimeoutForwarder(const QString &fileName) diff --git a/tools/assistant/tools/assistant/helpenginewrapper.h b/tools/assistant/tools/assistant/helpenginewrapper.h index 7349015..38bde9b 100644 --- a/tools/assistant/tools/assistant/helpenginewrapper.h +++ b/tools/assistant/tools/assistant/helpenginewrapper.h @@ -189,6 +189,8 @@ public: static const QString TrUnfiltered; + bool fullTextSearchFallbackEnabled() const; + signals: // For asynchronous doc updates triggered by external actions. diff --git a/tools/assistant/tools/assistant/remotecontrol.cpp b/tools/assistant/tools/assistant/remotecontrol.cpp index 06e5602..51bc733 100644 --- a/tools/assistant/tools/assistant/remotecontrol.cpp +++ b/tools/assistant/tools/assistant/remotecontrol.cpp @@ -58,6 +58,7 @@ #include #include +#include #ifdef Q_OS_WIN # include "remotecontrol_win.h" @@ -260,8 +261,25 @@ void RemoteControl::handleActivateKeywordCommand(const QString &arg) m_activateKeyword = arg; } else { m_mainWindow->setIndexString(arg); - if (!arg.isEmpty()) - helpEngine.indexWidget()->activateCurrentItem(); + if (!arg.isEmpty()) { + if (!helpEngine.indexWidget()->currentIndex().isValid() + && helpEngine.fullTextSearchFallbackEnabled()) { + if (QHelpSearchEngine *se = helpEngine.searchEngine()) { + m_mainWindow->setSearchVisible(true); + if (QHelpSearchQueryWidget *w = se->queryWidget()) { + w->collapseExtendedSearch(); + QList queryList; + queryList << QHelpSearchQuery(QHelpSearchQuery::DEFAULT, + QStringList(arg)); + w->setQuery(queryList); + se->search(queryList); + } + } + } else { + m_mainWindow->setIndexVisible(true); + helpEngine.indexWidget()->activateCurrentItem(); + } + } } } diff --git a/tools/assistant/tools/qcollectiongenerator/main.cpp b/tools/assistant/tools/qcollectiongenerator/main.cpp index 46e301c..1046e56 100644 --- a/tools/assistant/tools/qcollectiongenerator/main.cpp +++ b/tools/assistant/tools/qcollectiongenerator/main.cpp @@ -97,6 +97,10 @@ public: QString cacheDirectory() const { return m_cacheDirectory; } bool cacheDirRelativeToCollection() const { return m_cacheDirRelativeToCollection; } + bool fullTextSearchFallbackEnabled() const { + return m_enableFullTextSearchFallback; + } + private: void raiseErrorWithLine(); void readConfig(); @@ -125,6 +129,7 @@ private: QStringList m_filesToRegister; QString m_cacheDirectory; bool m_cacheDirRelativeToCollection; + bool m_enableFullTextSearchFallback; }; void CollectionConfigReader::raiseErrorWithLine() @@ -139,6 +144,7 @@ void CollectionConfigReader::readData(const QByteArray &contents) m_enableAddressBar = true; m_hideAddressBar = true; m_enableDocumentationManager = true; + m_enableFullTextSearchFallback = false; addData(contents); while (!atEnd()) { @@ -212,6 +218,9 @@ void CollectionConfigReader::readAssistantSettings() attributes().value(QLatin1String("base")) == QLatin1String("collection"); m_cacheDirectory = readElementText(); + } else if (name() == QLatin1String("enableFullTextSearchFallback")) { + if (readElementText() == QLatin1String("true")) + m_enableFullTextSearchFallback = true; } else { raiseErrorWithLine(); } @@ -511,6 +520,8 @@ int main(int argc, char *argv[]) !config.hideAddressBar()); CollectionConfiguration::setCreationTime(helpEngine, QDateTime::currentDateTime().toTime_t()); + CollectionConfiguration::setFullTextSearchFallbackEnabled(helpEngine, + config.fullTextSearchFallbackEnabled()); if (!config.applicationIcon().isEmpty()) { QFile icon(absoluteFileName(basePath, config.applicationIcon())); diff --git a/tools/assistant/tools/shared/collectionconfiguration.cpp b/tools/assistant/tools/shared/collectionconfiguration.cpp index e3944b6..2272c64 100644 --- a/tools/assistant/tools/shared/collectionconfiguration.cpp +++ b/tools/assistant/tools/shared/collectionconfiguration.cpp @@ -71,6 +71,7 @@ namespace { #endif )); const QString WindowTitleKey(QLatin1String("WindowTitle")); + const QString FullTextSearchFallbackKey(QLatin1String("FullTextSearchFallback")); } // anonymous namespace const QString CollectionConfiguration::DefaultZoomFactor(QLatin1String("0.0")); @@ -308,6 +309,19 @@ void CollectionConfiguration::copyConfiguration(const QHelpEngineCore &source, setAboutTexts(target, aboutTexts(source)); setAboutImages(target, aboutImages(source)); setDefaultHomePage(target, defaultHomePage(source)); + setFullTextSearchFallbackEnabled(target, fullTextSearchFallbackEnabled(source)); +} + +bool CollectionConfiguration:: fullTextSearchFallbackEnabled( + const QHelpEngineCore &helpEngine) +{ + return helpEngine.customValue(FullTextSearchFallbackKey, false).toBool(); +} + +void CollectionConfiguration::setFullTextSearchFallbackEnabled( + QHelpEngineCore &helpEngine, bool on) +{ + helpEngine.setCustomValue(FullTextSearchFallbackKey, on); } QT_END_NAMESPACE diff --git a/tools/assistant/tools/shared/collectionconfiguration.h b/tools/assistant/tools/shared/collectionconfiguration.h index b7bf247..aeb636f 100644 --- a/tools/assistant/tools/shared/collectionconfiguration.h +++ b/tools/assistant/tools/shared/collectionconfiguration.h @@ -136,6 +136,10 @@ public: static const QDateTime lastRegisterTime(const QHelpEngineCore &helpEngine); static void updateLastRegisterTime(QHelpEngineCore &helpEngine); + static bool fullTextSearchFallbackEnabled(const QHelpEngineCore &helpEngine); + static void setFullTextSearchFallbackEnabled(QHelpEngineCore &helpEngine, + bool on); + static const QString DefaultZoomFactor; static const QString ListSeparator; }; -- cgit v0.12