1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "variablemanager.h"
36 #include "editormanager/ieditor.h"
37 #include "editormanager/editormanager.h"
39 #include <utils/stringutils.h>
40 #include <utils/qtcassert.h>
42 #include <QtCore/QFileInfo>
43 #include <QtCore/QObject>
44 #include <QtCore/QMap>
45 #include <QtCore/QDebug>
49 class VMMapExpander : public Utils::AbstractQtcMacroExpander {
51 virtual bool resolveMacro(const QString &name, QString *ret)
54 *ret = Core::VariableManager::instance()->value(name, &found);
59 class VariableManagerPrivate : public QObject
64 QHash<QString, QString> m_map;
65 VMMapExpander m_macroExpander;
66 QMap<QString, QString> m_descriptions;
67 static VariableManager *m_instance;
70 VariableManager *VariableManagerPrivate::m_instance = 0;
72 VariableManager::VariableManager() : d(new VariableManagerPrivate)
74 VariableManagerPrivate::m_instance = this;
77 VariableManager::~VariableManager()
79 VariableManagerPrivate::m_instance = 0;
82 void VariableManager::insert(const QString &variable, const QString &value)
84 d->m_map.insert(variable, value);
87 bool VariableManager::remove(const QString &variable)
89 return d->m_map.remove(variable) > 0;
92 QString VariableManager::value(const QString &variable, bool *found)
94 emit variableUpdateRequested(variable);
96 *found = d->m_map.contains(variable);
98 return d->m_map.value(variable);
101 QString VariableManager::value(const QString &variable, const QString &defaultValue)
103 emit variableUpdateRequested(variable);
104 return d->m_map.value(variable, defaultValue);
107 Utils::AbstractMacroExpander *VariableManager::macroExpander()
109 return &d->m_macroExpander;
112 VariableManager* VariableManager::instance()
114 return VariableManagerPrivate::m_instance;
117 void VariableManager::registerVariable(const QString &variable, const QString &description)
119 d->m_descriptions.insert(variable, description);
122 QList<QString> VariableManager::variables() const
124 return d->m_descriptions.keys();
127 QString VariableManager::variableDescription(const QString &variable) const
129 return d->m_descriptions.value(variable);
134 #include "variablemanager.moc"