GUI: Add Setting for global include paths.

This commit adds new setting and GUI for global include dirs. When
project file with include dirs is loaded, global includes dirs are
added first and after them the include dirs from project file.
This commit is contained in:
Kimmo Varis 2010-11-26 22:35:45 +02:00
parent 88a1448a07
commit 2dfa1d540e
5 changed files with 132 additions and 59 deletions

View File

@ -66,6 +66,7 @@ ShowTypes;
#define SETTINGS_LOG_VIEW_WIDTH "Log/View width"
#define SETTINGS_LOG_VIEW_HEIGHT "Log/View height"
#define SETTINGS_MAINWND_SPLITTER_STATE "Mainwindow/Vertical splitter state"
#define SETTINGS_GLOBAL_INCLUDE_PATHS "Global include paths"
/// @}
#endif

View File

@ -341,6 +341,27 @@ bool MainWindow::GetCheckProject()
Settings MainWindow::GetCppcheckSettings()
{
Settings result;
QString globalIncludes = mSettings->value(SETTINGS_GLOBAL_INCLUDE_PATHS).toString();
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());
}
}
bool projectRead = GetCheckProject();
if (projectRead)
{
@ -417,7 +438,7 @@ void MainWindow::ProgramSettings()
SettingsDialog dialog(mSettings, mApplications, this);
if (dialog.exec() == QDialog::Accepted)
{
dialog.SaveCheckboxValues();
dialog.SaveSettingValues();
mUI.mResults->UpdateSettings(dialog.ShowFullPath(),
dialog.SaveFullPath(),
dialog.SaveAllErrors(),

View File

@ -23,9 +23,31 @@
<attribute name="title">
<string>General</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout_4">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Include paths:</string>
</property>
<property name="buddy">
<cstring>mEditIncludePaths</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="mEditIncludePaths"/>
</item>
<item>
<widget class="QPushButton" name="mBtnAddIncludePath">
<property name="text">
<string>Add...</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
@ -33,10 +55,20 @@
<property name="text">
<string>Number of threads: </string>
</property>
<property name="buddy">
<cstring>mJobs</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="mJobs"/>
<widget class="QLineEdit" name="mJobs">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
@ -82,8 +114,6 @@
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
@ -173,6 +203,8 @@
</widget>
<tabstops>
<tabstop>tabWidget</tabstop>
<tabstop>mEditIncludePaths</tabstop>
<tabstop>mBtnAddIncludePath</tabstop>
<tabstop>mJobs</tabstop>
<tabstop>mForce</tabstop>
<tabstop>mShowFullPath</tabstop>

View File

@ -25,6 +25,7 @@
#include <QListWidgetItem>
#include <QTabWidget>
#include <QSettings>
#include <QFileDialog>
#include "settingsdialog.h"
#include "applicationdialog.h"
#include "applicationlist.h"
@ -41,36 +42,33 @@ SettingsDialog::SettingsDialog(QSettings *programSettings,
mUI.setupUi(this);
mTempApplications->Copy(list);
connect(mUI.mButtons, SIGNAL(accepted()), this, SLOT(Ok()));
connect(mUI.mButtons, SIGNAL(rejected()), this, SLOT(reject()));
mUI.mEditIncludePaths->setText(programSettings->value(SETTINGS_GLOBAL_INCLUDE_PATHS).toString());
mUI.mJobs->setText(programSettings->value(SETTINGS_CHECK_THREADS, 1).toString());
mUI.mForce->setCheckState(BoolToCheckState(programSettings->value(SETTINGS_CHECK_FORCE, false).toBool()));
mUI.mShowFullPath->setCheckState(BoolToCheckState(programSettings->value(SETTINGS_SHOW_FULL_PATH, false).toBool()));
mUI.mShowNoErrorsMessage->setCheckState(BoolToCheckState(programSettings->value(SETTINGS_SHOW_NO_ERRORS, false).toBool()));
mUI.mShowDebugWarnings->setCheckState(BoolToCheckState(programSettings->value(SETTINGS_SHOW_DEBUG_WARNINGS, false).toBool()));
mUI.mSaveAllErrors->setCheckState(BoolToCheckState(programSettings->value(SETTINGS_SAVE_ALL_ERRORS, false).toBool()));
mUI.mSaveFullPath->setCheckState(BoolToCheckState(programSettings->value(SETTINGS_SAVE_FULL_PATH, false).toBool()));
connect(mUI.mButtons, SIGNAL(accepted()), this, SLOT(Ok()));
connect(mUI.mButtons, SIGNAL(rejected()), this, SLOT(reject()));
connect(mUI.mButtonAdd, SIGNAL(clicked()),
this, SLOT(AddApplication()));
connect(mUI.mButtonDelete, SIGNAL(clicked()),
this, SLOT(DeleteApplication()));
connect(mUI.mButtonModify, SIGNAL(clicked()),
this, SLOT(ModifyApplication()));
connect(mUI.mButtonDefault, SIGNAL(clicked()),
this, SLOT(DefaultApplication()));
connect(mUI.mListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem *)),
this, SLOT(ModifyApplication()));
connect(mUI.mBtnAddIncludePath, SIGNAL(clicked()),
this, SLOT(AddIncludePath()));
mUI.mListWidget->setSortingEnabled(false);
PopulateListWidget();
mUI.mSaveAllErrors->setCheckState(BoolToCheckState(programSettings->value(SETTINGS_SAVE_ALL_ERRORS, false).toBool()));
mUI.mSaveFullPath->setCheckState(BoolToCheckState(programSettings->value(SETTINGS_SAVE_FULL_PATH, false).toBool()));
LoadSettings();
}
@ -110,7 +108,7 @@ void SettingsDialog::SaveSettings()
mSettings->setValue(SETTINGS_CHECK_DIALOG_HEIGHT, size().height());
}
void SettingsDialog::SaveCheckboxValues()
void SettingsDialog::SaveSettingValues()
{
int jobs = mUI.mJobs->text().toInt();
if (jobs <= 0)
@ -125,6 +123,7 @@ void SettingsDialog::SaveCheckboxValues()
SaveCheckboxValue(mUI.mShowFullPath, SETTINGS_SHOW_FULL_PATH);
SaveCheckboxValue(mUI.mShowNoErrorsMessage, SETTINGS_SHOW_NO_ERRORS);
SaveCheckboxValue(mUI.mShowDebugWarnings, SETTINGS_SHOW_DEBUG_WARNINGS);
mSettings->setValue(SETTINGS_GLOBAL_INCLUDE_PATHS, mUI.mEditIncludePaths->text());
}
void SettingsDialog::SaveCheckboxValue(QCheckBox *box, const QString &name)
@ -229,5 +228,18 @@ bool SettingsDialog::ShowNoErrorsMessage()
return CheckStateToBool(mUI.mShowNoErrorsMessage->checkState());
}
void SettingsDialog::AddIncludePath()
{
QString selectedDir = QFileDialog::getExistingDirectory(this,
tr("Select include directory"),
QString());
if (!selectedDir.isEmpty())
{
QString text = mUI.mEditIncludePaths->text();
if (!text.isEmpty())
text += ';';
text += selectedDir;
mUI.mEditIncludePaths->setText(text);
}
}

View File

@ -48,7 +48,7 @@ public:
* @brief Save all values to QSettings
*
*/
void SaveCheckboxValues();
void SaveSettingValues();
/**
* @brief Get checkbox value for mShowFullPath
@ -109,6 +109,13 @@ protected slots:
*
*/
void DefaultApplication();
/**
* @brief Slot for adding new include path
*
*/
void AddIncludePath();
protected:
/**