1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
37 #include "utils_global.h"
39 #include <QtCore/QStringList>
40 #include <QtCore/QFuture>
41 #include <QtCore/QMap>
42 #include <QtCore/QStack>
43 #include <QtCore/QDir>
44 #include <QtCore/QTextCodec>
45 #include <QtGui/QTextDocument>
49 class QTCREATOR_UTILS_EXPORT FileIterator
53 explicit FileIterator(const QStringList &fileList,
54 const QList<QTextCodec *> encodings);
57 virtual bool hasNext() const;
58 virtual QString next();
59 virtual QTextCodec *encoding() const;
60 virtual int maxProgress() const;
61 virtual int currentProgress() const;
65 QStringListIterator *m_iterator;
66 QList<QTextCodec *> m_encodings;
70 class QTCREATOR_UTILS_EXPORT SubDirFileIterator : public FileIterator
73 SubDirFileIterator(const QStringList &directories, const QStringList &filters,
74 QTextCodec *encoding = 0);
78 QTextCodec *encoding() const;
79 int maxProgress() const;
80 int currentProgress() const;
83 QStringList m_filters;
84 QTextCodec *m_encoding;
85 mutable QStack<QDir> m_dirs;
86 mutable QStack<qreal> m_progressValues;
87 mutable QStack<bool> m_processedValues;
88 mutable qreal m_progress;
89 mutable QStringList m_currentFiles;
92 class QTCREATOR_UTILS_EXPORT FileSearchResult
96 FileSearchResult(QString fileName, int lineNumber, QString matchingLine,
97 int matchStart, int matchLength,
98 QStringList regexpCapturedTexts)
100 lineNumber(lineNumber),
101 matchingLine(matchingLine),
102 matchStart(matchStart),
103 matchLength(matchLength),
104 regexpCapturedTexts(regexpCapturedTexts)
109 QString matchingLine;
112 QStringList regexpCapturedTexts;
115 typedef QList<FileSearchResult> FileSearchResultList;
117 QTCREATOR_UTILS_EXPORT QFuture<FileSearchResultList> findInFiles(const QString &searchTerm, FileIterator *files,
118 QTextDocument::FindFlags flags, QMap<QString, QString> fileToContentsMap = QMap<QString, QString>());
120 QTCREATOR_UTILS_EXPORT QFuture<FileSearchResultList> findInFilesRegExp(const QString &searchTerm, FileIterator *files,
121 QTextDocument::FindFlags flags, QMap<QString, QString> fileToContentsMap = QMap<QString, QString>());
123 QTCREATOR_UTILS_EXPORT QString expandRegExpReplacement(const QString &replaceText, const QStringList &capturedTexts);
127 #endif // FILESEARCH_H