2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2013-01-28 17:12:19 +01:00
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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
|
|
|
|
2013-03-11 11:05:06 +01:00
|
|
|
static const char kFilePathPostfix[] = ":FilePath";
|
|
|
|
|
static const char kPathPostfix[] = ":Path";
|
2013-03-11 11:05:49 +01:00
|
|
|
static const char kFileNamePostfix[] = ":FileName";
|
|
|
|
|
static const char kFileBaseNamePostfix[] = ":FileBaseName";
|
2013-03-11 11:05:06 +01:00
|
|
|
|
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;
|
2013-03-11 11:52:05 +01:00
|
|
|
*ret = Core::VariableManager::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;
|
2013-03-11 11:52:05 +01:00
|
|
|
static VariableManagerPrivate *d;
|
2010-09-16 14:59:05 +02:00
|
|
|
|
2013-03-11 11:52:05 +01:00
|
|
|
|
|
|
|
|
VariableManager::VariableManager()
|
2009-07-13 11:39:08 +02:00
|
|
|
{
|
2013-03-11 11:52:05 +01:00
|
|
|
d = new VariableManagerPrivate;
|
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
|
|
|
{
|
2013-03-11 11:52:05 +01:00
|
|
|
variableManagerInstance->variableUpdateRequested(variable);
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (found)
|
2010-12-08 12:03:33 +01:00
|
|
|
*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);
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-11 11:05:06 +01:00
|
|
|
void VariableManager::registerFileVariables(const QByteArray &prefix, const QString &heading)
|
|
|
|
|
{
|
|
|
|
|
registerVariable(prefix + kFilePathPostfix, tr("%1: Full path including file name.").arg(heading));
|
|
|
|
|
registerVariable(prefix + kPathPostfix, tr("%1: Full path excluding file name.").arg(heading));
|
2013-03-11 11:05:49 +01:00
|
|
|
registerVariable(prefix + kFileNamePostfix, tr("%1: File name without including path.").arg(heading));
|
|
|
|
|
registerVariable(prefix + kFileBaseNamePostfix, tr("%1: File base name without path and suffix.").arg(heading));
|
2013-03-11 11:05:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool VariableManager::isFileVariable(const QByteArray &variable, const QByteArray &prefix)
|
|
|
|
|
{
|
|
|
|
|
return variable == prefix + kFilePathPostfix
|
2013-03-11 11:05:49 +01:00
|
|
|
|| variable == prefix + kPathPostfix
|
|
|
|
|
|| variable == prefix + kFileNamePostfix
|
|
|
|
|
|| variable == prefix + kFileBaseNamePostfix;
|
2013-03-11 11:05:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString VariableManager::fileVariableValue(const QByteArray &variable, const QByteArray &prefix,
|
|
|
|
|
const QString &fileName)
|
|
|
|
|
{
|
|
|
|
|
return fileVariableValue(variable, prefix, QFileInfo(fileName));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString VariableManager::fileVariableValue(const QByteArray &variable, const QByteArray &prefix,
|
|
|
|
|
const QFileInfo &fileInfo)
|
|
|
|
|
{
|
|
|
|
|
if (variable == prefix + kFilePathPostfix)
|
|
|
|
|
return fileInfo.filePath();
|
|
|
|
|
else if (variable == prefix + kPathPostfix)
|
|
|
|
|
return fileInfo.path();
|
2013-03-11 11:05:49 +01:00
|
|
|
else if (variable == prefix + kFileNamePostfix)
|
|
|
|
|
return fileInfo.fileName();
|
|
|
|
|
else if (variable == prefix + kFileBaseNamePostfix)
|
|
|
|
|
return fileInfo.baseName();
|
2013-03-11 11:05:06 +01:00
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-11 11:52:05 +01:00
|
|
|
QList<QByteArray> VariableManager::variables()
|
2011-02-10 20:58:17 +01:00
|
|
|
{
|
|
|
|
|
return d->m_descriptions.keys();
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-11 11:52:05 +01:00
|
|
|
QString VariableManager::variableDescription(const QByteArray &variable)
|
2011-02-10 20:58:17 +01:00
|
|
|
{
|
|
|
|
|
return d->m_descriptions.value(variable);
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-16 14:59:05 +02:00
|
|
|
} // namespace Core
|