GUI: Cleanup duplicate code.

This commit is contained in:
Kimmo Varis 2010-11-26 22:51:38 +02:00
parent 2dfa1d540e
commit 14ee95eab7
2 changed files with 28 additions and 27 deletions

View File

@ -338,6 +338,24 @@ bool MainWindow::GetCheckProject()
return false;
}
void MainWindow::AddIncludeDirs(const QStringList &includeDirs, Settings &result)
{
QString dir;
foreach(dir, includeDirs)
{
QString incdir;
if (!QDir::isAbsolutePath(dir))
incdir = mCurrentDirectory + "/";
incdir += dir;
incdir = QDir::cleanPath(incdir);
// include paths must end with '/'
if (!incdir.endsWith("/"))
incdir += "/";
result._includePaths.push_back(incdir.toStdString());
}
}
Settings MainWindow::GetCppcheckSettings()
{
Settings result;
@ -346,20 +364,7 @@ Settings MainWindow::GetCppcheckSettings()
if (!globalIncludes.isEmpty())
{
QStringList includes = globalIncludes.split(";");
QString dir;
foreach(dir, includes)
{
QString incdir;
if (!QDir::isAbsolutePath(dir))
incdir = mCurrentDirectory + "/";
incdir += dir;
incdir = QDir::cleanPath(incdir);
// include paths must end with '/'
if (!incdir.endsWith("/"))
incdir += "/";
result._includePaths.push_back(incdir.toStdString());
}
AddIncludeDirs(includes, result);
}
bool projectRead = GetCheckProject();
@ -367,20 +372,8 @@ Settings MainWindow::GetCppcheckSettings()
{
ProjectFile *pfile = mProject->GetProjectFile();
QStringList dirs = pfile->GetIncludeDirs();
QString dir;
foreach(dir, dirs)
{
QString incdir;
if (!QDir::isAbsolutePath(dir))
incdir = mCurrentDirectory + "/";
incdir += dir;
incdir = QDir::cleanPath(incdir);
AddIncludeDirs(dirs, result);
// include paths must end with '/'
if (!incdir.endsWith("/"))
incdir += "/";
result._includePaths.push_back(incdir.toStdString());
}
QStringList defines = pfile->GetDefines();
QString define;
foreach(define, defines)

View File

@ -25,6 +25,7 @@
#include <QSignalMapper>
#include <QActionGroup>
#include <QToolBar>
#include <QStringList>
#include "resultsview.h"
#include "settingsdialog.h"
@ -346,6 +347,13 @@ protected:
*/
void EnableProjectOpenActions(bool enable);
/**
* @brief Add include directories.
* @param includeDirs List of include directories to add.
* @param result Settings class where include directories are added.
*/
void AddIncludeDirs(const QStringList &includeDirs, Settings &result);
/**
* @brief Program settings
*