From 46f7a81b7b3b04dcc62b0e76387c66d6cb8732ab Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Mon, 28 Feb 2011 00:13:28 +0200 Subject: [PATCH] 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. --- gui/filelist.cpp | 52 ++++++++++++++++++++++++++++++++++++++++----- gui/filelist.h | 27 +++++++++++++++++++++++ gui/mainwindow.cpp | 2 ++ gui/projectfile.cpp | 2 +- 4 files changed, 77 insertions(+), 6 deletions(-) diff --git a/gui/filelist.cpp b/gui/filelist.cpp index cc1580904..4e26eb1f3 100644 --- a/gui/filelist.cpp +++ b/gui/filelist.cpp @@ -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; } diff --git a/gui/filelist.h b/gui/filelist.h index 1a1818408..a896e6070 100644 --- a/gui/filelist.h +++ b/gui/filelist.h @@ -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 diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 2239568a8..1901b0a08 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -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(); diff --git a/gui/projectfile.cpp b/gui/projectfile.cpp index 9ff0d79a3..cba444092 100644 --- a/gui/projectfile.cpp +++ b/gui/projectfile.cpp @@ -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";