Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qqmlformatoptions_p.h
Go to the documentation of this file.
1// Copyright (C) 2023 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4
5#ifndef QQmlFormatOptions_P_H
6#define QQmlFormatOptions_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtCore/qstring.h>
20#include <QtQmlDom/private/qqmldomoutwriter_p.h>
21#include <QtQmlDom/private/qqmldomlinewriter_p.h>
22#include <QtQmlToolingSettings/private/qqmltoolingsettings_p.h>
23
25
27
34
36{
37public:
39
42
43 static LineEndings detectLineEndings(const QString &code);
44
45 static LineEndings lineEndings(QQmlFormatOptionLineEndings endings, const QString &code)
46 {
47 switch (endings) {
48 case Native:
49 return detectLineEndings(code);
50 case OldMacOs:
51 return LineEndings::OldMacOs;
52 case Windows:
53 return LineEndings::Windows;
54 case Unix:
55 return LineEndings::Unix;
56 }
57 Q_UNREACHABLE_RETURN(LineEndings::Unix);
58 }
59
60 bool tabsEnabled() const { return m_options.formatOptions.useTabs; }
61 void setTabsEnabled(bool tabs) { m_options.formatOptions.useTabs = tabs; }
62 bool normalizeEnabled() const
63 {
64 return m_options.attributesSequence == AttributesSequence::Normalize;
65 }
66 void setNormalizeEnabled(bool normalize)
67 {
68 m_options.attributesSequence =
69 (normalize ? AttributesSequence::Normalize : AttributesSequence::Preserve);
70 }
71 bool objectsSpacing() const { return m_options.objectsSpacing; }
72 void setObjectsSpacing(bool spacing) { m_options.objectsSpacing = spacing; }
73 bool functionsSpacing() const { return m_options.functionsSpacing; }
74 void setFunctionsSpacing(bool spacing) { m_options.functionsSpacing = spacing; }
75
76 int indentWidth() const { return m_options.formatOptions.indentSize; }
77 void setIndentWidth(int width) { m_options.formatOptions.indentSize = width; }
78
79 QQmlJS::Dom::LineWriterOptions optionsForCode(const QString &code) const
80 {
81 QQmlJS::Dom::LineWriterOptions result = m_options;
82 result.lineEndings = lineEndings(m_newline, code);
83 return result;
84 }
85
86 static QQmlFormatOptionLineEndings parseEndings(const QString &endings);
87
88 QQmlFormatOptionLineEndings newline() const { return m_newline; }
89 void setNewline(const QQmlFormatOptionLineEndings &endings) { m_newline = endings; }
90
91 QStringList files() const { return m_files; }
92 void setFiles(const QStringList &newFiles) { m_files = newFiles; }
93 QStringList arguments() const { return m_arguments; }
94 void setArguments(const QStringList &newArguments) { m_arguments = newArguments; }
95 bool isVerbose() const { return m_verbose; }
96 void setIsVerbose(bool newVerbose) { m_verbose = newVerbose; }
97 bool isValid() const { return m_valid; }
98 void setIsValid(bool newValid) { m_valid = newValid; }
99 bool isInplace() const { return m_inplace; }
100 void setIsInplace(bool newInplace) { m_inplace = newInplace; }
101 bool forceEnabled() const { return m_force; }
102 void setForceEnabled(bool newForce) { m_force = newForce; }
103 bool ignoreSettingsEnabled() const { return m_ignoreSettings; }
104 void setIgnoreSettingsEnabled(bool newIgnoreSettings) { m_ignoreSettings = newIgnoreSettings; }
105 bool writeDefaultSettingsEnabled() const { return m_writeDefaultSettings; }
106 void setWriteDefaultSettingsEnabled(bool newWriteDefaultSettings)
107 {
108 m_writeDefaultSettings = newWriteDefaultSettings;
109 }
110
111 bool indentWidthSet() const { return m_indentWidthSet; }
112 void setIndentWidthSet(bool newIndentWidthSet) { m_indentWidthSet = newIndentWidthSet; }
113 QStringList errors() const { return m_errors; }
114 void addError(const QString &newError) { m_errors.append(newError); };
115
116 void applySettings(const QQmlFormatSettings &settings);
117
118private:
119 QQmlJS::Dom::LineWriterOptions m_options;
120
122
123 QStringList m_files;
124 QStringList m_arguments;
125 QStringList m_errors;
126
127 bool m_verbose = false;
128 bool m_valid = false;
129 bool m_inplace = false;
130 bool m_force = false;
131 bool m_ignoreSettings = false;
132 bool m_writeDefaultSettings = false;
133 bool m_indentWidthSet = false;
134};
135
136QT_END_NAMESPACE
137#endif // QQmlFormatOptions_P_H
void setArguments(const QStringList &newArguments)
void setTabsEnabled(bool tabs)
QStringList errors() const
void setNewline(const QQmlFormatOptionLineEndings &endings)
void setNormalizeEnabled(bool normalize)
QQmlJS::Dom::LineWriterOptions optionsForCode(const QString &code) const
bool objectsSpacing() const
QStringList files() const
static LineEndings detectLineEndings(const QString &code)
void applySettings(const QQmlFormatSettings &settings)
void setIndentWidthSet(bool newIndentWidthSet)
static LineEndings lineEndings(QQmlFormatOptionLineEndings endings, const QString &code)
void setForceEnabled(bool newForce)
static QQmlFormatOptionLineEndings parseEndings(const QString &endings)
void setIgnoreSettingsEnabled(bool newIgnoreSettings)
void setIsVerbose(bool newVerbose)
void setFunctionsSpacing(bool spacing)
void setIndentWidth(int width)
bool writeDefaultSettingsEnabled() const
QStringList arguments() const
bool normalizeEnabled() const
void setObjectsSpacing(bool spacing)
bool ignoreSettingsEnabled() const
void setIsValid(bool newValid)
void setIsInplace(bool newInplace)
bool functionsSpacing() const
void setWriteDefaultSettingsEnabled(bool newWriteDefaultSettings)
void setFiles(const QStringList &newFiles)
void addError(const QString &newError)
QQmlFormatOptionLineEndings newline() const
Combined button and popup list for selecting options.
QQmlFormatOptionLineEndings