2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2021 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2021-09-28 10:26:34 +02:00
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "utils/filepath.h"
|
|
|
|
|
#include <clang/Format/Format.h>
|
|
|
|
|
|
2021-11-01 16:20:08 +01:00
|
|
|
namespace CppEditor { class CppCodeStyleSettings; }
|
|
|
|
|
namespace ProjectExplorer { class Project; }
|
|
|
|
|
namespace TextEditor { class TabSettings; }
|
|
|
|
|
|
2021-09-28 10:26:34 +02:00
|
|
|
namespace ClangFormat {
|
|
|
|
|
|
|
|
|
|
class ClangFormatFile
|
|
|
|
|
{
|
|
|
|
|
public:
|
2022-08-01 17:28:42 +02:00
|
|
|
explicit ClangFormatFile(Utils::FilePath file);
|
|
|
|
|
clang::format::FormatStyle style();
|
2021-09-28 10:26:34 +02:00
|
|
|
|
|
|
|
|
Utils::FilePath filePath();
|
2022-04-04 14:53:05 +02:00
|
|
|
void resetStyleToQtC();
|
2021-09-28 10:26:34 +02:00
|
|
|
void setBasedOnStyle(QString styleName);
|
|
|
|
|
void setStyle(clang::format::FormatStyle style);
|
|
|
|
|
QString setStyle(QString style);
|
|
|
|
|
void clearBasedOnStyle();
|
|
|
|
|
|
|
|
|
|
using Field = std::pair<QString, QString>;
|
|
|
|
|
QString changeFields(QList<Field> fields);
|
|
|
|
|
QString changeField(Field field);
|
2021-11-01 16:20:08 +01:00
|
|
|
CppEditor::CppCodeStyleSettings toCppCodeStyleSettings(ProjectExplorer::Project *project) const;
|
|
|
|
|
TextEditor::TabSettings toTabSettings(ProjectExplorer::Project *project) const;
|
|
|
|
|
void fromCppCodeStyleSettings(const CppEditor::CppCodeStyleSettings &settings);
|
|
|
|
|
void fromTabSettings(const TextEditor::TabSettings &settings);
|
2022-04-04 14:53:05 +02:00
|
|
|
bool isReadOnly() const;
|
2022-08-01 17:28:42 +02:00
|
|
|
void setIsReadOnly(bool isReadOnly);
|
2021-09-28 10:26:34 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void saveNewFormat();
|
|
|
|
|
void saveNewFormat(QByteArray style);
|
2023-01-16 12:33:43 +01:00
|
|
|
void saveStyleToFile(clang::format::FormatStyle style, Utils::FilePath filePath);
|
2021-09-28 10:26:34 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Utils::FilePath m_filePath;
|
|
|
|
|
clang::format::FormatStyle m_style;
|
2022-08-01 17:28:42 +02:00
|
|
|
bool m_isReadOnly;
|
2021-09-28 10:26:34 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace ClangFormat
|