GUI: Rename methods in FileList and PathMatch

This commit is contained in:
Daniel Marjamäki 2017-07-28 10:55:51 +02:00
parent 24bdd6d246
commit c4bd70210c
5 changed files with 36 additions and 36 deletions

View File

@ -24,17 +24,17 @@
#include "path.h" #include "path.h"
#include "pathmatch.h" #include "pathmatch.h"
QStringList FileList::GetDefaultFilters() QStringList FileList::getDefaultFilters()
{ {
QStringList extensions; QStringList extensions;
extensions << "*.cpp" << "*.cxx" << "*.cc" << "*.c" << "*.c++" << "*.txx" << "*.tpp"; extensions << "*.cpp" << "*.cxx" << "*.cc" << "*.c" << "*.c++" << "*.txx" << "*.tpp";
return extensions; return extensions;
} }
bool FileList::FilterMatches(const QFileInfo &inf) bool FileList::filterMatches(const QFileInfo &inf)
{ {
if (inf.isFile()) { if (inf.isFile()) {
const QStringList filters = FileList::GetDefaultFilters(); const QStringList filters = FileList::getDefaultFilters();
QString ext("*."); QString ext("*.");
ext += inf.suffix(); ext += inf.suffix();
if (filters.contains(ext, Qt::CaseInsensitive)) if (filters.contains(ext, Qt::CaseInsensitive))
@ -43,18 +43,18 @@ bool FileList::FilterMatches(const QFileInfo &inf)
return false; return false;
} }
void FileList::AddFile(const QString &filepath) void FileList::addFile(const QString &filepath)
{ {
QFileInfo inf(filepath); QFileInfo inf(filepath);
if (FilterMatches(inf)) if (filterMatches(inf))
mFileList << inf; mFileList << inf;
} }
void FileList::AddDirectory(const QString &directory, bool recursive) void FileList::addDirectory(const QString &directory, bool recursive)
{ {
QDir dir(directory); QDir dir(directory);
dir.setSorting(QDir::Name); dir.setSorting(QDir::Name);
const QStringList filters = FileList::GetDefaultFilters(); const QStringList filters = FileList::getDefaultFilters();
const QStringList origNameFilters = dir.nameFilters(); const QStringList origNameFilters = dir.nameFilters();
dir.setNameFilters(filters); dir.setNameFilters(filters);
if (!recursive) { if (!recursive) {
@ -72,24 +72,24 @@ void FileList::AddDirectory(const QString &directory, bool recursive)
QFileInfo item; QFileInfo item;
foreach (item, list) { foreach (item, list) {
const QString path = item.canonicalFilePath(); const QString path = item.canonicalFilePath();
AddDirectory(path, recursive); addDirectory(path, recursive);
} }
} }
} }
void FileList::AddPathList(const QStringList &paths) void FileList::addPathList(const QStringList &paths)
{ {
QString path; QString path;
foreach (path, paths) { foreach (path, paths) {
QFileInfo inf(path); QFileInfo inf(path);
if (inf.isFile()) if (inf.isFile())
AddFile(path); addFile(path);
else else
AddDirectory(path, true); addDirectory(path, true);
} }
} }
QStringList FileList::GetFileList() const QStringList FileList::getFileList() const
{ {
if (mExcludedPaths.empty()) { if (mExcludedPaths.empty()) {
QStringList names; QStringList names;
@ -99,11 +99,11 @@ QStringList FileList::GetFileList() const
} }
return names; return names;
} else { } else {
return ApplyExcludeList(); return applyExcludeList();
} }
} }
void FileList::AddExcludeList(const QStringList &paths) void FileList::addExcludeList(const QStringList &paths)
{ {
mExcludedPaths = paths; mExcludedPaths = paths;
} }
@ -117,7 +117,7 @@ static std::vector<std::string> toStdStringList(const QStringList &stringList)
return ret; return ret;
} }
QStringList FileList::ApplyExcludeList() const QStringList FileList::applyExcludeList() const
{ {
#ifdef _WIN32 #ifdef _WIN32
const PathMatch pathMatch(toStdStringList(mExcludedPaths), true); const PathMatch pathMatch(toStdStringList(mExcludedPaths), true);
@ -128,7 +128,7 @@ QStringList FileList::ApplyExcludeList() const
QStringList paths; QStringList paths;
foreach (QFileInfo item, mFileList) { foreach (QFileInfo item, mFileList) {
QString name = QDir::fromNativeSeparators(item.canonicalFilePath()); QString name = QDir::fromNativeSeparators(item.canonicalFilePath());
if (!pathMatch.Match(name.toStdString())) if (!pathMatch.match(name.toStdString()))
paths << name; paths << name;
} }
return paths; return paths;

View File

@ -41,38 +41,38 @@ public:
* @brief Add filename to the list. * @brief Add filename to the list.
* @param filepath Full path to the file. * @param filepath Full path to the file.
*/ */
void AddFile(const QString &filepath); void addFile(const QString &filepath);
/** /**
* @brief Add files in the directory to the list. * @brief Add files in the directory to the list.
* @param directory Full pathname to directory to add. * @param directory Full pathname to directory to add.
* @param recursive If true also files in subdirectories are added. * @param recursive If true also files in subdirectories are added.
*/ */
void AddDirectory(const QString &directory, bool recursive = false); void addDirectory(const QString &directory, bool recursive = false);
/** /**
* @brief Add list of filenames and directories to the list. * @brief Add list of filenames and directories to the list.
* @param paths List of paths to add. * @param paths List of paths to add.
*/ */
void AddPathList(const QStringList &paths); void addPathList(const QStringList &paths);
/** /**
* @brief Return list of filenames (to check). * @brief Return list of filenames (to check).
* @return list of filenames to check. * @return list of filenames to check.
*/ */
QStringList GetFileList() const; QStringList getFileList() const;
/** /**
* @brief Add list of paths to exclusion list. * @brief Add list of paths to exclusion list.
* @param paths Paths to exclude. * @param paths Paths to exclude.
*/ */
void AddExcludeList(const QStringList &paths); void addExcludeList(const QStringList &paths);
/** /**
* @brief Return list of default filename extensions included. * @brief Return list of default filename extensions included.
* @return list of default filename extensions included. * @return list of default filename extensions included.
*/ */
static QStringList GetDefaultFilters(); static QStringList getDefaultFilters();
protected: protected:
@ -80,7 +80,7 @@ protected:
* @brief Test if filename matches the filename extensions filtering. * @brief Test if filename matches the filename extensions filtering.
* @return true if filename matches filtering. * @return true if filename matches filtering.
*/ */
static bool FilterMatches(const QFileInfo &inf); static bool filterMatches(const QFileInfo &inf);
/** /**
* @brief Get filtered list of paths. * @brief Get filtered list of paths.
@ -89,7 +89,7 @@ protected:
* exclude filters. * exclude filters.
* @return Filtered list of paths. * @return Filtered list of paths.
*/ */
QStringList ApplyExcludeList() const; QStringList applyExcludeList() const;
private: private:
QFileInfoList mFileList; QFileInfoList mFileList;

View File

@ -407,13 +407,13 @@ void MainWindow::doCheckFiles(const QStringList &files)
mIsLogfileLoaded = false; mIsLogfileLoaded = false;
FileList pathList; FileList pathList;
pathList.AddPathList(files); pathList.addPathList(files);
if (mProject) { if (mProject) {
pathList.AddExcludeList(mProject->getProjectFile()->getExcludedPaths()); pathList.addExcludeList(mProject->getProjectFile()->getExcludedPaths());
} else { } else {
enableProjectActions(false); enableProjectActions(false);
} }
QStringList fileNames = pathList.GetFileList(); QStringList fileNames = pathList.getFileList();
mUI.mResults->Clear(true); mUI.mResults->Clear(true);
mThread->ClearFiles(); mThread->ClearFiles();
@ -503,7 +503,7 @@ QStringList MainWindow::selectFilesToCheck(QFileDialog::FileMode mode)
tr("Select files to check"), tr("Select files to check"),
GetPath(SETTINGS_LAST_CHECK_PATH), GetPath(SETTINGS_LAST_CHECK_PATH),
tr("C/C++ Source, Compile database, Visual Studio (%1 %2 *.sln *.vcxproj)") tr("C/C++ Source, Compile database, Visual Studio (%1 %2 *.sln *.vcxproj)")
.arg(FileList::GetDefaultFilters().join(" ")) .arg(FileList::getDefaultFilters().join(" "))
.arg(compile_commands_json)); .arg(compile_commands_json));
if (selected.isEmpty()) if (selected.isEmpty())
mCurrentDirectory.clear(); mCurrentDirectory.clear();
@ -931,10 +931,10 @@ void MainWindow::reCheckSelected(QStringList files, bool all)
mCurrentDirectory = mUI.mResults->GetCheckDirectory(); mCurrentDirectory = mUI.mResults->GetCheckDirectory();
FileList pathList; FileList pathList;
pathList.AddPathList(files); pathList.addPathList(files);
if (mProject) if (mProject)
pathList.AddExcludeList(mProject->getProjectFile()->getExcludedPaths()); pathList.addExcludeList(mProject->getProjectFile()->getExcludedPaths());
QStringList fileNames = pathList.GetFileList(); QStringList fileNames = pathList.getFileList();
checkLockDownUI(); // lock UI while checking checkLockDownUI(); // lock UI while checking
mUI.mResults->CheckingStarted(fileNames.size()); mUI.mResults->CheckingStarted(fileNames.size());
mThread->SetCheckFiles(fileNames); mThread->SetCheckFiles(fileNames);

