cppcodemodelsettingspage.cpp 5.35 KB
Newer Older
1 2
/****************************************************************************
**
3 4
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
5 6 7 8 9 10 11
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
12 13 14
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
15
**
16 17 18 19 20 21 22
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
23 24 25 26
**
****************************************************************************/

#include "cppcodemodelsettingspage.h"
27 28

#include "clangdiagnosticconfigswidget.h"
29
#include "cppmodelmanager.h"
30 31 32 33
#include "cpptoolsconstants.h"
#include "ui_cppcodemodelsettingspage.h"

#include <coreplugin/icore.h>
34
#include <utils/algorithm.h>
35 36 37 38 39 40 41 42 43 44 45

#include <QTextStream>

using namespace CppTools;
using namespace CppTools::Internal;

CppCodeModelSettingsWidget::CppCodeModelSettingsWidget(QWidget *parent)
    : QWidget(parent)
    , m_ui(new Ui::CppCodeModelSettingsPage)
{
    m_ui->setupUi(this);
46

47
    m_ui->clangSettingsGroupBox->setVisible(true);
48 49 50 51 52 53 54 55 56 57 58
}

CppCodeModelSettingsWidget::~CppCodeModelSettingsWidget()
{
    delete m_ui;
}

void CppCodeModelSettingsWidget::setSettings(const QSharedPointer<CppCodeModelSettings> &s)
{
    m_settings = s;

59
    setupClangCodeModelWidgets();
60
    setupPchCheckBox();
61 62 63 64 65
}

void CppCodeModelSettingsWidget::applyToSettings() const
{
    bool changed = false;
66

67 68
    changed |= applyClangCodeModelWidgetsToSettings();
    changed |= applyPchCheckBoxToSettings();
69

70 71 72 73
    if (changed)
        m_settings->toSettings(Core::ICore::settings());
}

74
void CppCodeModelSettingsWidget::setupClangCodeModelWidgets()
75
{
76
    const bool isClangActive = CppModelManager::instance()->isClangCodeModelActive();
77

78 79
    m_ui->activateClangCodeModelPluginHint->setVisible(!isClangActive);
    m_ui->clangSettingsGroupBox->setEnabled(isClangActive);
80

81 82 83 84
    m_clangDiagnosticConfigsWidget = new ClangDiagnosticConfigsWidget(
                                            m_settings->clangCustomDiagnosticConfigs(),
                                            m_settings->clangDiagnosticConfigId());
    m_ui->clangSettingsGroupBox->layout()->addWidget(m_clangDiagnosticConfigsWidget);
85 86
}

87 88 89 90 91 92
void CppCodeModelSettingsWidget::setupPchCheckBox() const
{
    const bool ignorePch = m_settings->pchUsage() == CppCodeModelSettings::PchUse_None;
    m_ui->ignorePCHCheckBox->setChecked(ignorePch);
}

93 94
bool CppCodeModelSettingsWidget::applyClangCodeModelWidgetsToSettings() const
{
95
    bool settingsChanged = false;
96

97 98 99 100 101 102 103 104 105 106 107 108
    const Core::Id oldConfigId = m_settings->clangDiagnosticConfigId();
    const Core::Id currentConfigId = m_clangDiagnosticConfigsWidget->currentConfigId();
    if (oldConfigId != currentConfigId) {
        m_settings->setClangDiagnosticConfigId(currentConfigId);
        settingsChanged = true;
    }

    const ClangDiagnosticConfigs oldDiagnosticConfigs = m_settings->clangCustomDiagnosticConfigs();
    const ClangDiagnosticConfigs currentDiagnosticConfigs
            = m_clangDiagnosticConfigsWidget->customConfigs();
    if (oldDiagnosticConfigs != currentDiagnosticConfigs) {
        m_settings->setClangCustomDiagnosticConfigs(currentDiagnosticConfigs);
109 110
        settingsChanged = true;
    }
111

112
    return settingsChanged;
113 114
}

115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
bool CppCodeModelSettingsWidget::applyPchCheckBoxToSettings() const
{
    const bool newIgnorePch = m_ui->ignorePCHCheckBox->isChecked();
    const bool previousIgnorePch = m_settings->pchUsage() == CppCodeModelSettings::PchUse_None;

    if (newIgnorePch != previousIgnorePch) {
        const CppCodeModelSettings::PCHUsage pchUsage = m_ui->ignorePCHCheckBox->isChecked()
                ? CppCodeModelSettings::PchUse_None
                : CppCodeModelSettings::PchUse_BuildSystem;
        m_settings->setPCHUsage(pchUsage);

        return true;
    }

    return false;
}

132 133 134 135 136 137 138 139 140 141 142 143
CppCodeModelSettingsPage::CppCodeModelSettingsPage(QSharedPointer<CppCodeModelSettings> &settings,
                                                   QObject *parent)
    : Core::IOptionsPage(parent)
    , m_settings(settings)
{
    setId(Constants::CPP_CODE_MODEL_SETTINGS_ID);
    setDisplayName(QCoreApplication::translate("CppTools",Constants::CPP_CODE_MODEL_SETTINGS_NAME));
    setCategory(Constants::CPP_SETTINGS_CATEGORY);
    setDisplayCategory(QCoreApplication::translate("CppTools",Constants::CPP_SETTINGS_TR_CATEGORY));
    setCategoryIcon(QLatin1String(Constants::SETTINGS_CATEGORY_CPP_ICON));
}

144
QWidget *CppCodeModelSettingsPage::widget()
145
{
146 147 148 149
    if (!m_widget) {
        m_widget = new CppCodeModelSettingsWidget;
        m_widget->setSettings(m_settings);
    }
150 151 152 153 154 155 156 157 158
    return m_widget;
}

void CppCodeModelSettingsPage::apply()
{
    if (m_widget)
        m_widget->applyToSettings();
}

159
void CppCodeModelSettingsPage::finish()
160
{
161
    delete m_widget;
162
}