Added new filter into "Import Existing Project" and "Edit Files"

Extended classes:
- SelectableFilesModel
- SelectableFilesDialog
- FilesSelectionWizardPage

Task-number: QTCREATORBUG-8805
Change-Id: I0ff2f458fce2d7b0ceee24ace7dc2fafddc5ad5d
Reviewed-by: Petar Perisin <petar.perisin@gmail.com>
Reviewed-by: Daniel Teske <daniel.teske@digia.com>
This commit is contained in:
Pawel Faron
2013-04-16 20:52:55 +02:00
parent adb6e518ef
commit ec145f36f3
5 changed files with 219 additions and 69 deletions

View File

@@ -48,22 +48,9 @@ FilesSelectionWizardPage::FilesSelectionWizardPage(GenericProjectWizardDialog *g
{ {
QVBoxLayout *layout = new QVBoxLayout(this); QVBoxLayout *layout = new QVBoxLayout(this);
QHBoxLayout *hbox = new QHBoxLayout; createShowFileFilterControls(layout);
m_filterLabel = new QLabel; createHideFileFilterControls(layout);
m_filterLabel->setText(tr("Hide files matching:")); createApplyButton(layout);
m_filterLabel->hide();
hbox->addWidget(m_filterLabel);
m_filterLineEdit = new QLineEdit;
const QString filter = Core::ICore::settings()->value(QLatin1String(Constants::FILEFILTER_SETTING),
QLatin1String(Constants::FILEFILTER_DEFAULT)).toString();
m_filterLineEdit->setText(filter);
m_filterLineEdit->hide();
hbox->addWidget(m_filterLineEdit);
m_applyFilterButton = new QPushButton(tr("Apply Filter"), this);
m_applyFilterButton->hide();
hbox->addWidget(m_applyFilterButton);
layout->addLayout(hbox);
m_view = new QTreeView; m_view = new QTreeView;
m_view->setMinimumSize(500, 400); m_view->setMinimumSize(500, 400);
@@ -74,6 +61,54 @@ FilesSelectionWizardPage::FilesSelectionWizardPage(GenericProjectWizardDialog *g
layout->addWidget(m_view); layout->addWidget(m_view);
layout->addWidget(m_label); layout->addWidget(m_label);
}
void FilesSelectionWizardPage::createHideFileFilterControls(QVBoxLayout *layout)
{
QHBoxLayout *hbox = new QHBoxLayout;
m_hideFilesFilterLabel = new QLabel;
m_hideFilesFilterLabel->setText(tr("Hide files matching:"));
m_hideFilesFilterLabel->hide();
hbox->addWidget(m_hideFilesFilterLabel);
m_hideFilesfilterLineEdit = new QLineEdit;
const QString filter = Core::ICore::settings()->value(QLatin1String(Constants::HIDE_FILE_FILTER_SETTING),
QLatin1String(Constants::HIDE_FILE_FILTER_DEFAULT)).toString();
m_hideFilesfilterLineEdit->setText(filter);
m_hideFilesfilterLineEdit->hide();
hbox->addWidget(m_hideFilesfilterLineEdit);
layout->addLayout(hbox);
}
void FilesSelectionWizardPage::createShowFileFilterControls(QVBoxLayout *layout)
{
QHBoxLayout *hbox = new QHBoxLayout;
m_showFilesFilterLabel = new QLabel;
m_showFilesFilterLabel->setText(tr("Show files matching:"));
m_showFilesFilterLabel->hide();
hbox->addWidget(m_showFilesFilterLabel);
m_showFilesfilterLineEdit = new QLineEdit;
const QString filter = Core::ICore::settings()->value(QLatin1String(Constants::SHOW_FILE_FILTER_SETTING),
QLatin1String(Constants::SHOW_FILE_FILTER_DEFAULT)).toString();
m_showFilesfilterLineEdit->setText(filter);
m_showFilesfilterLineEdit->hide();
hbox->addWidget(m_showFilesfilterLineEdit);
layout->addLayout(hbox);
}
void FilesSelectionWizardPage::createApplyButton(QVBoxLayout *layout)
{
QHBoxLayout *hbox = new QHBoxLayout;
QSpacerItem *horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
hbox->addItem(horizontalSpacer);
m_applyFilterButton = new QPushButton(tr("Apply Filter"), this);
m_applyFilterButton->hide();
hbox->addWidget(m_applyFilterButton);
layout->addLayout(hbox);
connect(m_applyFilterButton, SIGNAL(clicked()), this, SLOT(applyFilter())); connect(m_applyFilterButton, SIGNAL(clicked()), this, SLOT(applyFilter()));
} }
@@ -88,8 +123,13 @@ void FilesSelectionWizardPage::initializePage()
connect(m_model, SIGNAL(parsingFinished()), connect(m_model, SIGNAL(parsingFinished()),
this, SLOT(parsingFinished())); this, SLOT(parsingFinished()));
m_model->startParsing(); m_model->startParsing();
m_filterLabel->setVisible(false);
m_filterLineEdit->setVisible(false); m_hideFilesFilterLabel->setVisible(false);
m_hideFilesfilterLineEdit->setVisible(false);
m_showFilesFilterLabel->setVisible(false);
m_showFilesfilterLineEdit->setVisible(false);
m_applyFilterButton->setVisible(false); m_applyFilterButton->setVisible(false);
m_view->setVisible(false); m_view->setVisible(false);
m_label->setVisible(true); m_label->setVisible(true);
@@ -110,8 +150,13 @@ void FilesSelectionWizardPage::parsingProgress(const QString &text)
void FilesSelectionWizardPage::parsingFinished() void FilesSelectionWizardPage::parsingFinished()
{ {
m_finished = true; m_finished = true;
m_filterLabel->setVisible(true);
m_filterLineEdit->setVisible(true); m_hideFilesFilterLabel->setVisible(true);
m_hideFilesfilterLineEdit->setVisible(true);
m_showFilesFilterLabel->setVisible(true);
m_showFilesfilterLineEdit->setVisible(true);
m_applyFilterButton->setVisible(true); m_applyFilterButton->setVisible(true);
m_view->setVisible(true); m_view->setVisible(true);
m_label->setVisible(false); m_label->setVisible(false);
@@ -139,9 +184,13 @@ QStringList FilesSelectionWizardPage::selectedFiles() const
void FilesSelectionWizardPage::applyFilter() void FilesSelectionWizardPage::applyFilter()
{ {
const QString filter = m_filterLineEdit->text(); const QString showFilesFilter = m_showFilesfilterLineEdit->text();
Core::ICore::settings()->setValue(QLatin1String(Constants::FILEFILTER_SETTING), filter); Core::ICore::settings()->setValue(QLatin1String(Constants::SHOW_FILE_FILTER_SETTING), showFilesFilter);
m_model->applyFilter(filter);
const QString hideFilesFilter = m_hideFilesfilterLineEdit->text();
Core::ICore::settings()->setValue(QLatin1String(Constants::HIDE_FILE_FILTER_SETTING), hideFilesFilter);
m_model->applyFilter(showFilesFilter, hideFilesFilter);
} }
} // namespace Internal } // namespace Internal

View File

@@ -31,8 +31,11 @@
#define FILESSELECTIONWIZARDPAGE_H #define FILESSELECTIONWIZARDPAGE_H
#include <QWizardPage> #include <QWizardPage>
#include <QLabel>
#include <QTreeView> class QVBoxLayout;
class QLabel;
class QTreeView;
class QLineEdit;
namespace GenericProjectManager { namespace GenericProjectManager {
namespace Internal { namespace Internal {
@@ -58,11 +61,21 @@ private slots:
void parsingFinished(); void parsingFinished();
private: private:
void createHideFileFilterControls(QVBoxLayout *layout);
void createShowFileFilterControls(QVBoxLayout *layout);
void createApplyButton(QVBoxLayout *layout);
GenericProjectWizardDialog *m_genericProjectWizardDialog; GenericProjectWizardDialog *m_genericProjectWizardDialog;
SelectableFilesModel *m_model; SelectableFilesModel *m_model;
QLabel *m_filterLabel;
QLineEdit *m_filterLineEdit; QLabel *m_hideFilesFilterLabel;
QLineEdit *m_hideFilesfilterLineEdit;
QLabel *m_showFilesFilterLabel;
QLineEdit *m_showFilesfilterLineEdit;
QPushButton *m_applyFilterButton; QPushButton *m_applyFilterButton;
QTreeView *m_view; QTreeView *m_view;
QLabel *m_label; QLabel *m_label;
bool m_finished; bool m_finished;

View File

@@ -47,8 +47,11 @@ const char CONFIG_MIMETYPE[] = "application/vnd.nokia.qt.generic.config";
// Project // Project
const char GENERICPROJECT_ID[] = "GenericProjectManager.GenericProject"; const char GENERICPROJECT_ID[] = "GenericProjectManager.GenericProject";
const char FILEFILTER_SETTING[] = "GenericProject/FileFilter"; const char HIDE_FILE_FILTER_SETTING[] = "GenericProject/FileFilter";
const char FILEFILTER_DEFAULT[] = "Makefile*; *.o; *.obj; *~; *.files; *.config; *.creator; *.user; *.includes"; const char HIDE_FILE_FILTER_DEFAULT[] = "Makefile*; *.o; *.obj; *~; *.files; *.config; *.creator; *.user; *.includes";
const char SHOW_FILE_FILTER_SETTING[] = "GenericProject/ShowFileFilter";
const char SHOW_FILE_FILTER_DEFAULT[] = "*.c; *.cc; *.cpp; *.cp; *.cxx; *.c++; *.h; *.hh; *.hpp; *.hxx;";
} // namespace Constants } // namespace Constants
} // namespace GenericProjectManager } // namespace GenericProjectManager

View File

@@ -40,6 +40,7 @@
#include <QLineEdit> #include <QLineEdit>
#include <QPushButton> #include <QPushButton>
#include <QTreeView> #include <QTreeView>
#include <QDir>
namespace GenericProjectManager { namespace GenericProjectManager {
namespace Internal { namespace Internal {
@@ -116,18 +117,27 @@ bool SelectableFilesModel::filter(Tree *t)
return false; return false;
if (m_files.contains(t->fullPath)) if (m_files.contains(t->fullPath))
return false; return false;
foreach (const Glob &g, m_filter) {
if (g.mode == Glob::EXACT) { bool showFilterMatch = false;
if (g.matchString == t->name)
return true; //First loop through show file filters and
} else if (g.mode == Glob::ENDSWITH) { //if any of them match, cotinue checking.
if (t->name.endsWith(g.matchString)) foreach (const Glob &g, m_showFilesFilter) {
return true; if (g.isMatch(t->name)) {
} else if (g.mode == Glob::REGEXP) { showFilterMatch = true;
if (g.matchRegexp.exactMatch(t->name)) break;
return true;
} }
} }
//If none of the "show file" filters match just return
if (!showFilterMatch)
return true;
foreach (const Glob &g, m_hideFilesFilter) {
if (g.isMatch(t->name))
return true;
}
return false; return false;
} }
@@ -381,9 +391,10 @@ QList<Glob> SelectableFilesModel::parseFilter(const QString &filter)
return result; return result;
} }
void SelectableFilesModel::applyFilter(const QString &filter) void SelectableFilesModel::applyFilter(const QString &showFilesfilter, const QString &hideFilesfilter)
{ {
m_filter = parseFilter(filter); m_showFilesFilter = parseFilter(showFilesfilter);
m_hideFilesFilter = parseFilter(hideFilesfilter);
applyFilter(createIndex(0, 0, m_root)); applyFilter(createIndex(0, 0, m_root));
} }
@@ -512,22 +523,9 @@ SelectableFilesDialog::SelectableFilesDialog(const QString &path, const QStringL
m_view = new QTreeView(this); m_view = new QTreeView(this);
QHBoxLayout *hbox = new QHBoxLayout; createShowFileFilterControls(layout);
m_filterLabel = new QLabel(this); createHideFileFilterControls(layout);
m_filterLabel->setText(tr("Hide files matching:")); createApplyButton(layout);
m_filterLabel->hide();
hbox->addWidget(m_filterLabel);
m_filterLineEdit = new QLineEdit(this);
const QString filter = Core::ICore::settings()->value(QLatin1String(Constants::FILEFILTER_SETTING),
QLatin1String(Constants::FILEFILTER_DEFAULT)).toString();
m_filterLineEdit->setText(filter);
m_filterLineEdit->hide();
hbox->addWidget(m_filterLineEdit);
m_applyFilterButton = new QPushButton(tr("Apply Filter"), this);
m_applyFilterButton->hide();
hbox->addWidget(m_applyFilterButton);
layout->addLayout(hbox);
m_selectableFilesModel = new SelectableFilesModel(path, this); m_selectableFilesModel = new SelectableFilesModel(path, this);
m_selectableFilesModel->setInitialMarkedFiles(files); m_selectableFilesModel->setInitialMarkedFiles(files);
@@ -553,8 +551,6 @@ SelectableFilesDialog::SelectableFilesDialog(const QString &path, const QStringL
this, SLOT(reject())); this, SLOT(reject()));
layout->addWidget(buttonBox); layout->addWidget(buttonBox);
connect(m_applyFilterButton, SIGNAL(clicked()), this, SLOT(applyFilter()));
connect(m_selectableFilesModel, SIGNAL(parsingProgress(QString)), connect(m_selectableFilesModel, SIGNAL(parsingProgress(QString)),
this, SLOT(parsingProgress(QString))); this, SLOT(parsingProgress(QString)));
connect(m_selectableFilesModel, SIGNAL(parsingFinished()), connect(m_selectableFilesModel, SIGNAL(parsingFinished()),
@@ -563,6 +559,55 @@ SelectableFilesDialog::SelectableFilesDialog(const QString &path, const QStringL
m_selectableFilesModel->startParsing(); m_selectableFilesModel->startParsing();
} }
void SelectableFilesDialog::createHideFileFilterControls(QVBoxLayout *layout)
{
QHBoxLayout *hbox = new QHBoxLayout;
m_hideFilesFilterLabel = new QLabel;
m_hideFilesFilterLabel->setText(tr("Hide files matching:"));
m_hideFilesFilterLabel->hide();
hbox->addWidget(m_hideFilesFilterLabel);
m_hideFilesfilterLineEdit = new QLineEdit;
const QString filter = Core::ICore::settings()->value(QLatin1String(Constants::HIDE_FILE_FILTER_SETTING),
QLatin1String(Constants::HIDE_FILE_FILTER_DEFAULT)).toString();
m_hideFilesfilterLineEdit->setText(filter);
m_hideFilesfilterLineEdit->hide();
hbox->addWidget(m_hideFilesfilterLineEdit);
layout->addLayout(hbox);
}
void SelectableFilesDialog::createShowFileFilterControls(QVBoxLayout *layout)
{
QHBoxLayout *hbox = new QHBoxLayout;
m_showFilesFilterLabel = new QLabel;
m_showFilesFilterLabel->setText(tr("Show files matching:"));
m_showFilesFilterLabel->hide();
hbox->addWidget(m_showFilesFilterLabel);
m_showFilesfilterLineEdit = new QLineEdit;
const QString filter = Core::ICore::settings()->value(QLatin1String(Constants::SHOW_FILE_FILTER_SETTING),
QLatin1String(Constants::SHOW_FILE_FILTER_DEFAULT)).toString();
m_showFilesfilterLineEdit->setText(filter);
m_showFilesfilterLineEdit->hide();
hbox->addWidget(m_showFilesfilterLineEdit);
layout->addLayout(hbox);
}
void SelectableFilesDialog::createApplyButton(QVBoxLayout *layout)
{
QHBoxLayout *hbox = new QHBoxLayout;
QSpacerItem *horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
hbox->addItem(horizontalSpacer);
m_applyFilterButton = new QPushButton(tr("Apply Filter"), this);
m_applyFilterButton->hide();
hbox->addWidget(m_applyFilterButton);
layout->addLayout(hbox);
connect(m_applyFilterButton, SIGNAL(clicked()), this, SLOT(applyFilter()));
}
SelectableFilesDialog::~SelectableFilesDialog() SelectableFilesDialog::~SelectableFilesDialog()
{ {
m_selectableFilesModel->cancel(); m_selectableFilesModel->cancel();
@@ -576,8 +621,12 @@ void SelectableFilesDialog::parsingProgress(const QString &fileName)
void SelectableFilesDialog::parsingFinished() void SelectableFilesDialog::parsingFinished()
{ {
m_filterLabel->show(); m_hideFilesFilterLabel->show();
m_filterLineEdit->show(); m_hideFilesfilterLineEdit->show();
m_showFilesFilterLabel->show();
m_showFilesfilterLineEdit->show();
m_applyFilterButton->show(); m_applyFilterButton->show();
m_view->show(); m_view->show();
m_progressLabel->hide(); m_progressLabel->hide();
@@ -610,10 +659,16 @@ QStringList SelectableFilesDialog::selectedFiles() const
void SelectableFilesDialog::applyFilter() void SelectableFilesDialog::applyFilter()
{ {
const QString filter = m_filterLineEdit->text(); const QString showFilesFilter = m_showFilesfilterLineEdit->text();
Core::ICore::settings()->setValue(QLatin1String(Constants::FILEFILTER_SETTING), filter); Core::ICore::settings()->setValue(QLatin1String(Constants::SHOW_FILE_FILTER_SETTING), showFilesFilter);
m_selectableFilesModel->applyFilter(filter);
const QString hideFilesFilter = m_hideFilesfilterLineEdit->text();
Core::ICore::settings()->setValue(QLatin1String(Constants::HIDE_FILE_FILTER_SETTING), hideFilesFilter);
m_selectableFilesModel->applyFilter(showFilesFilter, hideFilesFilter);
} }
} // namespace Internal } // namespace Internal
} // namespace GenericProjectManager } // namespace GenericProjectManager

View File

@@ -34,11 +34,14 @@
#include <QSet> #include <QSet>
#include <QFutureInterface> #include <QFutureInterface>
#include <QFutureWatcher> #include <QFutureWatcher>
#include <QFileSystemModel>
#include <QDialog> #include <QDialog>
#include <QTreeView> #include <QTreeView>
#include <QLabel> #include <QLabel>
class QLabel;
class QTreeView;
class QVBoxLayout;
namespace GenericProjectManager { namespace GenericProjectManager {
namespace Internal { namespace Internal {
@@ -61,6 +64,21 @@ struct Glob
Mode mode; Mode mode;
QString matchString; QString matchString;
mutable QRegExp matchRegexp; mutable QRegExp matchRegexp;
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;
}
}; };
class SelectableFilesModel : public QAbstractItemModel class SelectableFilesModel : public QAbstractItemModel
@@ -90,7 +108,7 @@ public:
void startParsing(); void startParsing();
void waitForFinished(); void waitForFinished();
void cancel(); void cancel();
void applyFilter(const QString &filter); void applyFilter(const QString &selectFilesfilter, const QString &hideFilesfilter);
signals: signals:
void parsingFinished(); void parsingFinished();
@@ -120,7 +138,9 @@ private:
Tree *m_rootForFuture; Tree *m_rootForFuture;
int m_futureCount; int m_futureCount;
bool m_allFiles; bool m_allFiles;
QList<Glob> m_filter;
QList<Glob> m_hideFilesFilter;
QList<Glob> m_showFilesFilter;
}; };
class SelectableFilesDialog : public QDialog class SelectableFilesDialog : public QDialog
@@ -139,10 +159,19 @@ private slots:
private: private:
void smartExpand(const QModelIndex &index); void smartExpand(const QModelIndex &index);
void createShowFileFilterControls(QVBoxLayout *layout);
void createHideFileFilterControls(QVBoxLayout *layout);
void createApplyButton(QVBoxLayout *layout);
SelectableFilesModel *m_selectableFilesModel; SelectableFilesModel *m_selectableFilesModel;
QLabel *m_filterLabel;
QLineEdit *m_filterLineEdit; QLabel *m_hideFilesFilterLabel;
QLineEdit *m_hideFilesfilterLineEdit;
QLabel *m_showFilesFilterLabel;
QLineEdit *m_showFilesfilterLineEdit;
QPushButton *m_applyFilterButton; QPushButton *m_applyFilterButton;
QTreeView *m_view; QTreeView *m_view;
QLabel *m_preservedFiles; QLabel *m_preservedFiles;
QLabel *m_progressLabel; QLabel *m_progressLabel;
@@ -152,3 +181,4 @@ private:
} // namespace GenericProjectManager } // namespace GenericProjectManager
#endif // SELECTABLEFILESMODEL_H #endif // SELECTABLEFILESMODEL_H