forked from qt-creator/qt-creator
Clang: Activate the code model with a check box
If the plugin is not activated, show a hint. The underlying settings are still mime type based. This will be addressed in a follow-up change. Change-Id: I24b232365d505a0022a78e96eb496d219a8b7c5b Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com> Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
This commit is contained in:
@@ -58,41 +58,16 @@ void CppCodeModelSettingsWidget::setSettings(const QSharedPointer<CppCodeModelSe
|
|||||||
{
|
{
|
||||||
m_settings = s;
|
m_settings = s;
|
||||||
|
|
||||||
applyToWidget(m_ui->cChooser, QLatin1String(Constants::C_SOURCE_MIMETYPE));
|
setupClangCodeModelWidgets();
|
||||||
applyToWidget(m_ui->cppChooser, QLatin1String(Constants::CPP_SOURCE_MIMETYPE));
|
|
||||||
applyToWidget(m_ui->objcChooser, QLatin1String(Constants::OBJECTIVE_C_SOURCE_MIMETYPE));
|
|
||||||
applyToWidget(m_ui->objcppChooser, QLatin1String(Constants::OBJECTIVE_CPP_SOURCE_MIMETYPE));
|
|
||||||
applyToWidget(m_ui->hChooser, QLatin1String(Constants::C_HEADER_MIMETYPE));
|
|
||||||
|
|
||||||
m_ui->ignorePCHCheckBox->setChecked(s->pchUsage() == CppCodeModelSettings::PchUse_None);
|
m_ui->ignorePCHCheckBox->setChecked(s->pchUsage() == CppCodeModelSettings::PchUse_None);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppCodeModelSettingsWidget::applyToWidget(QComboBox *chooser, const QString &mimeType) const
|
|
||||||
{
|
|
||||||
chooser->clear();
|
|
||||||
|
|
||||||
QStringList names = m_settings->availableModelManagerSupportProvidersByName().keys();
|
|
||||||
Utils::sort(names);
|
|
||||||
foreach (const QString &name, names) {
|
|
||||||
const QString &id = m_settings->availableModelManagerSupportProvidersByName()[name];
|
|
||||||
chooser->addItem(name, id);
|
|
||||||
if (id == m_settings->modelManagerSupportIdForMimeType(mimeType))
|
|
||||||
chooser->setCurrentIndex(chooser->count() - 1);
|
|
||||||
}
|
|
||||||
chooser->setEnabled(names.size() > 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CppCodeModelSettingsWidget::applyToSettings() const
|
void CppCodeModelSettingsWidget::applyToSettings() const
|
||||||
{
|
{
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
changed |= applyToSettings(m_ui->cChooser, QLatin1String(Constants::C_SOURCE_MIMETYPE));
|
|
||||||
changed |= applyToSettings(m_ui->cppChooser, QLatin1String(Constants::CPP_SOURCE_MIMETYPE));
|
if (applyClangCodeModelWidgetsToSettings())
|
||||||
changed |= applyToSettings(m_ui->objcChooser,
|
changed = true;
|
||||||
QLatin1String(Constants::OBJECTIVE_C_SOURCE_MIMETYPE));
|
|
||||||
changed |= applyToSettings(m_ui->objcppChooser,
|
|
||||||
QLatin1String(Constants::OBJECTIVE_CPP_SOURCE_MIMETYPE));
|
|
||||||
changed |= applyToSettings(m_ui->hChooser,
|
|
||||||
QLatin1String(Constants::C_HEADER_MIMETYPE));
|
|
||||||
|
|
||||||
if (m_ui->ignorePCHCheckBox->isChecked() !=
|
if (m_ui->ignorePCHCheckBox->isChecked() !=
|
||||||
(m_settings->pchUsage() == CppCodeModelSettings::PchUse_None)) {
|
(m_settings->pchUsage() == CppCodeModelSettings::PchUse_None)) {
|
||||||
@@ -106,14 +81,38 @@ void CppCodeModelSettingsWidget::applyToSettings() const
|
|||||||
m_settings->toSettings(Core::ICore::settings());
|
m_settings->toSettings(Core::ICore::settings());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CppCodeModelSettingsWidget::applyToSettings(QComboBox *chooser, const QString &mimeType) const
|
static bool isClangCodeModelActive(const CppCodeModelSettings &settings)
|
||||||
{
|
{
|
||||||
QString newId = chooser->itemData(chooser->currentIndex()).toString();
|
const QString currentCodeModelId
|
||||||
QString currentId = m_settings->modelManagerSupportIdForMimeType(mimeType);
|
= settings.modelManagerSupportIdForMimeType(QLatin1String(Constants::CPP_SOURCE_MIMETYPE));
|
||||||
if (newId == currentId)
|
return currentCodeModelId != settings.defaultId();
|
||||||
return false;
|
}
|
||||||
|
|
||||||
|
void CppCodeModelSettingsWidget::setupClangCodeModelWidgets() const
|
||||||
|
{
|
||||||
|
bool isClangActive = false;
|
||||||
|
const bool isClangAvailable = m_settings->availableModelManagerSupportProvidersByName().size() > 1;
|
||||||
|
if (isClangAvailable)
|
||||||
|
isClangActive = isClangCodeModelActive(*m_settings.data());
|
||||||
|
|
||||||
|
m_ui->activateClangCodeModelPluginHint->setVisible(!isClangAvailable);
|
||||||
|
m_ui->useClangCheckBox->setEnabled(isClangAvailable);
|
||||||
|
m_ui->useClangCheckBox->setChecked(isClangActive);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CppCodeModelSettingsWidget::applyClangCodeModelWidgetsToSettings() const
|
||||||
|
{
|
||||||
|
// Once the underlying settings are not mime type based anymore, simplify here.
|
||||||
|
// Until then, ensure that the settings are set uniformly for all the mime types
|
||||||
|
// to avoid surprises.
|
||||||
|
|
||||||
|
const QString activeCodeModelId = m_ui->useClangCheckBox->isChecked()
|
||||||
|
? QLatin1String("ClangCodeMode.ClangCodeMode")
|
||||||
|
: QLatin1String("CppTools.BuiltinCodeModel");
|
||||||
|
|
||||||
|
foreach (const QString &mimeType, m_settings->supportedMimeTypes())
|
||||||
|
m_settings->setModelManagerSupportIdForMimeType(mimeType, activeCodeModelId);
|
||||||
|
|
||||||
m_settings->setModelManagerSupportIdForMimeType(mimeType, newId);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -58,8 +58,8 @@ public:
|
|||||||
void applyToSettings() const;
|
void applyToSettings() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool applyToSettings(QComboBox *chooser, const QString &mimeType) const;
|
void setupClangCodeModelWidgets() const;
|
||||||
void applyToWidget(QComboBox *chooser, const QString &mimeType) const;
|
bool applyClangCodeModelWidgetsToSettings() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::CppCodeModelSettingsPage *m_ui;
|
Ui::CppCodeModelSettingsPage *m_ui;
|
||||||
|
@@ -20,70 +20,23 @@
|
|||||||
<string>Code Completion and Semantic Highlighting</string>
|
<string>Code Completion and Semantic Highlighting</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QFormLayout" name="formLayout">
|
<layout class="QFormLayout" name="formLayout">
|
||||||
<item row="0" column="0">
|
<property name="fieldGrowthPolicy">
|
||||||
<widget class="QLabel" name="cLabel">
|
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
|
||||||
<property name="text">
|
</property>
|
||||||
<string>C</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="1">
|
|
||||||
<widget class="QComboBox" name="cChooser">
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="0">
|
<item row="1" column="0">
|
||||||
<widget class="QLabel" name="cppLabel">
|
<widget class="QCheckBox" name="useClangCheckBox">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>C++</string>
|
<string>Use Clang Code Model</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="0" column="0">
|
||||||
<widget class="QComboBox" name="cppChooser">
|
<widget class="QLabel" name="activateClangCodeModelPluginHint">
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="0">
|
|
||||||
<widget class="QLabel" name="objcLabel">
|
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Objective C</string>
|
<string><i>Activate the Clang Code Model plugin to enable the options here.</i></string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="1">
|
|
||||||
<widget class="QComboBox" name="objcChooser"/>
|
|
||||||
</item>
|
|
||||||
<item row="3" column="0">
|
|
||||||
<widget class="QLabel" name="objcppLabel">
|
|
||||||
<property name="text">
|
|
||||||
<string>Objective C++</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="3" column="1">
|
|
||||||
<widget class="QComboBox" name="objcppChooser"/>
|
|
||||||
</item>
|
|
||||||
<item row="4" column="0">
|
|
||||||
<widget class="QLabel" name="hLabel">
|
|
||||||
<property name="text">
|
|
||||||
<string>Headers</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="4" column="1">
|
|
||||||
<widget class="QComboBox" name="hChooser"/>
|
|
||||||
</item>
|
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
Reference in New Issue
Block a user