View File

@ -34,7 +34,7 @@ PathMatch::PathMatch(const std::vector<std::string> &excludedPaths, bool caseSen
_workingDirectory.push_back(Path::getCurrentPath()); _workingDirectory.push_back(Path::getCurrentPath());
} }
bool PathMatch::Match(const std::string &path) const bool PathMatch::match(const std::string &path) const
{ {
if (path.empty()) if (path.empty())
return false; return false;
@ -49,7 +49,7 @@ bool PathMatch::Match(const std::string &path) const
// Filtering directory name // Filtering directory name
if (endsWith(excludedPath,'/')) { if (endsWith(excludedPath,'/')) {
if (!endsWith(findpath,'/')) if (!endsWith(findpath,'/'))
findpath = RemoveFilename(findpath); findpath = removeFilename(findpath);
if (excludedPath.length() > findpath.length()) if (excludedPath.length() > findpath.length())
continue; continue;
@ -78,7 +78,7 @@ bool PathMatch::Match(const std::string &path) const
return false; return false;
} }
std::string PathMatch::RemoveFilename(const std::string &path) std::string PathMatch::removeFilename(const std::string &path)
{ {
const std::size_t ind = path.find_last_of('/'); const std::size_t ind = path.find_last_of('/');
return path.substr(0, ind + 1); return path.substr(0, ind + 1);

View File

@ -46,7 +46,7 @@ public:
* @param path Path to match. * @param path Path to match.
* @return true if any of the masks match the path, false otherwise. * @return true if any of the masks match the path, false otherwise.
*/ */
bool Match(const std::string &path) const; bool match(const std::string &path) const;
protected: protected:
@ -55,7 +55,7 @@ protected:
* @param path Path to edit. * @param path Path to edit.
* @return path without filename part. * @return path without filename part.
*/ */
static std::string RemoveFilename(const std::string &path); static std::string removeFilename(const std::string &path);
private: private:
std::vector<std::string> _excludedPaths; std::vector<std::string> _excludedPaths;