2013-09-06 13:14:15 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2013-09-06 13:14:15 +02:00
|
|
|
**
|
|
|
|
|
** 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
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2013-09-06 13:14:15 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2013-09-06 13:14:15 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "cppcodemodelsettings.h"
|
2016-02-22 17:18:18 +01:00
|
|
|
|
|
|
|
|
#include "clangdiagnosticconfigsmodel.h"
|
2013-09-06 13:14:15 +02:00
|
|
|
#include "cpptoolsconstants.h"
|
|
|
|
|
|
2016-02-22 17:18:18 +01:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2015-11-11 10:47:27 +01:00
|
|
|
#include <QSettings>
|
|
|
|
|
|
2013-09-06 13:14:15 +02:00
|
|
|
using namespace CppTools;
|
|
|
|
|
|
2016-02-22 17:18:18 +01:00
|
|
|
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 clangDiagnosticConfigsArrayOptionsKey()
|
|
|
|
|
{ return QLatin1String("diagnosticOptions"); }
|
|
|
|
|
|
|
|
|
|
static QString pchUsageKey()
|
|
|
|
|
{ return QLatin1String(Constants::CPPTOOLS_MODEL_MANAGER_PCH_USAGE); }
|
2013-12-10 14:32:09 +01:00
|
|
|
|
2017-01-12 18:01:12 +01:00
|
|
|
static QString interpretAmbiguousHeadersAsCHeadersKey()
|
|
|
|
|
{ return QLatin1String(Constants::CPPTOOLS_INTERPRET_AMBIGIUOUS_HEADERS_AS_C_HEADERS); }
|
|
|
|
|
|
2016-08-16 13:37:49 +02:00
|
|
|
static QString skipIndexingBigFilesKey()
|
|
|
|
|
{ return QLatin1String(Constants::CPPTOOLS_SKIP_INDEXING_BIG_FILES); }
|
|
|
|
|
|
|
|
|
|
static QString indexerFileSizeLimitKey()
|
|
|
|
|
{ return QLatin1String(Constants::CPPTOOLS_INDEXER_FILE_SIZE_LIMIT); }
|
|
|
|
|
|
2013-09-06 13:14:15 +02:00
|
|
|
void CppCodeModelSettings::fromSettings(QSettings *s)
|
|
|
|
|
{
|
|
|
|
|
s->beginGroup(QLatin1String(Constants::CPPTOOLS_SETTINGSGROUP));
|
2015-06-02 17:25:41 +02:00
|
|
|
|
2016-02-22 17:18:18 +01:00
|
|
|
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.setCommandLineOptions(s->value(clangDiagnosticConfigsArrayOptionsKey()).toStringList());
|
|
|
|
|
m_clangCustomDiagnosticConfigs.append(config);
|
|
|
|
|
}
|
|
|
|
|
s->endArray();
|
|
|
|
|
|
|
|
|
|
const Core::Id diagnosticConfigId = Core::Id::fromSetting(
|
|
|
|
|
s->value(clangDiagnosticConfigKey(),
|
|
|
|
|
initialClangDiagnosticConfigId().toSetting()));
|
|
|
|
|
setClangDiagnosticConfigId(diagnosticConfigId);
|
|
|
|
|
|
|
|
|
|
const QVariant pchUsageVariant = s->value(pchUsageKey(), initialPchUsage());
|
|
|
|
|
setPCHUsage(static_cast<PCHUsage>(pchUsageVariant.toInt()));
|
2016-08-16 13:37:49 +02:00
|
|
|
|
2017-01-12 18:01:12 +01:00
|
|
|
const QVariant interpretAmbiguousHeadersAsCHeaders
|
|
|
|
|
= s->value(interpretAmbiguousHeadersAsCHeadersKey(), false);
|
|
|
|
|
setInterpretAmbigiousHeadersAsCHeaders(interpretAmbiguousHeadersAsCHeaders.toBool());
|
|
|
|
|
|
2016-08-16 13:37:49 +02:00
|
|
|
const QVariant skipIndexingBigFiles = s->value(skipIndexingBigFilesKey(), true);
|
|
|
|
|
setSkipIndexingBigFiles(skipIndexingBigFiles.toBool());
|
|
|
|
|
|
|
|
|
|
const QVariant indexerFileSizeLimit = s->value(indexerFileSizeLimitKey(), 5);
|
|
|
|
|
setIndexerFileSizeLimitInMb(indexerFileSizeLimit.toInt());
|
|
|
|
|
|
2013-09-06 13:14:15 +02:00
|
|
|
s->endGroup();
|
2015-05-08 15:48:17 +02:00
|
|
|
|
|
|
|
|
emit changed();
|
2013-09-06 13:14:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CppCodeModelSettings::toSettings(QSettings *s)
|
|
|
|
|
{
|
|
|
|
|
s->beginGroup(QLatin1String(Constants::CPPTOOLS_SETTINGSGROUP));
|
2015-11-11 10:47:27 +01:00
|
|
|
|
2016-02-22 17:18:18 +01:00
|
|
|
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(clangDiagnosticConfigsArrayOptionsKey(), config.commandLineOptions());
|
|
|
|
|
}
|
|
|
|
|
s->endArray();
|
|
|
|
|
|
|
|
|
|
s->setValue(clangDiagnosticConfigKey(), clangDiagnosticConfigId().toSetting());
|
|
|
|
|
s->setValue(pchUsageKey(), pchUsage());
|
2017-01-12 18:01:12 +01:00
|
|
|
|
|
|
|
|
s->setValue(interpretAmbiguousHeadersAsCHeadersKey(), interpretAmbigiousHeadersAsCHeaders());
|
2016-08-16 13:37:49 +02:00
|
|
|
s->setValue(skipIndexingBigFilesKey(), skipIndexingBigFiles());
|
|
|
|
|
s->setValue(indexerFileSizeLimitKey(), indexerFileSizeLimitInMb());
|
2013-09-06 13:14:15 +02:00
|
|
|
|
2015-11-11 10:47:27 +01:00
|
|
|
s->endGroup();
|
2015-06-02 17:25:41 +02:00
|
|
|
|
2015-05-08 15:48:17 +02:00
|
|
|
emit changed();
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-22 17:18:18 +01:00
|
|
|
Core::Id CppCodeModelSettings::clangDiagnosticConfigId() const
|
|
|
|
|
{
|
|
|
|
|
return m_clangDiagnosticConfigId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CppCodeModelSettings::setClangDiagnosticConfigId(const Core::Id &configId)
|
2015-11-10 16:54:53 +01:00
|
|
|
{
|
2016-02-22 17:18:18 +01:00
|
|
|
m_clangDiagnosticConfigId = configId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const ClangDiagnosticConfig CppCodeModelSettings::clangDiagnosticConfig() const
|
|
|
|
|
{
|
2016-02-26 17:50:38 +01:00
|
|
|
const ClangDiagnosticConfigsModel configsModel(m_clangCustomDiagnosticConfigs);
|
2016-02-22 17:18:18 +01:00
|
|
|
|
|
|
|
|
return configsModel.configWithId(clangDiagnosticConfigId());
|
2015-11-10 16:54:53 +01:00
|
|
|
}
|
|
|
|
|
|
2016-02-22 17:18:18 +01:00
|
|
|
ClangDiagnosticConfigs CppCodeModelSettings::clangCustomDiagnosticConfigs() const
|
2015-11-10 16:54:53 +01:00
|
|
|
{
|
2016-02-22 17:18:18 +01:00
|
|
|
return m_clangCustomDiagnosticConfigs;
|
2015-11-10 16:54:53 +01:00
|
|
|
}
|
|
|
|
|
|
2016-02-22 17:18:18 +01:00
|
|
|
void CppCodeModelSettings::setClangCustomDiagnosticConfigs(const ClangDiagnosticConfigs &configs)
|
2015-11-10 16:54:53 +01:00
|
|
|
{
|
2016-02-22 17:18:18 +01:00
|
|
|
m_clangCustomDiagnosticConfigs = configs;
|
2015-11-10 16:54:53 +01:00
|
|
|
}
|
|
|
|
|
|
2015-11-11 10:47:27 +01:00
|
|
|
CppCodeModelSettings::PCHUsage CppCodeModelSettings::pchUsage() const
|
2013-09-06 13:14:15 +02:00
|
|
|
{
|
2015-11-11 10:47:27 +01:00
|
|
|
return m_pchUsage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CppCodeModelSettings::setPCHUsage(CppCodeModelSettings::PCHUsage pchUsage)
|
|
|
|
|
{
|
|
|
|
|
m_pchUsage = pchUsage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CppCodeModelSettings::emitChanged()
|
|
|
|
|
{
|
|
|
|
|
emit changed();
|
2013-09-06 13:14:15 +02:00
|
|
|
}
|
2016-08-16 13:37:49 +02:00
|
|
|
|
2017-01-12 18:01:12 +01:00
|
|
|
bool CppCodeModelSettings::interpretAmbigiousHeadersAsCHeaders() const
|
|
|
|
|
{
|
|
|
|
|
return m_interpretAmbigiousHeadersAsCHeaders;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CppCodeModelSettings::setInterpretAmbigiousHeadersAsCHeaders(bool yesno)
|
|
|
|
|
{
|
|
|
|
|
m_interpretAmbigiousHeadersAsCHeaders = yesno;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-16 13:37:49 +02:00
|
|
|
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;
|
|
|
|
|
}
|