2009-03-01 08:38:21 +01:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2022-02-05 11:45:17 +01:00
|
|
|
* Copyright (C) 2007-2022 Cppcheck team.
|
2009-03-01 08:38:21 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2009-09-27 17:08:31 +02:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-03-01 08:38:21 +01:00
|
|
|
*/
|
|
|
|
|
2021-04-03 21:30:50 +02:00
|
|
|
#include "settingsdialog.h"
|
2009-03-01 08:38:21 +01:00
|
|
|
|
2022-04-13 12:24:00 +02:00
|
|
|
#include "application.h"
|
2009-05-23 12:37:30 +02:00
|
|
|
#include "applicationdialog.h"
|
2010-07-17 21:34:07 +02:00
|
|
|
#include "applicationlist.h"
|
2019-06-23 19:04:53 +02:00
|
|
|
#include "codeeditorstyle.h"
|
|
|
|
#include "codeeditstyledialog.h"
|
2009-07-02 10:32:29 +02:00
|
|
|
#include "common.h"
|
2022-02-02 16:17:28 +01:00
|
|
|
#include "translationhandler.h"
|
|
|
|
|
2022-03-19 19:54:20 +01:00
|
|
|
#include "ui_settings.h"
|
|
|
|
|
2022-02-02 16:17:28 +01:00
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QList>
|
|
|
|
#include <QSettings>
|
|
|
|
#include <QThread>
|
|
|
|
#include <QWidget>
|
2009-03-01 08:38:21 +01:00
|
|
|
|
2011-05-13 09:25:52 +02:00
|
|
|
SettingsDialog::SettingsDialog(ApplicationList *list,
|
2011-01-09 23:21:51 +01:00
|
|
|
TranslationHandler *translator,
|
2022-10-30 10:59:43 +01:00
|
|
|
bool premium,
|
2009-06-06 11:51:14 +02:00
|
|
|
QWidget *parent) :
|
2010-04-15 20:08:51 +02:00
|
|
|
QDialog(parent),
|
|
|
|
mApplications(list),
|
2011-01-13 22:38:08 +01:00
|
|
|
mTempApplications(new ApplicationList(this)),
|
2022-03-19 19:54:20 +01:00
|
|
|
mTranslator(translator),
|
2022-10-30 10:59:43 +01:00
|
|
|
mUI(new Ui::Settings),
|
|
|
|
mPremium(premium)
|
2009-03-01 08:38:21 +01:00
|
|
|
{
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->setupUi(this);
|
|
|
|
mUI->mPythonPathWarning->setStyleSheet("color: red");
|
2011-05-13 09:25:52 +02:00
|
|
|
QSettings settings;
|
2017-07-28 05:18:43 +02:00
|
|
|
mTempApplications->copy(list);
|
2009-07-02 18:14:12 +02:00
|
|
|
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mJobs->setText(settings.value(SETTINGS_CHECK_THREADS, 1).toString());
|
|
|
|
mUI->mForce->setCheckState(boolToCheckState(settings.value(SETTINGS_CHECK_FORCE, false).toBool()));
|
|
|
|
mUI->mShowFullPath->setCheckState(boolToCheckState(settings.value(SETTINGS_SHOW_FULL_PATH, false).toBool()));
|
|
|
|
mUI->mShowNoErrorsMessage->setCheckState(boolToCheckState(settings.value(SETTINGS_SHOW_NO_ERRORS, false).toBool()));
|
|
|
|
mUI->mShowDebugWarnings->setCheckState(boolToCheckState(settings.value(SETTINGS_SHOW_DEBUG_WARNINGS, false).toBool()));
|
|
|
|
mUI->mSaveAllErrors->setCheckState(boolToCheckState(settings.value(SETTINGS_SAVE_ALL_ERRORS, false).toBool()));
|
|
|
|
mUI->mSaveFullPath->setCheckState(boolToCheckState(settings.value(SETTINGS_SAVE_FULL_PATH, false).toBool()));
|
|
|
|
mUI->mInlineSuppressions->setCheckState(boolToCheckState(settings.value(SETTINGS_INLINE_SUPPRESSIONS, false).toBool()));
|
|
|
|
mUI->mEnableInconclusive->setCheckState(boolToCheckState(settings.value(SETTINGS_INCONCLUSIVE_ERRORS, false).toBool()));
|
|
|
|
mUI->mShowStatistics->setCheckState(boolToCheckState(settings.value(SETTINGS_SHOW_STATISTICS, false).toBool()));
|
|
|
|
mUI->mShowErrorId->setCheckState(boolToCheckState(settings.value(SETTINGS_SHOW_ERROR_ID, false).toBool()));
|
2022-10-22 20:27:24 +02:00
|
|
|
mUI->mCheckForUpdates->setCheckState(boolToCheckState(settings.value(SETTINGS_CHECK_FOR_UPDATES, false).toBool()));
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mEditPythonPath->setText(settings.value(SETTINGS_PYTHON_PATH, QString()).toString());
|
2020-09-12 10:35:00 +02:00
|
|
|
validateEditPythonPath();
|
2022-10-30 10:59:43 +01:00
|
|
|
if (premium)
|
|
|
|
mUI->mEditMisraFile->setVisible(false);
|
|
|
|
else
|
|
|
|
mUI->mEditMisraFile->setText(settings.value(SETTINGS_MISRA_FILE, QString()).toString());
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mEditMisraFile->setText(settings.value(SETTINGS_MISRA_FILE, QString()).toString());
|
2017-07-28 13:43:49 +02:00
|
|
|
|
2017-08-07 23:00:24 +02:00
|
|
|
#ifdef Q_OS_WIN
|
2022-03-19 19:54:20 +01:00
|
|
|
//mUI->mTabClang->setVisible(true);
|
|
|
|
mUI->mEditClangPath->setText(settings.value(SETTINGS_CLANG_PATH, QString()).toString());
|
|
|
|
mUI->mEditVsIncludePaths->setText(settings.value(SETTINGS_VS_INCLUDE_PATHS, QString()).toString());
|
|
|
|
connect(mUI->mBtnBrowseClangPath, &QPushButton::released, this, &SettingsDialog::browseClangPath);
|
2017-08-07 23:00:24 +02:00
|
|
|
#else
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mTabClang->setVisible(false);
|
2017-08-07 23:00:24 +02:00
|
|
|
#endif
|
2019-06-25 15:29:15 +02:00
|
|
|
mCurrentStyle = new CodeEditorStyle(CodeEditorStyle::loadSettings(&settings));
|
2019-06-23 19:04:53 +02:00
|
|
|
manageStyleControls();
|
|
|
|
|
2022-03-19 19:54:20 +01:00
|
|
|
connect(mUI->mEditPythonPath, SIGNAL(textEdited(const QString&)),
|
2020-09-12 10:35:00 +02:00
|
|
|
this, SLOT(validateEditPythonPath()));
|
|
|
|
|
2022-03-19 19:54:20 +01:00
|
|
|
connect(mUI->mButtons, &QDialogButtonBox::accepted, this, &SettingsDialog::ok);
|
|
|
|
connect(mUI->mButtons, &QDialogButtonBox::rejected, this, &SettingsDialog::reject);
|
|
|
|
connect(mUI->mBtnAddApplication, SIGNAL(clicked()),
|
2017-07-28 13:43:49 +02:00
|
|
|
this, SLOT(addApplication()));
|
2022-03-19 19:54:20 +01:00
|
|
|
connect(mUI->mBtnRemoveApplication, SIGNAL(clicked()),
|
2017-07-28 13:43:49 +02:00
|
|
|
this, SLOT(removeApplication()));
|
2022-03-19 19:54:20 +01:00
|
|
|
connect(mUI->mBtnEditApplication, SIGNAL(clicked()),
|
2017-07-28 13:43:49 +02:00
|
|
|
this, SLOT(editApplication()));
|
2022-03-19 19:54:20 +01:00
|
|
|
connect(mUI->mBtnDefaultApplication, SIGNAL(clicked()),
|
2017-07-28 13:43:49 +02:00
|
|
|
this, SLOT(defaultApplication()));
|
2022-03-19 19:54:20 +01:00
|
|
|
connect(mUI->mListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
|
2017-07-28 13:43:49 +02:00
|
|
|
this, SLOT(editApplication()));
|
2009-05-23 12:37:30 +02:00
|
|
|
|
2022-03-19 19:54:20 +01:00
|
|
|
connect(mUI->mBtnBrowsePythonPath, &QPushButton::clicked, this, &SettingsDialog::browsePythonPath);
|
|
|
|
connect(mUI->mBtnBrowseMisraFile, &QPushButton::clicked, this, &SettingsDialog::browseMisraFile);
|
|
|
|
connect(mUI->mBtnEditTheme, SIGNAL(clicked()), this, SLOT(editCodeEditorStyle()));
|
|
|
|
connect(mUI->mThemeSystem, SIGNAL(released()), this, SLOT(setCodeEditorStyleDefault()));
|
|
|
|
connect(mUI->mThemeDark, SIGNAL(released()), this, SLOT(setCodeEditorStyleDefault()));
|
|
|
|
connect(mUI->mThemeLight, SIGNAL(released()), this, SLOT(setCodeEditorStyleDefault()));
|
|
|
|
connect(mUI->mThemeCustom, SIGNAL(toggled(bool)), mUI->mBtnEditTheme, SLOT(setEnabled(bool)));
|
2017-08-14 00:23:21 +02:00
|
|
|
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mListWidget->setSortingEnabled(false);
|
2017-07-28 13:43:49 +02:00
|
|
|
populateApplicationList();
|
2009-03-22 13:32:07 +01:00
|
|
|
|
2010-12-27 17:00:44 +01:00
|
|
|
const int count = QThread::idealThreadCount();
|
|
|
|
if (count != -1)
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mLblIdealThreads->setText(QString::number(count));
|
2010-12-27 17:00:44 +01:00
|
|
|
else
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mLblIdealThreads->setText(tr("N/A"));
|
2010-12-27 17:00:44 +01:00
|
|
|
|
2017-07-28 13:43:49 +02:00
|
|
|
loadSettings();
|
|
|
|
initTranslationsList();
|
2009-03-01 08:38:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SettingsDialog::~SettingsDialog()
|
|
|
|
{
|
2017-07-28 13:43:49 +02:00
|
|
|
saveSettings();
|
fixed memory leak in `cppcheck-gui` (#4248)
* settingsdialog.cpp: fixed memory leak
Direct leak of 200 byte(s) in 1 object(s) allocated from:
#0 0xa15a2d in operator new(unsigned long) (/mnt/s/GitHub/cppcheck-fw/cmake-build-debug-wsl-kali-clang-asan-ubsan/bin/cppcheck-gui+0xa15a2d)
#1 0xe639af in SettingsDialog::SettingsDialog(ApplicationList*, TranslationHandler*, QWidget*) /mnt/s/GitHub/cppcheck-fw/gui/settingsdialog.cpp:75:21
#2 0xc67807 in MainWindow::programSettings() /mnt/s/GitHub/cppcheck-fw/gui/mainwindow.cpp:1064:20
#3 0xd1deb8 in QtPrivate::FunctorCall<QtPrivate::IndexesList<>, QtPrivate::List<>, void, void (MainWindow::*)()>::call(void (MainWindow::*)(), MainWindow*, void**) /usr/include/x86_64-linux-gnu/qt5/QtCore/qobjectdefs_impl.h:152:13
#4 0xd1db5c in void QtPrivate::FunctionPointer<void (MainWindow::*)()>::call<QtPrivate::List<>, void>(void (MainWindow::*)(), MainWindow*, void**) /usr/include/x86_64-linux-gnu/qt5/QtCore/qobjectdefs_impl.h:185:13
#5 0xd1d675 in QtPrivate::QSlotObject<void (MainWindow::*)(), QtPrivate::List<>, void>::impl(int, QtPrivate::QSlotObjectBase*, QObject*, void**, bool*) /usr/include/x86_64-linux-gnu/qt5/QtCore/qobjectdefs_impl.h:418:17
#6 0x7f9687f26132 (/usr/lib/x86_64-linux-gnu/libQt5Core.so.5+0x2e6132)
#7 0x7f96889ccdc1 in QAction::triggered(bool) (/usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5+0x15cdc1)
* resultstree.cpp: adjusted TODO about memory leaks
2022-07-09 22:32:48 +02:00
|
|
|
delete mCurrentStyle;
|
2022-03-19 19:54:20 +01:00
|
|
|
delete mUI;
|
2009-03-22 13:32:07 +01:00
|
|
|
}
|
|
|
|
|
2017-07-28 13:43:49 +02:00
|
|
|
void SettingsDialog::initTranslationsList()
|
2011-01-09 23:21:51 +01:00
|
|
|
{
|
2017-07-28 13:43:49 +02:00
|
|
|
const QString current = mTranslator->getCurrentLanguage();
|
2022-03-21 17:14:26 +01:00
|
|
|
for (const TranslationInfo& translation : mTranslator->getTranslations()) {
|
2011-02-07 11:30:13 +01:00
|
|
|
QListWidgetItem *item = new QListWidgetItem;
|
|
|
|
item->setText(translation.mName);
|
2018-06-18 14:19:14 +02:00
|
|
|
item->setData(mLangCodeRole, QVariant(translation.mCode));
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mListLanguages->addItem(item);
|
2015-01-21 18:35:00 +01:00
|
|
|
if (translation.mCode == current || translation.mCode == current.mid(0, 2))
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mListLanguages->setCurrentItem(item);
|
2011-01-09 23:21:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-28 13:43:49 +02:00
|
|
|
Qt::CheckState SettingsDialog::boolToCheckState(bool yes)
|
2009-03-22 13:32:07 +01:00
|
|
|
{
|
2011-10-13 20:53:06 +02:00
|
|
|
if (yes) {
|
2009-03-22 13:32:07 +01:00
|
|
|
return Qt::Checked;
|
|
|
|
}
|
|
|
|
return Qt::Unchecked;
|
|
|
|
}
|
|
|
|
|
2017-07-28 13:43:49 +02:00
|
|
|
bool SettingsDialog::checkStateToBool(Qt::CheckState state)
|
2009-03-22 13:32:07 +01:00
|
|
|
{
|
2011-10-13 20:53:06 +02:00
|
|
|
if (state == Qt::Checked) {
|
2009-03-22 13:32:07 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-28 13:43:49 +02:00
|
|
|
void SettingsDialog::loadSettings()
|
2009-03-22 13:32:07 +01:00
|
|
|
{
|
2011-05-13 09:25:52 +02:00
|
|
|
QSettings settings;
|
|
|
|
resize(settings.value(SETTINGS_CHECK_DIALOG_WIDTH, 800).toInt(),
|
|
|
|
settings.value(SETTINGS_CHECK_DIALOG_HEIGHT, 600).toInt());
|
2009-03-22 13:32:07 +01:00
|
|
|
}
|
|
|
|
|
2017-07-28 13:43:49 +02:00
|
|
|
void SettingsDialog::saveSettings() const
|
2009-03-22 13:32:07 +01:00
|
|
|
{
|
2011-05-13 09:25:52 +02:00
|
|
|
QSettings settings;
|
|
|
|
settings.setValue(SETTINGS_CHECK_DIALOG_WIDTH, size().width());
|
|
|
|
settings.setValue(SETTINGS_CHECK_DIALOG_HEIGHT, size().height());
|
2009-03-22 13:32:07 +01:00
|
|
|
}
|
|
|
|
|
2017-07-28 13:43:49 +02:00
|
|
|
void SettingsDialog::saveSettingValues() const
|
2009-03-22 13:32:07 +01:00
|
|
|
{
|
2022-03-19 19:54:20 +01:00
|
|
|
int jobs = mUI->mJobs->text().toInt();
|
2011-10-13 20:53:06 +02:00
|
|
|
if (jobs <= 0) {
|
2009-05-24 10:53:29 +02:00
|
|
|
jobs = 1;
|
|
|
|
}
|
|
|
|
|
2011-05-13 09:25:52 +02:00
|
|
|
QSettings settings;
|
|
|
|
settings.setValue(SETTINGS_CHECK_THREADS, jobs);
|
2022-03-19 19:54:20 +01:00
|
|
|
saveCheckboxValue(&settings, mUI->mForce, SETTINGS_CHECK_FORCE);
|
|
|
|
saveCheckboxValue(&settings, mUI->mSaveAllErrors, SETTINGS_SAVE_ALL_ERRORS);
|
|
|
|
saveCheckboxValue(&settings, mUI->mSaveFullPath, SETTINGS_SAVE_FULL_PATH);
|
|
|
|
saveCheckboxValue(&settings, mUI->mShowFullPath, SETTINGS_SHOW_FULL_PATH);
|
|
|
|
saveCheckboxValue(&settings, mUI->mShowNoErrorsMessage, SETTINGS_SHOW_NO_ERRORS);
|
|
|
|
saveCheckboxValue(&settings, mUI->mShowDebugWarnings, SETTINGS_SHOW_DEBUG_WARNINGS);
|
|
|
|
saveCheckboxValue(&settings, mUI->mInlineSuppressions, SETTINGS_INLINE_SUPPRESSIONS);
|
|
|
|
saveCheckboxValue(&settings, mUI->mEnableInconclusive, SETTINGS_INCONCLUSIVE_ERRORS);
|
|
|
|
saveCheckboxValue(&settings, mUI->mShowStatistics, SETTINGS_SHOW_STATISTICS);
|
|
|
|
saveCheckboxValue(&settings, mUI->mShowErrorId, SETTINGS_SHOW_ERROR_ID);
|
2022-10-22 20:27:24 +02:00
|
|
|
saveCheckboxValue(&settings, mUI->mCheckForUpdates, SETTINGS_CHECK_FOR_UPDATES);
|
2022-03-19 19:54:20 +01:00
|
|
|
settings.setValue(SETTINGS_PYTHON_PATH, mUI->mEditPythonPath->text());
|
|
|
|
settings.setValue(SETTINGS_MISRA_FILE, mUI->mEditMisraFile->text());
|
2011-02-07 11:30:13 +01:00
|
|
|
|
2017-08-07 23:00:24 +02:00
|
|
|
#ifdef Q_OS_WIN
|
2022-03-19 19:54:20 +01:00
|
|
|
settings.setValue(SETTINGS_CLANG_PATH, mUI->mEditClangPath->text());
|
|
|
|
settings.setValue(SETTINGS_VS_INCLUDE_PATHS, mUI->mEditVsIncludePaths->text());
|
2017-08-07 23:00:24 +02:00
|
|
|
#endif
|
|
|
|
|
2022-03-19 19:54:20 +01:00
|
|
|
const QListWidgetItem *currentLang = mUI->mListLanguages->currentItem();
|
2014-05-02 07:16:10 +02:00
|
|
|
if (currentLang) {
|
2018-06-18 14:19:14 +02:00
|
|
|
const QString langcode = currentLang->data(mLangCodeRole).toString();
|
2014-05-02 07:16:10 +02:00
|
|
|
settings.setValue(SETTINGS_LANGUAGE, langcode);
|
|
|
|
}
|
2019-06-25 15:29:15 +02:00
|
|
|
CodeEditorStyle::saveSettings(&settings, *mCurrentStyle);
|
2009-03-22 13:32:07 +01:00
|
|
|
}
|
|
|
|
|
2017-07-28 13:43:49 +02:00
|
|
|
void SettingsDialog::saveCheckboxValue(QSettings *settings, QCheckBox *box,
|
2011-05-13 09:25:52 +02:00
|
|
|
const QString &name)
|
2009-03-22 13:32:07 +01:00
|
|
|
{
|
2017-07-28 13:43:49 +02:00
|
|
|
settings->setValue(name, checkStateToBool(box->checkState()));
|
2009-03-01 08:38:21 +01:00
|
|
|
}
|
2009-05-23 12:37:30 +02:00
|
|
|
|
2020-09-12 10:35:00 +02:00
|
|
|
void SettingsDialog::validateEditPythonPath()
|
|
|
|
{
|
2022-03-19 19:54:20 +01:00
|
|
|
const auto pythonPath = mUI->mEditPythonPath->text();
|
2020-09-12 10:35:00 +02:00
|
|
|
if (pythonPath.isEmpty()) {
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mEditPythonPath->setStyleSheet("");
|
|
|
|
mUI->mPythonPathWarning->hide();
|
2020-09-12 10:35:00 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QFileInfo pythonPathInfo(pythonPath);
|
|
|
|
if (!pythonPathInfo.exists() ||
|
|
|
|
!pythonPathInfo.isFile() ||
|
|
|
|
!pythonPathInfo.isExecutable()) {
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mEditPythonPath->setStyleSheet("QLineEdit {border: 1px solid red}");
|
|
|
|
mUI->mPythonPathWarning->setText(tr("The executable file \"%1\" is not available").arg(pythonPath));
|
|
|
|
mUI->mPythonPathWarning->show();
|
2020-09-12 10:35:00 +02:00
|
|
|
} else {
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mEditPythonPath->setStyleSheet("");
|
|
|
|
mUI->mPythonPathWarning->hide();
|
2020-09-12 10:35:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-28 13:43:49 +02:00
|
|
|
void SettingsDialog::addApplication()
|
2009-05-23 12:37:30 +02:00
|
|
|
{
|
2011-04-02 15:30:09 +02:00
|
|
|
Application app;
|
|
|
|
ApplicationDialog dialog(tr("Add a new application"), app, this);
|
2009-05-23 12:37:30 +02:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (dialog.exec() == QDialog::Accepted) {
|
2017-07-28 05:18:43 +02:00
|
|
|
mTempApplications->addApplication(app);
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mListWidget->addItem(app.getName());
|
2009-05-23 12:37:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-28 13:43:49 +02:00
|
|
|
void SettingsDialog::removeApplication()
|
2009-05-23 12:37:30 +02:00
|
|
|
{
|
2022-03-21 17:14:26 +01:00
|
|
|
for (QListWidgetItem *item : mUI->mListWidget->selectedItems()) {
|
2022-03-19 19:54:20 +01:00
|
|
|
const int removeIndex = mUI->mListWidget->row(item);
|
2017-07-28 05:18:43 +02:00
|
|
|
const int currentDefault = mTempApplications->getDefaultApplication();
|
|
|
|
mTempApplications->removeApplication(removeIndex);
|
2011-02-25 11:04:10 +01:00
|
|
|
if (removeIndex == currentDefault)
|
|
|
|
// If default app is removed set default to unknown
|
2017-07-28 05:18:43 +02:00
|
|
|
mTempApplications->setDefault(-1);
|
2011-02-25 11:04:10 +01:00
|
|
|
else if (removeIndex < currentDefault)
|
|
|
|
// Move default app one up if earlier app was removed
|
2017-07-28 05:18:43 +02:00
|
|
|
mTempApplications->setDefault(currentDefault - 1);
|
2009-05-23 12:37:30 +02:00
|
|
|
}
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mListWidget->clear();
|
2017-07-28 13:43:49 +02:00
|
|
|
populateApplicationList();
|
2009-05-23 12:37:30 +02:00
|
|
|
}
|
|
|
|
|
2017-07-28 13:43:49 +02:00
|
|
|
void SettingsDialog::editApplication()
|
2009-05-23 12:37:30 +02:00
|
|
|
{
|
2022-03-21 17:14:26 +01:00
|
|
|
for (QListWidgetItem *item : mUI->mListWidget->selectedItems()) {
|
2022-10-02 07:12:40 +02:00
|
|
|
const int row = mUI->mListWidget->row(item);
|
2017-07-28 05:18:43 +02:00
|
|
|
Application& app = mTempApplications->getApplication(row);
|
2011-04-02 15:30:09 +02:00
|
|
|
ApplicationDialog dialog(tr("Modify an application"), app, this);
|
2009-05-23 12:37:30 +02:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (dialog.exec() == QDialog::Accepted) {
|
2015-11-28 21:39:48 +01:00
|
|
|
QString name = app.getName();
|
2017-07-28 05:18:43 +02:00
|
|
|
if (mTempApplications->getDefaultApplication() == row)
|
2015-11-28 21:39:48 +01:00
|
|
|
name += tr(" [Default]");
|
|
|
|
item->setText(name);
|
2009-05-23 12:37:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-28 13:43:49 +02:00
|
|
|
void SettingsDialog::defaultApplication()
|
2009-05-23 17:45:05 +02:00
|
|
|
{
|
2022-03-19 19:54:20 +01:00
|
|
|
QList<QListWidgetItem *> selected = mUI->mListWidget->selectedItems();
|
2013-01-16 15:37:07 +01:00
|
|
|
if (!selected.isEmpty()) {
|
2022-10-02 07:12:40 +02:00
|
|
|
const int index = mUI->mListWidget->row(selected[0]);
|
2017-07-28 05:18:43 +02:00
|
|
|
mTempApplications->setDefault(index);
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mListWidget->clear();
|
2017-07-28 13:43:49 +02:00
|
|
|
populateApplicationList();
|
2009-05-23 17:45:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-28 13:43:49 +02:00
|
|
|
void SettingsDialog::populateApplicationList()
|
2009-05-23 12:37:30 +02:00
|
|
|
{
|
2017-07-28 05:18:43 +02:00
|
|
|
const int defapp = mTempApplications->getDefaultApplication();
|
|
|
|
for (int i = 0; i < mTempApplications->getApplicationCount(); i++) {
|
|
|
|
const Application& app = mTempApplications->getApplication(i);
|
2011-04-02 15:11:01 +02:00
|
|
|
QString name = app.getName();
|
2011-10-13 20:53:06 +02:00
|
|
|
if (i == defapp) {
|
2011-02-25 10:45:04 +01:00
|
|
|
name += " ";
|
|
|
|
name += tr("[Default]");
|
|
|
|
}
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mListWidget->addItem(name);
|
2009-05-23 12:37:30 +02:00
|
|
|
}
|
2009-06-08 15:58:26 +02:00
|
|
|
|
2011-02-25 12:15:53 +01:00
|
|
|
// Select default application, or if there is no default app then the
|
|
|
|
// first item.
|
|
|
|
if (defapp == -1)
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mListWidget->setCurrentRow(0);
|
2011-10-13 20:53:06 +02:00
|
|
|
else {
|
2017-07-28 05:18:43 +02:00
|
|
|
if (mTempApplications->getApplicationCount() > defapp)
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mListWidget->setCurrentRow(defapp);
|
2011-02-25 12:15:53 +01:00
|
|
|
else
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mListWidget->setCurrentRow(0);
|
2009-06-08 15:58:26 +02:00
|
|
|
}
|
2009-05-23 12:37:30 +02:00
|
|
|
}
|
|
|
|
|
2017-07-28 13:43:49 +02:00
|
|
|
void SettingsDialog::ok()
|
2009-05-24 11:08:51 +02:00
|
|
|
{
|
2017-07-28 05:18:43 +02:00
|
|
|
mApplications->copy(mTempApplications);
|
2009-05-24 11:08:51 +02:00
|
|
|
accept();
|
|
|
|
}
|
|
|
|
|
2017-07-28 13:43:49 +02:00
|
|
|
bool SettingsDialog::showFullPath() const
|
2009-06-03 20:18:22 +02:00
|
|
|
{
|
2022-03-19 19:54:20 +01:00
|
|
|
return checkStateToBool(mUI->mShowFullPath->checkState());
|
2009-06-03 20:18:22 +02:00
|
|
|
}
|
|
|
|
|
2017-07-28 13:43:49 +02:00
|
|
|
bool SettingsDialog::saveFullPath() const
|
2009-06-03 20:18:22 +02:00
|
|
|
{
|
2022-03-19 19:54:20 +01:00
|
|
|
return checkStateToBool(mUI->mSaveFullPath->checkState());
|
2009-06-03 20:18:22 +02:00
|
|
|
}
|
|
|
|
|
2017-07-28 13:43:49 +02:00
|
|
|
bool SettingsDialog::saveAllErrors() const
|
2009-06-03 20:18:22 +02:00
|
|
|
{
|
2022-03-19 19:54:20 +01:00
|
|
|
return checkStateToBool(mUI->mSaveAllErrors->checkState());
|
2009-06-03 20:18:22 +02:00
|
|
|
}
|
2009-06-09 09:51:27 +02:00
|
|
|
|
2017-07-28 13:43:49 +02:00
|
|
|
bool SettingsDialog::showNoErrorsMessage() const
|
2009-06-09 09:51:27 +02:00
|
|
|
{
|
2022-03-19 19:54:20 +01:00
|
|
|
return checkStateToBool(mUI->mShowNoErrorsMessage->checkState());
|
2009-06-09 09:51:27 +02:00
|
|
|
}
|
|
|
|
|
2017-07-28 13:43:49 +02:00
|
|
|
bool SettingsDialog::showErrorId() const
|
2012-10-27 11:16:52 +02:00
|
|
|
{
|
2022-03-19 19:54:20 +01:00
|
|
|
return checkStateToBool(mUI->mShowErrorId->checkState());
|
2012-10-27 11:16:52 +02:00
|
|
|
}
|
|
|
|
|
2017-07-28 13:43:49 +02:00
|
|
|
bool SettingsDialog::showInconclusive() const
|
2015-10-15 11:59:17 +02:00
|
|
|
{
|
2022-03-19 19:54:20 +01:00
|
|
|
return checkStateToBool(mUI->mEnableInconclusive->checkState());
|
2015-10-15 11:59:17 +02:00
|
|
|
}
|
|
|
|
|
2017-08-14 00:23:21 +02:00
|
|
|
void SettingsDialog::browsePythonPath()
|
|
|
|
{
|
|
|
|
QString fileName = QFileDialog::getOpenFileName(this, tr("Select python binary"), QDir::rootPath());
|
|
|
|
if (fileName.contains("python", Qt::CaseInsensitive))
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mEditPythonPath->setText(fileName);
|
2017-08-14 00:23:21 +02:00
|
|
|
}
|
|
|
|
|
2018-01-20 14:13:09 +01:00
|
|
|
void SettingsDialog::browseMisraFile()
|
|
|
|
{
|
|
|
|
const QString fileName = QFileDialog::getOpenFileName(this, tr("Select MISRA File"), QDir::homePath(), "Misra File (*.pdf *.txt)");
|
|
|
|
if (!fileName.isEmpty())
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mEditMisraFile->setText(fileName);
|
2018-01-20 14:13:09 +01:00
|
|
|
}
|
|
|
|
|
2019-06-23 19:04:53 +02:00
|
|
|
// Slot to set default light style
|
|
|
|
void SettingsDialog::setCodeEditorStyleDefault()
|
|
|
|
{
|
2022-03-19 19:54:20 +01:00
|
|
|
if (mUI->mThemeSystem->isChecked())
|
2019-07-22 15:55:36 +02:00
|
|
|
*mCurrentStyle = CodeEditorStyle::getSystemTheme();
|
2022-03-19 19:54:20 +01:00
|
|
|
if (mUI->mThemeLight->isChecked())
|
2019-07-22 15:55:36 +02:00
|
|
|
*mCurrentStyle = defaultStyleLight;
|
2022-03-19 19:54:20 +01:00
|
|
|
if (mUI->mThemeDark->isChecked())
|
2019-07-22 15:55:36 +02:00
|
|
|
*mCurrentStyle = defaultStyleDark;
|
2019-06-23 19:04:53 +02:00
|
|
|
manageStyleControls();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Slot to edit custom style
|
|
|
|
void SettingsDialog::editCodeEditorStyle()
|
|
|
|
{
|
2019-07-22 12:50:42 +02:00
|
|
|
StyleEditDialog dlg(*mCurrentStyle, this);
|
2022-10-02 07:12:40 +02:00
|
|
|
const int nResult = dlg.exec();
|
2019-06-25 15:29:15 +02:00
|
|
|
if (nResult == QDialog::Accepted) {
|
2019-07-22 12:50:42 +02:00
|
|
|
*mCurrentStyle = dlg.getStyle();
|
2019-06-23 19:04:53 +02:00
|
|
|
manageStyleControls();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-10 15:47:20 +02:00
|
|
|
void SettingsDialog::browseClangPath()
|
|
|
|
{
|
|
|
|
QString selectedDir = QFileDialog::getExistingDirectory(this,
|
2021-08-07 20:51:18 +02:00
|
|
|
tr("Select clang path"),
|
|
|
|
QDir::rootPath());
|
2017-08-10 15:47:20 +02:00
|
|
|
|
|
|
|
if (!selectedDir.isEmpty()) {
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mEditClangPath->setText(selectedDir);
|
2017-08-10 15:47:20 +02:00
|
|
|
}
|
|
|
|
}
|
2019-06-23 19:04:53 +02:00
|
|
|
|
|
|
|
void SettingsDialog::manageStyleControls()
|
|
|
|
{
|
2022-10-02 07:12:40 +02:00
|
|
|
const bool isSystemTheme = mCurrentStyle->isSystemTheme();
|
|
|
|
const bool isDefaultLight = !isSystemTheme && *mCurrentStyle == defaultStyleLight;
|
|
|
|
const bool isDefaultDark = !isSystemTheme && *mCurrentStyle == defaultStyleDark;
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mThemeSystem->setChecked(isSystemTheme);
|
|
|
|
mUI->mThemeLight->setChecked(isDefaultLight && !isDefaultDark);
|
|
|
|
mUI->mThemeDark->setChecked(!isDefaultLight && isDefaultDark);
|
|
|
|
mUI->mThemeCustom->setChecked(!isSystemTheme && !isDefaultLight && !isDefaultDark);
|
|
|
|
mUI->mBtnEditTheme->setEnabled(!isSystemTheme && !isDefaultLight && !isDefaultDark);
|
2019-06-30 21:43:25 +02:00
|
|
|
}
|
|
|
|
|