summaryrefslogtreecommitdiffstats
path: root/tools/assistant/lib
diff options
context:
space:
mode:
Diffstat (limited to 'tools/assistant/lib')
-rw-r--r--tools/assistant/lib/lib.pro96
-rw-r--r--tools/assistant/lib/qhelpprojectdata.cpp49
-rw-r--r--tools/assistant/lib/qhelpsearchengine.cpp14
-rw-r--r--tools/assistant/lib/qhelpsearchindexreader.cpp106
-rw-r--r--tools/assistant/lib/qhelpsearchindexreader_clucene.cpp60
-rw-r--r--tools/assistant/lib/qhelpsearchindexreader_clucene_p.h36
-rw-r--r--tools/assistant/lib/qhelpsearchindexreader_default.cpp49
-rw-r--r--tools/assistant/lib/qhelpsearchindexreader_default_p.h37
-rw-r--r--tools/assistant/lib/qhelpsearchindexreader_p.h108
-rw-r--r--tools/assistant/lib/qhelpsearchquerywidget.cpp295
10 files changed, 581 insertions, 269 deletions
diff --git a/tools/assistant/lib/lib.pro b/tools/assistant/lib/lib.pro
index bd9ed53..5d6d436 100644
--- a/tools/assistant/lib/lib.pro
+++ b/tools/assistant/lib/lib.pro
@@ -1,65 +1,71 @@
-QT += sql xml network
+QT += sql \
+ xml \
+ network
TEMPLATE = lib
TARGET = QtHelp
-DEFINES += QHELP_LIB QT_CLUCENE_SUPPORT
-CONFIG += qt warn_on
-
+DEFINES += QHELP_LIB \
+ QT_CLUCENE_SUPPORT
+CONFIG += qt \
+ warn_on
include(../../../src/qbase.pri)
-
QMAKE_TARGET_PRODUCT = Help
-QMAKE_TARGET_DESCRIPTION = Help application framework.
+QMAKE_TARGET_DESCRIPTION = Help \
+ application \
+ framework.
DEFINES -= QT_ASCII_CAST_WARNINGS
-
qclucene = QtCLucene$${QT_LIBINFIX}
-if(!debug_and_release|build_pass):CONFIG(debug, debug|release) {
+if(!debug_and_release|build_pass):CONFIG(debug, debug|release) {
mac:qclucene = $${qclucene}_debug
win32:qclucene = $${qclucene}d
}
linux-lsb-g++:LIBS += --lsb-shared-libs=$$qclucene
-unix:QMAKE_PKGCONFIG_REQUIRES += QtNetwork QtSql QtXml
+unix:QMAKE_PKGCONFIG_REQUIRES += QtNetwork \
+ QtSql \
+ QtXml
LIBS += -l$$qclucene
-unix:QMAKE_PKGCONFIG_REQUIRES += QtNetwork QtSql QtXml
-
+unix:QMAKE_PKGCONFIG_REQUIRES += QtNetwork \
+ QtSql \
+ QtXml
RESOURCES += helpsystem.qrc
-
SOURCES += qhelpenginecore.cpp \
- qhelpengine.cpp \
- qhelpdbreader.cpp \
- qhelpcontentwidget.cpp \
- qhelpindexwidget.cpp \
- qhelpgenerator.cpp \
- qhelpdatainterface.cpp \
- qhelpprojectdata.cpp \
- qhelpcollectionhandler.cpp \
- qhelpsearchengine.cpp \
- qhelpsearchquerywidget.cpp \
- qhelpsearchresultwidget.cpp \
- qhelpsearchindex_default.cpp \
- qhelpsearchindexwriter_default.cpp \
- qhelpsearchindexreader_default.cpp
+ qhelpengine.cpp \
+ qhelpdbreader.cpp \
+ qhelpcontentwidget.cpp \
+ qhelpindexwidget.cpp \
+ qhelpgenerator.cpp \
+ qhelpdatainterface.cpp \
+ qhelpprojectdata.cpp \
+ qhelpcollectionhandler.cpp \
+ qhelpsearchengine.cpp \
+ qhelpsearchquerywidget.cpp \
+ qhelpsearchresultwidget.cpp \
+ qhelpsearchindex_default.cpp \
+ qhelpsearchindexwriter_default.cpp \
+ qhelpsearchindexreader_default.cpp \
+ qhelpsearchindexreader.cpp
# access to clucene
SOURCES += qhelpsearchindexwriter_clucene.cpp \
- qhelpsearchindexreader_clucene.cpp
-
+ qhelpsearchindexreader_clucene.cpp
HEADERS += qhelpenginecore.h \
- qhelpengine.h \
- qhelpengine_p.h \
- qhelp_global.h \
- qhelpdbreader_p.h \
- qhelpcontentwidget.h \
- qhelpindexwidget.h \
- qhelpgenerator_p.h \
- qhelpdatainterface_p.h \
- qhelpprojectdata_p.h \
- qhelpcollectionhandler_p.h \
- qhelpsearchengine.h \
- qhelpsearchquerywidget.h \
- qhelpsearchresultwidget.h \
- qhelpsearchindex_default_p.h \
- qhelpsearchindexwriter_default_p.h \
- qhelpsearchindexreader_default_p.h
+ qhelpengine.h \
+ qhelpengine_p.h \
+ qhelp_global.h \
+ qhelpdbreader_p.h \
+ qhelpcontentwidget.h \
+ qhelpindexwidget.h \
+ qhelpgenerator_p.h \
+ qhelpdatainterface_p.h \
+ qhelpprojectdata_p.h \
+ qhelpcollectionhandler_p.h \
+ qhelpsearchengine.h \
+ qhelpsearchquerywidget.h \
+ qhelpsearchresultwidget.h \
+ qhelpsearchindex_default_p.h \
+ qhelpsearchindexwriter_default_p.h \
+ qhelpsearchindexreader_default_p.h \
+ qhelpsearchindexreader_p.h
# access to clucene
HEADERS += qhelpsearchindexwriter_clucene_p.h \
- qhelpsearchindexreader_clucene_p.h
+ qhelpsearchindexreader_clucene_p.h
diff --git a/tools/assistant/lib/qhelpprojectdata.cpp b/tools/assistant/lib/qhelpprojectdata.cpp
index 8947a36..9412f1c 100644
--- a/tools/assistant/lib/qhelpprojectdata.cpp
+++ b/tools/assistant/lib/qhelpprojectdata.cpp
@@ -41,9 +41,11 @@
#include "qhelpprojectdata_p.h"
+#include <QtCore/QDir>
#include <QtCore/QFileInfo>
#include <QtCore/QStack>
#include <QtCore/QMap>
+#include <QtCore/QRegExp>
#include <QtCore/QVariant>
#include <QtXml/QXmlStreamReader>
@@ -73,6 +75,9 @@ private:
void readKeywords();
void readFiles();
void raiseUnknownTokenError();
+ void addMatchingFiles(const QString &pattern);
+
+ QMap<QString, QStringList> dirEntriesCache;
};
void QHelpProjectDataPrivate::raiseUnknownTokenError()
@@ -161,7 +166,7 @@ void QHelpProjectDataPrivate::readFilterSection()
readNext();
if (isStartElement()) {
if (name() == QLatin1String("filterAttribute"))
- filterSectionList.last().addFilterAttribute(readElementText());
+ filterSectionList.last().addFilterAttribute(readElementText());
else if (name() == QLatin1String("toc"))
readTOC();
else if (name() == QLatin1String("keywords"))
@@ -244,7 +249,7 @@ void QHelpProjectDataPrivate::readFiles()
readNext();
if (isStartElement()) {
if (name() == QLatin1String("file"))
- filterSectionList.last().addFile(readElementText());
+ addMatchingFiles(readElementText());
else
raiseUnknownTokenError();
} else if (isEndElement()) {
@@ -258,7 +263,47 @@ void QHelpProjectDataPrivate::readFiles()
}
}
+// Expand file pattern and add matches into list. If the pattern does not match
+// any files, insert the pattern itself so the QHelpGenerator will emit a
+// meaningful warning later.
+void QHelpProjectDataPrivate::addMatchingFiles(const QString &pattern)
+{
+ // The pattern matching is expensive, so we skip it if no
+ // wildcard symbols occur in the string.
+ if (!pattern.contains('?') && !pattern.contains('*')
+ && !pattern.contains('[') && !pattern.contains(']')) {
+ filterSectionList.last().addFile(pattern);
+ return;
+ }
+ QFileInfo fileInfo(rootPath + '/' + pattern);
+ const QDir &dir = fileInfo.dir();
+ const QString &path = dir.canonicalPath();
+
+ // QDir::entryList() is expensive, so we cache the results.
+ QMap<QString, QStringList>::ConstIterator it = dirEntriesCache.find(path);
+ const QStringList &entries = it != dirEntriesCache.constEnd() ?
+ it.value() : dir.entryList(QDir::Files);
+ if (it == dirEntriesCache.constEnd())
+ dirEntriesCache.insert(path, entries);
+
+ bool matchFound = false;
+#ifdef Q_OS_WIN
+ Qt::CaseSensitivity cs = Qt::CaseInsensitive;
+#else
+ Qt::CaseSensitivity cs = Qt::CaseSensitive;
+#endif
+ QRegExp regExp(fileInfo.fileName(), cs, QRegExp::Wildcard);
+ foreach (const QString &file, entries) {
+ if (regExp.exactMatch(file)) {
+ matchFound = true;
+ filterSectionList.last().
+ addFile(QFileInfo(pattern).dir().path() + '/' + file);
+ }
+ }
+ if (!matchFound)
+ filterSectionList.last().addFile(pattern);
+}
/*!
\internal
diff --git a/tools/assistant/lib/qhelpsearchengine.cpp b/tools/assistant/lib/qhelpsearchengine.cpp
index 2a41d04..94c5f7e 100644
--- a/tools/assistant/lib/qhelpsearchengine.cpp
+++ b/tools/assistant/lib/qhelpsearchengine.cpp
@@ -44,6 +44,7 @@
#include "qhelpsearchquerywidget.h"
#include "qhelpsearchresultwidget.h"
+#include "qhelpsearchindexreader_p.h"
#if defined(QT_CLUCENE_SUPPORT)
# include "qhelpsearchindexreader_clucene_p.h"
# include "qhelpsearchindexwriter_clucene_p.h"
@@ -147,8 +148,11 @@ private:
return;
if (!indexReader) {
- indexReader = new QHelpSearchIndexReader();
-
+#if defined(QT_CLUCENE_SUPPORT)
+ indexReader = new QHelpSearchIndexReaderClucene();
+#else
+ indexReader = new QHelpSearchIndexReaderDefault();
+#endif // QT_CLUCENE_SUPPORT
connect(indexReader, SIGNAL(searchingStarted()), this, SIGNAL(searchingStarted()));
connect(indexReader, SIGNAL(searchingFinished(int)), this, SIGNAL(searchingFinished(int)));
}
@@ -181,7 +185,7 @@ private slots:
{
#if defined(QT_CLUCENE_SUPPORT)
if (indexWriter && !helpEngine.isNull()) {
- indexWriter->optimizeIndex();
+ indexWriter->optimizeIndex();
}
#endif
}
@@ -192,7 +196,7 @@ private:
QHelpSearchQueryWidget *queryWidget;
QHelpSearchResultWidget *resultWidget;
- QHelpSearchIndexReader *indexReader;
+ qt::fulltextsearch::QHelpSearchIndexReader *indexReader;
QHelpSearchIndexWriter *indexWriter;
QPointer<QHelpEngineCore> helpEngine;
@@ -321,7 +325,7 @@ QHelpSearchEngine::QHelpSearchEngine(QHelpEngineCore *helpEngine, QObject *paren
: QObject(parent)
{
d = new QHelpSearchEnginePrivate(helpEngine);
-
+
connect(helpEngine, SIGNAL(setupFinished()), this, SLOT(indexDocumentation()));
connect(d, SIGNAL(indexingStarted()), this, SIGNAL(indexingStarted()));
diff --git a/tools/assistant/lib/qhelpsearchindexreader.cpp b/tools/assistant/lib/qhelpsearchindexreader.cpp
new file mode 100644
index 0000000..a0fcbe5
--- /dev/null
+++ b/tools/assistant/lib/qhelpsearchindexreader.cpp
@@ -0,0 +1,106 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt Assistant of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://www.qtsoftware.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qhelpsearchindexreader_p.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace qt {
+ namespace fulltextsearch {
+
+QHelpSearchIndexReader::QHelpSearchIndexReader()
+ : QThread()
+ , m_cancel(false)
+{
+ // nothing todo
+}
+
+QHelpSearchIndexReader::~QHelpSearchIndexReader()
+{
+ mutex.lock();
+ this->m_cancel = true;
+ mutex.unlock();
+
+ wait();
+}
+
+void QHelpSearchIndexReader::cancelSearching()
+{
+ mutex.lock();
+ this->m_cancel = true;
+ mutex.unlock();
+}
+
+void QHelpSearchIndexReader::search(const QString &collectionFile, const QString &indexFilesFolder,
+ const QList<QHelpSearchQuery> &queryList)
+{
+ wait();
+
+ this->hitList.clear();
+ this->m_cancel = false;
+ this->m_query = queryList;
+ this->m_collectionFile = collectionFile;
+ this->m_indexFilesFolder = indexFilesFolder;
+
+ start(QThread::NormalPriority);
+}
+
+int QHelpSearchIndexReader::hitsCount() const
+{
+ QMutexLocker lock(&mutex);
+ return hitList.count();
+}
+
+QList<QHelpSearchEngine::SearchHit> QHelpSearchIndexReader::hits(int start,
+ int end) const
+{
+ QList<QHelpSearchEngine::SearchHit> hits;
+ QMutexLocker lock(&mutex);
+ for (int i = start; i < end && i < hitList.count(); ++i)
+ hits.append(hitList.at(i));
+ return hits;
+}
+
+
+ } // namespace fulltextsearch
+} // namespace qt
+
+QT_END_NAMESPACE
diff --git a/tools/assistant/lib/qhelpsearchindexreader_clucene.cpp b/tools/assistant/lib/qhelpsearchindexreader_clucene.cpp
index 89d6040..b417078 100644
--- a/tools/assistant/lib/qhelpsearchindexreader_clucene.cpp
+++ b/tools/assistant/lib/qhelpsearchindexreader_clucene.cpp
@@ -59,60 +59,18 @@ namespace qt {
namespace fulltextsearch {
namespace clucene {
-QHelpSearchIndexReader::QHelpSearchIndexReader()
- : QThread()
- , m_cancel(false)
+QHelpSearchIndexReaderClucene::QHelpSearchIndexReaderClucene()
+ : QHelpSearchIndexReader()
{
// nothing todo
}
-QHelpSearchIndexReader::~QHelpSearchIndexReader()
+QHelpSearchIndexReaderClucene::~QHelpSearchIndexReaderClucene()
{
- mutex.lock();
- this->m_cancel = true;
- mutex.unlock();
-
- wait();
}
-void QHelpSearchIndexReader::cancelSearching()
-{
- mutex.lock();
- this->m_cancel = true;
- mutex.unlock();
-}
-void QHelpSearchIndexReader::search(const QString &collectionFile, const QString &indexFilesFolder,
- const QList<QHelpSearchQuery> &queryList)
-{
- wait();
-
- this->hitList.clear();
- this->m_cancel = false;
- this->m_query = queryList;
- this->m_collectionFile = collectionFile;
- this->m_indexFilesFolder = indexFilesFolder;
-
- start(QThread::NormalPriority);
-}
-
-int QHelpSearchIndexReader::hitsCount() const
-{
- QMutexLocker lock(&mutex);
- return hitList.count();
-}
-
-QList<QHelpSearchEngine::SearchHit> QHelpSearchIndexReader::hits(int start,
- int end) const
-{
- QList<QHelpSearchEngine::SearchHit> hits;
- QMutexLocker lock(&mutex);
- for (int i = start; i < end && i < hitList.count(); ++i)
- hits.append(hitList.at(i));
- return hits;
-}
-
-void QHelpSearchIndexReader::run()
+void QHelpSearchIndexReaderClucene::run()
{
mutex.lock();
@@ -140,7 +98,7 @@ void QHelpSearchIndexReader::run()
if(QCLuceneIndexReader::indexExists(indexPath)) {
mutex.lock();
if (m_cancel) {
- mutex.unlock();
+ mutex.unlock();
return;
}
mutex.unlock();
@@ -227,7 +185,7 @@ void QHelpSearchIndexReader::run()
}
}
-bool QHelpSearchIndexReader::defaultQuery(const QString &term, QCLuceneBooleanQuery &booleanQuery,
+bool QHelpSearchIndexReaderClucene::defaultQuery(const QString &term, QCLuceneBooleanQuery &booleanQuery,
QCLuceneStandardAnalyzer &analyzer)
{
const QLatin1String c("content");
@@ -244,7 +202,7 @@ bool QHelpSearchIndexReader::defaultQuery(const QString &term, QCLuceneBooleanQu
return false;
}
-bool QHelpSearchIndexReader::buildQuery(QCLuceneBooleanQuery &booleanQuery,
+bool QHelpSearchIndexReaderClucene::buildQuery(QCLuceneBooleanQuery &booleanQuery,
const QList<QHelpSearchQuery> &queryList, QCLuceneStandardAnalyzer &analyzer)
{
foreach (const QHelpSearchQuery query, queryList) {
@@ -344,7 +302,7 @@ bool QHelpSearchIndexReader::buildQuery(QCLuceneBooleanQuery &booleanQuery,
return true;
}
-bool QHelpSearchIndexReader::buildTryHarderQuery(QCLuceneBooleanQuery &booleanQuery,
+bool QHelpSearchIndexReaderClucene::buildTryHarderQuery(QCLuceneBooleanQuery &booleanQuery,
const QList<QHelpSearchQuery> &queryList, QCLuceneStandardAnalyzer &analyzer)
{
bool retVal = false;
@@ -367,7 +325,7 @@ bool QHelpSearchIndexReader::buildTryHarderQuery(QCLuceneBooleanQuery &booleanQu
return retVal;
}
-void QHelpSearchIndexReader::boostSearchHits(const QHelpEngineCore &engine,
+void QHelpSearchIndexReaderClucene::boostSearchHits(const QHelpEngineCore &engine,
QList<QHelpSearchEngine::SearchHit> &hitList, const QList<QHelpSearchQuery> &queryList)
{
foreach (const QHelpSearchQuery query, queryList) {
diff --git a/tools/assistant/lib/qhelpsearchindexreader_clucene_p.h b/tools/assistant/lib/qhelpsearchindexreader_clucene_p.h
index 8876d80..93ac6a8 100644
--- a/tools/assistant/lib/qhelpsearchindexreader_clucene_p.h
+++ b/tools/assistant/lib/qhelpsearchindexreader_clucene_p.h
@@ -53,44 +53,24 @@
// We mean it.
//
-#include "qhelpsearchengine.h"
+#include "qhelpsearchindexreader_p.h"
#include "fulltextsearch/qanalyzer_p.h"
#include "fulltextsearch/qquery_p.h"
-#include <QtCore/QList>
-#include <QtCore/QMutex>
-#include <QtCore/QObject>
-#include <QtCore/QString>
-#include <QtCore/QThread>
-#include <QtCore/QWaitCondition>
-
-class QHelpEngineCore;
-
QT_BEGIN_NAMESPACE
namespace qt {
namespace fulltextsearch {
namespace clucene {
-class QHelpSearchIndexReader : public QThread
+class QHelpSearchIndexReaderClucene : public QHelpSearchIndexReader
{
Q_OBJECT
public:
- QHelpSearchIndexReader();
- ~QHelpSearchIndexReader();
-
- void cancelSearching();
- void search(const QString &collectionFile,
- const QString &indexFilesFolder,
- const QList<QHelpSearchQuery> &queryList);
- int hitsCount() const;
- QList<QHelpSearchEngine::SearchHit> hits(int start, int end) const;
-
-signals:
- void searchingStarted();
- void searchingFinished(int hits);
+ QHelpSearchIndexReaderClucene();
+ ~QHelpSearchIndexReaderClucene();
private:
void run();
@@ -102,14 +82,6 @@ private:
const QList<QHelpSearchQuery> &queryList, QCLuceneStandardAnalyzer &analyzer);
void boostSearchHits(const QHelpEngineCore &engine, QList<QHelpSearchEngine::SearchHit> &hitList,
const QList<QHelpSearchQuery> &queryList);
-
-private:
- mutable QMutex mutex;
- QList<QHelpSearchEngine::SearchHit> hitList;
- bool m_cancel;
- QString m_collectionFile;
- QList<QHelpSearchQuery> m_query;
- QString m_indexFilesFolder;
};
} // namespace clucene
diff --git a/tools/assistant/lib/qhelpsearchindexreader_default.cpp b/tools/assistant/lib/qhelpsearchindexreader_default.cpp
index 91af925..fbf8a09 100644
--- a/tools/assistant/lib/qhelpsearchindexreader_default.cpp
+++ b/tools/assistant/lib/qhelpsearchindexreader_default.cpp
@@ -492,56 +492,17 @@ void Reader::cleanupIndex(EntryTable &entryTable)
}
-QHelpSearchIndexReader::QHelpSearchIndexReader()
- : QThread()
- , m_cancel(false)
+QHelpSearchIndexReaderDefault::QHelpSearchIndexReaderDefault()
+ : QHelpSearchIndexReader()
{
// nothing todo
}
-QHelpSearchIndexReader::~QHelpSearchIndexReader()
+QHelpSearchIndexReaderDefault::~QHelpSearchIndexReaderDefault()
{
- mutex.lock();
- this->m_cancel = true;
- waitCondition.wakeOne();
- mutex.unlock();
-
- wait();
-}
-
-void QHelpSearchIndexReader::cancelSearching()
-{
- mutex.lock();
- this->m_cancel = true;
- mutex.unlock();
-}
-
-void QHelpSearchIndexReader::search(const QString &collectionFile,
- const QString &indexFilesFolder,
- const QList<QHelpSearchQuery> &queryList)
-{
- QMutexLocker lock(&mutex);
-
- this->hitList.clear();
- this->m_cancel = false;
- this->m_query = queryList;
- this->m_collectionFile = collectionFile;
- this->m_indexFilesFolder = indexFilesFolder;
-
- start(QThread::NormalPriority);
-}
-
-int QHelpSearchIndexReader::hitsCount() const
-{
- return hitList.count();
}
-QHelpSearchEngine::SearchHit QHelpSearchIndexReader::hit(int index) const
-{
- return hitList.at(index);
-}
-
-void QHelpSearchIndexReader::run()
+void QHelpSearchIndexReaderDefault::run()
{
mutex.lock();
@@ -571,7 +532,7 @@ void QHelpSearchIndexReader::run()
QHelpEngineCore engine(collectionFile, 0);
if (!engine.setupData())
return;
-
+
const QStringList registeredDocs = engine.registeredDocumentations();
const QStringList indexedNamespaces = engine.customValue(key).toString().
split(QLatin1String("|"), QString::SkipEmptyParts);
diff --git a/tools/assistant/lib/qhelpsearchindexreader_default_p.h b/tools/assistant/lib/qhelpsearchindexreader_default_p.h
index f0e59b4..d21fc08 100644
--- a/tools/assistant/lib/qhelpsearchindexreader_default_p.h
+++ b/tools/assistant/lib/qhelpsearchindexreader_default_p.h
@@ -54,19 +54,10 @@
//
#include "qhelpsearchindex_default_p.h"
-#include "qhelpsearchengine.h"
+#include "qhelpsearchindexreader_p.h"
#include <QtCore/QHash>
#include <QtCore/QPair>
-#include <QtCore/QList>
-#include <QtCore/QMutex>
-#include <QtCore/QString>
-#include <QtCore/QThread>
-#include <QtCore/QObject>
-#include <QtCore/QVector>
-#include <QtCore/QByteArray>
-#include <QtCore/QStringList>
-#include <QtCore/QWaitCondition>
QT_BEGIN_NAMESPACE
@@ -121,39 +112,19 @@ private:
};
-class QHelpSearchIndexReader : public QThread
+class QHelpSearchIndexReaderDefault : public QHelpSearchIndexReader
{
Q_OBJECT
public:
- QHelpSearchIndexReader();
- ~QHelpSearchIndexReader();
-
- void cancelSearching();
- void search(const QString &collectionFile,
- const QString &indexFilesFolder,
- const QList<QHelpSearchQuery> &queryList);
-
- int hitsCount() const;
- QHelpSearchEngine::SearchHit hit(int index) const;
-
-signals:
- void searchingStarted();
- void searchingFinished(int hits);
+ QHelpSearchIndexReaderDefault();
+ ~QHelpSearchIndexReaderDefault();
private:
void run();
private:
- QMutex mutex;
Reader m_reader;
- QWaitCondition waitCondition;
- QList<QHelpSearchEngine::SearchHit> hitList;
-
- bool m_cancel;
- QList<QHelpSearchQuery> m_query;
- QString m_collectionFile;
- QString m_indexFilesFolder;
};
} // namespace std
diff --git a/tools/assistant/lib/qhelpsearchindexreader_p.h b/tools/assistant/lib/qhelpsearchindexreader_p.h
new file mode 100644
index 0000000..c8f2b44
--- /dev/null
+++ b/tools/assistant/lib/qhelpsearchindexreader_p.h
@@ -0,0 +1,108 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt Assistant of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://www.qtsoftware.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QHELPSEARCHINDEXREADER_H
+#define QHELPSEARCHINDEXREADER_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of the help generator tools. This header file may change from version
+// to version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qhelpsearchengine.h"
+
+#include <QtCore/QList>
+#include <QtCore/QMutex>
+#include <QtCore/QObject>
+#include <QtCore/QString>
+#include <QtCore/QThread>
+#include <QtCore/QWaitCondition>
+
+QT_BEGIN_NAMESPACE
+
+class QHelpEngineCore;
+
+namespace qt {
+ namespace fulltextsearch {
+
+class QHelpSearchIndexReader : public QThread
+{
+ Q_OBJECT
+
+public:
+ QHelpSearchIndexReader();
+ ~QHelpSearchIndexReader();
+
+ void cancelSearching();
+ void search(const QString &collectionFile,
+ const QString &indexFilesFolder,
+ const QList<QHelpSearchQuery> &queryList);
+ int hitsCount() const;
+ QList<QHelpSearchEngine::SearchHit> hits(int start, int end) const;
+
+signals:
+ void searchingStarted();
+ void searchingFinished(int hits);
+
+protected:
+ mutable QMutex mutex;
+ QList<QHelpSearchEngine::SearchHit> hitList;
+ bool m_cancel;
+ QString m_collectionFile;
+ QList<QHelpSearchQuery> m_query;
+ QString m_indexFilesFolder;
+
+private:
+ virtual void run()=0;
+};
+
+ } // namespace fulltextsearch
+} // namespace qt
+
+QT_END_NAMESPACE
+
+#endif // QHELPSEARCHINDEXREADER_H
diff --git a/tools/assistant/lib/qhelpsearchquerywidget.cpp b/tools/assistant/lib/qhelpsearchquerywidget.cpp
index 00444b1..110df4f 100644
--- a/tools/assistant/lib/qhelpsearchquerywidget.cpp
+++ b/tools/assistant/lib/qhelpsearchquerywidget.cpp
@@ -43,9 +43,12 @@
#include <QtCore/QDebug>
+#include <QtCore/QAbstractListModel>
#include <QtCore/QObject>
#include <QtCore/QStringList>
+#include <QtCore/QtGlobal>
+#include <QtGui/QCompleter>
#include <QtGui/QLabel>
#include <QtGui/QLayout>
#include <QtGui/QLineEdit>
@@ -60,8 +63,46 @@ class QHelpSearchQueryWidgetPrivate : public QObject
Q_OBJECT
private:
+ struct QueryHistory {
+ explicit QueryHistory() : curQuery(-1) {}
+ QList<QList<QHelpSearchQuery> > queries;
+ int curQuery;
+ };
+
+ class CompleterModel : public QAbstractListModel
+ {
+ public:
+ explicit CompleterModel(QObject *parent)
+ : QAbstractListModel(parent) {}
+
+ int rowCount(const QModelIndex &parent = QModelIndex()) const
+ {
+ return parent.isValid() ? 0 : termList.size();
+ }
+
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const
+ {
+ if (!index.isValid() || index.row() >= termList.count()||
+ (role != Qt::EditRole && role != Qt::DisplayRole))
+ return QVariant();
+ return termList.at(index.row());
+ }
+
+ void addTerm(const QString &term)
+ {
+ if (!termList.contains(term)) {
+ termList.append(term);
+ reset();
+ }
+ }
+
+ private:
+ QStringList termList;
+ };
+
QHelpSearchQueryWidgetPrivate()
- : QObject()
+ : QObject(), simpleSearch(true),
+ searchCompleter(new CompleterModel(this), this)
{
searchButton = 0;
advancedSearchWidget = 0;
@@ -136,11 +177,102 @@ private:
return wordList;
}
+ void saveQuery(const QList<QHelpSearchQuery> &query, QueryHistory &queryHist)
+ {
+ // 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);
+ foreach (const QHelpSearchQuery &queryPart, query) {
+ static_cast<CompleterModel *>(searchCompleter.model())->
+ addTerm(queryPart.wordList.join(" "));
+ }
+ }
+ }
+
+ void nextOrPrevQuery(int maxOrMinIndex, int addend,
+ QToolButton *thisButton, QToolButton *otherButton)
+ {
+ QueryHistory *queryHist;
+ QList<QLineEdit *> lineEdits;
+ if (simpleSearch) {
+ queryHist = &simpleQueries;
+ lineEdits << defaultQuery;
+ } else {
+ queryHist = &complexQueries;
+ lineEdits << allQuery << atLeastQuery << similarQuery
+ << withoutQuery << exactQuery;
+ }
+ foreach (QLineEdit *lineEdit, lineEdits)
+ lineEdit->clear();
+
+ // Otherwise, the respective button would be disabled.
+ Q_ASSERT(queryHist->curQuery != maxOrMinIndex);
+
+ queryHist->curQuery += addend;
+ const QList<QHelpSearchQuery> &query =
+ queryHist->queries.at(queryHist->curQuery);
+ foreach (const QHelpSearchQuery &queryPart, query) {
+ QLineEdit *lineEdit;
+ switch (queryPart.fieldName) {
+ case QHelpSearchQuery::DEFAULT:
+ lineEdit = defaultQuery;
+ break;
+ case QHelpSearchQuery::ALL:
+ lineEdit = allQuery;
+ break;
+ case QHelpSearchQuery::ATLEAST:
+ lineEdit = atLeastQuery;
+ break;
+ case QHelpSearchQuery::FUZZY:
+ lineEdit = similarQuery;
+ break;
+ case QHelpSearchQuery::WITHOUT:
+ lineEdit = withoutQuery;
+ break;
+ case QHelpSearchQuery::PHRASE:
+ lineEdit = exactQuery;
+ break;
+ default:
+ Q_ASSERT(0);
+ }
+ lineEdit->setText(queryPart.wordList.join(" "));
+ }
+
+ if (queryHist->curQuery == maxOrMinIndex)
+ thisButton->setEnabled(false);
+ otherButton->setEnabled(true);
+ }
+
+ void enableOrDisableToolButtons()
+ {
+ const QueryHistory &queryHist =
+ simpleSearch ? simpleQueries : complexQueries;
+ prevQueryButton->setEnabled(queryHist.curQuery > 0);
+ nextQueryButton->setEnabled(queryHist.curQuery <
+ queryHist.queries.size() - 1);
+ }
+
private slots:
void showHideAdvancedSearch()
{
- bool hidden = advancedSearchWidget->isHidden();
- if (hidden) {
+ if (simpleSearch) {
advancedSearchWidget->show();
showHideAdvancedSearchButton->setText((QLatin1String("-")));
} else {
@@ -148,12 +280,86 @@ private slots:
showHideAdvancedSearchButton->setText((QLatin1String("+")));
}
- defaultQuery->setEnabled(!hidden);
+ simpleSearch = !simpleSearch;
+ defaultQuery->setEnabled(simpleSearch);
+ enableOrDisableToolButtons();
+ }
+
+ void searchRequested()
+ {
+ QList<QHelpSearchQuery> queryList;
+#if !defined(QT_CLUCENE_SUPPORT)
+ queryList.append(QHelSearchQuery(QHelpSearchQuery::DEFAULT,
+ QStringList(defaultQuery->text())));
+
+#else
+ if (defaultQuery->isEnabled()) {
+ queryList.append(QHelpSearchQuery(QHelpSearchQuery::DEFAULT,
+ buildTermList(escapeString(defaultQuery->text()))));
+ } else {
+ const QRegExp exp(QLatin1String("\\s+"));
+ QStringList lst = similarQuery->text().split(exp, QString::SkipEmptyParts);
+ if (!lst.isEmpty()) {
+ QStringList fuzzy;
+ foreach (const QString term, lst)
+ fuzzy += buildTermList(escapeString(term));
+ queryList.append(QHelpSearchQuery(QHelpSearchQuery::FUZZY, fuzzy));
+ }
+
+ lst = withoutQuery->text().split(exp, QString::SkipEmptyParts);
+ if (!lst.isEmpty()) {
+ QStringList without;
+ foreach (const QString term, lst)
+ without.append(escapeString(term));
+ queryList.append(QHelpSearchQuery(QHelpSearchQuery::WITHOUT, without));
+ }
+
+ if (!exactQuery->text().isEmpty()) {
+ QString phrase = exactQuery->text().remove(QLatin1Char('\"'));
+ phrase = escapeString(phrase.simplified());
+ queryList.append(QHelpSearchQuery(QHelpSearchQuery::PHRASE, QStringList(phrase)));
+ }
+
+ lst = allQuery->text().split(exp, QString::SkipEmptyParts);
+ if (!lst.isEmpty()) {
+ QStringList all;
+ foreach (const QString term, lst)
+ all.append(escapeString(term));
+ queryList.append(QHelpSearchQuery(QHelpSearchQuery::ALL, all));
+ }
+
+ lst = atLeastQuery->text().split(exp, QString::SkipEmptyParts);
+ if (!lst.isEmpty()) {
+ QStringList atLeast;
+ foreach (const QString term, lst)
+ atLeast += buildTermList(escapeString(term));
+ queryList.append(QHelpSearchQuery(QHelpSearchQuery::ATLEAST, atLeast));
+ }
+ }
+#endif
+ QueryHistory &queryHist = simpleSearch ? simpleQueries : complexQueries;
+ saveQuery(queryList, queryHist);
+ queryHist.curQuery = queryHist.queries.size() - 1;
+ if (queryHist.curQuery > 0)
+ prevQueryButton->setEnabled(true);
+ nextQueryButton->setEnabled(false);
+ }
+
+ void nextQuery()
+ {
+ nextOrPrevQuery((simpleSearch ? simpleQueries : complexQueries).queries.size() - 1,
+ 1, nextQueryButton, prevQueryButton);
+ }
+
+ void prevQuery()
+ {
+ nextOrPrevQuery(0, -1, prevQueryButton, nextQueryButton);
}
private:
friend class QHelpSearchQueryWidget;
+ bool simpleSearch;
QPushButton *searchButton;
QWidget* advancedSearchWidget;
QToolButton *showHideAdvancedSearchButton;
@@ -163,6 +369,11 @@ private:
QLineEdit *withoutQuery;
QLineEdit *allQuery;
QLineEdit *atLeastQuery;
+ QToolButton *nextQueryButton;
+ QToolButton *prevQueryButton;
+ QueryHistory simpleQueries;
+ QueryHistory complexQueries;
+ QCompleter searchCompleter;
};
#include "qhelpsearchquerywidget.moc"
@@ -199,13 +410,26 @@ QHelpSearchQueryWidget::QHelpSearchQueryWidget(QWidget *parent)
QHBoxLayout* hBoxLayout = new QHBoxLayout();
QLabel *label = new QLabel(tr("Search for:"), this);
d->defaultQuery = new QLineEdit(this);
+ d->defaultQuery->setCompleter(&d->searchCompleter);
+ d->prevQueryButton = new QToolButton(this);
+ d->prevQueryButton->setArrowType(Qt::LeftArrow);
+ d->prevQueryButton->setToolTip(tr("Previous search"));
+ d->prevQueryButton->setEnabled(false);
+ d->nextQueryButton = new QToolButton(this);
+ d->nextQueryButton->setArrowType(Qt::RightArrow);
+ d->nextQueryButton->setToolTip(tr("Next search"));
+ d->nextQueryButton->setEnabled(false);
d->searchButton = new QPushButton(tr("Search"), this);
hBoxLayout->addWidget(label);
hBoxLayout->addWidget(d->defaultQuery);
+ hBoxLayout->addWidget(d->prevQueryButton);
+ hBoxLayout->addWidget(d->nextQueryButton);
hBoxLayout->addWidget(d->searchButton);
vLayout->addLayout(hBoxLayout);
+ connect(d->prevQueryButton, SIGNAL(clicked()), d, SLOT(prevQuery()));
+ connect(d->nextQueryButton, SIGNAL(clicked()), d, SLOT(nextQuery()));
connect(d->searchButton, SIGNAL(clicked()), this, SIGNAL(search()));
connect(d->defaultQuery, SIGNAL(returnPressed()), this, SIGNAL(search()));
@@ -236,26 +460,31 @@ QHelpSearchQueryWidget::QHelpSearchQueryWidget(QWidget *parent)
label = new QLabel(tr("words <B>similar</B> to:"), this);
gLayout->addWidget(label, 0, 0);
d->similarQuery = new QLineEdit(this);
+ d->similarQuery->setCompleter(&d->searchCompleter);
gLayout->addWidget(d->similarQuery, 0, 1);
label = new QLabel(tr("<B>without</B> the words:"), this);
gLayout->addWidget(label, 1, 0);
d->withoutQuery = new QLineEdit(this);
+ d->withoutQuery->setCompleter(&d->searchCompleter);
gLayout->addWidget(d->withoutQuery, 1, 1);
label = new QLabel(tr("with <B>exact phrase</B>:"), this);
gLayout->addWidget(label, 2, 0);
d->exactQuery = new QLineEdit(this);
+ d->exactQuery->setCompleter(&d->searchCompleter);
gLayout->addWidget(d->exactQuery, 2, 1);
label = new QLabel(tr("with <B>all</B> of the words:"), this);
gLayout->addWidget(label, 3, 0);
d->allQuery = new QLineEdit(this);
+ d->allQuery->setCompleter(&d->searchCompleter);
gLayout->addWidget(d->allQuery, 3, 1);
label = new QLabel(tr("with <B>at least one</B> of the words:"), this);
gLayout->addWidget(label, 4, 0);
d->atLeastQuery = new QLineEdit(this);
+ d->atLeastQuery->setCompleter(&d->searchCompleter);
gLayout->addWidget(d->atLeastQuery, 4, 1);
vLayout->addWidget(d->advancedSearchWidget);
@@ -269,6 +498,7 @@ QHelpSearchQueryWidget::QHelpSearchQueryWidget(QWidget *parent)
connect(d->showHideAdvancedSearchButton, SIGNAL(clicked()),
d, SLOT(showHideAdvancedSearch()));
#endif
+ connect(this, SIGNAL(search()), d, SLOT(searchRequested()));
}
/*!
@@ -285,59 +515,10 @@ QHelpSearchQueryWidget::~QHelpSearchQueryWidget()
*/
QList<QHelpSearchQuery> QHelpSearchQueryWidget::query() const
{
-#if !defined(QT_CLUCENE_SUPPORT)
- QList<QHelpSearchQuery> queryList;
- queryList.append(QHelpSearchQuery(QHelpSearchQuery::DEFAULT,
- QStringList(d->defaultQuery->text())));
-
- return queryList;
-#else
- QList<QHelpSearchQuery> queryList;
- if (d->defaultQuery->isEnabled()) {
- queryList.append(QHelpSearchQuery(QHelpSearchQuery::DEFAULT,
- d->buildTermList(d->escapeString(d->defaultQuery->text()))));
- } else {
- const QRegExp exp(QLatin1String("\\s+"));
- QStringList lst = d->similarQuery->text().split(exp, QString::SkipEmptyParts);
- if (!lst.isEmpty()) {
- QStringList fuzzy;
- foreach (const QString term, lst)
- fuzzy += d->buildTermList(d->escapeString(term));
- queryList.append(QHelpSearchQuery(QHelpSearchQuery::FUZZY, fuzzy));
- }
-
- lst = d->withoutQuery->text().split(exp, QString::SkipEmptyParts);
- if (!lst.isEmpty()) {
- QStringList without;
- foreach (const QString term, lst)
- without.append(d->escapeString(term));
- queryList.append(QHelpSearchQuery(QHelpSearchQuery::WITHOUT, without));
- }
-
- if (!d->exactQuery->text().isEmpty()) {
- QString phrase = d->exactQuery->text().remove(QLatin1Char('\"'));
- phrase = d->escapeString(phrase.simplified());
- queryList.append(QHelpSearchQuery(QHelpSearchQuery::PHRASE, QStringList(phrase)));
- }
-
- lst = d->allQuery->text().split(exp, QString::SkipEmptyParts);
- if (!lst.isEmpty()) {
- QStringList all;
- foreach (const QString term, lst)
- all.append(d->escapeString(term));
- queryList.append(QHelpSearchQuery(QHelpSearchQuery::ALL, all));
- }
-
- lst = d->atLeastQuery->text().split(exp, QString::SkipEmptyParts);
- if (!lst.isEmpty()) {
- QStringList atLeast;
- foreach (const QString term, lst)
- atLeast += d->buildTermList(d->escapeString(term));
- queryList.append(QHelpSearchQuery(QHelpSearchQuery::ATLEAST, atLeast));
- }
- }
- return queryList;
-#endif
+ const QHelpSearchQueryWidgetPrivate::QueryHistory &queryHist =
+ d->simpleSearch ? d->simpleQueries : d->complexQueries;
+ return queryHist.queries.isEmpty() ?
+ QList<QHelpSearchQuery>() : queryHist.queries.last();
}
/*! \reimp