2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-06-20 11:57:20 +02:00
|
|
|
**
|
2013-01-28 17:12:19 +01:00
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2011-06-20 11:57:20 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-06-20 11:57:20 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2011-06-20 11:57:20 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, 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, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2011-06-20 11:57:20 +02:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
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 <QDialog>
|
|
|
|
|
#include <QTreeView>
|
|
|
|
|
#include <QLabel>
|
2011-06-20 11:57:20 +02:00
|
|
|
|
2013-04-22 13:01:37 +02:00
|
|
|
QT_BEGIN_NAMESPACE
|
2013-04-16 20:52:55 +02:00
|
|
|
class QVBoxLayout;
|
2013-04-22 13:01:37 +02:00
|
|
|
QT_END_NAMESPACE
|
2013-04-16 20:52:55 +02:00
|
|
|
|
2011-06-20 11:57:20 +02:00
|
|
|
namespace GenericProjectManager {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
struct Tree
|
|
|
|
|
{
|
|
|
|
|
QString name;
|
|
|
|
|
Qt::CheckState checked;
|
2013-02-18 18:47:54 +01:00
|
|
|
bool isDir;
|
2011-06-20 11:57:20 +02:00
|
|
|
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;
|
|
|
|
|
Tree *parent;
|
|
|
|
|
};
|
|
|
|
|
|
2011-06-28 18:57:16 +02:00
|
|
|
struct Glob
|
|
|
|
|
{
|
|
|
|
|
enum Mode { EXACT, ENDSWITH, REGEXP };
|
|
|
|
|
Mode mode;
|
|
|
|
|
QString matchString;
|
2012-04-30 12:01:15 +02:00
|
|
|
mutable QRegExp matchRegexp;
|
2013-04-16 20:52:55 +02:00
|
|
|
|
|
|
|
|
bool isMatch(const QString &text) const
|
|
|
|
|
{
|
|
|
|
|
if (mode == Glob::EXACT) {
|
|
|
|
|
if (text == matchString)
|
|
|
|
|
return true;
|
|
|
|
|
} else if (mode == Glob::ENDSWITH) {
|
|
|
|
|
if (text.endsWith(matchString))
|
|
|
|
|
return true;
|
|
|
|
|
} else if (mode == Glob::REGEXP) {
|
|
|
|
|
if (matchRegexp.exactMatch(text))
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2011-06-28 18:57:16 +02:00
|
|
|
};
|
|
|
|
|
|
2011-06-20 11:57:20 +02:00
|
|
|
class SelectableFilesModel : public QAbstractItemModel
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
2012-08-14 15:37:38 +02:00
|
|
|
|
2011-06-20 11:57:20 +02:00
|
|
|
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 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();
|
2013-04-16 20:52:55 +02:00
|
|
|
void applyFilter(const QString &selectFilesfilter, const QString &hideFilesfilter);
|
2012-08-14 15:37:38 +02:00
|
|
|
|
2011-06-21 17:12:44 +02:00
|
|
|
signals:
|
|
|
|
|
void parsingFinished();
|
|
|
|
|
void parsingProgress(const QString &filename);
|
2012-08-14 15:37:38 +02:00
|
|
|
|
2011-06-21 17:12:44 +02:00
|
|
|
private slots:
|
|
|
|
|
void buildTreeFinished();
|
2012-08-14 15:37:38 +02:00
|
|
|
|
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-21 17:12:44 +02:00
|
|
|
QFutureWatcher<void> m_watcher;
|
|
|
|
|
Tree *m_rootForFuture;
|
|
|
|
|
int m_futureCount;
|
|
|
|
|
bool m_allFiles;
|
2013-04-16 20:52:55 +02:00
|
|
|
|
|
|
|
|
QList<Glob> m_hideFilesFilter;
|
|
|
|
|
QList<Glob> m_showFilesFilter;
|
2011-06-20 11:57:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class SelectableFilesDialog : public QDialog
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
2012-08-14 15:37:38 +02:00
|
|
|
|
2011-06-20 11:57:20 +02:00
|
|
|
public:
|
2012-02-29 11:19:18 +01:00
|
|
|
SelectableFilesDialog(const QString &path, const QStringList files, 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);
|
2013-04-16 20:52:55 +02:00
|
|
|
void createShowFileFilterControls(QVBoxLayout *layout);
|
|
|
|
|
void createHideFileFilterControls(QVBoxLayout *layout);
|
|
|
|
|
void createApplyButton(QVBoxLayout *layout);
|
2011-06-20 11:57:20 +02:00
|
|
|
SelectableFilesModel *m_selectableFilesModel;
|
2013-04-16 20:52:55 +02:00
|
|
|
|
|
|
|
|
QLabel *m_hideFilesFilterLabel;
|
|
|
|
|
QLineEdit *m_hideFilesfilterLineEdit;
|
|
|
|
|
|
|
|
|
|
QLabel *m_showFilesFilterLabel;
|
|
|
|
|
QLineEdit *m_showFilesfilterLineEdit;
|
|
|
|
|
|
2011-06-28 18:57:16 +02:00
|
|
|
QPushButton *m_applyFilterButton;
|
2013-04-16 20:52:55 +02:00
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
2012-08-14 15:37:38 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace GenericProjectManager
|
2011-06-20 11:57:20 +02:00
|
|
|
|
|
|
|
|
#endif // SELECTABLEFILESMODEL_H
|
2013-04-16 20:52:55 +02:00
|
|
|
|