Commit d6781f18 authored by Daniel Teske's avatar Daniel Teske
Browse files

ResourceEditor: Small interface tweaks for ResourceNode



Change-Id: I13886ac8e8850efe312d101c154a6add70d780ec
Reviewed-by: default avatarJarek Kobus <jaroslaw.kobus@digia.com>
parent ae781b19
......@@ -240,7 +240,7 @@ void ResourceFile::refresh()
}
}
void ResourceFile::addFile(int prefix_idx, const QString &file, int file_idx)
int ResourceFile::addFile(int prefix_idx, const QString &file, int file_idx)
{
Prefix * const p = m_prefix_list[prefix_idx];
Q_ASSERT(p);
......@@ -249,19 +249,21 @@ void ResourceFile::addFile(int prefix_idx, const QString &file, int file_idx)
if (file_idx == -1)
file_idx = files.size();
files.insert(file_idx, new File(p, absolutePath(file)));
return file_idx;
}
void ResourceFile::addPrefix(const QString &prefix, const QString &lang, int prefix_idx)
int ResourceFile::addPrefix(const QString &prefix, const QString &lang, int prefix_idx)
{
QString fixed_prefix = fixPrefix(prefix);
if (indexOfPrefix(fixed_prefix, lang) != -1)
return;
return -1;
Q_ASSERT(prefix_idx >= -1 && prefix_idx <= m_prefix_list.size());
if (prefix_idx == -1)
prefix_idx = m_prefix_list.size();
m_prefix_list.insert(prefix_idx, new Prefix(fixed_prefix));
m_prefix_list[prefix_idx]->lang = lang;
return prefix_idx;
}
void ResourceFile::removePrefix(int prefix_idx)
......@@ -281,16 +283,37 @@ void ResourceFile::removeFile(int prefix_idx, int file_idx)
fileList.removeAt(file_idx);
}
void ResourceFile::replacePrefix(int prefix_idx, const QString &prefix)
bool ResourceFile::replacePrefix(int prefix_idx, const QString &prefix)
{
const QString fixed_prefix = fixPrefix(prefix);
Q_ASSERT(prefix_idx >= 0 && prefix_idx < m_prefix_list.count());
m_prefix_list[prefix_idx]->name = fixPrefix(prefix);
const int existingIndex = indexOfPrefix(fixed_prefix, m_prefix_list.at(prefix_idx)->lang, prefix_idx);
if (existingIndex != -1) // prevent duplicated prefix + lang combinations
return false;
m_prefix_list[prefix_idx]->name = fixed_prefix;
return true;
}
void ResourceFile::replaceLang(int prefix_idx, const QString &lang)
bool ResourceFile::replaceLang(int prefix_idx, const QString &lang)
{
Q_ASSERT(prefix_idx >= 0 && prefix_idx < m_prefix_list.count());
const int existingIndex = indexOfPrefix(m_prefix_list.at(prefix_idx)->name, lang, prefix_idx);
if (existingIndex != -1) // prevent duplicated prefix + lang combinations
return false;
m_prefix_list[prefix_idx]->lang = lang;
return true;
}
bool ResourceFile::replacePrefixAndLang(int prefix_idx, const QString &prefix, const QString &lang)
{
const QString fixed_prefix = fixPrefix(prefix);
Q_ASSERT(prefix_idx >= 0 && prefix_idx < m_prefix_list.count());
const int existingIndex = indexOfPrefix(fixed_prefix, lang, prefix_idx);
if (existingIndex != -1) // prevent duplicated prefix + lang combinations
return false;
m_prefix_list[prefix_idx]->name = fixed_prefix;
return true;
}
void ResourceFile::replaceAlias(int prefix_idx, int file_idx, const QString &alias)
......@@ -347,8 +370,16 @@ void ResourceFile::replaceFile(int pref_idx, int file_idx, const QString &file)
int ResourceFile::indexOfPrefix(const QString &prefix, const QString &lang) const
{
return indexOfPrefix(prefix, lang, -1);
}
int ResourceFile::indexOfPrefix(const QString &prefix, const QString &lang, int skip) const
{
QString fixed_prefix = fixPrefix(prefix);
for (int i = 0; i < m_prefix_list.size(); ++i) {
if (i == skip)
continue;
if (m_prefix_list.at(i)->name == fixed_prefix
&& m_prefix_list.at(i)->lang == lang)
return i;
......
......@@ -148,21 +148,20 @@ public:
QString file(int prefix_idx, int file_idx) const;
QString alias(int prefix_idx, int file_idx) const;
void addFile(int prefix_idx, const QString &file, int file_idx = -1);
void addPrefix(const QString &prefix, const QString &lang, int prefix_idx = -1);
int addFile(int prefix_idx, const QString &file, int file_idx = -1);
int addPrefix(const QString &prefix, const QString &lang, int prefix_idx = -1);
void removePrefix(int prefix_idx);
void removeFile(int prefix_idx, int file_idx);
void replacePrefix(int prefix_idx, const QString &prefix);
void replaceLang(int prefix_idx, const QString &lang);
bool replacePrefix(int prefix_idx, const QString &prefix);
bool replaceLang(int prefix_idx, const QString &lang);
bool replacePrefixAndLang(int prefix_idx, const QString &prefix, const QString &lang);
void replaceAlias(int prefix_idx, int file_idx, const QString &alias);
bool renameFile(const QString fileName, const QString &newFileName);
private:
void replaceFile(int pref_idx, int file_idx, const QString &file);
public:
int indexOfPrefix(const QString &prefix, const QString &lang) const;
int indexOfFile(int pref_idx, const QString &file) const;
......@@ -186,6 +185,7 @@ public:
private:
void clearPrefixList();
int indexOfPrefix(const QString &prefix, const QString &lang, int skip) const;
};
/*!
......
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