summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJarek Kobus <jaroslaw.kobus@qt.io>2017-03-14 16:26:11 +0100
committerJarek Kobus <jaroslaw.kobus@qt.io>2017-05-02 07:26:53 +0000
commit256bbc4f139036a780a63b80af8bb461a77d333a (patch)
tree0d821ad0bb41fcc1d7ac6eb829b577e1a40aa08c
parente9fb5c1669654adbfc7a73c6385df17aef34905b (diff)
downloadqttools-256bbc4f139036a780a63b80af8bb461a77d333a.tar.gz
Refactor some API
Deprecate old sfuff. Adjust documentation accordingly. Change-Id: I976823b29cb05dcf5880cb97f17408f85dae2e1b Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io>
-rw-r--r--src/assistant/assistant/centralwidget.cpp20
-rw-r--r--src/assistant/assistant/remotecontrol.cpp7
-rw-r--r--src/assistant/assistant/searchwidget.cpp9
-rw-r--r--src/assistant/assistant/searchwidget.h2
-rw-r--r--src/assistant/help/qhelpenginecore.cpp10
-rw-r--r--src/assistant/help/qhelpindexwidget.cpp6
-rw-r--r--src/assistant/help/qhelpsearchengine.cpp188
-rw-r--r--src/assistant/help/qhelpsearchengine.h27
-rw-r--r--src/assistant/help/qhelpsearchindexreader.cpp6
-rw-r--r--src/assistant/help/qhelpsearchindexreader_default.cpp28
-rw-r--r--src/assistant/help/qhelpsearchindexreader_default_p.h2
-rw-r--r--src/assistant/help/qhelpsearchindexreader_p.h8
-rw-r--r--src/assistant/help/qhelpsearchquerywidget.cpp108
-rw-r--r--src/assistant/help/qhelpsearchquerywidget.h9
-rw-r--r--src/assistant/help/qhelpsearchresultwidget.cpp19
15 files changed, 255 insertions, 194 deletions
diff --git a/src/assistant/assistant/centralwidget.cpp b/src/assistant/assistant/centralwidget.cpp
index 98e038786..fa4df3b92 100644
--- a/src/assistant/assistant/centralwidget.cpp
+++ b/src/assistant/assistant/centralwidget.cpp
@@ -539,25 +539,11 @@ void CentralWidget::highlightSearchTerms()
TRACE_OBJ
QHelpSearchEngine *searchEngine =
HelpEngineWrapper::instance().searchEngine();
- const QList<QHelpSearchQuery> &queryList = searchEngine->query();
-
- QStringList terms;
- for (const QHelpSearchQuery &query : queryList) {
- switch (query.fieldName) {
- default: break;
- case QHelpSearchQuery::ALL: {
- case QHelpSearchQuery::PHRASE:
- case QHelpSearchQuery::DEFAULT:
- case QHelpSearchQuery::ATLEAST:
- for (QString term : query.wordList)
- terms.append(term.remove(QLatin1Char('"')));
- }
- }
- }
+ const QStringList &words = searchEngine->searchInput().split(QRegExp("\\W+"), QString::SkipEmptyParts);
HelpViewer *viewer = currentHelpViewer();
- for (const QString & term : qAsConst(terms))
- viewer->findText(term, 0, false, true);
+ for (const QString &word : words)
+ viewer->findText(word, 0, false, true);
disconnect(viewer, SIGNAL(loadFinished(bool)), this,
SLOT(highlightSearchTerms()));
}
diff --git a/src/assistant/assistant/remotecontrol.cpp b/src/assistant/assistant/remotecontrol.cpp
index 147634322..e577a667b 100644
--- a/src/assistant/assistant/remotecontrol.cpp
+++ b/src/assistant/assistant/remotecontrol.cpp
@@ -183,11 +183,8 @@ void RemoteControl::handleActivateKeywordCommand(const QString &arg)
m_mainWindow->setSearchVisible(true);
if (QHelpSearchQueryWidget *w = se->queryWidget()) {
w->collapseExtendedSearch();
- QList<QHelpSearchQuery> queryList;
- queryList << QHelpSearchQuery(QHelpSearchQuery::DEFAULT,
- QStringList(arg));
- w->setQuery(queryList);
- se->search(queryList);
+ w->setSearchInput(arg);
+ se->search(arg);
}
}
} else {
diff --git a/src/assistant/assistant/searchwidget.cpp b/src/assistant/assistant/searchwidget.cpp
index 75e0ad91b..3aefe46c2 100644
--- a/src/assistant/assistant/searchwidget.cpp
+++ b/src/assistant/assistant/searchwidget.cpp
@@ -76,7 +76,7 @@ SearchWidget::SearchWidget(QHelpSearchEngine *engine, QWidget *parent)
SLOT(searchingFinished(int)));
QTextBrowser* browser = resultWidget->findChild<QTextBrowser*>();
- if (browser) // Will be null if lib was configured not to use CLucene.
+ if (browser)
browser->viewport()->installEventFilter(this);
}
@@ -122,8 +122,7 @@ void SearchWidget::resetZoom()
void SearchWidget::search() const
{
TRACE_OBJ
- QList<QHelpSearchQuery> query = searchEngine->queryWidget()->query();
- searchEngine->search(query);
+ searchEngine->search(searchEngine->queryWidget()->searchInput());
}
void SearchWidget::searchingStarted()
@@ -132,10 +131,10 @@ void SearchWidget::searchingStarted()
qApp->setOverrideCursor(QCursor(Qt::WaitCursor));
}
-void SearchWidget::searchingFinished(int hits)
+void SearchWidget::searchingFinished(int searchResultCount)
{
TRACE_OBJ
- Q_UNUSED(hits)
+ Q_UNUSED(searchResultCount)
qApp->restoreOverrideCursor();
}
diff --git a/src/assistant/assistant/searchwidget.h b/src/assistant/assistant/searchwidget.h
index a0c179ddb..8a8a4e719 100644
--- a/src/assistant/assistant/searchwidget.h
+++ b/src/assistant/assistant/searchwidget.h
@@ -59,7 +59,7 @@ signals:
private slots:
void search() const;
void searchingStarted();
- void searchingFinished(int hits);
+ void searchingFinished(int searchResultCount);
private:
bool eventFilter(QObject* o, QEvent *e) override;
diff --git a/src/assistant/help/qhelpenginecore.cpp b/src/assistant/help/qhelpenginecore.cpp
index f3b475321..51e9bade1 100644
--- a/src/assistant/help/qhelpenginecore.cpp
+++ b/src/assistant/help/qhelpenginecore.cpp
@@ -153,11 +153,11 @@ void QHelpEngineCorePrivate::errorReceived(const QString &msg)
The core help engine can be used to perform different tasks.
By calling linksForIdentifier() the engine returns
- urls specifying the file locations inside the help system. The
+ URLs specifying the file locations inside the help system. The
actual file data can then be retrived by calling fileData(). In
contrast to all other functions in this class, linksForIdentifier()
depends on the currently set custom filter. Depending on the filter,
- the function may return different hits.
+ the function may return different results.
Every help engine can contain any number of custom filters. A custom
filter is defined by a name and set of filter attributes and can be
@@ -629,9 +629,9 @@ QByteArray QHelpEngineCore::fileData(const QUrl &url) const
}
/*!
- Returns a map of hits found for the \a id. A hit contains the
- title of the document and the url where the keyword is located.
- The result depends on the current filter, meaning only the keywords
+ Returns documents found for the \a id. The map contains the
+ document titles and their URLs.
+ The returned map contents depends on the current filter, meaning only the keywords
registered for the current filter will be returned.
*/
QMap<QString, QUrl> QHelpEngineCore::linksForIdentifier(const QString &id) const
diff --git a/src/assistant/help/qhelpindexwidget.cpp b/src/assistant/help/qhelpindexwidget.cpp
index 58b292646..375ddb6b8 100644
--- a/src/assistant/help/qhelpindexwidget.cpp
+++ b/src/assistant/help/qhelpindexwidget.cpp
@@ -282,8 +282,8 @@ bool QHelpIndexModel::isCreatingIndex() const
}
/*!
- Returns all hits found for the \a keyword. A hit consists of
- the URL and the document title.
+ Returns all documents found for the \a keyword. The returned map consists of the
+ document titles and their URLs.
*/
QMap<QString, QUrl> QHelpIndexModel::linksForKeyword(const QString &keyword) const
{
@@ -382,7 +382,7 @@ QModelIndex QHelpIndexModel::filter(const QString &filter, const QString &wildca
This signal is emitted when the item representing the \a keyword
is activated and the item has more than one link associated.
- The \a links consist of the document title and their URL.
+ The \a links consist of the document titles and their URLs.
*/
QHelpIndexWidget::QHelpIndexWidget()
diff --git a/src/assistant/help/qhelpsearchengine.cpp b/src/assistant/help/qhelpsearchengine.cpp
index d9c65b71e..5f9edb265 100644
--- a/src/assistant/help/qhelpsearchengine.cpp
+++ b/src/assistant/help/qhelpsearchengine.cpp
@@ -66,17 +66,41 @@ public:
QString m_snippet;
};
+/*!
+ \class QHelpSearchResult
+ \since 5.9
+ \inmodule QtHelp
+ \brief The QHelpSearchResult class provides the data associated with the
+ search result.
+
+ The QHelpSearchResult object is a data object that describes a single search result.
+ The vector of search result objects is returned by QHelpSearchEngine::searchResults().
+ The description of the search result contains the document title and URL
+ that the search input matched. It also contains the snippet from
+ the document content containing the best match of the search input.
+ \sa QHelpSearchEngine
+*/
+
+/*!
+ Constructs a new empty QHelpSearchResult.
+*/
QHelpSearchResult::QHelpSearchResult()
: d(new QHelpSearchResultData)
{
}
-
+/*!
+ Constructs a copy of \a other.
+*/
QHelpSearchResult::QHelpSearchResult(const QHelpSearchResult &other)
: d(other.d)
{
}
+/*!
+ Constructs the search result containing \a url, \a title and \a snippet
+ as the description of the result.
+*/
QHelpSearchResult::QHelpSearchResult(const QUrl &url, const QString &title, const QString &snippet)
: d(new QHelpSearchResultData)
{
@@ -85,26 +109,41 @@ QHelpSearchResult::QHelpSearchResult(const QUrl &url, const QString &title, cons
d->m_snippet = snippet;
}
+/*!
+ Destroys the search result.
+*/
QHelpSearchResult::~QHelpSearchResult()
{
}
+/*!
+ Assigns \a other to this search result and returns a reference to this search result.
+*/
QHelpSearchResult &QHelpSearchResult::operator=(const QHelpSearchResult &other)
{
d = other.d;
return *this;
}
+/*!
+ Returns the document title of the search result.
+*/
QString QHelpSearchResult::title() const
{
return d->m_title;
}
+/*!
+ Returns the document URL of the search result.
+*/
QUrl QHelpSearchResult::url() const
{
return d->m_url;
}
+/*!
+ Returns the document snippet containing the search phrase of the search result.
+*/
QString QHelpSearchResult::snippet() const
{
return d->m_snippet;
@@ -121,7 +160,7 @@ signals:
void indexingFinished();
void searchingStarted();
- void searchingFinished(int searchResults);
+ void searchingFinished(int searchResultCount);
private:
QHelpSearchEnginePrivate(QHelpEngineCore *helpEngine)
@@ -139,20 +178,16 @@ private:
delete indexWriter;
}
- int hitCount() const
+ int searchResultCount() const
{
- int count = 0;
- if (indexReader)
- count = indexReader->hitCount();
-
- return count;
+ return indexReader ? indexReader->searchResultCount() : 0;
}
QVector<QHelpSearchResult> searchResults(int start, int end) const
{
return indexReader ?
- indexReader->searchResults(start, end) :
- QVector<QHelpSearchResult>();
+ indexReader->searchResults(start, end) :
+ QVector<QHelpSearchResult>();
}
void updateIndex(bool reindex = false)
@@ -181,7 +216,7 @@ private:
indexWriter->cancelIndexing();
}
- void search(const QList<QHelpSearchQuery> &queryList)
+ void search(const QString &searchInput)
{
if (helpEngine.isNull())
return;
@@ -195,9 +230,9 @@ private:
connect(indexReader, SIGNAL(searchingFinished(int)), this, SIGNAL(searchingFinished(int)));
}
- m_queryList = queryList;
+ m_searchInput = searchInput;
indexReader->cancelSearching();
- indexReader->search(helpEngine->collectionFile(), indexFilesFolder(), queryList);
+ indexReader->search(helpEngine->collectionFile(), indexFilesFolder(), searchInput);
}
void cancelSearching()
@@ -231,14 +266,14 @@ private:
QPointer<QHelpEngineCore> helpEngine;
- QList<QHelpSearchQuery> m_queryList;
+ QString m_searchInput;
};
#include "qhelpsearchengine.moc"
-
/*!
\class QHelpSearchQuery
+ \obsolete
\since 4.4
\inmodule QtHelp
\brief The QHelpSearchQuery class contains the field name and the associated
@@ -248,6 +283,8 @@ private:
term. Depending on the field the search term might get split up into separate
terms to be parsed differently by the search engine.
+ \note This class has been deprecated in favor of QString.
+
\sa QHelpSearchQueryWidget
*/
@@ -269,15 +306,14 @@ private:
\value DEFAULT the default field provided by the search widget, several terms should be
split and stored in the word list except search terms enclosed in quotes.
- \value FUZZY a field only provided in use with clucene. Terms should be split in separate
+ \value FUZZY \obsolete Terms should be split in separate
words and passed to the search engine.
- \value WITHOUT a field only provided in use with clucene. Terms should be split in separate
+ \value WITHOUT \obsolete Terms should be split in separate
words and passed to the search engine.
- \value PHRASE a field only provided in use with clucene. Terms should not be split in separate
- words.
- \value ALL a field only provided in use with clucene. Terms should be split in separate
+ \value PHRASE \obsolete Terms should not be split in separate words.
+ \value ALL \obsolete Terms should be split in separate
words and passed to the search engine
- \value ATLEAST a field only provided in use with clucene. Terms should be split in separate
+ \value ATLEAST \obsolete Terms should be split in separate
words and passed to the search engine
*/
@@ -297,23 +333,20 @@ private:
on the end of the indexing process the indexingFinished() is emitted. To stop
the indexing one can call cancelIndexing().
- While the indexing process has finished, the search engine can now be used to search
- thru its index for a given term. To do this one may use the possibility of creating the
- QHelpSearchQuery list by self or reuse the QHelpSearchQueryWidget which has the inbuild
- functionality to set up a proper search queries list that get's passed to the search engines
- search() function.
-
- After the list of querys has been passed to the search engine, the signal searchingStarted()
- is emitted and after the search has finished the searchingFinished() signal is emitted. The
- search process can be stopped by calling cancelSearching().
+ When the indexing process has finished, the search engine can be used to
+ search through the index for a given term using the search() function. When
+ the search input is passed to the search engine, the searchingStarted()
+ signal is emitted. When the search finishes, the searchingFinished() signal
+ is emitted. The search process can be stopped by calling cancelSearching().
- If the search succeeds, the searchingFinished() will be called with the search hits count,
- which can be reused to fetch the search hits from the search engine. Calling the hits()
- function with the range of hits you would like to get will return a list of the requested
- SearchHits. They basically constist at the moment of a pair of strings where the values
- of that pair are the documentation file path and the page title.
+ If the search succeeds, searchingFinished() is called with the search result
+ count to fetch the search results from the search engine. Calling the
+ searchResults() function with a range returns a list of QHelpSearchResult
+ objects within the range. The results consist of the document title and URL,
+ as well as a snippet from the document that contains the best match for the
+ search input.
- To display the given hits use the QHelpSearchResultWidget or build up your own one if you need
+ To display the given search results use the QHelpSearchResultWidget or build up your own one if you need
more advanced functionality. Note that the QHelpSearchResultWidget can not be instantiated
directly, you must retrieve the widget from the search engine in use as all connections will be
established for you by the widget itself.
@@ -338,10 +371,10 @@ private:
*/
/*!
- \fn void QHelpSearchEngine::searchingFinished(int hits)
+ \fn void QHelpSearchEngine::searchingFinished(int searchResultCount)
This signal is emitted when the search process is complete.
- The hit count is stored in \a hits.
+ The search result count is stored in \a searchResultCount.
*/
/*!
@@ -397,26 +430,37 @@ QHelpSearchResultWidget* QHelpSearchEngine::resultWidget()
/*!
\obsolete
- Returns the amount of hits the search engine found.
- \sa hitCount()
+ Use searchResultCount() instead.
*/
int QHelpSearchEngine::hitsCount() const
{
- return d->hitCount();
+ return d->searchResultCount();
}
/*!
\since 4.6
- Returns the amount of hits the search engine found.
+ \obsolete
+ Use searchResultCount() instead.
*/
int QHelpSearchEngine::hitCount() const
{
- return d->hitCount();
+ return d->searchResultCount();
+}
+
+/*!
+ \since 5.9
+ Returns the number of results the search engine found.
+*/
+int QHelpSearchEngine::searchResultCount() const
+{
+ return d->searchResultCount();
}
-// TODO: obsolete the SearchHit typedef and hits methods
/*!
\typedef QHelpSearchEngine::SearchHit
+ \obsolete
+
+ Use QHelpSearchResult instead.
Typedef for QPair<QString, QString>.
The values of that pair are the documentation file path and the page title.
@@ -425,7 +469,8 @@ int QHelpSearchEngine::hitCount() const
*/
/*!
- Returns a list of search hits within the range of \a start \a end.
+ \obsolete
+ Use searchResults() instead.
*/
QList<QHelpSearchEngine::SearchHit> QHelpSearchEngine::hits(int start, int end) const
{
@@ -435,19 +480,34 @@ QList<QHelpSearchEngine::SearchHit> QHelpSearchEngine::hits(int start, int end)
return hits;
}
-// TODO: add a doc for searchResults() and for QHelpSearchResult class
+/*!
+ \since 5.9
+ Returns a list of search results within the range from the index
+ specified by \a start to the index specified by \a end.
+*/
QVector<QHelpSearchResult> QHelpSearchEngine::searchResults(int start, int end) const
{
return d->searchResults(start, end);
}
/*!
- Returns the list of queries last searched for.
+ \since 5.9
+ Returns the phrase that was last searched for.
+*/
+QString QHelpSearchEngine::searchInput() const
+{
+ return d->m_searchInput;
+}
+
+/*!
+ \obsolete
\since 4.5
+ Use searchInput() instead.
*/
QList<QHelpSearchQuery> QHelpSearchEngine::query() const
{
- return d->m_queryList;
+ return QList<QHelpSearchQuery>() << QHelpSearchQuery(QHelpSearchQuery::DEFAULT,
+ d->m_searchInput.split(QChar::Space));
}
/*!
@@ -474,13 +534,39 @@ void QHelpSearchEngine::cancelSearching()
d->cancelSearching();
}
+
+/*!
+ \since 5.9
+ Starts the search process using the given search phrase \a searchInput.
+
+ The phrase may consist of several words. By default, the search engine returns
+ the list of documents that contain all the specified words.
+ The phrase may contain any combination of the logical operators AND, OR, and
+ NOT. The operator must be written in all capital letters, otherwise it will
+ be considered a part of the search phrase.
+
+ If double quotation marks are used to group the words,
+ the search engine will search for an exact match of the quoted phrase.
+
+ For more information about the text query syntax,
+ see \l {https://sqlite.org/fts5.html#full_text_query_syntax}
+ {SQLite FTS5 Extension}.
+*/
+void QHelpSearchEngine::search(const QString &searchInput)
+{
+ d->search(searchInput);
+}
+
/*!
- Starts the search process using the given list of queries \a queryList
- build by the search field name and the values to search for.
+ \obsolete
+ Use search(const QString &searchInput) instead.
*/
void QHelpSearchEngine::search(const QList<QHelpSearchQuery> &queryList)
{
- d->search(queryList);
+ if (queryList.isEmpty())
+ return;
+
+ d->search(queryList.first().wordList.join(QChar::Space));
}
void QHelpSearchEngine::scheduleIndexDocumentation()
diff --git a/src/assistant/help/qhelpsearchengine.h b/src/assistant/help/qhelpsearchengine.h
index 3c136a505..51ac975d7 100644
--- a/src/assistant/help/qhelpsearchengine.h
+++ b/src/assistant/help/qhelpsearchengine.h
@@ -58,8 +58,6 @@ class QHelpSearchEnginePrivate;
class QHelpSearchResultData;
class QHelpSearchResultWidget;
-// TODO: obsolete it and use just QString for input
-
class QHELP_EXPORT QHelpSearchQuery
{
public:
@@ -74,8 +72,6 @@ public:
QStringList wordList;
};
-// TODO: Add doc for it
-
class QHELP_EXPORT QHelpSearchResult
{
public:
@@ -105,23 +101,28 @@ public:
QHelpSearchQueryWidget* queryWidget();
QHelpSearchResultWidget* resultWidget();
-#ifdef QT_DEPRECATED
+#if QT_DEPRECATED_SINCE(5, 9)
+ typedef QPair<QString, QString> SearchHit;
+
QT_DEPRECATED int hitsCount() const;
+ QT_DEPRECATED int hitCount() const;
+ QT_DEPRECATED QList<SearchHit> hits(int start, int end) const;
+ QT_DEPRECATED QList<QHelpSearchQuery> query() const;
#endif
- int hitCount() const;
-
- typedef QPair<QString, QString> SearchHit;
- QList<SearchHit> hits(int start, int end) const;
+ int searchResultCount() const;
QVector<QHelpSearchResult> searchResults(int start, int end) const;
-
- QList<QHelpSearchQuery> query() const;
+ QString searchInput() const;
public Q_SLOTS:
void reindexDocumentation();
void cancelIndexing();
- void search(const QList<QHelpSearchQuery> &queryList);
+#if QT_DEPRECATED_SINCE(5, 9)
+ QT_DEPRECATED void search(const QList<QHelpSearchQuery> &queryList);
+#endif
+
+ void search(const QString &searchInput);
void cancelSearching();
Q_SIGNALS:
@@ -129,7 +130,7 @@ Q_SIGNALS:
void indexingFinished();
void searchingStarted();
- void searchingFinished(int hits);
+ void searchingFinished(int searchResultCount);
private Q_SLOTS:
void scheduleIndexDocumentation();
diff --git a/src/assistant/help/qhelpsearchindexreader.cpp b/src/assistant/help/qhelpsearchindexreader.cpp
index 1aa7714f1..71be91f9f 100644
--- a/src/assistant/help/qhelpsearchindexreader.cpp
+++ b/src/assistant/help/qhelpsearchindexreader.cpp
@@ -56,20 +56,20 @@ void QHelpSearchIndexReader::cancelSearching()
}
void QHelpSearchIndexReader::search(const QString &collectionFile, const QString &indexFilesFolder,
- const QList<QHelpSearchQuery> &queryList)
+ const QString &searchInput)
{
wait();
m_searchResults.clear();
m_cancel = false;
- m_query = queryList;
+ m_searchInput = searchInput;
m_collectionFile = collectionFile;
m_indexFilesFolder = indexFilesFolder;
start(QThread::NormalPriority);
}
-int QHelpSearchIndexReader::hitCount() const
+int QHelpSearchIndexReader::searchResultCount() const
{
QMutexLocker lock(&m_mutex);
return m_searchResults.count();
diff --git a/src/assistant/help/qhelpsearchindexreader_default.cpp b/src/assistant/help/qhelpsearchindexreader_default.cpp
index b57f3c344..86945bfb1 100644
--- a/src/assistant/help/qhelpsearchindexreader_default.cpp
+++ b/src/assistant/help/qhelpsearchindexreader_default.cpp
@@ -109,7 +109,7 @@ static void bindNamespacesAndAttributes(QSqlQuery *query, const QMultiMap<QStrin
QVector<QHelpSearchResult> Reader::queryTable(const QSqlDatabase &db,
const QString &tableName,
- const QString &term) const
+ const QString &searchInput) const
{
const QString nsPlaceholders = namespacePlaceholders(m_namespaces);
QSqlQuery query(db);
@@ -119,7 +119,7 @@ QVector<QHelpSearchResult> Reader::queryTable(const QSqlDatabase &db,
QLatin1String(") AND ") + tableName +
QLatin1String(" MATCH ? ORDER BY rank"));
bindNamespacesAndAttributes(&query, m_namespaces);
- query.addBindValue(term);
+ query.addBindValue(searchInput);
query.exec();
QVector<QHelpSearchResult> results;
@@ -134,7 +134,7 @@ QVector<QHelpSearchResult> Reader::queryTable(const QSqlDatabase &db,
return results;
}
-void Reader::searchInDB(const QString &term)
+void Reader::searchInDB(const QString &searchInput)
{
const QString &uniqueId = QHelpGlobal::uniquifyConnectionName(QLatin1String("QHelpReader"), this);
{
@@ -143,9 +143,9 @@ void Reader::searchInDB(const QString &term)
db.setDatabaseName(m_indexPath + QLatin1String("/fts"));
if (db.open()) {
const QVector<QHelpSearchResult> titleResults = queryTable(db,
- QLatin1String("titles"), term);
+ QLatin1String("titles"), searchInput);
const QVector<QHelpSearchResult> contentResults = queryTable(db,
- QLatin1String("contents"), term);
+ QLatin1String("contents"), searchInput);
// merge results form title and contents searches
m_searchResults = QVector<QHelpSearchResult>();
@@ -195,25 +195,13 @@ void QHelpSearchIndexReaderDefault::run()
if (m_cancel)
return;
- const QList<QHelpSearchQuery> queryList = m_query;
+ const QString searchInput = m_searchInput;
const QString collectionFile = m_collectionFile;
const QString indexPath = m_indexFilesFolder;
lock.unlock();
- QString queryTerm;
-
- // TODO: we may want to translate the QHelpSearchQuery list into
- // simple phrase using AND, OR, NOT or quotes in order to
- // keep working the public interface of QHelpSearchQuery
- for (const QHelpSearchQuery &query : queryList) {
- if (query.fieldName == QHelpSearchQuery::DEFAULT) {
- queryTerm = query.wordList.at(0);
- break;
- }
- }
-
- if (queryTerm.isEmpty())
+ if (searchInput.isEmpty())
return;
QHelpEngineCore engine(collectionFile, 0);
@@ -248,7 +236,7 @@ void QHelpSearchIndexReaderDefault::run()
lock.unlock();
m_searchResults.clear();
- m_reader.searchInDB(queryTerm); // TODO: should this be interruptible as well ???
+ m_reader.searchInDB(searchInput); // TODO: should this be interruptible as well ???
lock.relock();
m_searchResults = m_reader.searchResults();
diff --git a/src/assistant/help/qhelpsearchindexreader_default_p.h b/src/assistant/help/qhelpsearchindexreader_default_p.h
index 0e9dcaed5..b31b532c6 100644
--- a/src/assistant/help/qhelpsearchindexreader_default_p.h
+++ b/src/assistant/help/qhelpsearchindexreader_default_p.h
@@ -72,7 +72,7 @@ public:
private:
QVector<QHelpSearchResult> queryTable(const QSqlDatabase &db,
const QString &tableName,
- const QString &term) const;
+ const QString &searchInput) const;
QString m_indexPath;
QMultiMap<QString, QStringList> m_namespaces;
diff --git a/src/assistant/help/qhelpsearchindexreader_p.h b/src/assistant/help/qhelpsearchindexreader_p.h
index 0a5ef11a5..924f3e4ec 100644
--- a/src/assistant/help/qhelpsearchindexreader_p.h
+++ b/src/assistant/help/qhelpsearchindexreader_p.h
@@ -75,20 +75,20 @@ public:
void cancelSearching();
void search(const QString &collectionFile,
const QString &indexFilesFolder,
- const QList<QHelpSearchQuery> &queryList);
- int hitCount() const;
+ const QString &searchInput);
+ int searchResultCount() const;
QVector<QHelpSearchResult> searchResults(int start, int end) const;
signals:
void searchingStarted();
- void searchingFinished(int searchResults);
+ void searchingFinished(int searchResultCount);
protected:
mutable QMutex m_mutex;
QVector<QHelpSearchResult> m_searchResults;
bool m_cancel = false;
QString m_collectionFile;
- QList<QHelpSearchQuery> m_query;
+ QString m_searchInput;
QString m_indexFilesFolder;
private:
diff --git a/src/assistant/help/qhelpsearchquerywidget.cpp b/src/assistant/help/qhelpsearchquerywidget.cpp
index 332d8a431..6300635da 100644
--- a/src/assistant/help/qhelpsearchquerywidget.cpp
+++ b/src/assistant/help/qhelpsearchquerywidget.cpp
@@ -61,7 +61,7 @@ class QHelpSearchQueryWidgetPrivate : public QObject
private:
struct QueryHistory {
explicit QueryHistory() : curQuery(-1) {}
- QList<QList<QHelpSearchQuery> > queries;
+ QStringList queries;
int curQuery;
};
@@ -119,52 +119,29 @@ private:
m_searchButton->setText(QHelpSearchQueryWidget::tr("Search"));
}
- void saveQuery(const QList<QHelpSearchQuery> &query, QueryHistory &queryHist)
+ void saveQuery(const QString &query)
{
// We only add the query to the list if it is different from the last one.
- bool insert = false;
- if (queryHist.queries.empty())
- insert = true;
- else {
- const QList<QHelpSearchQuery> &lastQuery = queryHist.queries.last();
- if (lastQuery.size() != query.size()) {
- insert = true;
- } else {
- for (int i = 0; i < query.size(); ++i) {
- if (query.at(i).fieldName != lastQuery.at(i).fieldName
- || query.at(i).wordList != lastQuery.at(i).wordList) {
- insert = true;
- break;
- }
- }
- }
- }
- if (insert) {
- queryHist.queries.append(query);
- for (const QHelpSearchQuery &queryPart : query) {
- static_cast<CompleterModel *>(m_searchCompleter.model())->
- addTerm(queryPart.wordList.join(QLatin1Char(' ')));
- }
- }
+ if (!m_queries.queries.isEmpty() && m_queries.queries.last() == query)
+ return;
+
+ m_queries.queries.append(query);
+ static_cast<CompleterModel *>(m_searchCompleter.model())->addTerm(query);
}
void nextOrPrevQuery(int maxOrMinIndex, int addend, QToolButton *thisButton,
QToolButton *otherButton)
{
- QueryHistory *queryHist;
- queryHist = &m_queries;
m_lineEdit->clear();
// Otherwise, the respective button would be disabled.
- Q_ASSERT(queryHist->curQuery != maxOrMinIndex);
+ Q_ASSERT(m_queries.curQuery != maxOrMinIndex);
- queryHist->curQuery += addend;
- const QList<QHelpSearchQuery> &query =
- queryHist->queries.at(queryHist->curQuery);
- for (const QHelpSearchQuery &queryPart : query)
- m_lineEdit->setText(queryPart.wordList.join(QLatin1Char(' ')));
+ m_queries.curQuery = qBound(0, m_queries.curQuery + addend, m_queries.queries.count() - 1);
+ const QString &query = m_queries.queries.at(m_queries.curQuery);
+ m_lineEdit->setText(query);
- if (queryHist->curQuery == maxOrMinIndex)
+ if (m_queries.curQuery == maxOrMinIndex)
thisButton->setEnabled(false);
otherButton->setEnabled(true);
}
@@ -198,13 +175,9 @@ private slots:
void searchRequested()
{
- QList<QHelpSearchQuery> queryList;
- queryList.append(QHelpSearchQuery(QHelpSearchQuery::DEFAULT,
- QStringList(m_lineEdit->text())));
- QueryHistory &queryHist = m_queries;
- saveQuery(queryList, queryHist);
- queryHist.curQuery = queryHist.queries.size() - 1;
- if (queryHist.curQuery > 0)
+ saveQuery(m_lineEdit->text());
+ m_queries.curQuery = m_queries.queries.size() - 1;
+ if (m_queries.curQuery > 0)
m_prevQueryButton->setEnabled(true);
m_nextQueryButton->setEnabled(false);
}
@@ -250,8 +223,7 @@ private:
This signal is emitted when a the user has the search button invoked.
After receiving the signal you can ask the QHelpSearchQueryWidget for the
- build list of QHelpSearchQuery's that you may pass to the QHelpSearchEngine's
- search() function.
+ search input that you may pass to the QHelpSearchEngine::search() function.
*/
/*!
@@ -321,28 +293,56 @@ void QHelpSearchQueryWidget::collapseExtendedSearch()
}
/*!
- Returns a list of queries to use in combination with the search engines
- search(QList<QHelpSearchQuery> &queryList) function.
+ \obsolete
+
+ Use searchInput() instead.
*/
QList<QHelpSearchQuery> QHelpSearchQueryWidget::query() const
{
+ return QList<QHelpSearchQuery>() << QHelpSearchQuery(QHelpSearchQuery::DEFAULT,
+ searchInput().split(QChar::Space, QString::SkipEmptyParts));
+}
+
+/*!
+ \obsolete
+
+ Use setSearchInput() instead.
+*/
+void QHelpSearchQueryWidget::setQuery(const QList<QHelpSearchQuery> &queryList)
+{
+ if (queryList.isEmpty())
+ return;
+
+ setSearchInput(queryList.first().wordList.join(QChar::Space));
+}
+
+/*!
+ \since 5.9
+
+ Returns a search phrase to use in combination with the
+ QHelpSearchEngine::search(const QString &searchInput) function.
+*/
+QString QHelpSearchQueryWidget::searchInput() const
+{
if (d->m_queries.queries.isEmpty())
- return QList<QHelpSearchQuery>();
+ return QString();
return d->m_queries.queries.last();
}
/*!
- 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<QHelpSearchQuery> &queryList) function to perform the
- actual search.
+ \since 5.9
+
+ Sets the QHelpSearchQueryWidget input field to the value specified by
+ \a searchInput.
+
+ \note The QHelpSearchEngine::search(const QString &searchInput) function has
+ to be called to perform the actual search.
*/
-void QHelpSearchQueryWidget::setQuery(const QList<QHelpSearchQuery> &queryList)
+void QHelpSearchQueryWidget::setSearchInput(const QString &searchInput)
{
d->m_lineEdit->clear();
- for (const QHelpSearchQuery &q : queryList)
- d->m_lineEdit->setText(d->m_lineEdit->text() + q.wordList.join(QChar::Space) + QChar::Space);
+ d->m_lineEdit->setText(searchInput);
d->searchRequested();
}
diff --git a/src/assistant/help/qhelpsearchquerywidget.h b/src/assistant/help/qhelpsearchquerywidget.h
index 5216bb44a..7a36f235a 100644
--- a/src/assistant/help/qhelpsearchquerywidget.h
+++ b/src/assistant/help/qhelpsearchquerywidget.h
@@ -66,8 +66,13 @@ public:
void expandExtendedSearch();
void collapseExtendedSearch();
- QList<QHelpSearchQuery> query() const;
- void setQuery(const QList<QHelpSearchQuery> &queryList);
+#if QT_DEPRECATED_SINCE(5, 9)
+ QT_DEPRECATED QList<QHelpSearchQuery> query() const;
+ QT_DEPRECATED void setQuery(const QList<QHelpSearchQuery> &queryList);
+#endif
+
+ QString searchInput() const;
+ void setSearchInput(const QString &searchInput);
bool isCompactMode() const;
Q_SLOT void setCompactMode(bool on);
diff --git a/src/assistant/help/qhelpsearchresultwidget.cpp b/src/assistant/help/qhelpsearchresultwidget.cpp
index 40ae94e72..6bb512e9a 100644
--- a/src/assistant/help/qhelpsearchresultwidget.cpp
+++ b/src/assistant/help/qhelpsearchresultwidget.cpp
@@ -132,13 +132,13 @@ private slots:
void showNextResultPage()
{
if (!searchEngine.isNull()
- && resultLastToShow < searchEngine->hitCount()) {
+ && resultLastToShow < searchEngine->searchResultCount()) {
resultLastToShow += 20;
resultFirstToShow += 20;
resultTextBrowser->showResultPage(searchEngine->searchResults(resultFirstToShow,
resultLastToShow), isIndexing);
- if (resultLastToShow >= searchEngine->hitCount())
+ if (resultLastToShow >= searchEngine->searchResultCount())
updateNextButtonState(false);
}
updateHitRange();
@@ -147,7 +147,7 @@ private slots:
void showLastResultPage()
{
if (!searchEngine.isNull()) {
- resultLastToShow = searchEngine->hitCount();
+ resultLastToShow = searchEngine->searchResultCount();
resultFirstToShow = resultLastToShow - (resultLastToShow % 20);
if (resultFirstToShow == resultLastToShow)
@@ -177,7 +177,7 @@ private slots:
{
if (!searchEngine.isNull()) {
int count = resultLastToShow % 20;
- if (count == 0 || resultLastToShow != searchEngine->hitCount())
+ if (count == 0 || resultLastToShow != searchEngine->searchResultCount())
count = 20;
resultLastToShow -= count;
@@ -260,9 +260,9 @@ private:
int count = 0;
if (!searchEngine.isNull()) {
- count = searchEngine->hitCount();
+ count = searchEngine->searchResultCount();
if (count > 0) {
- first = resultFirstToShow +1;
+ first = resultFirstToShow + 1;
last = resultLastToShow > count ? count : resultLastToShow;
}
}
@@ -294,9 +294,8 @@ private:
\class QHelpSearchResultWidget
\since 4.4
\inmodule QtHelp
- \brief The QHelpSearchResultWidget class provides either a tree
- widget or a text browser depending on the used search engine to display
- the hits found by the search.
+ \brief The QHelpSearchResultWidget class provides a text browser to display
+ search results.
*/
/*!
@@ -366,7 +365,7 @@ QHelpSearchResultWidget::QHelpSearchResultWidget(QHelpSearchEngine *engine)
void QHelpSearchResultWidget::changeEvent(QEvent *event)
{
if (event->type() == QEvent::LanguageChange)
- d->setResults(d->searchEngine->hitCount());
+ d->setResults(d->searchEngine->searchResultCount());
}
/*!