From 5c10cfd59ea09a9b4328688245deca805724841f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 30 Oct 2022 10:59:43 +0100 Subject: [PATCH] GUI: fix path issue with backslashes. hide non-premium setting in premium settings dialog. --- gui/mainwindow.cpp | 18 ++++++++++++++---- gui/settingsdialog.cpp | 8 +++++++- gui/settingsdialog.h | 3 +++ 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 45d9454cc..a7147cf68 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -72,6 +72,16 @@ static const QString OnlineHelpURL("https://cppcheck.sourceforge.io/manual.html"); static const QString compile_commands_json("compile_commands.json"); +static QString fromNativePath(const QString& p) { +#ifdef Q_OS_WIN + QString ret(p); + ret.replace('\\', '/'); + return ret; +#else + return p; +#endif +} + MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) : mSettings(settings), mApplications(new ApplicationList(this)), @@ -913,7 +923,7 @@ Settings MainWindow::getCppcheckSettings() if (!mProjectFile->getImportProject().isEmpty()) result.checkAllConfigurations = false; - const QString &buildDir = mProjectFile->getBuildDir(); + const QString &buildDir = fromNativePath(mProjectFile->getBuildDir()); if (!buildDir.isEmpty()) { if (QDir(buildDir).isAbsolute()) { result.buildDir = buildDir.toStdString(); @@ -949,7 +959,7 @@ Settings MainWindow::getCppcheckSettings() result.checkUnknownFunctionReturn.insert(s.toStdString()); QString filesDir(getDataDir()); - const QString pythonCmd = mSettings->value(SETTINGS_PYTHON_PATH).toString(); + const QString pythonCmd = fromNativePath(mSettings->value(SETTINGS_PYTHON_PATH).toString()); for (const QString& addon : mProjectFile->getAddons()) { QString addonFilePath = ProjectFile::getAddonFilePath(filesDir, addon); if (addonFilePath.isEmpty()) @@ -961,7 +971,7 @@ Settings MainWindow::getCppcheckSettings() json += "{ \"script\":\"" + addonFilePath + "\""; if (!pythonCmd.isEmpty()) json += ", \"python\":\"" + pythonCmd + "\""; - QString misraFile = mSettings->value(SETTINGS_MISRA_FILE).toString(); + QString misraFile = fromNativePath(mSettings->value(SETTINGS_MISRA_FILE).toString()); if (addon == "misra" && !misraFile.isEmpty()) { QString arg; if (misraFile.endsWith(".pdf", Qt::CaseInsensitive)) @@ -1102,7 +1112,7 @@ void MainWindow::checkLockDownUI() void MainWindow::programSettings() { - SettingsDialog dialog(mApplications, mTranslation, this); + SettingsDialog dialog(mApplications, mTranslation, isCppcheckPremium(), this); if (dialog.exec() == QDialog::Accepted) { dialog.saveSettingValues(); mSettings->sync(); diff --git a/gui/settingsdialog.cpp b/gui/settingsdialog.cpp index d53b2212d..f7d09cb31 100644 --- a/gui/settingsdialog.cpp +++ b/gui/settingsdialog.cpp @@ -37,12 +37,14 @@ SettingsDialog::SettingsDialog(ApplicationList *list, TranslationHandler *translator, + bool premium, QWidget *parent) : QDialog(parent), mApplications(list), mTempApplications(new ApplicationList(this)), mTranslator(translator), - mUI(new Ui::Settings) + mUI(new Ui::Settings), + mPremium(premium) { mUI->setupUi(this); mUI->mPythonPathWarning->setStyleSheet("color: red"); @@ -63,6 +65,10 @@ SettingsDialog::SettingsDialog(ApplicationList *list, mUI->mCheckForUpdates->setCheckState(boolToCheckState(settings.value(SETTINGS_CHECK_FOR_UPDATES, false).toBool())); mUI->mEditPythonPath->setText(settings.value(SETTINGS_PYTHON_PATH, QString()).toString()); validateEditPythonPath(); + if (premium) + mUI->mEditMisraFile->setVisible(false); + else + mUI->mEditMisraFile->setText(settings.value(SETTINGS_MISRA_FILE, QString()).toString()); mUI->mEditMisraFile->setText(settings.value(SETTINGS_MISRA_FILE, QString()).toString()); #ifdef Q_OS_WIN diff --git a/gui/settingsdialog.h b/gui/settingsdialog.h index 59d1ecd89..d1caab630 100644 --- a/gui/settingsdialog.h +++ b/gui/settingsdialog.h @@ -45,6 +45,7 @@ class SettingsDialog : public QDialog { public: SettingsDialog(ApplicationList *list, TranslationHandler *translator, + bool premium, QWidget *parent = nullptr); SettingsDialog(const SettingsDialog &) = delete; ~SettingsDialog() override; @@ -238,6 +239,8 @@ private: void manageStyleControls(); static const int mLangCodeRole = Qt::UserRole; + + bool mPremium; }; /// @} #endif // SETTINGSDIALOG_H