cppcodestylepreferences.cpp 3.32 KB
Newer Older
Christian Kamm's avatar
Christian Kamm committed
1 2 3 4 5 6
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
Christian Kamm's avatar
Christian Kamm committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
29
** Nokia at qt-info@nokia.com.
Christian Kamm's avatar
Christian Kamm committed
30 31 32
**
**************************************************************************/

33 34 35 36 37 38
#include "cppcodestylepreferences.h"

using namespace CppTools;

static const char *settingsSuffixKey = "CodeStyleSettings";

Jarek Kobus's avatar
Jarek Kobus committed
39 40
CppCodeStylePreferences::CppCodeStylePreferences(QObject *parent) :
    ICodeStylePreferences(parent)
41 42 43 44 45 46 47 48
{
    connect(this, SIGNAL(currentValueChanged(QVariant)),
            this, SLOT(slotCurrentValueChanged(QVariant)));
}

QVariant CppCodeStylePreferences::value() const
{
    QVariant v;
Jarek Kobus's avatar
Jarek Kobus committed
49
    v.setValue(codeStyleSettings());
50 51 52 53 54 55 56 57
    return v;
}

void CppCodeStylePreferences::setValue(const QVariant &data)
{
    if (!data.canConvert<CppCodeStyleSettings>())
        return;

Jarek Kobus's avatar
Jarek Kobus committed
58
    setCodeStyleSettings(data.value<CppCodeStyleSettings>());
59 60
}

Jarek Kobus's avatar
Jarek Kobus committed
61
CppCodeStyleSettings CppCodeStylePreferences::codeStyleSettings() const
62 63 64 65
{
    return m_data;
}

Jarek Kobus's avatar
Jarek Kobus committed
66
void CppCodeStylePreferences::setCodeStyleSettings(const CppCodeStyleSettings &data)
67 68 69 70 71 72 73 74 75
{
    if (m_data == data)
        return;

    m_data = data;

    QVariant v;
    v.setValue(data);
    emit valueChanged(v);
Jarek Kobus's avatar
Jarek Kobus committed
76 77
    emit codeStyleSettingsChanged(m_data);
    if (!currentDelegate()) {
78 79 80 81
        emit currentValueChanged(v);
    }
}

Jarek Kobus's avatar
Jarek Kobus committed
82
CppCodeStyleSettings CppCodeStylePreferences::currentCodeStyleSettings() const
83 84 85 86 87 88 89 90 91 92 93 94 95 96
{
    QVariant v = currentValue();
    if (!v.canConvert<CppCodeStyleSettings>()) {
        // warning
        return CppCodeStyleSettings();
    }
    return v.value<CppCodeStyleSettings>();
}

void CppCodeStylePreferences::slotCurrentValueChanged(const QVariant &value)
{
    if (!value.canConvert<CppCodeStyleSettings>())
        return;

Jarek Kobus's avatar
Jarek Kobus committed
97
    emit currentCodeStyleSettingsChanged(value.value<CppCodeStyleSettings>());
98 99 100 101 102 103 104 105 106
}

QString CppCodeStylePreferences::settingsSuffix() const
{
    return settingsSuffixKey;
}

void CppCodeStylePreferences::toMap(const QString &prefix, QVariantMap *map) const
{
Jarek Kobus's avatar
Jarek Kobus committed
107 108 109 110
    ICodeStylePreferences::toMap(prefix, map);
    if (currentDelegate())
        return;

111 112 113 114 115
    m_data.toMap(prefix, map);
}

void CppCodeStylePreferences::fromMap(const QString &prefix, const QVariantMap &map)
{
Jarek Kobus's avatar
Jarek Kobus committed
116 117 118 119
    ICodeStylePreferences::fromMap(prefix, map);
    if (currentDelegate())
        return;

120 121 122
    m_data.fromMap(prefix, map);
}