2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
|
|
|
|
|
** Contact: http://www.qt-project.org/legal
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, 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, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 15:08:31 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "variablemanager.h"
|
2012-02-14 16:43:51 +01:00
|
|
|
#include "idocument.h"
|
2010-09-16 14:59:05 +02:00
|
|
|
#include "editormanager/ieditor.h"
|
|
|
|
|
#include "editormanager/editormanager.h"
|
|
|
|
|
|
2010-11-08 19:54:19 +01:00
|
|
|
#include <utils/stringutils.h>
|
2010-09-16 14:59:05 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2009-10-01 16:38:08 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QFileInfo>
|
|
|
|
|
#include <QObject>
|
|
|
|
|
#include <QMap>
|
|
|
|
|
#include <QDebug>
|
2010-09-16 14:59:05 +02:00
|
|
|
|
|
|
|
|
namespace Core {
|
|
|
|
|
|
2011-07-06 19:02:18 +02:00
|
|
|
class VMMapExpander : public Utils::AbstractQtcMacroExpander
|
|
|
|
|
{
|
2010-11-08 19:54:19 +01:00
|
|
|
public:
|
|
|
|
|
virtual bool resolveMacro(const QString &name, QString *ret)
|
|
|
|
|
{
|
2010-12-08 12:03:33 +01:00
|
|
|
bool found;
|
2011-12-21 11:29:35 +01:00
|
|
|
*ret = Core::VariableManager::instance()->value(name.toUtf8(), &found);
|
2010-12-08 12:03:33 +01:00
|
|
|
return found;
|
2010-11-08 19:54:19 +01:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2011-07-06 19:02:18 +02:00
|
|
|
class VariableManagerPrivate
|
2010-09-16 14:59:05 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2011-12-21 11:29:35 +01:00
|
|
|
QHash<QByteArray, QString> m_map;
|
2010-11-08 19:54:19 +01:00
|
|
|
VMMapExpander m_macroExpander;
|
2011-12-21 11:29:35 +01:00
|
|
|
QMap<QByteArray, QString> m_descriptions;
|
2010-09-16 14:59:05 +02:00
|
|
|
};
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2011-12-21 11:29:35 +01:00
|
|
|
/*!
|
|
|
|
|
\class Core::VariableManager
|
|
|
|
|
\brief The VaraiableManager class holds a generic map from variable names
|
|
|
|
|
to string values.
|
|
|
|
|
|
|
|
|
|
The names of the variables are stored as QByteArray. They are typically
|
|
|
|
|
7-bit-clean. In cases where this is not possible, Latin-1 encoding is
|
|
|
|
|
assumed.
|
|
|
|
|
*/
|
|
|
|
|
|
2011-07-06 19:02:18 +02:00
|
|
|
static VariableManager *variableManagerInstance = 0;
|
2010-09-16 14:59:05 +02:00
|
|
|
|
|
|
|
|
VariableManager::VariableManager() : d(new VariableManagerPrivate)
|
2009-07-13 11:39:08 +02:00
|
|
|
{
|
2011-07-06 19:02:18 +02:00
|
|
|
variableManagerInstance = this;
|
2009-07-13 11:39:08 +02:00
|
|
|
}
|
|
|
|
|
|
2010-09-16 14:59:05 +02:00
|
|
|
VariableManager::~VariableManager()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2011-07-06 19:02:18 +02:00
|
|
|
variableManagerInstance = 0;
|
|
|
|
|
delete d;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2011-12-21 11:29:35 +01:00
|
|
|
void VariableManager::insert(const QByteArray &variable, const QString &value)
|
2010-09-16 14:59:05 +02:00
|
|
|
{
|
2010-12-08 12:03:33 +01:00
|
|
|
d->m_map.insert(variable, value);
|
2010-09-16 14:59:05 +02:00
|
|
|
}
|
|
|
|
|
|
2011-12-21 11:29:35 +01:00
|
|
|
bool VariableManager::remove(const QByteArray &variable)
|
2010-09-16 14:59:05 +02:00
|
|
|
{
|
2010-12-08 12:03:33 +01:00
|
|
|
return d->m_map.remove(variable) > 0;
|
2010-09-16 14:59:05 +02:00
|
|
|
}
|
|
|
|
|
|
2011-12-21 11:29:35 +01:00
|
|
|
QString VariableManager::value(const QByteArray &variable, bool *found)
|
2010-09-16 14:59:05 +02:00
|
|
|
{
|
2010-12-08 12:03:33 +01:00
|
|
|
emit variableUpdateRequested(variable);
|
|
|
|
|
if (found) {
|
|
|
|
|
*found = d->m_map.contains(variable);
|
|
|
|
|
}
|
|
|
|
|
return d->m_map.value(variable);
|
2010-09-16 14:59:05 +02:00
|
|
|
}
|
|
|
|
|
|
2010-11-08 19:54:19 +01:00
|
|
|
Utils::AbstractMacroExpander *VariableManager::macroExpander()
|
|
|
|
|
{
|
|
|
|
|
return &d->m_macroExpander;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-06 19:02:18 +02:00
|
|
|
VariableManager *VariableManager::instance()
|
2010-09-16 14:59:05 +02:00
|
|
|
{
|
2011-07-06 19:02:18 +02:00
|
|
|
return variableManagerInstance;
|
2010-09-16 14:59:05 +02:00
|
|
|
}
|
2010-12-08 12:03:33 +01:00
|
|
|
|
2011-12-21 11:29:35 +01:00
|
|
|
void VariableManager::registerVariable(const QByteArray &variable, const QString &description)
|
2011-02-10 20:58:17 +01:00
|
|
|
{
|
|
|
|
|
d->m_descriptions.insert(variable, description);
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-21 11:29:35 +01:00
|
|
|
QList<QByteArray> VariableManager::variables() const
|
2011-02-10 20:58:17 +01:00
|
|
|
{
|
|
|
|
|
return d->m_descriptions.keys();
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-21 11:29:35 +01:00
|
|
|
QString VariableManager::variableDescription(const QByteArray &variable) const
|
2011-02-10 20:58:17 +01:00
|
|
|
{
|
|
|
|
|
return d->m_descriptions.value(variable);
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-16 14:59:05 +02:00
|
|
|
} // namespace Core
|