Commit d4de9185 authored by Daniel Teske's avatar Daniel Teske

ResourceEditor: A prefix is uniquely identified by prefix + language

So add checks for language everwhere.

Change-Id: Iba1035065f34d2008b53f1c73518eb5ad5c54850
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
Reviewed-by: default avatarJarek Kobus <jaroslaw.kobus@digia.com>
parent 38f7fa74
......@@ -151,7 +151,7 @@ bool ResourceFile::load()
prefix = QString(QLatin1Char('/'));
const QString language = relt.attribute(QLatin1String("lang"));
const int idx = indexOfPrefix(prefix);
const int idx = indexOfPrefix(prefix, language);
Prefix * p = 0;
if (idx == -1) {
p = new Prefix(prefix, language);
......@@ -328,16 +328,17 @@ void ResourceFile::addFile(int prefix_idx, const QString &file, int file_idx)
files.insert(file_idx, new File(p, absolutePath(file)));
}
void ResourceFile::addPrefix(const QString &prefix, int prefix_idx)
void ResourceFile::addPrefix(const QString &prefix, const QString &lang, int prefix_idx)
{
QString fixed_prefix = fixPrefix(prefix);
if (indexOfPrefix(fixed_prefix) != -1)
if (indexOfPrefix(fixed_prefix, lang) != -1)
return;
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;
}
void ResourceFile::removePrefix(int prefix_idx)
......@@ -421,11 +422,12 @@ void ResourceFile::replaceFile(int pref_idx, int file_idx, const QString &file)
fileList[file_idx]->name = file;
}
int ResourceFile::indexOfPrefix(const QString &prefix) const
int ResourceFile::indexOfPrefix(const QString &prefix, const QString &lang) const
{
QString fixed_prefix = fixPrefix(prefix);
for (int i = 0; i < m_prefix_list.size(); ++i) {
if (m_prefix_list.at(i)->name == fixed_prefix)
if (m_prefix_list.at(i)->name == fixed_prefix
&& m_prefix_list.at(i)->lang == lang)
return i;
}
return -1;
......@@ -460,9 +462,9 @@ QString ResourceFile::absolutePath(const QString &rel_path) const
return QDir::cleanPath(rc);
}
bool ResourceFile::contains(const QString &prefix, const QString &file) const
bool ResourceFile::contains(const QString &prefix, const QString &lang, const QString &file) const
{
int pref_idx = indexOfPrefix(prefix);
int pref_idx = indexOfPrefix(prefix, lang);
if (pref_idx == -1)
return false;
if (file.isEmpty())
......@@ -864,12 +866,12 @@ QString ResourceModel::file(const QModelIndex &index) const
return m_resource_file.file(index.parent().row(), index.row());
}
QModelIndex ResourceModel::getIndex(const QString &prefix, const QString &file)
QModelIndex ResourceModel::getIndex(const QString &prefix, const QString &lang, const QString &file)
{
if (prefix.isEmpty())
return QModelIndex();
const int pref_idx = m_resource_file.indexOfPrefix(prefix);
const int pref_idx = m_resource_file.indexOfPrefix(prefix, lang);
if (pref_idx == -1)
return QModelIndex();
......@@ -897,12 +899,12 @@ QModelIndex ResourceModel::addNewPrefix()
const QString format = QLatin1String("/new/prefix%1");
int i = 1;
QString prefix = format.arg(i);
for ( ; m_resource_file.contains(prefix); i++)
for ( ; m_resource_file.contains(prefix, QString()); i++)
prefix = format.arg(i);
i = rowCount(QModelIndex());
beginInsertRows(QModelIndex(), i, i);
m_resource_file.addPrefix(prefix);
m_resource_file.addPrefix(prefix, QString());
endInsertRows();
setDirty(true);
......@@ -974,8 +976,7 @@ void ResourceModel::insertPrefix(int prefixIndex, const QString &prefix,
const QString &lang)
{
beginInsertRows(QModelIndex(), prefixIndex, prefixIndex);
m_resource_file.addPrefix(prefix, prefixIndex);
m_resource_file.replaceLang(prefixIndex, lang);
m_resource_file.addPrefix(prefix, lang, prefixIndex);
endInsertRows();
setDirty(true);
}
......@@ -1008,8 +1009,7 @@ void ResourceModel::changePrefix(const QModelIndex &model_idx, const QString &pr
const int prefix_idx = model_idx.row();
if (m_resource_file.prefix(prefix_idx) == ResourceFile::fixPrefix(prefix))
return;
if (m_resource_file.contains(prefix))
if (m_resource_file.contains(prefix, m_resource_file.lang(prefix_idx)))
return;
m_resource_file.replacePrefix(prefix_idx, prefix);
......
......@@ -155,7 +155,7 @@ public:
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, int prefix_idx = -1);
void addPrefix(const QString &prefix, const QString &lang, int prefix_idx = -1);
void removePrefix(int prefix_idx);
void removeFile(int prefix_idx, int file_idx);
......@@ -169,10 +169,10 @@ public:
private:
void replaceFile(int pref_idx, int file_idx, const QString &file);
public:
int indexOfPrefix(const QString &prefix) const;
int indexOfPrefix(const QString &prefix, const QString &lang) const;
int indexOfFile(int pref_idx, const QString &file) const;
bool contains(const QString &prefix, const QString &file = QString()) const;
bool contains(const QString &prefix, const QString &lang, const QString &file = QString()) const;
bool contains(int pref_idx, const QString &file) const;
QString relativePath(const QString &abs_path) const;
......@@ -243,7 +243,7 @@ public:
virtual void changeLang(const QModelIndex &idx, const QString &lang);
virtual void changeAlias(const QModelIndex &idx, const QString &alias);
virtual QModelIndex deleteItem(const QModelIndex &idx);
QModelIndex getIndex(const QString &prefix, const QString &file);
QModelIndex getIndex(const QString &prefix, const QString &lang, const QString &file);
QModelIndex prefixIndex(const QModelIndex &sel_idx) const;
QString absolutePath(const QString &path) 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