CppCheck: Use more FilePath

Change-Id: I45da67df4b76032303b57f567d73ae01bf9f2e91
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2021-09-30 16:58:46 +02:00
parent cc8d65aa25
commit 04f6f6bbc0
4 changed files with 17 additions and 18 deletions

View File

@@ -39,9 +39,10 @@
#include <debugger/analyzer/analyzericons.h> #include <debugger/analyzer/analyzericons.h>
#include <QCheckBox> #include <QCheckBox>
#include <QDir>
#include <QFormLayout> #include <QFormLayout>
using namespace Utils;
namespace Cppcheck { namespace Cppcheck {
namespace Internal { namespace Internal {
@@ -102,7 +103,7 @@ OptionsWidget::OptionsWidget(QWidget *parent)
void OptionsWidget::load(const CppcheckOptions &options) void OptionsWidget::load(const CppcheckOptions &options)
{ {
m_binary->setPath(options.binary); m_binary->setFilePath(options.binary);
m_customArguments->setText(options.customArguments); m_customArguments->setText(options.customArguments);
m_ignorePatterns->setText(options.ignoredPatterns); m_ignorePatterns->setText(options.ignoredPatterns);
m_warning->setChecked(options.warning); m_warning->setChecked(options.warning);
@@ -121,7 +122,7 @@ void OptionsWidget::load(const CppcheckOptions &options)
void OptionsWidget::save(CppcheckOptions &options) const void OptionsWidget::save(CppcheckOptions &options) const
{ {
options.binary = m_binary->filePath().toString(); options.binary = m_binary->filePath();
options.customArguments = m_customArguments->text(); options.customArguments = m_customArguments->text();
options.ignoredPatterns = m_ignorePatterns->text(); options.ignoredPatterns = m_ignorePatterns->text();
options.warning = m_warning->isChecked(); options.warning = m_warning->isChecked();
@@ -149,14 +150,13 @@ CppcheckOptionsPage::CppcheckOptionsPage(CppcheckTool &tool, CppcheckTrigger &tr
setCategoryIconPath(Analyzer::Icons::SETTINGSCATEGORY_ANALYZER); setCategoryIconPath(Analyzer::Icons::SETTINGSCATEGORY_ANALYZER);
CppcheckOptions options; CppcheckOptions options;
if (Utils::HostOsInfo::isAnyUnixHost()) { if (HostOsInfo::isAnyUnixHost()) {
options.binary = "cppcheck"; options.binary = "cppcheck";
} else { } else {
QString programFiles = QDir::fromNativeSeparators( FilePath programFiles = FilePath::fromUserInput(qEnvironmentVariable("PROGRAMFILES"));
QString::fromLocal8Bit(qgetenv("PROGRAMFILES")));
if (programFiles.isEmpty()) if (programFiles.isEmpty())
programFiles = "C:/Program Files"; programFiles = "C:/Program Files";
options.binary = programFiles + "/Cppcheck/cppcheck.exe"; options.binary = programFiles / "Cppcheck/cppcheck.exe";
} }
load(options); load(options);
@@ -190,7 +190,7 @@ void CppcheckOptionsPage::save(const CppcheckOptions &options) const
QSettings *s = Core::ICore::settings(); QSettings *s = Core::ICore::settings();
QTC_ASSERT(s, return); QTC_ASSERT(s, return);
s->beginGroup(Constants::SETTINGS_ID); s->beginGroup(Constants::SETTINGS_ID);
s->setValue(Constants::SETTINGS_BINARY, options.binary); s->setValue(Constants::SETTINGS_BINARY, options.binary.toString());
s->setValue(Constants::SETTINGS_CUSTOM_ARGUMENTS, options.customArguments); s->setValue(Constants::SETTINGS_CUSTOM_ARGUMENTS, options.customArguments);
s->setValue(Constants::SETTINGS_IGNORE_PATTERNS, options.ignoredPatterns); s->setValue(Constants::SETTINGS_IGNORE_PATTERNS, options.ignoredPatterns);
s->setValue(Constants::SETTINGS_WARNING, options.warning); s->setValue(Constants::SETTINGS_WARNING, options.warning);
@@ -213,8 +213,8 @@ void CppcheckOptionsPage::load(CppcheckOptions &options) const
QSettings *s = Core::ICore::settings(); QSettings *s = Core::ICore::settings();
QTC_ASSERT(s, return); QTC_ASSERT(s, return);
s->beginGroup(Constants::SETTINGS_ID); s->beginGroup(Constants::SETTINGS_ID);
options.binary = s->value(Constants::SETTINGS_BINARY, options.binary = FilePath::fromString(s->value(Constants::SETTINGS_BINARY,
options.binary).toString(); options.binary.toString()).toString());
options.customArguments = s->value(Constants::SETTINGS_CUSTOM_ARGUMENTS, options.customArguments = s->value(Constants::SETTINGS_CUSTOM_ARGUMENTS,
options.customArguments).toString(); options.customArguments).toString();
options.ignoredPatterns = s->value(Constants::SETTINGS_IGNORE_PATTERNS, options.ignoredPatterns = s->value(Constants::SETTINGS_IGNORE_PATTERNS,

View File

@@ -26,6 +26,7 @@
#pragma once #pragma once
#include <coreplugin/dialogs/ioptionspage.h> #include <coreplugin/dialogs/ioptionspage.h>
#include <utils/filepath.h>
#include <QCoreApplication> #include <QCoreApplication>
#include <QPointer> #include <QPointer>
@@ -36,9 +37,7 @@ class QLineEdit;
class QCheckBox; class QCheckBox;
QT_END_NAMESPACE QT_END_NAMESPACE
namespace Utils { namespace Utils { class PathChooser; }
class PathChooser;
}
namespace Cppcheck { namespace Cppcheck {
namespace Internal { namespace Internal {
@@ -50,7 +49,7 @@ class OptionsWidget;
class CppcheckOptions final class CppcheckOptions final
{ {
public: public:
QString binary; Utils::FilePath binary;
bool warning = true; bool warning = true;
bool style = true; bool style = true;

View File

@@ -74,7 +74,7 @@ CppcheckRunner::~CppcheckRunner()
m_queueTimer.stop(); m_queueTimer.stop();
} }
void CppcheckRunner::reconfigure(const QString &binary, const QString &arguments) void CppcheckRunner::reconfigure(const FilePath &binary, const QString &arguments)
{ {
m_binary = binary; m_binary = binary;
m_arguments = arguments; m_arguments = arguments;
@@ -157,7 +157,7 @@ void CppcheckRunner::checkQueued()
else else
m_queue.begin().value() = files; m_queue.begin().value() = files;
m_process->setCommand(CommandLine(FilePath::fromString(m_binary), arguments, CommandLine::Raw)); m_process->setCommand(CommandLine(m_binary, arguments, CommandLine::Raw));
m_process->start(); m_process->start();
} }

View File

@@ -45,7 +45,7 @@ public:
explicit CppcheckRunner(CppcheckTool &tool); explicit CppcheckRunner(CppcheckTool &tool);
~CppcheckRunner() override; ~CppcheckRunner() override;
void reconfigure(const QString &binary, const QString &arguments); void reconfigure(const Utils::FilePath &binary, const QString &arguments);
void addToQueue(const Utils::FilePaths &files, void addToQueue(const Utils::FilePaths &files,
const QString &additionalArguments = {}); const QString &additionalArguments = {});
void removeFromQueue(const Utils::FilePaths &files); void removeFromQueue(const Utils::FilePaths &files);
@@ -63,7 +63,7 @@ private:
CppcheckTool &m_tool; CppcheckTool &m_tool;
Utils::QtcProcess *m_process = nullptr; Utils::QtcProcess *m_process = nullptr;
QString m_binary; Utils::FilePath m_binary;
QString m_arguments; QString m_arguments;
QHash<QString, Utils::FilePaths> m_queue; QHash<QString, Utils::FilePaths> m_queue;
Utils::FilePaths m_currentFiles; Utils::FilePaths m_currentFiles;