summaryrefslogtreecommitdiff
path: root/src/plugins/analyzerbase/analyzersettings.cpp
blob: 3e2c1eb42a52ef5ace70f92cea2fbf11da8d08ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/**************************************************************************
**
** This file is part of Qt Creator Instrumentation Tools
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Author: Milian Wolff, KDAB (milian.wolff@kdab.com)
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** 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
** Nokia at qt-info@nokia.com.
**
**************************************************************************/

#include "analyzersettings.h"

#include "analyzermanager.h"
#include "ianalyzertool.h"
#include "analyzerplugin.h"
#include "analyzeroptionspage.h"

#include <coreplugin/icore.h>
#include <valgrind/xmlprotocol/error.h>
#include <utils/qtcassert.h>

#include <QtCore/QSettings>

using namespace Analyzer;
using namespace Analyzer::Internal;

static const QLatin1String groupC("Analyzer");

AnalyzerGlobalSettings *AnalyzerGlobalSettings::m_instance = 0;

AbstractAnalyzerSubConfig::AbstractAnalyzerSubConfig(QObject *parent)
: QObject(parent)
{

}

AbstractAnalyzerSubConfig::~AbstractAnalyzerSubConfig()
{
}

AnalyzerSettings::AnalyzerSettings(QObject *parent)
: QObject(parent)
{
}

AnalyzerSettings::~AnalyzerSettings()
{
}

bool AnalyzerSettings::fromMap(const QVariantMap &map)
{
    bool ret = true;
    foreach(AbstractAnalyzerSubConfig *config, subConfigs()) {
        ret = ret && config->fromMap(map);
    }
    return ret;
}

QVariantMap AnalyzerSettings::defaults() const
{
    QVariantMap map;
    foreach(AbstractAnalyzerSubConfig *config, subConfigs()) {
        map.unite(config->defaults());
    }
    return map;
}

QVariantMap AnalyzerSettings::toMap() const
{
    QVariantMap map;
    foreach(AbstractAnalyzerSubConfig *config, subConfigs()) {
        map.unite(config->toMap());
    }
    return map;
}

AnalyzerGlobalSettings::AnalyzerGlobalSettings(QObject *parent)
: AnalyzerSettings(parent)
{
    QTC_ASSERT(!m_instance, return);
    m_instance = this;
}

AnalyzerGlobalSettings *AnalyzerGlobalSettings::instance()
{
    if (!m_instance)
        m_instance = new AnalyzerGlobalSettings(AnalyzerPlugin::instance());

    return m_instance;
}

AnalyzerGlobalSettings::~AnalyzerGlobalSettings()
{
    qDeleteAll(m_subConfigFactories);
    m_instance = 0;
}

void AnalyzerGlobalSettings::readSettings()
{
    QSettings *settings = Core::ICore::instance()->settings();

    QVariantMap map;

    settings->beginGroup(groupC);
    // read the values from config, using the keys from the defaults value map
    const QVariantMap def = defaults();
    for (QVariantMap::ConstIterator it = def.constBegin(); it != def.constEnd(); ++it)
        map.insert(it.key(), settings->value(it.key(), it.value()));
    settings->endGroup();

    // apply the values to our member variables
    fromMap(map);
}

void AnalyzerGlobalSettings::writeSettings() const
{
    QSettings *settings = Core::ICore::instance()->settings();
    settings->beginGroup(groupC);
    const QVariantMap map = toMap();
    for (QVariantMap::ConstIterator it = map.begin(); it != map.end(); ++it)
        settings->setValue(it.key(), it.value());
    settings->endGroup();
}

void AnalyzerGlobalSettings::registerSubConfigFactory(AbstractAnalyzerSubConfigFactory *factory)
{
    m_subConfigFactories << factory;

    AbstractAnalyzerSubConfig *config = factory->createGlobalSubConfig(this);
    addSubConfig(config);
    AnalyzerPlugin::instance()->addAutoReleasedObject(new AnalyzerOptionsPage(config));

    readSettings();
}

QList<AbstractAnalyzerSubConfigFactory *> AnalyzerGlobalSettings::subConfigFactories() const
{
    return m_subConfigFactories;
}

AnalyzerProjectSettings::AnalyzerProjectSettings(QObject *parent)
: AnalyzerSettings(parent)
{
    // add sub configs
    foreach(AbstractAnalyzerSubConfigFactory *factory, AnalyzerGlobalSettings::instance()->subConfigFactories()) {
        addSubConfig(factory->createProjectSubConfig(parent));
    }

    // take defaults from global settings
    AnalyzerGlobalSettings *gs = AnalyzerGlobalSettings::instance();
    fromMap(gs->toMap());
}

AnalyzerProjectSettings::~AnalyzerProjectSettings()
{
}

QString AnalyzerProjectSettings::displayName() const
{
    return tr("Analyzer Settings");
}

bool AnalyzerProjectSettings::fromMap(const QVariantMap &map)
{
    return AnalyzerSettings::fromMap(map);
}

QVariantMap AnalyzerProjectSettings::toMap() const
{
    return AnalyzerSettings::toMap();
}