Commit 72785e3a authored by Nikolai Kosjar's avatar Nikolai Kosjar

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: default avatarChristian Stenger <christian.stenger@theqtcompany.com>
Reviewed-by: default avatarEike Ziller <eike.ziller@theqtcompany.com>
parent 942aa12f
......@@ -58,41 +58,16 @@ void CppCodeModelSettingsWidget::setSettings(const QSharedPointer<CppCodeModelSe
{
m_settings = s;
applyToWidget(m_ui->cChooser, QLatin1String(Constants::C_SOURCE_MIMETYPE));
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));
setupClangCodeModelWidgets();
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
{
bool changed = false;
changed |= applyToSettings(m_ui->cChooser, QLatin1String(Constants::C_SOURCE_MIMETYPE));
changed |= applyToSettings(m_ui->cppChooser, QLatin1String(Constants::CPP_SOURCE_MIMETYPE));
changed |= applyToSettings(m_ui->objcChooser,
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 (applyClangCodeModelWidgetsToSettings())
changed = true;
if (m_ui->ignorePCHCheckBox->isChecked() !=
(m_settings->pchUsage() == CppCodeModelSettings::PchUse_None)) {
......@@ -106,14 +81,38 @@ void CppCodeModelSettingsWidget::applyToSettings() const
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();
QString currentId = m_settings->modelManagerSupportIdForMimeType(mimeType);
if (newId == currentId)
return false;
const QString currentCodeModelId
= settings.modelManagerSupportIdForMimeType(QLatin1String(Constants::CPP_SOURCE_MIMETYPE));
return currentCodeModelId != settings.defaultId();
}
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;
}
......
......@@ -58,8 +58,8 @@ public:
void applyToSettings() const;
private:
bool applyToSettings(QComboBox *chooser, const QString &mimeType) const;
void applyToWidget(QComboBox *chooser, const QString &mimeType) const;
void setupClangCodeModelWidgets() const;
bool applyClangCodeModelWidgetsToSettings() const;
private:
Ui::CppCodeModelSettingsPage *m_ui;
......
......@@ -20,70 +20,23 @@
<string>Code Completion and Semantic Highlighting</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="cLabel">
<property name="text">
<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>
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<item row="1" column="0">
<widget class="QLabel" name="cppLabel">
<widget class="QCheckBox" name="useClangCheckBox">
<property name="text">
<string>C++</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="cppChooser">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<string>Use Clang Code Model</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="objcLabel">
<property name="text">
<string>Objective C</string>
</property>
</widget>
</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">
<item row="0" column="0">
<widget class="QLabel" name="activateClangCodeModelPluginHint">
<property name="text">
<string>Headers</string>
<string>&lt;i&gt;Activate the Clang Code Model plugin to enable the options here.&lt;/i&gt;</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QComboBox" name="hChooser"/>
</item>
</layout>
</widget>
</item>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment