diff options
Diffstat (limited to 'tools/assistant/lib/qhelpprojectdata.cpp')
-rw-r--r-- | tools/assistant/lib/qhelpprojectdata.cpp | 61 |
1 files changed, 53 insertions, 8 deletions
diff --git a/tools/assistant/lib/qhelpprojectdata.cpp b/tools/assistant/lib/qhelpprojectdata.cpp index f8a276a..77a5157 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 @@ -324,7 +369,7 @@ QString QHelpProjectData::errorMessage() const } /*! - \reimp + \internal */ QString QHelpProjectData::namespaceName() const { @@ -332,7 +377,7 @@ QString QHelpProjectData::namespaceName() const } /*! - \reimp + \internal */ QString QHelpProjectData::virtualFolder() const { @@ -340,7 +385,7 @@ QString QHelpProjectData::virtualFolder() const } /*! - \reimp + \internal */ QList<QHelpDataCustomFilter> QHelpProjectData::customFilters() const { @@ -348,7 +393,7 @@ QList<QHelpDataCustomFilter> QHelpProjectData::customFilters() const } /*! - \reimp + \internal */ QList<QHelpDataFilterSection> QHelpProjectData::filterSections() const { @@ -356,7 +401,7 @@ QList<QHelpDataFilterSection> QHelpProjectData::filterSections() const } /*! - \reimp + \internal */ QMap<QString, QVariant> QHelpProjectData::metaData() const { @@ -364,7 +409,7 @@ QMap<QString, QVariant> QHelpProjectData::metaData() const } /*! - \reimp + \internal */ QString QHelpProjectData::rootPath() const { |