From 2dfa1d540e89e14581428d7169b7781e4821a91c Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Fri, 26 Nov 2010 22:35:45 +0200 Subject: [PATCH] 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. --- gui/common.h | 1 + gui/mainwindow.cpp | 23 +++++++- gui/settings.ui | 122 ++++++++++++++++++++++++++--------------- gui/settingsdialog.cpp | 36 ++++++++---- gui/settingsdialog.h | 9 ++- 5 files changed, 132 insertions(+), 59 deletions(-) diff --git a/gui/common.h b/gui/common.h index 6c4a436ef..b560f1f4f 100644 --- a/gui/common.h +++ b/gui/common.h @@ -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 diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index b3087d367..f4a1aa596 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -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(), diff --git a/gui/settings.ui b/gui/settings.ui index 97c831249..7769d4e75 100644 --- a/gui/settings.ui +++ b/gui/settings.ui @@ -23,66 +23,96 @@ General - + - + - - - - - Number of threads: - - - - - - - - - - + - Check all #ifdef configurations + Include paths: + + + mEditIncludePaths - - - Show full path of files - - + - + - Show "No errors found" message when no errors found + Add... - - - - Show internal warnings in log - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - + + + + + + Number of threads: + + + mJobs + + + + + + + + 0 + 0 + + + + + + + + + + Check all #ifdef configurations + + + + + + + Show full path of files + + + + + + + Show "No errors found" message when no errors found + + + + + + + Show internal warnings in log + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + @@ -173,6 +203,8 @@ tabWidget + mEditIncludePaths + mBtnAddIncludePath mJobs mForce mShowFullPath diff --git a/gui/settingsdialog.cpp b/gui/settingsdialog.cpp index ae2e51fe8..ff62e1f16 100644 --- a/gui/settingsdialog.cpp +++ b/gui/settingsdialog.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #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); + } +} diff --git a/gui/settingsdialog.h b/gui/settingsdialog.h index 9697910f4..650cd30db 100644 --- a/gui/settingsdialog.h +++ b/gui/settingsdialog.h @@ -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: /**