GUI: Take filtering into use in GUI.

Add applying of filtering into list of files to check if we have
an active project file. Filtering is quite much similar to the
filtering in CLI.

If we have directory filter ("gui/") then we check all paths if
they contain "gui" part. In practice we search for string "/gui"
from the paths. If we have filename filtering
("gui/projectfile.cpp") then we check if any of the paths end
with that.
This commit is contained in:
Kimmo Varis 2011-02-28 00:13:28 +02:00
parent 9de4ce8c8e
commit 46f7a81b7b
4 changed files with 77 additions and 6 deletions

View File

@ -96,12 +96,54 @@ void FileList::AddPathList(const QStringList &paths)
QStringList FileList::GetFileList() const
{
QStringList names;
QFileInfo item;
foreach(item, mFileList)
if (mIgnoredPaths.empty())
{
QStringList names;
foreach(QFileInfo item, mFileList)
{
QString name = QDir::fromNativeSeparators(item.canonicalFilePath());
names << name;
}
return names;
}
else
{
return ApplyIgnoreList();
}
}
void FileList::AddIngoreList(const QStringList &paths)
{
mIgnoredPaths = paths;
}
QStringList FileList::ApplyIgnoreList() const
{
QStringList paths;
foreach(QFileInfo item, mFileList)
{
QString name = QDir::fromNativeSeparators(item.canonicalFilePath());
names << name;
if (!Match(name))
paths << name;
}
return names;
return paths;
}
bool FileList::Match(const QString &path) const
{
for (int i = 0; i < mIgnoredPaths.size(); i++)
{
if (mIgnoredPaths[i].endsWith('/'))
{
const QString pathignore("/" + mIgnoredPaths[i]);
if (path.indexOf(pathignore) != -1)
return true;
}
else
{
if (path.endsWith(mIgnoredPaths[i]))
return true;
}
}
return false;
}

View File

@ -30,6 +30,10 @@
* can be also added recursively when all files in subdirectories are added too.
* The filenames are matched against the filter and only those files whose
* filename extension is included in the filter list are added.
*
* This class also handles filtering of paths against ignore filters given. If
* there is ignore filters then only paths not matching those filters are
* returned.
*/
class FileList
{
@ -60,6 +64,12 @@ public:
*/
QStringList GetFileList() const;
/**
* @brief Add list of paths to ignore list.
* @param paths Paths to ignore.
*/
void AddIngoreList(const QStringList &paths);
protected:
/**
@ -74,8 +84,25 @@ protected:
*/
bool FilterMatches(const QFileInfo &inf);
/**
* @brief Get filtered list of paths.
* This method takes the list of paths and applies the ignore lists to
* it. And then returns the list of paths that did not match the
* ignore filters.
* @return Filtered list of paths.
*/
QStringList ApplyIgnoreList() const;
/**
* @brief Test if path matches any of the ignore filters.
* @param path Path to test against filters.
* @return true if any of the filters matches, false otherwise.
*/
bool Match(const QString &path) const;
private:
QFileInfoList mFileList;
QStringList mIgnoredPaths;
};
#endif // FILELIST_H

View File

@ -191,6 +191,8 @@ void MainWindow::DoCheckFiles(const QStringList &files)
FileList pathList;
pathList.AddPathList(files);
if (mProject)
pathList.AddIngoreList(mProject->GetProjectFile()->GetIgnoredPaths());
QStringList fileNames = pathList.GetFileList();
mUI.mResults->Clear();

View File

@ -37,7 +37,7 @@ static const char PathName[] = "dir";
static const char PathNameAttrib[] = "name";
static const char RootPathName[] = "root";
static const char RootPathNameAttrib[] = "name";
static const char IgnoreElementName[] = "defines";
static const char IgnoreElementName[] = "ignore";
static const char IgnorePathName[] = "path";
static const char IgnorePathNameAttrib[] = "name";