forked from qt-creator/qt-creator
Clang: Make some functions available for reuse
Change-Id: I7b85ea104a852c1168578949247efb8387a95f30 Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
@@ -140,20 +140,6 @@ void BackendCommunicator::initializeBackend()
|
|||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
Utf8String currentCppEditorDocumentFilePath()
|
|
||||||
{
|
|
||||||
Utf8String currentCppEditorDocumentFilePath;
|
|
||||||
|
|
||||||
const auto currentEditor = Core::EditorManager::currentEditor();
|
|
||||||
if (currentEditor && CppTools::CppModelManager::isCppEditor(currentEditor)) {
|
|
||||||
const auto currentDocument = currentEditor->document();
|
|
||||||
if (currentDocument)
|
|
||||||
currentCppEditorDocumentFilePath = currentDocument->filePath().toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
return currentCppEditorDocumentFilePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
void removeDuplicates(Utf8StringVector &visibleEditorDocumentsFilePaths)
|
void removeDuplicates(Utf8StringVector &visibleEditorDocumentsFilePaths)
|
||||||
{
|
{
|
||||||
std::sort(visibleEditorDocumentsFilePaths.begin(),
|
std::sort(visibleEditorDocumentsFilePaths.begin(),
|
||||||
@@ -204,7 +190,8 @@ Utf8StringVector visibleCppEditorDocumentsFilePaths()
|
|||||||
|
|
||||||
void BackendCommunicator::documentVisibilityChanged()
|
void BackendCommunicator::documentVisibilityChanged()
|
||||||
{
|
{
|
||||||
documentVisibilityChanged(currentCppEditorDocumentFilePath(), visibleCppEditorDocumentsFilePaths());
|
documentVisibilityChanged(Utils::currentCppEditorDocumentFilePath(),
|
||||||
|
visibleCppEditorDocumentsFilePaths());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BackendCommunicator::isNotWaitingForCompletion() const
|
bool BackendCommunicator::isNotWaitingForCompletion() const
|
||||||
@@ -480,7 +467,7 @@ void BackendCommunicator::documentsOpened(const FileContainers &fileContainers)
|
|||||||
Utf8String currentDocument;
|
Utf8String currentDocument;
|
||||||
Utf8StringVector visibleDocuments;
|
Utf8StringVector visibleDocuments;
|
||||||
if (!m_postponeBackendJobs) {
|
if (!m_postponeBackendJobs) {
|
||||||
currentDocument = currentCppEditorDocumentFilePath();
|
currentDocument = Utils::currentCppEditorDocumentFilePath();
|
||||||
visibleDocuments = visibleCppEditorDocumentsFilePaths();
|
visibleDocuments = visibleCppEditorDocumentsFilePaths();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -354,5 +354,19 @@ void generateCompilationDB(::Utils::FileName projectDir, CppTools::ProjectInfo p
|
|||||||
compileCommandsFile.close();
|
compileCommandsFile.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString currentCppEditorDocumentFilePath()
|
||||||
|
{
|
||||||
|
QString filePath;
|
||||||
|
|
||||||
|
const auto currentEditor = Core::EditorManager::currentEditor();
|
||||||
|
if (currentEditor && CppTools::CppModelManager::isCppEditor(currentEditor)) {
|
||||||
|
const auto currentDocument = currentEditor->document();
|
||||||
|
if (currentDocument)
|
||||||
|
filePath = currentDocument->filePath().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return filePath;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Utils
|
} // namespace Utils
|
||||||
} // namespace Clang
|
} // namespace Clang
|
||||||
|
@@ -62,6 +62,8 @@ QString projectPartIdForFile(const QString &filePath);
|
|||||||
int clangColumn(const QTextBlock &line, int cppEditorColumn);
|
int clangColumn(const QTextBlock &line, int cppEditorColumn);
|
||||||
int cppEditorColumn(const QTextBlock &line, int clangColumn);
|
int cppEditorColumn(const QTextBlock &line, int clangColumn);
|
||||||
|
|
||||||
|
QString currentCppEditorDocumentFilePath();
|
||||||
|
|
||||||
QString diagnosticCategoryPrefixRemoved(const QString &text);
|
QString diagnosticCategoryPrefixRemoved(const QString &text);
|
||||||
|
|
||||||
::Utils::CodeModelIcon::Type iconTypeForToken(const ClangBackEnd::TokenInfoContainer &token);
|
::Utils::CodeModelIcon::Type iconTypeForToken(const ClangBackEnd::TokenInfoContainer &token);
|
||||||
|
@@ -30,6 +30,7 @@
|
|||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
#include <QUuid>
|
||||||
|
|
||||||
namespace CppTools {
|
namespace CppTools {
|
||||||
|
|
||||||
@@ -203,11 +204,18 @@ void ClangDiagnosticConfigsModel::removeConfigWithId(const Core::Id &id)
|
|||||||
m_diagnosticConfigs.removeOne(configWithId(id));
|
m_diagnosticConfigs.removeOne(configWithId(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
ClangDiagnosticConfigs ClangDiagnosticConfigsModel::configs() const
|
ClangDiagnosticConfigs ClangDiagnosticConfigsModel::allConfigs() const
|
||||||
{
|
{
|
||||||
return m_diagnosticConfigs;
|
return m_diagnosticConfigs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ClangDiagnosticConfigs ClangDiagnosticConfigsModel::customConfigs() const
|
||||||
|
{
|
||||||
|
return Utils::filtered(allConfigs(), [](const ClangDiagnosticConfig &config) {
|
||||||
|
return !config.isReadOnly();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
bool ClangDiagnosticConfigsModel::hasConfigWithId(const Core::Id &id) const
|
bool ClangDiagnosticConfigsModel::hasConfigWithId(const Core::Id &id) const
|
||||||
{
|
{
|
||||||
return indexOfConfig(id) != -1;
|
return indexOfConfig(id) != -1;
|
||||||
@@ -237,13 +245,24 @@ QVector<Core::Id> ClangDiagnosticConfigsModel::changedOrRemovedConfigs(
|
|||||||
const int i = newConfigsModel.indexOfConfig(old.id());
|
const int i = newConfigsModel.indexOfConfig(old.id());
|
||||||
if (i == -1)
|
if (i == -1)
|
||||||
changedConfigs.append(old.id()); // Removed
|
changedConfigs.append(old.id()); // Removed
|
||||||
else if (newConfigsModel.configs().value(i) != old)
|
else if (newConfigsModel.allConfigs().value(i) != old)
|
||||||
changedConfigs.append(old.id()); // Changed
|
changedConfigs.append(old.id()); // Changed
|
||||||
}
|
}
|
||||||
|
|
||||||
return changedConfigs;
|
return changedConfigs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ClangDiagnosticConfig ClangDiagnosticConfigsModel::createCustomConfig(
|
||||||
|
const ClangDiagnosticConfig &config, const QString &displayName)
|
||||||
|
{
|
||||||
|
ClangDiagnosticConfig copied = config;
|
||||||
|
copied.setId(Core::Id::fromString(QUuid::createUuid().toString()));
|
||||||
|
copied.setDisplayName(displayName);
|
||||||
|
copied.setIsReadOnly(false);
|
||||||
|
|
||||||
|
return copied;
|
||||||
|
}
|
||||||
|
|
||||||
QStringList ClangDiagnosticConfigsModel::globalDiagnosticOptions()
|
QStringList ClangDiagnosticConfigsModel::globalDiagnosticOptions()
|
||||||
{
|
{
|
||||||
return {
|
return {
|
||||||
|
@@ -45,7 +45,9 @@ public:
|
|||||||
void appendOrUpdate(const ClangDiagnosticConfig &config);
|
void appendOrUpdate(const ClangDiagnosticConfig &config);
|
||||||
void removeConfigWithId(const Core::Id &id);
|
void removeConfigWithId(const Core::Id &id);
|
||||||
|
|
||||||
ClangDiagnosticConfigs configs() const;
|
ClangDiagnosticConfigs allConfigs() const;
|
||||||
|
ClangDiagnosticConfigs customConfigs() const;
|
||||||
|
|
||||||
bool hasConfigWithId(const Core::Id &id) const;
|
bool hasConfigWithId(const Core::Id &id) const;
|
||||||
const ClangDiagnosticConfig &configWithId(const Core::Id &id) const;
|
const ClangDiagnosticConfig &configWithId(const Core::Id &id) const;
|
||||||
int indexOfConfig(const Core::Id &id) const;
|
int indexOfConfig(const Core::Id &id) const;
|
||||||
@@ -53,6 +55,8 @@ public:
|
|||||||
static QString displayNameWithBuiltinIndication(const ClangDiagnosticConfig &config);
|
static QString displayNameWithBuiltinIndication(const ClangDiagnosticConfig &config);
|
||||||
static QVector<Core::Id> changedOrRemovedConfigs(const ClangDiagnosticConfigs &oldConfigs,
|
static QVector<Core::Id> changedOrRemovedConfigs(const ClangDiagnosticConfigs &oldConfigs,
|
||||||
const ClangDiagnosticConfigs &newConfigs);
|
const ClangDiagnosticConfigs &newConfigs);
|
||||||
|
static ClangDiagnosticConfig createCustomConfig(const ClangDiagnosticConfig &config,
|
||||||
|
const QString &displayName);
|
||||||
static QStringList globalDiagnosticOptions();
|
static QStringList globalDiagnosticOptions();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@@ -634,17 +634,6 @@ void ClangDiagnosticConfigsWidget::onCurrentConfigChanged(int index)
|
|||||||
syncOtherWidgetsToComboBox();
|
syncOtherWidgetsToComboBox();
|
||||||
}
|
}
|
||||||
|
|
||||||
static ClangDiagnosticConfig createCustomConfig(const ClangDiagnosticConfig &config,
|
|
||||||
const QString &displayName)
|
|
||||||
{
|
|
||||||
ClangDiagnosticConfig copied = config;
|
|
||||||
copied.setId(Core::Id::fromString(QUuid::createUuid().toString()));
|
|
||||||
copied.setDisplayName(displayName);
|
|
||||||
copied.setIsReadOnly(false);
|
|
||||||
|
|
||||||
return copied;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ClangDiagnosticConfigsWidget::onCopyButtonClicked()
|
void ClangDiagnosticConfigsWidget::onCopyButtonClicked()
|
||||||
{
|
{
|
||||||
const ClangDiagnosticConfig &config = selectedConfig();
|
const ClangDiagnosticConfig &config = selectedConfig();
|
||||||
@@ -657,7 +646,8 @@ void ClangDiagnosticConfigsWidget::onCopyButtonClicked()
|
|||||||
tr("%1 (Copy)").arg(config.displayName()),
|
tr("%1 (Copy)").arg(config.displayName()),
|
||||||
&diaglogAccepted);
|
&diaglogAccepted);
|
||||||
if (diaglogAccepted) {
|
if (diaglogAccepted) {
|
||||||
const ClangDiagnosticConfig customConfig = createCustomConfig(config, newName);
|
const ClangDiagnosticConfig customConfig
|
||||||
|
= ClangDiagnosticConfigsModel::createCustomConfig(config, newName);
|
||||||
m_diagnosticConfigsModel.appendOrUpdate(customConfig);
|
m_diagnosticConfigsModel.appendOrUpdate(customConfig);
|
||||||
emit customConfigsChanged(customConfigs());
|
emit customConfigsChanged(customConfigs());
|
||||||
|
|
||||||
@@ -996,11 +986,7 @@ void ClangDiagnosticConfigsWidget::disconnectDiagnosticOptionsChanged()
|
|||||||
|
|
||||||
ClangDiagnosticConfigs ClangDiagnosticConfigsWidget::customConfigs() const
|
ClangDiagnosticConfigs ClangDiagnosticConfigsWidget::customConfigs() const
|
||||||
{
|
{
|
||||||
const ClangDiagnosticConfigs allConfigs = m_diagnosticConfigsModel.configs();
|
return m_diagnosticConfigsModel.customConfigs();
|
||||||
|
|
||||||
return Utils::filtered(allConfigs, [](const ClangDiagnosticConfig &config){
|
|
||||||
return !config.isReadOnly();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setupTreeView(QTreeView *view, QAbstractItemModel *model, int expandToDepth = 0)
|
static void setupTreeView(QTreeView *view, QAbstractItemModel *model, int expandToDepth = 0)
|
||||||
|
Reference in New Issue
Block a user