diff options
author | Oswald Buddenhagen <oswald.buddenhagen@qt.io> | 2016-10-24 19:30:24 +0200 |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@qt.io> | 2016-11-01 17:34:55 +0000 |
commit | 424639ecac9d2e404d2bfaff7f46b45ed98664b8 (patch) | |
tree | 6ed64f844d8dca4e94e05ce2fa74e923d11220f1 /src/plugins/resourceeditor/qrceditor/resourcefile.cpp | |
parent | 1589ce3ce855833a50b4e12c86f2b9b5a83d7b02 (diff) |
make resource file handling able to deal with QMakeProject's VFS
resources.prf may create virtual qrc files when RESOURCES contains
non-qrc files.
Change-Id: If591de9b32b775059d67e94bc3cb06d23ee44b08
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
Diffstat (limited to 'src/plugins/resourceeditor/qrceditor/resourcefile.cpp')
-rw-r--r-- | src/plugins/resourceeditor/qrceditor/resourcefile.cpp | 55 |
1 files changed, 36 insertions, 19 deletions
diff --git a/src/plugins/resourceeditor/qrceditor/resourcefile.cpp b/src/plugins/resourceeditor/qrceditor/resourcefile.cpp index d034a0556c..b139e7fda4 100644 --- a/src/plugins/resourceeditor/qrceditor/resourcefile.cpp +++ b/src/plugins/resourceeditor/qrceditor/resourcefile.cpp @@ -99,9 +99,10 @@ bool FileList::containsFile(File *file) ** ResourceFile */ -ResourceFile::ResourceFile(const QString &file_name) +ResourceFile::ResourceFile(const QString &file_name, const QString &contents) { setFileName(file_name); + m_contents = contents; } ResourceFile::~ResourceFile() @@ -118,28 +119,44 @@ Core::IDocument::OpenResult ResourceFile::load() return Core::IDocument::OpenResult::ReadError; } - QFile file(m_file_name); - if (!file.open(QIODevice::ReadOnly)) { - m_error_message = file.errorString(); - return Core::IDocument::OpenResult::ReadError; - } - QByteArray data = file.readAll(); - // Detect line ending style - m_textFileFormat = Utils::TextFileFormat::detect(data); - // we always write UTF-8 when saving - m_textFileFormat.codec = QTextCodec::codecForName("UTF-8"); - file.close(); - clearPrefixList(); QDomDocument doc; - QString error_msg; - int error_line, error_col; - if (!doc.setContent(data, &error_msg, &error_line, &error_col)) { - m_error_message = tr("XML error on line %1, col %2: %3") - .arg(error_line).arg(error_col).arg(error_msg); - return Core::IDocument::OpenResult::CannotHandle; + if (m_contents.isEmpty()) { + + // Regular file + QFile file(m_file_name); + if (!file.open(QIODevice::ReadOnly)) { + m_error_message = file.errorString(); + return Core::IDocument::OpenResult::ReadError; + } + QByteArray data = file.readAll(); + // Detect line ending style + m_textFileFormat = Utils::TextFileFormat::detect(data); + // we always write UTF-8 when saving + m_textFileFormat.codec = QTextCodec::codecForName("UTF-8"); + file.close(); + + QString error_msg; + int error_line, error_col; + if (!doc.setContent(data, &error_msg, &error_line, &error_col)) { + m_error_message = tr("XML error on line %1, col %2: %3") + .arg(error_line).arg(error_col).arg(error_msg); + return Core::IDocument::OpenResult::CannotHandle; + } + + } else { + + // Virtual file from qmake evaluator + QString error_msg; + int error_line, error_col; + if (!doc.setContent(m_contents, &error_msg, &error_line, &error_col)) { + m_error_message = tr("XML error on line %1, col %2: %3") + .arg(error_line).arg(error_col).arg(error_msg); + return Core::IDocument::OpenResult::CannotHandle; + } + } QDomElement root = doc.firstChildElement(QLatin1String("RCC")); |