2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-06-20 11:57:20 +02:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 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
|
2014-10-01 13:21:18 +02:00
|
|
|
** conditions see http://www.qt.io/licensing. For further information
|
|
|
|
|
** use the contact form at http://www.qt.io/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
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
|
|
|
|
** 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>
|
2013-08-24 23:10:17 +02:00
|
|
|
#include "projectexplorer_export.h"
|
|
|
|
|
|
|
|
|
|
namespace Utils { class PathChooser; }
|
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
|
|
|
|
2013-08-24 23:10:17 +02:00
|
|
|
namespace ProjectExplorer {
|
2011-06-20 11:57:20 +02:00
|
|
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
2013-08-24 23:10:17 +02:00
|
|
|
class PROJECTEXPLORER_EXPORT SelectableFilesModel : public QAbstractItemModel
|
2011-06-20 11:57:20 +02:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
2012-08-14 15:37:38 +02:00
|
|
|
|
2011-06-20 11:57:20 +02:00
|
|
|
public:
|
2013-08-24 23:10:17 +02:00
|
|
|
SelectableFilesModel(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
|
|
|
|
2013-08-24 23:10:17 +02:00
|
|
|
void startParsing(const QString &baseDir);
|
2011-06-21 17:12:44 +02:00
|
|
|
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
|
|
|
|
2013-08-24 23:10:17 +02:00
|
|
|
void selectAllFiles();
|
|
|
|
|
|
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 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;
|
2013-11-21 16:38:16 +01:00
|
|
|
void buildTree(const QString &baseDir, Tree *tree, QFutureInterface<void> &fi, int symlinkDepth);
|
2011-06-20 11:57:20 +02:00
|
|
|
void deleteTree(Tree *tree);
|
|
|
|
|
void propagateUp(const QModelIndex &index);
|
|
|
|
|
void propagateDown(const QModelIndex &index);
|
2013-08-24 23:10:17 +02:00
|
|
|
void selectAllFiles(Tree *root);
|
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
|
|
|
};
|
|
|
|
|
|
2013-08-24 23:10:17 +02:00
|
|
|
class PROJECTEXPLORER_EXPORT SelectableFilesDialogEditFiles : public QDialog
|
2011-06-20 11:57:20 +02:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
2012-08-14 15:37:38 +02:00
|
|
|
|
2011-06-20 11:57:20 +02:00
|
|
|
public:
|
2014-05-19 18:34:53 +03:00
|
|
|
SelectableFilesDialogEditFiles(const QString &path, const QStringList &files, QWidget *parent);
|
2013-08-24 23:10:17 +02:00
|
|
|
~SelectableFilesDialogEditFiles();
|
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();
|
|
|
|
|
|
2013-08-24 23:10:17 +02:00
|
|
|
protected:
|
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);
|
2013-08-24 23:10:17 +02:00
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
2013-08-24 23:10:17 +02:00
|
|
|
class SelectableFilesDialogAddDirectory : public SelectableFilesDialogEditFiles
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
2014-05-19 18:34:53 +03:00
|
|
|
SelectableFilesDialogAddDirectory(const QString &path, const QStringList &files, QWidget *parent);
|
2013-08-24 23:10:17 +02:00
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
|
void validityOfDirectoryChanged(bool validState);
|
|
|
|
|
void parsingFinished();
|
|
|
|
|
void startParsing();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Utils::PathChooser *m_pathChooser;
|
|
|
|
|
QLabel *m_sourceDirectoryLabel;
|
|
|
|
|
QPushButton *m_startParsingButton;
|
|
|
|
|
|
|
|
|
|
void setWidgetsEnabled(bool enabled);
|
|
|
|
|
void createPathChooser(QVBoxLayout *layout, const QString &path);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace ProjectExplorer
|
2011-06-20 11:57:20 +02:00
|
|
|
|
|
|
|
|
#endif // SELECTABLEFILESMODEL_H
|
2013-04-16 20:52:55 +02:00
|
|
|
|