OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qmlprojectmanager / fileformat / filefilteritems.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** Other Usage
24 **
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #ifndef FILEFILTERITEMS_H
34 #define FILEFILTERITEMS_H
35
36 #include "qmlprojectitem.h"
37 #include "filesystemwatcher.h"
38
39 #include <QtCore/QObject>
40 #include <QtCore/QSet>
41 #include <QtCore/QTimer>
42
43 #include <QtDeclarative/qdeclarative.h>
44
45 QT_FORWARD_DECLARE_CLASS(QDir)
46
47 namespace QmlProjectManager {
48
49 class FileFilterBaseItem : public QmlProjectContentItem {
50     Q_OBJECT
51
52     Q_PROPERTY(QString directory READ directory WRITE setDirectory NOTIFY directoryChanged)
53     Q_PROPERTY(bool recursive READ recursive WRITE setRecursive NOTIFY recursiveChanged)
54     Q_PROPERTY(QStringList paths READ pathsProperty WRITE setPathsProperty)
55
56     Q_PROPERTY(QStringList files READ files NOTIFY filesChanged DESIGNABLE false)
57
58 public:
59     FileFilterBaseItem(QObject *parent = 0);
60
61     QString directory() const;
62     void setDirectory(const QString &directoryPath);
63
64     void setDefaultDirectory(const QString &directoryPath);
65
66     QString filter() const;
67     void setFilter(const QString &filter);
68
69     bool recursive() const;
70     void setRecursive(bool recursive);
71
72     QStringList pathsProperty() const;
73     void setPathsProperty(const QStringList &paths);
74
75     virtual QStringList files() const;
76     bool matchesFile(const QString &filePath) const;
77
78 signals:
79     void directoryChanged();
80     void recursiveChanged();
81     void pathsChanged();
82     void filesChanged(const QSet<QString> &added, const QSet<QString> &removed);
83
84 private slots:
85     void updateFileList();
86     void updateFileListNow();
87
88 private:
89     QString absolutePath(const QString &path) const;
90     QString absoluteDir() const;
91
92     bool fileMatches(const QString &fileName) const;
93     QSet<QString> filesInSubTree(const QDir &rootDir, const QDir &dir, QSet<QString> *parsedDirs = 0);
94
95     QString m_rootDir;
96     QString m_defaultDir;
97
98     QString m_filter;
99     // simple "*.png" patterns are stored in m_fileSuffixes, otherwise store in m_regExpList
100     QList<QString> m_fileSuffixes;
101     QList<QRegExp> m_regExpList;
102
103     enum RecursiveOption {
104         Recurse,
105         DoNotRecurse,
106         RecurseDefault // not set explicitly
107     };
108
109     RecursiveOption m_recurse;
110
111     QStringList m_explicitFiles;
112
113     QSet<QString> m_files;
114     FileSystemWatcher m_dirWatcher;
115     QTimer m_updateFileListTimer;
116
117
118     friend class ProjectItem;
119 };
120
121 class QmlFileFilterItem : public FileFilterBaseItem {
122     Q_OBJECT
123
124 public:
125     QmlFileFilterItem(QObject *parent = 0);
126 };
127
128 class JsFileFilterItem : public FileFilterBaseItem {
129     Q_OBJECT
130     Q_PROPERTY(QString filter READ filter WRITE setFilter NOTIFY filterChanged)
131
132     void setFilter(const QString &filter);
133
134 signals:
135     void filterChanged();
136
137 public:
138     JsFileFilterItem(QObject *parent = 0);
139 };
140
141 class ImageFileFilterItem : public FileFilterBaseItem {
142     Q_OBJECT
143     Q_PROPERTY(QString filter READ filter WRITE setFilter NOTIFY filterChanged)
144
145     void setFilter(const QString &filter);
146
147 signals:
148     void filterChanged();
149
150 public:
151     ImageFileFilterItem(QObject *parent = 0);
152 };
153
154 class CssFileFilterItem : public FileFilterBaseItem {
155     Q_OBJECT
156     Q_PROPERTY(QString filter READ filter WRITE setFilter NOTIFY filterChanged)
157
158     void setFilter(const QString &filter);
159
160 signals:
161     void filterChanged();
162
163 public:
164     CssFileFilterItem(QObject *parent = 0);
165 };
166
167 class OtherFileFilterItem : public FileFilterBaseItem {
168     Q_OBJECT
169     Q_PROPERTY(QString filter READ filter WRITE setFilter NOTIFY filterChanged)
170
171     void setFilter(const QString &filter);
172
173 signals:
174     void filterChanged();
175
176 public:
177     OtherFileFilterItem(QObject *parent = 0);
178 };
179
180 } // namespace QmlProjectManager
181
182 QML_DECLARE_TYPE(QmlProjectManager::QmlFileFilterItem)
183 QML_DECLARE_TYPE(QmlProjectManager::JsFileFilterItem)
184 QML_DECLARE_TYPE(QmlProjectManager::ImageFileFilterItem)
185 QML_DECLARE_TYPE(QmlProjectManager::CssFileFilterItem)
186 QML_DECLARE_TYPE(QmlProjectManager::OtherFileFilterItem)
187
188 #endif // FILEFILTERITEMS_HPROJECTITEM_H