1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "cppcodemodelsettings.h"
#include "clangdiagnosticconfigsmodel.h"
#include "cpptoolsconstants.h"
#include <utils/qtcassert.h>
#include <QSettings>
using namespace CppTools;
static Core::Id initialClangDiagnosticConfigId()
{ return Core::Id(Constants::CPP_CLANG_BUILTIN_CONFIG_ID_EVERYTHING_WITH_EXCEPTIONS); }
static CppCodeModelSettings::PCHUsage initialPchUsage()
{ return CppCodeModelSettings::PchUse_None; }
static QString clangDiagnosticConfigKey()
{ return QStringLiteral("ClangDiagnosticConfig"); }
static QString clangDiagnosticConfigsArrayKey()
{ return QStringLiteral("ClangDiagnosticConfigs"); }
static QString clangDiagnosticConfigsArrayIdKey()
{ return QLatin1String("id"); }
static QString clangDiagnosticConfigsArrayDisplayNameKey()
{ return QLatin1String("displayName"); }
static QString clangDiagnosticConfigsArrayWarningsKey()
{ return QLatin1String("diagnosticOptions"); }
static QString clangDiagnosticConfigsArrayClangTidyChecksKey()
{ return QLatin1String("clangTidyChecks"); }
static QString clangDiagnosticConfigsArrayClazyChecksKey()
{ return QLatin1String("clazyChecks"); }
static QString pchUsageKey()
{ return QLatin1String(Constants::CPPTOOLS_MODEL_MANAGER_PCH_USAGE); }
static QString interpretAmbiguousHeadersAsCHeadersKey()
{ return QLatin1String(Constants::CPPTOOLS_INTERPRET_AMBIGIUOUS_HEADERS_AS_C_HEADERS); }
static QString skipIndexingBigFilesKey()
{ return QLatin1String(Constants::CPPTOOLS_SKIP_INDEXING_BIG_FILES); }
static QString indexerFileSizeLimitKey()
{ return QLatin1String(Constants::CPPTOOLS_INDEXER_FILE_SIZE_LIMIT); }
static ClangDiagnosticConfigs customDiagnosticConfigsFromSettings(QSettings *s)
{
QTC_ASSERT(s->group() == QLatin1String(Constants::CPPTOOLS_SETTINGSGROUP),
return ClangDiagnosticConfigs());
ClangDiagnosticConfigs configs;
const int size = s->beginReadArray(clangDiagnosticConfigsArrayKey());
for (int i = 0; i < size; ++i) {
s->setArrayIndex(i);
ClangDiagnosticConfig config;
config.setId(Core::Id::fromSetting(s->value(clangDiagnosticConfigsArrayIdKey())));
config.setDisplayName(s->value(clangDiagnosticConfigsArrayDisplayNameKey()).toString());
config.setClangOptions(s->value(clangDiagnosticConfigsArrayWarningsKey()).toStringList());
config.setClangTidyChecks(s->value(clangDiagnosticConfigsArrayClangTidyChecksKey()).toString());
config.setClazyChecks(s->value(clangDiagnosticConfigsArrayClazyChecksKey()).toString());
configs.append(config);
}
s->endArray();
return configs;
}
static Core::Id clangDiagnosticConfigIdFromSettings(QSettings *s)
{
QTC_ASSERT(s->group() == QLatin1String(Constants::CPPTOOLS_SETTINGSGROUP), return Core::Id());
return Core::Id::fromSetting(
s->value(clangDiagnosticConfigKey(), initialClangDiagnosticConfigId().toSetting()));
}
void CppCodeModelSettings::fromSettings(QSettings *s)
{
s->beginGroup(QLatin1String(Constants::CPPTOOLS_SETTINGSGROUP));
setClangCustomDiagnosticConfigs(customDiagnosticConfigsFromSettings(s));
setClangDiagnosticConfigId(clangDiagnosticConfigIdFromSettings(s));
const QVariant pchUsageVariant = s->value(pchUsageKey(), initialPchUsage());
setPCHUsage(static_cast<PCHUsage>(pchUsageVariant.toInt()));
const QVariant interpretAmbiguousHeadersAsCHeaders
= s->value(interpretAmbiguousHeadersAsCHeadersKey(), false);
setInterpretAmbigiousHeadersAsCHeaders(interpretAmbiguousHeadersAsCHeaders.toBool());
const QVariant skipIndexingBigFiles = s->value(skipIndexingBigFilesKey(), true);
setSkipIndexingBigFiles(skipIndexingBigFiles.toBool());
const QVariant indexerFileSizeLimit = s->value(indexerFileSizeLimitKey(), 5);
setIndexerFileSizeLimitInMb(indexerFileSizeLimit.toInt());
s->endGroup();
emit changed();
}
void CppCodeModelSettings::toSettings(QSettings *s)
{
s->beginGroup(QLatin1String(Constants::CPPTOOLS_SETTINGSGROUP));
const ClangDiagnosticConfigs previousConfigs = customDiagnosticConfigsFromSettings(s);
const Core::Id previousConfigId = clangDiagnosticConfigIdFromSettings(s);
s->beginWriteArray(clangDiagnosticConfigsArrayKey());
for (int i = 0, size = m_clangCustomDiagnosticConfigs.size(); i < size; ++i) {
const ClangDiagnosticConfig &config = m_clangCustomDiagnosticConfigs.at(i);
s->setArrayIndex(i);
s->setValue(clangDiagnosticConfigsArrayIdKey(), config.id().toSetting());
s->setValue(clangDiagnosticConfigsArrayDisplayNameKey(), config.displayName());
s->setValue(clangDiagnosticConfigsArrayWarningsKey(), config.clangOptions());
s->setValue(clangDiagnosticConfigsArrayClangTidyChecksKey(), config.clangTidyChecks());
s->setValue(clangDiagnosticConfigsArrayClazyChecksKey(), config.clazyChecks());
}
s->endArray();
s->setValue(clangDiagnosticConfigKey(), clangDiagnosticConfigId().toSetting());
s->setValue(pchUsageKey(), pchUsage());
s->setValue(interpretAmbiguousHeadersAsCHeadersKey(), interpretAmbigiousHeadersAsCHeaders());
s->setValue(skipIndexingBigFilesKey(), skipIndexingBigFiles());
s->setValue(indexerFileSizeLimitKey(), indexerFileSizeLimitInMb());
s->endGroup();
QVector<Core::Id> invalidated
= ClangDiagnosticConfigsModel::changedOrRemovedConfigs(previousConfigs,
m_clangCustomDiagnosticConfigs);
if (previousConfigId != clangDiagnosticConfigId() && !invalidated.contains(previousConfigId))
invalidated.append(previousConfigId);
if (!invalidated.isEmpty())
emit clangDiagnosticConfigsInvalidated(invalidated);
emit changed();
}
Core::Id CppCodeModelSettings::clangDiagnosticConfigId() const
{
return m_clangDiagnosticConfigId;
}
void CppCodeModelSettings::setClangDiagnosticConfigId(const Core::Id &configId)
{
m_clangDiagnosticConfigId = configId;
}
const ClangDiagnosticConfig CppCodeModelSettings::clangDiagnosticConfig() const
{
const ClangDiagnosticConfigsModel configsModel(m_clangCustomDiagnosticConfigs);
return configsModel.configWithId(clangDiagnosticConfigId());
}
ClangDiagnosticConfigs CppCodeModelSettings::clangCustomDiagnosticConfigs() const
{
return m_clangCustomDiagnosticConfigs;
}
void CppCodeModelSettings::setClangCustomDiagnosticConfigs(const ClangDiagnosticConfigs &configs)
{
m_clangCustomDiagnosticConfigs = configs;
}
CppCodeModelSettings::PCHUsage CppCodeModelSettings::pchUsage() const
{
return m_pchUsage;
}
void CppCodeModelSettings::setPCHUsage(CppCodeModelSettings::PCHUsage pchUsage)
{
m_pchUsage = pchUsage;
}
bool CppCodeModelSettings::interpretAmbigiousHeadersAsCHeaders() const
{
return m_interpretAmbigiousHeadersAsCHeaders;
}
void CppCodeModelSettings::setInterpretAmbigiousHeadersAsCHeaders(bool yesno)
{
m_interpretAmbigiousHeadersAsCHeaders = yesno;
}
bool CppCodeModelSettings::skipIndexingBigFiles() const
{
return m_skipIndexingBigFiles;
}
void CppCodeModelSettings::setSkipIndexingBigFiles(bool yesno)
{
m_skipIndexingBigFiles = yesno;
}
int CppCodeModelSettings::indexerFileSizeLimitInMb() const
{
return m_indexerFileSizeLimitInMB;
}
void CppCodeModelSettings::setIndexerFileSizeLimitInMb(int sizeInMB)
{
m_indexerFileSizeLimitInMB = sizeInMB;
}
|