2016-02-22 17:18:18 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** 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 "clangdiagnosticconfigsmodel.h"
|
|
|
|
|
|
2019-01-28 12:40:03 +01:00
|
|
|
#include "cpptoolsreuse.h"
|
2016-02-22 17:18:18 +01:00
|
|
|
#include "cpptoolsconstants.h"
|
|
|
|
|
|
|
|
|
|
#include <utils/algorithm.h>
|
|
|
|
|
|
|
|
|
|
#include <QCoreApplication>
|
2019-01-29 16:03:38 +01:00
|
|
|
#include <QUuid>
|
2016-02-22 17:18:18 +01:00
|
|
|
|
|
|
|
|
namespace CppTools {
|
|
|
|
|
|
2019-09-25 15:46:15 +02:00
|
|
|
ClangDiagnosticConfigsModel::ClangDiagnosticConfigsModel(const ClangDiagnosticConfigs &configs)
|
2016-02-22 17:18:18 +01:00
|
|
|
{
|
2019-09-25 15:46:15 +02:00
|
|
|
m_diagnosticConfigs.append(configs);
|
2016-02-22 17:18:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ClangDiagnosticConfigsModel::size() const
|
|
|
|
|
{
|
|
|
|
|
return m_diagnosticConfigs.size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const ClangDiagnosticConfig &ClangDiagnosticConfigsModel::at(int index) const
|
|
|
|
|
{
|
|
|
|
|
return m_diagnosticConfigs.at(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClangDiagnosticConfigsModel::appendOrUpdate(const ClangDiagnosticConfig &config)
|
|
|
|
|
{
|
|
|
|
|
const int index = indexOfConfig(config.id());
|
|
|
|
|
|
|
|
|
|
if (index >= 0 && index < m_diagnosticConfigs.size())
|
|
|
|
|
m_diagnosticConfigs.replace(index, config);
|
|
|
|
|
else
|
|
|
|
|
m_diagnosticConfigs.append(config);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-26 13:59:38 +02:00
|
|
|
void ClangDiagnosticConfigsModel::removeConfigWithId(const Utils::Id &id)
|
2016-02-22 17:18:18 +01:00
|
|
|
{
|
|
|
|
|
m_diagnosticConfigs.removeOne(configWithId(id));
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-29 16:03:38 +01:00
|
|
|
ClangDiagnosticConfigs ClangDiagnosticConfigsModel::allConfigs() const
|
2016-02-22 17:18:18 +01:00
|
|
|
{
|
|
|
|
|
return m_diagnosticConfigs;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-29 16:03:38 +01:00
|
|
|
ClangDiagnosticConfigs ClangDiagnosticConfigsModel::customConfigs() const
|
|
|
|
|
{
|
|
|
|
|
return Utils::filtered(allConfigs(), [](const ClangDiagnosticConfig &config) {
|
|
|
|
|
return !config.isReadOnly();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-26 13:59:38 +02:00
|
|
|
bool ClangDiagnosticConfigsModel::hasConfigWithId(const Utils::Id &id) const
|
2016-02-26 17:50:38 +01:00
|
|
|
{
|
|
|
|
|
return indexOfConfig(id) != -1;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-26 13:59:38 +02:00
|
|
|
const ClangDiagnosticConfig &ClangDiagnosticConfigsModel::configWithId(const Utils::Id &id) const
|
2016-02-22 17:18:18 +01:00
|
|
|
{
|
|
|
|
|
return m_diagnosticConfigs.at(indexOfConfig(id));
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-26 13:59:38 +02:00
|
|
|
QVector<Utils::Id> ClangDiagnosticConfigsModel::changedOrRemovedConfigs(
|
2018-01-19 13:18:43 +01:00
|
|
|
const ClangDiagnosticConfigs &oldConfigs, const ClangDiagnosticConfigs &newConfigs)
|
|
|
|
|
{
|
|
|
|
|
ClangDiagnosticConfigsModel newConfigsModel(newConfigs);
|
2020-06-26 13:59:38 +02:00
|
|
|
QVector<Utils::Id> changedConfigs;
|
2018-01-19 13:18:43 +01:00
|
|
|
|
|
|
|
|
for (const ClangDiagnosticConfig &old: oldConfigs) {
|
|
|
|
|
const int i = newConfigsModel.indexOfConfig(old.id());
|
|
|
|
|
if (i == -1)
|
|
|
|
|
changedConfigs.append(old.id()); // Removed
|
2019-01-29 16:03:38 +01:00
|
|
|
else if (newConfigsModel.allConfigs().value(i) != old)
|
2018-01-19 13:18:43 +01:00
|
|
|
changedConfigs.append(old.id()); // Changed
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return changedConfigs;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-29 16:03:38 +01:00
|
|
|
ClangDiagnosticConfig ClangDiagnosticConfigsModel::createCustomConfig(
|
2019-10-21 14:59:57 +02:00
|
|
|
const ClangDiagnosticConfig &baseConfig, const QString &displayName)
|
2019-01-29 16:03:38 +01:00
|
|
|
{
|
2019-10-21 14:59:57 +02:00
|
|
|
ClangDiagnosticConfig copied = baseConfig;
|
2020-06-26 13:59:38 +02:00
|
|
|
copied.setId(Utils::Id::fromString(QUuid::createUuid().toString()));
|
2019-01-29 16:03:38 +01:00
|
|
|
copied.setDisplayName(displayName);
|
|
|
|
|
copied.setIsReadOnly(false);
|
|
|
|
|
|
|
|
|
|
return copied;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-22 16:03:09 +02:00
|
|
|
QStringList ClangDiagnosticConfigsModel::globalDiagnosticOptions()
|
|
|
|
|
{
|
|
|
|
|
return {
|
|
|
|
|
// Avoid undesired warnings from e.g. Q_OBJECT
|
|
|
|
|
QStringLiteral("-Wno-unknown-pragmas"),
|
2018-05-29 08:43:14 +02:00
|
|
|
QStringLiteral("-Wno-unknown-warning-option"),
|
|
|
|
|
|
|
|
|
|
// qdoc commands
|
|
|
|
|
QStringLiteral("-Wno-documentation-unknown-command")
|
2018-05-22 16:03:09 +02:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-26 13:59:38 +02:00
|
|
|
int ClangDiagnosticConfigsModel::indexOfConfig(const Utils::Id &id) const
|
2016-02-22 17:18:18 +01:00
|
|
|
{
|
|
|
|
|
return Utils::indexOf(m_diagnosticConfigs, [&](const ClangDiagnosticConfig &config) {
|
|
|
|
|
return config.id() == id;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace CppTools
|