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 {
|
||||
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)
|
||||
{
|
||||
std::sort(visibleEditorDocumentsFilePaths.begin(),
|
||||
@@ -204,7 +190,8 @@ Utf8StringVector visibleCppEditorDocumentsFilePaths()
|
||||
|
||||
void BackendCommunicator::documentVisibilityChanged()
|
||||
{
|
||||
documentVisibilityChanged(currentCppEditorDocumentFilePath(), visibleCppEditorDocumentsFilePaths());
|
||||
documentVisibilityChanged(Utils::currentCppEditorDocumentFilePath(),
|
||||
visibleCppEditorDocumentsFilePaths());
|
||||
}
|
||||
|
||||
bool BackendCommunicator::isNotWaitingForCompletion() const
|
||||
@@ -480,7 +467,7 @@ void BackendCommunicator::documentsOpened(const FileContainers &fileContainers)
|
||||
Utf8String currentDocument;
|
||||
Utf8StringVector visibleDocuments;
|
||||
if (!m_postponeBackendJobs) {
|
||||
currentDocument = currentCppEditorDocumentFilePath();
|
||||
currentDocument = Utils::currentCppEditorDocumentFilePath();
|
||||
visibleDocuments = visibleCppEditorDocumentsFilePaths();
|
||||
}
|
||||
|
||||
|
@@ -354,5 +354,19 @@ void generateCompilationDB(::Utils::FileName projectDir, CppTools::ProjectInfo p
|
||||
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 Clang
|
||||
|
@@ -62,6 +62,8 @@ QString projectPartIdForFile(const QString &filePath);
|
||||
int clangColumn(const QTextBlock &line, int cppEditorColumn);
|
||||
int cppEditorColumn(const QTextBlock &line, int clangColumn);
|
||||
|
||||
QString currentCppEditorDocumentFilePath();
|
||||
|
||||
QString diagnosticCategoryPrefixRemoved(const QString &text);
|
||||
|
||||
::Utils::CodeModelIcon::Type iconTypeForToken(const ClangBackEnd::TokenInfoContainer &token);
|
||||
|
@@ -30,6 +30,7 @@
|
||||
#include <utils/algorithm.h>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QUuid>
|
||||
|
||||
namespace CppTools {
|
||||
|
||||
@@ -203,11 +204,18 @@ void ClangDiagnosticConfigsModel::removeConfigWithId(const Core::Id &id)
|
||||
m_diagnosticConfigs.removeOne(configWithId(id));
|
||||
}
|
||||
|
||||
ClangDiagnosticConfigs ClangDiagnosticConfigsModel::configs() const
|
||||
ClangDiagnosticConfigs ClangDiagnosticConfigsModel::allConfigs() const
|
||||
{
|
||||
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
|
||||
{
|
||||
return indexOfConfig(id) != -1;
|
||||
@@ -237,13 +245,24 @@ QVector<Core::Id> ClangDiagnosticConfigsModel::changedOrRemovedConfigs(
|
||||
const int i = newConfigsModel.indexOfConfig(old.id());
|
||||
if (i == -1)
|
||||
changedConfigs.append(old.id()); // Removed
|
||||
else if (newConfigsModel.configs().value(i) != old)
|
||||
else if (newConfigsModel.allConfigs().value(i) != old)
|
||||
changedConfigs.append(old.id()); // Changed
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
return {
|
||||
|
@@ -45,7 +45,9 @@ public:
|
||||
void appendOrUpdate(const ClangDiagnosticConfig &config);
|
||||
void removeConfigWithId(const Core::Id &id);
|
||||
|
||||
ClangDiagnosticConfigs configs() const;
|
||||
ClangDiagnosticConfigs allConfigs() const;
|
||||
ClangDiagnosticConfigs customConfigs() const;
|
||||
|
||||
bool hasConfigWithId(const Core::Id &id) const;
|
||||
const ClangDiagnosticConfig &configWithId(const Core::Id &id) const;
|
||||
int indexOfConfig(const Core::Id &id) const;
|
||||
@@ -53,6 +55,8 @@ public:
|
||||
static QString displayNameWithBuiltinIndication(const ClangDiagnosticConfig &config);
|
||||
static QVector<Core::Id> changedOrRemovedConfigs(const ClangDiagnosticConfigs &oldConfigs,
|
||||
const ClangDiagnosticConfigs &newConfigs);
|
||||
static ClangDiagnosticConfig createCustomConfig(const ClangDiagnosticConfig &config,
|
||||
const QString &displayName);
|
||||
static QStringList globalDiagnosticOptions();
|
||||
|
||||
private:
|
||||
|
@@ -634,17 +634,6 @@ void ClangDiagnosticConfigsWidget::onCurrentConfigChanged(int index)
|
||||
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()
|
||||
{
|
||||
const ClangDiagnosticConfig &config = selectedConfig();
|
||||
@@ -657,7 +646,8 @@ void ClangDiagnosticConfigsWidget::onCopyButtonClicked()
|
||||
tr("%1 (Copy)").arg(config.displayName()),
|
||||
&diaglogAccepted);
|
||||
if (diaglogAccepted) {
|
||||
const ClangDiagnosticConfig customConfig = createCustomConfig(config, newName);
|
||||
const ClangDiagnosticConfig customConfig
|
||||
= ClangDiagnosticConfigsModel::createCustomConfig(config, newName);
|
||||
m_diagnosticConfigsModel.appendOrUpdate(customConfig);
|
||||
emit customConfigsChanged(customConfigs());
|
||||
|
||||
@@ -996,11 +986,7 @@ void ClangDiagnosticConfigsWidget::disconnectDiagnosticOptionsChanged()
|
||||
|
||||
ClangDiagnosticConfigs ClangDiagnosticConfigsWidget::customConfigs() const
|
||||
{
|
||||
const ClangDiagnosticConfigs allConfigs = m_diagnosticConfigsModel.configs();
|
||||
|
||||
return Utils::filtered(allConfigs, [](const ClangDiagnosticConfig &config){
|
||||
return !config.isReadOnly();
|
||||
});
|
||||
return m_diagnosticConfigsModel.customConfigs();
|
||||
}
|
||||
|
||||
static void setupTreeView(QTreeView *view, QAbstractItemModel *model, int expandToDepth = 0)
|
||||
|
Reference in New Issue
Block a user