Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qqmlformatsettings.cpp
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
// Qt-Security score:significant
4
5
#
include
"qqmlformatsettings_p.h"
6
7
#
include
<
QCommandLineParser
>
8
#
include
<
QJsonArray
>
9
#
include
<
QJsonDocument
>
10
#
include
<
QJsonObject
>
11
12
using
namespace
Qt::StringLiterals;
13
14
QQmlFormatSettings::QQmlFormatSettings(
const
QString &toolName) : QQmlToolingSettings(toolName)
15
{
16
addOption(s_useTabsSetting,
false
);
17
addOption(s_indentWidthSetting, 4);
18
addOption(s_maxColumnWidthSetting, -1);
19
addOption(s_normalizeSetting,
false
);
20
addOption(s_newlineSetting, u"native"_s,
21
QStringList { u"unix"_s, u"windows"_s, u"macos"_s, u"native"_s });
22
addOption(s_objectsSpacingSetting,
false
);
23
addOption(s_functionsSpacingSetting,
false
);
24
addOption(s_groupAttributesTogetherSetting,
false
);
25
addOption(s_sortImportsSetting,
false
);
26
addOption(s_singleLineEmptyObjectsSetting,
false
);
27
addOption(s_semiColonRuleSetting, u"always"_s, QStringList{ u"always"_s, u"essential"_s });
28
}
29
30
void
QQmlFormatSettings::addOption(
const
QString &name,
const
QVariant &defaultValue,
const
QStringList &allowedValues)
31
{
32
QQmlToolingSettings::addOption(name, defaultValue);
33
if
(defaultValue.typeId() == QMetaType::QString) {
34
Q_ASSERT(!allowedValues.isEmpty());
35
m_allowedValues[name] = allowedValues;
36
}
37
}
38
39
bool
QQmlFormatSettings::outputOptions()
const
40
{
41
QJsonObject root;
42
QJsonArray optionsArray;
43
for
(
auto
it = m_values.constBegin(); it != m_values.constEnd(); ++it) {
44
QJsonObject option;
45
option[u"name"] = it.key();
46
option[u"value"] = QJsonValue::fromVariant(it.value());
47
option[u"hint"] = QString::fromUtf8(it.value().typeName());
48
49
if
(it.value().typeId() == QMetaType::QString)
50
option[u"hint"] = m_allowedValues[it.key()].join(u',');
51
52
optionsArray.append(option);
53
}
54
root[u"options"] = optionsArray;
55
56
QCommandLineParser::showMessageAndExit(
57
QCommandLineParser::MessageType::Information,
58
QString::fromUtf8(QJsonDocument(root).toJson()), EXIT_SUCCESS);
59
return
true
;
60
}
qtdeclarative
src
qmlformat
qqmlformatsettings.cpp
Generated on
for Qt by
1.18.0