diff options
author | Konstantin Ritt <ritt.ks@gmail.com> | 2015-01-26 13:08:48 +0400 |
---|---|---|
committer | Konstantin Ritt <ritt.ks@gmail.com> | 2015-01-28 14:15:53 +0000 |
commit | 88ff6fcf61d7f20119831cb8d3ee63bf80003953 (patch) | |
tree | 8fcd4ab5f2645c7ca5114b472796db1ba22d08b6 /src/plugins | |
parent | 6e8dc29293be8342e7ae10c8fb158ee96bdacecf (diff) |
Minor improvements to Qt-Assimp briging code
Change-Id: I3301a3615443bfd361de97de79b587e22517cf66
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/sceneparsers/assimp/assimphelpers.cpp | 46 | ||||
-rw-r--r-- | src/plugins/sceneparsers/assimp/assimphelpers_p.h | 4 |
2 files changed, 25 insertions, 25 deletions
diff --git a/src/plugins/sceneparsers/assimp/assimphelpers.cpp b/src/plugins/sceneparsers/assimp/assimphelpers.cpp index 4310d6764..5102595ab 100644 --- a/src/plugins/sceneparsers/assimp/assimphelpers.cpp +++ b/src/plugins/sceneparsers/assimp/assimphelpers.cpp @@ -41,11 +41,11 @@ #include "assimphelpers_p.h" +#include <QFileDevice> #include <QFileInfo> #include <QUrl> #include <QDir> #include <QDebug> -#include <QMap> QT_BEGIN_NAMESPACE @@ -67,6 +67,7 @@ AssimpIOStream::AssimpIOStream(QIODevice *device) : Assimp::IOStream(), m_device(device) { + Q_ASSERT(m_device != Q_NULLPTR); } /*! @@ -75,10 +76,7 @@ AssimpIOStream::AssimpIOStream(QIODevice *device) : AssimpIOStream::~AssimpIOStream() { // Owns m_device - if (m_device && m_device->isOpen()) { - m_device->close(); - delete m_device; - } + delete m_device; } /*! @@ -147,6 +145,8 @@ size_t AssimpIOStream::FileSize() const void AssimpIOStream::Flush() { // QIODevice has no flush method + if (QFileDevice *file = qobject_cast<QFileDevice *>(m_device)) + file->flush(); } /*! @@ -165,16 +165,16 @@ void AssimpIOStream::Flush() AssimpIOSystem::AssimpIOSystem() : Assimp::IOSystem() { - m_openModeMaps[QStringLiteral("r")] = QIODevice::ReadOnly; - m_openModeMaps[QStringLiteral("r+")] = QIODevice::ReadWrite; - m_openModeMaps[QStringLiteral("w")] = QIODevice::WriteOnly|QIODevice::Truncate; - m_openModeMaps[QStringLiteral("w+")] = QIODevice::ReadWrite|QIODevice::Truncate; - m_openModeMaps[QStringLiteral("a")] = QIODevice::WriteOnly|QIODevice::Append; - m_openModeMaps[QStringLiteral("a+")] = QIODevice::ReadWrite|QIODevice::Append; - m_openModeMaps[QStringLiteral("wb")] = QIODevice::WriteOnly; - m_openModeMaps[QStringLiteral("wt")] = QIODevice::WriteOnly; - m_openModeMaps[QStringLiteral("rb")] = QIODevice::ReadOnly; - m_openModeMaps[QStringLiteral("rt")] = QIODevice::ReadOnly; + m_openModeMaps[QByteArrayLiteral("r")] = QIODevice::ReadOnly; + m_openModeMaps[QByteArrayLiteral("r+")] = QIODevice::ReadWrite; + m_openModeMaps[QByteArrayLiteral("w")] = QIODevice::WriteOnly | QIODevice::Truncate; + m_openModeMaps[QByteArrayLiteral("w+")] = QIODevice::ReadWrite | QIODevice::Truncate; + m_openModeMaps[QByteArrayLiteral("a")] = QIODevice::WriteOnly | QIODevice::Append; + m_openModeMaps[QByteArrayLiteral("a+")] = QIODevice::ReadWrite | QIODevice::Append; + m_openModeMaps[QByteArrayLiteral("wb")] = QIODevice::WriteOnly; + m_openModeMaps[QByteArrayLiteral("wt")] = QIODevice::WriteOnly | QIODevice::Text; + m_openModeMaps[QByteArrayLiteral("rb")] = QIODevice::ReadOnly; + m_openModeMaps[QByteArrayLiteral("rt")] = QIODevice::ReadOnly | QIODevice::Text; } /*! @@ -206,16 +206,16 @@ char AssimpIOSystem::getOsSeparator() const */ Assimp::IOStream *AssimpIOSystem::Open(const char *pFile, const char *pMode) { - QIODevice::OpenMode openMode = QIODevice::NotOpen; - QString cleanedMode = QString::fromUtf8(pMode).trimmed(); - if (m_openModeMaps.contains(cleanedMode)) - openMode = m_openModeMaps[cleanedMode]; + const QString fileName(QString::fromUtf8(pFile)); + const QByteArray cleanedMode(QByteArray(pMode).trimmed()); + + const QIODevice::OpenMode openMode = m_openModeMaps.value(cleanedMode, QIODevice::NotOpen); - QFile *file = new QFile(QString::fromUtf8(pFile)); + QScopedPointer<QFile> file(new QFile(fileName)); if (file->open(openMode)) - return new AssimpIOStream(file); - delete file; - return NULL; + return new AssimpIOStream(file.take()); + + return Q_NULLPTR; } /*! diff --git a/src/plugins/sceneparsers/assimp/assimphelpers_p.h b/src/plugins/sceneparsers/assimp/assimphelpers_p.h index 6e0f1fa17..df5ba179f 100644 --- a/src/plugins/sceneparsers/assimp/assimphelpers_p.h +++ b/src/plugins/sceneparsers/assimp/assimphelpers_p.h @@ -69,7 +69,7 @@ public : void Flush() Q_DECL_OVERRIDE; private: - QIODevice *m_device; + QIODevice *const m_device; }; //CUSTOM FILE IMPORTER TO HANDLE QT RESOURCES WITHIN ASSIMP @@ -84,7 +84,7 @@ public : void Close(Assimp::IOStream *pFile) Q_DECL_OVERRIDE; private: - QMap<QString, QIODevice::OpenMode> m_openModeMaps; + QMap<QByteArray, QIODevice::OpenMode> m_openModeMaps; }; } // AssimpHelper namespace |