Commit cce26703 authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

Fix warnings about QFileInfo being instantiated on empty string.



Do not insert currentDocument variable for empty files.
Polish VariableManager, QLatin1String(), const-correctness.
Reviewed-by: default avatarDaniel Molkentin <daniel.molkentin@nokia.com>
parent 3dde364a
......@@ -54,65 +54,74 @@ void VariableManager::insert(const QString &variable, const QString &value)
void VariableManager::insertFileInfo(const QString &tag, const QFileInfo &file)
{
insert(tag, file.filePath());
insert(tag+":absoluteFilePath", file.absoluteFilePath());
insert(tag+":absolutePath", file.absolutePath());
insert(tag+":baseName", file.baseName());
insert(tag+":canonicalPath", file.canonicalPath());
insert(tag+":canonicalFilePath", file.canonicalFilePath());
insert(tag+":completeBaseName", file.completeBaseName());
insert(tag+":completeSuffix", file.completeSuffix());
insert(tag+":fileName", file.fileName());
insert(tag+":filePath", file.filePath());
insert(tag+":path", file.path());
insert(tag+":suffix", file.suffix());
insert(tag + QLatin1String(":absoluteFilePath"), file.absoluteFilePath());
insert(tag + QLatin1String(":absolutePath"), file.absolutePath());
insert(tag + QLatin1String(":baseName"), file.baseName());
insert(tag + QLatin1String(":canonicalPath"), file.canonicalPath());
insert(tag + QLatin1String(":canonicalFilePath"), file.canonicalFilePath());
insert(tag + QLatin1String(":completeBaseName"), file.completeBaseName());
insert(tag + QLatin1String(":completeSuffix"), file.completeSuffix());
insert(tag + QLatin1String(":fileName"), file.fileName());
insert(tag + QLatin1String(":filePath"), file.filePath());
insert(tag + QLatin1String(":path"), file.path());
insert(tag + QLatin1String(":suffix"), file.suffix());
}
void VariableManager::removeFileInfo(const QString &tag)
{
remove(tag);
remove(tag+":absoluteFilePath");
remove(tag+":absolutePath");
remove(tag+":baseName");
remove(tag+":canonicalPath");
remove(tag+":canonicalFilePath");
remove(tag+":completeBaseName");
remove(tag+":completeSuffix");
remove(tag+":fileName");
remove(tag+":filePath");
remove(tag+":path");
remove(tag+":suffix");
if (remove(tag)) {
remove(tag + QLatin1String(":absoluteFilePath"));
remove(tag + QLatin1String(":absolutePath"));
remove(tag + QLatin1String(":baseName"));
remove(tag + QLatin1String(":canonicalPath"));
remove(tag + QLatin1String(":canonicalFilePath"));
remove(tag + QLatin1String(":completeBaseName"));
remove(tag + QLatin1String(":completeSuffix"));
remove(tag + QLatin1String(":fileName"));
remove(tag + QLatin1String(":filePath"));
remove(tag + QLatin1String(":path"));
remove(tag + QLatin1String(":suffix"));
}
}
void VariableManager::updateCurrentDocument(Core::IEditor *editor)
{
removeFileInfo("CURRENT_DOCUMENT");
if (editor==NULL || editor->file()==NULL)
return;
insertFileInfo("CURRENT_DOCUMENT", editor->file()->fileName());
const QString currentDocumentTag = QLatin1String("CURRENT_DOCUMENT");
removeFileInfo(currentDocumentTag);
if (editor) {
if (const Core::IFile *file = editor->file()) {
const QString fileName = file->fileName();
if (!fileName.isEmpty())
insertFileInfo(currentDocumentTag, fileName);
}
}
}
QString VariableManager::value(const QString &variable)
QString VariableManager::value(const QString &variable) const
{
return m_map.value(variable);
}
QString VariableManager::value(const QString &variable, const QString &defaultValue)
QString VariableManager::value(const QString &variable, const QString &defaultValue) const
{
return m_map.value(variable, defaultValue);
}
void VariableManager::remove(const QString &variable)
bool VariableManager::remove(const QString &variable)
{
m_map.remove(variable);
return m_map.remove(variable) > 0;
}
QString VariableManager::resolve(const QString &stringWithVariables)
QString VariableManager::resolve(const QString &stringWithVariables) const
{
QString result = stringWithVariables;
QMapIterator<QString, QString> i(m_map);
while (i.hasNext()) {
i.next();
result.replace(QString("${%1}").arg(i.key()), i.value());
QString key = QLatin1String("${");
key += i.key();
key += QLatin1Char('}');
result.replace(key, i.value());
}
return result;
}
......@@ -56,10 +56,10 @@ public:
void insert(const QString &variable, const QString &value);
void insertFileInfo(const QString &tag, const QFileInfo &file);
void removeFileInfo(const QString &tag);
QString value(const QString &variable);
QString value(const QString &variable, const QString &defaultValue);
void remove(const QString &variable);
QString resolve(const QString &stringWithVariables);
QString value(const QString &variable) const;
QString value(const QString &variable, const QString &defaultValue) const;
bool remove(const QString &variable);
QString resolve(const QString &stringWithVariables) const;
private slots:
void updateCurrentDocument(Core::IEditor *editor);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment