LP-56 - Better txpid option namings, fix tabs-spaces, tooltips. headers, variable...
[librepilot.git] / ground / openpilotgcs / src / plugins / coreplugin / variablemanager.cpp
blob2d62e415022730bede7914a766bffe5bd98d5d98
1 /**
2 ******************************************************************************
4 * @file variablemanager.cpp
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
7 * @addtogroup GCSPlugins GCS Plugins
8 * @{
9 * @addtogroup CorePlugin Core Plugin
10 * @{
11 * @brief The Core GCS plugin
12 *****************************************************************************/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * for more details.
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "variablemanager.h"
31 #include <QtCore/QFileInfo>
33 using namespace Core;
35 VariableManager *VariableManager::m_instance = 0;
37 VariableManager::VariableManager(QObject *parent) : QObject(parent)
39 m_instance = this;
42 VariableManager::~VariableManager()
44 m_instance = 0;
47 void VariableManager::insert(const QString &variable, const QString &value)
49 m_map.insert(variable, value);
52 void VariableManager::insertFileInfo(const QString &tag, const QFileInfo &file)
54 insert(tag, file.filePath());
55 insert(tag + QLatin1String(":absoluteFilePath"), file.absoluteFilePath());
56 insert(tag + QLatin1String(":absolutePath"), file.absolutePath());
57 insert(tag + QLatin1String(":baseName"), file.baseName());
58 insert(tag + QLatin1String(":canonicalPath"), file.canonicalPath());
59 insert(tag + QLatin1String(":canonicalFilePath"), file.canonicalFilePath());
60 insert(tag + QLatin1String(":completeBaseName"), file.completeBaseName());
61 insert(tag + QLatin1String(":completeSuffix"), file.completeSuffix());
62 insert(tag + QLatin1String(":fileName"), file.fileName());
63 insert(tag + QLatin1String(":filePath"), file.filePath());
64 insert(tag + QLatin1String(":path"), file.path());
65 insert(tag + QLatin1String(":suffix"), file.suffix());
68 void VariableManager::removeFileInfo(const QString &tag)
70 if (remove(tag)) {
71 remove(tag + QLatin1String(":absoluteFilePath"));
72 remove(tag + QLatin1String(":absolutePath"));
73 remove(tag + QLatin1String(":baseName"));
74 remove(tag + QLatin1String(":canonicalPath"));
75 remove(tag + QLatin1String(":canonicalFilePath"));
76 remove(tag + QLatin1String(":completeBaseName"));
77 remove(tag + QLatin1String(":completeSuffix"));
78 remove(tag + QLatin1String(":fileName"));
79 remove(tag + QLatin1String(":filePath"));
80 remove(tag + QLatin1String(":path"));
81 remove(tag + QLatin1String(":suffix"));
85 QString VariableManager::value(const QString &variable) const
87 return m_map.value(variable);
90 QString VariableManager::value(const QString &variable, const QString &defaultValue) const
92 return m_map.value(variable, defaultValue);
95 bool VariableManager::remove(const QString &variable)
97 return m_map.remove(variable) > 0;
100 QString VariableManager::resolve(const QString &stringWithVariables) const
102 QString result = stringWithVariables;
104 QMapIterator<QString, QString> i(m_map);
105 while (i.hasNext()) {
106 i.next();
107 QString key = QLatin1String("${");
108 key += i.key();
109 key += QLatin1Char('}');
110 result.replace(key, i.value());
112 return result;