Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/tools/assistant/lib/qhelpprojectdata.cpp

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the Qt Assistant of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    4242#include "qhelpprojectdata_p.h"
    4343
     44#include <QtCore/QDir>
    4445#include <QtCore/QFileInfo>
    4546#include <QtCore/QStack>
    4647#include <QtCore/QMap>
     48#include <QtCore/QRegExp>
    4749#include <QtCore/QVariant>
    4850#include <QtXml/QXmlStreamReader>
     
    7476    void readFiles();
    7577    void raiseUnknownTokenError();
     78    void addMatchingFiles(const QString &pattern);
     79
     80    QMap<QString, QStringList> dirEntriesCache;
    7681};
    7782
     
    162167        if (isStartElement()) {
    163168            if (name() == QLatin1String("filterAttribute"))
    164                 filterSectionList.last().addFilterAttribute(readElementText());                         
     169                filterSectionList.last().addFilterAttribute(readElementText());
    165170            else if (name() == QLatin1String("toc"))
    166171                readTOC();
     
    245250        if (isStartElement()) {
    246251            if (name() == QLatin1String("file"))
    247                 filterSectionList.last().addFile(readElementText());
     252                addMatchingFiles(readElementText());
    248253            else
    249254                raiseUnknownTokenError();
     
    259264}
    260265
    261 
     266// Expand file pattern and add matches into list. If the pattern does not match
     267// any files, insert the pattern itself so the QHelpGenerator will emit a
     268// meaningful warning later.
     269void QHelpProjectDataPrivate::addMatchingFiles(const QString &pattern)
     270{
     271    // The pattern matching is expensive, so we skip it if no
     272    // wildcard symbols occur in the string.
     273    if (!pattern.contains('?') && !pattern.contains('*')
     274        && !pattern.contains('[') && !pattern.contains(']')) {
     275        filterSectionList.last().addFile(pattern);
     276        return;
     277    }
     278
     279    QFileInfo fileInfo(rootPath + '/' + pattern);
     280    const QDir &dir = fileInfo.dir();
     281    const QString &path = dir.canonicalPath();
     282
     283    // QDir::entryList() is expensive, so we cache the results.
     284    QMap<QString, QStringList>::ConstIterator it = dirEntriesCache.find(path);
     285    const QStringList &entries = it != dirEntriesCache.constEnd() ?
     286                                 it.value() : dir.entryList(QDir::Files);
     287    if (it == dirEntriesCache.constEnd())
     288        dirEntriesCache.insert(path, entries);
     289
     290    bool matchFound = false;
     291#ifdef Q_OS_WIN
     292    Qt::CaseSensitivity cs = Qt::CaseInsensitive;
     293#else
     294    Qt::CaseSensitivity cs = Qt::CaseSensitive;
     295#endif
     296    QRegExp regExp(fileInfo.fileName(), cs, QRegExp::Wildcard);
     297    foreach (const QString &file, entries) {
     298        if (regExp.exactMatch(file)) {
     299            matchFound = true;
     300            filterSectionList.last().
     301                addFile(QFileInfo(pattern).dir().path() + '/' + file);
     302        }
     303    }
     304    if (!matchFound)
     305        filterSectionList.last().addFile(pattern);
     306}
    262307
    263308/*!
     
    325370
    326371/*!
    327     \reimp
     372    \internal
    328373*/
    329374QString QHelpProjectData::namespaceName() const
     
    333378
    334379/*!
    335     \reimp
     380    \internal
    336381*/
    337382QString QHelpProjectData::virtualFolder() const
     
    341386
    342387/*!
    343     \reimp
     388    \internal
    344389*/
    345390QList<QHelpDataCustomFilter> QHelpProjectData::customFilters() const
     
    349394
    350395/*!
    351     \reimp
     396    \internal
    352397*/
    353398QList<QHelpDataFilterSection> QHelpProjectData::filterSections() const
     
    357402
    358403/*!
    359     \reimp
     404    \internal
    360405*/
    361406QMap<QString, QVariant> QHelpProjectData::metaData() const
     
    365410
    366411/*!
    367     \reimp
     412    \internal
    368413*/
    369414QString QHelpProjectData::rootPath() const
Note: See TracChangeset for help on using the changeset viewer.