Commit 38e575fa authored by Jarek Kobus's avatar Jarek Kobus Committed by Eike Ziller

Fix assert on undo in qrc editor

Before creating AddFilesCommand we check if
files to be added are already in qrc file. If they all are in
we don't create AddFilesCommand.

Task-number: QTCREATORBUG-6508
Change-Id: I633f7393f1185023052ceaa0465282e1dc7957a2
Reviewed-by: default avatarEike Ziller <>
parent 5ab4e69f
......@@ -417,6 +417,7 @@ void QrcEditor::onAddFiles()
: m_treeview->model()->parent(current).row();
int const cursorFileArrayIndex = currentIsPrefixNode ? 0 : current.row();
QStringList fileNames = m_treeview->fileNamesToAdd();
fileNames = m_treeview->existingFilesSubtracted(prefixArrayIndex, fileNames);
if (fileNames.isEmpty())
......@@ -793,36 +793,45 @@ QModelIndex ResourceModel::addFiles(const QModelIndex &model_idx, const QStringL
return index(lastFileArrayIndex, 0, prefixModelIndex);
QStringList ResourceModel::existingFilesSubtracted(int prefixIndex, const QStringList &fileNames) const
const QModelIndex prefixModelIdx = index(prefixIndex, 0, QModelIndex());
QStringList uniqueList;
if (prefixModelIdx.isValid()) {
foreach (const QString &file, fileNames) {
if (!m_resource_file.contains(prefixIndex, file) && !uniqueList.contains(file))
return uniqueList;
void ResourceModel::addFiles(int prefixIndex, const QStringList &fileNames, int cursorFile,
int &firstFile, int &lastFile)
const QModelIndex prefix_model_idx = index(prefixIndex, 0, QModelIndex());
const QStringList &file_list = fileNames;
firstFile = -1;
lastFile = -1;
if (!prefix_model_idx.isValid()) {
const int prefix_idx = prefixIndex;
QStringList unique_list;
foreach (const QString &file, file_list) {
if (!m_resource_file.contains(prefix_idx, file) && !unique_list.contains(file))
QStringList unique_list = existingFilesSubtracted(prefixIndex, fileNames);
if (unique_list.isEmpty()) {
const int cnt = m_resource_file.fileCount(prefix_idx);
const int cnt = m_resource_file.fileCount(prefixIndex);
beginInsertRows(prefix_model_idx, cnt, cnt + unique_list.count() - 1); // ### FIXME
foreach (const QString &file, unique_list)
m_resource_file.addFile(prefix_idx, file);
m_resource_file.addFile(prefixIndex, file);
const QFileInfo fi(file_list.last());
const QFileInfo fi(unique_list.last());
m_lastResourceDir = fi.absolutePath();
......@@ -216,6 +216,7 @@ public:
virtual QModelIndex addNewPrefix();
virtual QModelIndex addFiles(const QModelIndex &idx, const QStringList &file_list);
QStringList existingFilesSubtracted(int prefixIndex, const QStringList &fileNames) const;
void addFiles(int prefixIndex, const QStringList &fileNames, int cursorFile, int &firstFile, int &lastFile);
void insertPrefix(int prefixIndex, const QString &prefix, const QString &lang);
void insertFile(int prefixIndex, int fileIndex, const QString &fileName, const QString &alias);
......@@ -305,6 +305,11 @@ EntryBackup * ResourceView::removeEntry(const QModelIndex &index)
return m_qrcModel->removeEntry(index);
QStringList ResourceView::existingFilesSubtracted(int prefixIndex, const QStringList &fileNames) const
return m_qrcModel->existingFilesSubtracted(prefixIndex, fileNames);
void ResourceView::addFiles(int prefixIndex, const QStringList &fileNames, int cursorFile,
int &firstFile, int &lastFile)
......@@ -117,6 +117,7 @@ public:
void findSamePlacePostDeletionModelIndex(int &row, QModelIndex &parent) const;
EntryBackup *removeEntry(const QModelIndex &index);
QStringList existingFilesSubtracted(int prefixIndex, const QStringList &fileNames) const;
void addFiles(int prefixIndex, const QStringList &fileNames, int cursorFile,
int &firstFile, int &lastFile);
void removeFiles(int prefixIndex, int firstFileIndex, int lastFileIndex);
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