2011-06-20 11:57:20 +02:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2012-01-26 18:33:46 +01:00
|
|
|
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2011-06-20 11:57:20 +02:00
|
|
|
**
|
2011-11-02 15:59:12 +01:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2011-06-20 11:57:20 +02:00
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
|
|
|
|
** 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.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
|
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-11-02 15:59:12 +01:00
|
|
|
** Nokia at qt-info@nokia.com.
|
2011-06-20 11:57:20 +02:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#ifndef SELECTABLEFILESMODEL_H
|
|
|
|
|
#define SELECTABLEFILESMODEL_H
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QAbstractItemModel>
|
|
|
|
|
#include <QSet>
|
|
|
|
|
#include <QFutureInterface>
|
|
|
|
|
#include <QFutureWatcher>
|
|
|
|
|
#include <QFileSystemModel>
|
|
|
|
|
#include <QDialog>
|
|
|
|
|
#include <QTreeView>
|
|
|
|
|
#include <QLabel>
|
2011-06-20 11:57:20 +02:00
|
|
|
|
|
|
|
|
namespace GenericProjectManager {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct Tree
|
|
|
|
|
{
|
|
|
|
|
QString name;
|
|
|
|
|
Qt::CheckState checked;
|
|
|
|
|
QList<Tree *> childDirectories;
|
|
|
|
|
QList<Tree *> files;
|
2011-06-28 18:57:16 +02:00
|
|
|
QList<Tree *> visibleFiles;
|
2011-06-20 11:57:20 +02:00
|
|
|
QIcon icon;
|
|
|
|
|
QString fullPath;
|
2011-06-28 18:57:16 +02:00
|
|
|
bool isDir;
|
2011-06-20 11:57:20 +02:00
|
|
|
Tree *parent;
|
|
|
|
|
};
|
|
|
|
|
|
2011-06-28 18:57:16 +02:00
|
|
|
struct Glob
|
|
|
|
|
{
|
|
|
|
|
enum Mode { EXACT, ENDSWITH, REGEXP };
|
|
|
|
|
Mode mode;
|
|
|
|
|
QString matchString;
|
|
|
|
|
QRegExp matchRegexp;
|
|
|
|
|
};
|
|
|
|
|
|
2011-06-20 11:57:20 +02:00
|
|
|
class SelectableFilesModel : public QAbstractItemModel
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
2011-06-21 17:12:44 +02:00
|
|
|
SelectableFilesModel(const QString &baseDir, QObject *parent);
|
2011-06-20 11:57:20 +02:00
|
|
|
~SelectableFilesModel();
|
|
|
|
|
|
2011-06-21 17:12:44 +02:00
|
|
|
void setSuffixes(QSet<QString> suffixes);
|
|
|
|
|
void setInitialMarkedFiles(const QStringList &files);
|
|
|
|
|
|
2011-06-20 11:57:20 +02:00
|
|
|
int columnCount(const QModelIndex &parent) const;
|
|
|
|
|
int rowCount(const QModelIndex &parent) const;
|
|
|
|
|
QModelIndex index(int row, int column, const QModelIndex &parent) const;
|
|
|
|
|
QModelIndex parent(const QModelIndex &child) const;
|
|
|
|
|
|
|
|
|
|
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
|
|
|
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
|
|
|
|
Qt::ItemFlags flags(const QModelIndex &index) const;
|
|
|
|
|
|
|
|
|
|
QStringList selectedFiles() const;
|
2011-06-21 17:12:44 +02:00
|
|
|
QStringList selectedPaths() const;
|
2011-07-01 18:56:44 +02:00
|
|
|
QStringList preservedFiles() const;
|
2011-06-21 17:12:44 +02:00
|
|
|
|
|
|
|
|
// only call this once
|
|
|
|
|
void startParsing();
|
|
|
|
|
void waitForFinished();
|
|
|
|
|
void cancel();
|
2011-06-28 18:57:16 +02:00
|
|
|
void applyFilter(const QString &filter);
|
2011-06-21 17:12:44 +02:00
|
|
|
signals:
|
|
|
|
|
void parsingFinished();
|
|
|
|
|
void parsingProgress(const QString &filename);
|
|
|
|
|
private slots:
|
|
|
|
|
void buildTreeFinished();
|
2011-06-20 11:57:20 +02:00
|
|
|
private:
|
2011-06-28 18:57:16 +02:00
|
|
|
QList<Glob> parseFilter(const QString &filter);
|
|
|
|
|
Qt::CheckState applyFilter(const QModelIndex &index);
|
|
|
|
|
bool filter(Tree *t);
|
2011-06-21 17:12:44 +02:00
|
|
|
void init();
|
|
|
|
|
void run(QFutureInterface<void> &fi);
|
2011-06-20 11:57:20 +02:00
|
|
|
void collectFiles(Tree *root, QStringList *result) const;
|
2011-06-21 17:12:44 +02:00
|
|
|
void collectPaths(Tree *root, QStringList *result) const;
|
|
|
|
|
void buildTree(const QString &baseDir, Tree *tree, QFutureInterface<void> &fi);
|
2011-06-20 11:57:20 +02:00
|
|
|
void deleteTree(Tree *tree);
|
|
|
|
|
void propagateUp(const QModelIndex &index);
|
|
|
|
|
void propagateDown(const QModelIndex &index);
|
2011-06-21 17:12:44 +02:00
|
|
|
Tree *m_root;
|
|
|
|
|
// Used in the future thread need to all not used after calling startParsing
|
2011-06-20 11:57:20 +02:00
|
|
|
QString m_baseDir;
|
|
|
|
|
QSet<QString> m_files;
|
2011-07-01 18:56:44 +02:00
|
|
|
QStringList m_outOfBaseDirFiles;
|
2011-06-20 11:57:20 +02:00
|
|
|
QSet<QString> m_suffixes;
|
2011-06-21 17:12:44 +02:00
|
|
|
QFutureWatcher<void> m_watcher;
|
|
|
|
|
Tree *m_rootForFuture;
|
|
|
|
|
int m_futureCount;
|
|
|
|
|
bool m_allFiles;
|
2011-06-28 18:57:16 +02:00
|
|
|
QList<Glob> m_filter;
|
2011-06-20 11:57:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class SelectableFilesDialog : public QDialog
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
|
|
|
|
SelectableFilesDialog(const QString &path, const QStringList files, const QSet<QString> &suffixes, QWidget *parent);
|
2011-06-21 17:12:44 +02:00
|
|
|
~SelectableFilesDialog();
|
2011-06-20 11:57:20 +02:00
|
|
|
QStringList selectedFiles() const;
|
2011-06-21 17:12:44 +02:00
|
|
|
|
|
|
|
|
private slots:
|
2011-06-28 18:57:16 +02:00
|
|
|
void applyFilter();
|
2011-06-21 17:12:44 +02:00
|
|
|
void parsingProgress(const QString &fileName);
|
|
|
|
|
void parsingFinished();
|
|
|
|
|
|
2011-06-20 11:57:20 +02:00
|
|
|
private:
|
2011-06-21 17:12:44 +02:00
|
|
|
void smartExpand(const QModelIndex &index);
|
2011-06-20 11:57:20 +02:00
|
|
|
SelectableFilesModel *m_selectableFilesModel;
|
2011-06-28 18:57:16 +02:00
|
|
|
QLabel *m_filterLabel;
|
|
|
|
|
QLineEdit *m_filterLineEdit;
|
|
|
|
|
QPushButton *m_applyFilterButton;
|
2011-06-21 17:12:44 +02:00
|
|
|
QTreeView *m_view;
|
2011-07-01 18:56:44 +02:00
|
|
|
QLabel *m_preservedFiles;
|
2011-06-21 17:12:44 +02:00
|
|
|
QLabel *m_progressLabel;
|
2011-06-20 11:57:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif // SELECTABLEFILESMODEL_H
|