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:
		| @@ -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