summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2016-05-03 15:03:37 +0200
committerSean Harmer <sean.harmer@kdab.com>2016-05-05 17:32:52 +0000
commite4c406cde4777b7afdea58cfcde9767033a0d208 (patch)
treef9229e793540f38508d8e3c4d9346c9eb47cc672 /src/plugins
parentdabbc9e962e25eaca5709df317ad1781c5d06172 (diff)
GLTFIO: move QFile::readAll() into resolveLocalData()
The only caller had to handle the naked returned QFile manually. By hiding the loading in the callee, we can allocate the QFile on the stack and simplify the caller. Saves a few bytes in text size, too. Change-Id: I5b9d7991a39edf8245ae3609fde47f2e15e49817 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/sceneparsers/gltf/gltfio.cpp13
-rw-r--r--src/plugins/sceneparsers/gltf/gltfio.h4
2 files changed, 7 insertions, 10 deletions
diff --git a/src/plugins/sceneparsers/gltf/gltfio.cpp b/src/plugins/sceneparsers/gltf/gltfio.cpp
index 92c2ae2f6..68d43dc1b 100644
--- a/src/plugins/sceneparsers/gltf/gltfio.cpp
+++ b/src/plugins/sceneparsers/gltf/gltfio.cpp
@@ -1237,10 +1237,7 @@ void GLTFIO::loadBufferData()
{
for (auto &bufferData : m_bufferDatas) {
if (!bufferData.data) {
- QFile* bufferFile = resolveLocalData(bufferData.path);
- QByteArray *data = new QByteArray(bufferFile->readAll());
- bufferData.data = data;
- delete bufferFile;
+ bufferData.data = new QByteArray(resolveLocalData(bufferData.path));
}
}
}
@@ -1253,15 +1250,15 @@ void GLTFIO::unloadBufferData()
}
}
-QFile *GLTFIO::resolveLocalData(QString path) const
+QByteArray GLTFIO::resolveLocalData(const QString &path) const
{
QDir d(m_basePath);
Q_ASSERT(d.exists());
QString absPath = d.absoluteFilePath(path);
- QFile* f = new QFile(absPath);
- f->open(QIODevice::ReadOnly);
- return f;
+ QFile f(absPath);
+ f.open(QIODevice::ReadOnly);
+ return f.readAll();
}
QVariant GLTFIO::parameterValueFromJSON(int type, const QJsonValue &value) const
diff --git a/src/plugins/sceneparsers/gltf/gltfio.h b/src/plugins/sceneparsers/gltf/gltfio.h
index a0ffbcb65..684b07c58 100644
--- a/src/plugins/sceneparsers/gltf/gltfio.h
+++ b/src/plugins/sceneparsers/gltf/gltfio.h
@@ -61,7 +61,7 @@
QT_BEGIN_NAMESPACE
-class QFile;
+class QByteArray;
namespace Qt3DCore {
class QEntity;
@@ -162,7 +162,7 @@ private:
void loadBufferData();
void unloadBufferData();
- QFile* resolveLocalData(QString path) const;
+ QByteArray resolveLocalData(const QString &path) const;
QVariant parameterValueFromJSON(int type, const QJsonValue &value) const;
static QAttribute::VertexBaseType accessorTypeFromJSON(int componentType);