Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qtexturefilereader.cpp
Go to the documentation of this file.
1// Copyright (C) 2018 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5
6#include "qpkmhandler_p.h"
7#include "qktxhandler_p.h"
8#include "qastchandler_p.h"
9
10#include <QFileInfo>
11
13
15
20
22{
23 delete m_handler;
24}
25
27{
28 if (!canRead())
29 return QTextureFileData();
30 return m_handler->read();
31}
32
34{
35 if (!checked) {
36 checked = true;
37 if (!init())
38 return false;
39
40 QByteArray headerBlock = m_device->peek(64);
41 QFileInfo fi(m_fileName);
42 QByteArray suffix = fi.suffix().toLower().toLatin1();
43 QByteArray logName = fi.fileName().toUtf8();
44
45 // Currently the handlers are hardcoded; later maybe a list of plugins
46 if (QPkmHandler::canRead(suffix, headerBlock)) {
47 m_handler = new QPkmHandler(m_device, logName);
48 } else if (QKtxHandler::canRead(suffix, headerBlock)) {
49 m_handler = new QKtxHandler(m_device, logName);
50 } else if (QAstcHandler::canRead(suffix, headerBlock)) {
51 m_handler = new QAstcHandler(m_device, logName);
52 }
53 // else if OtherHandler::canRead() ...etc.
54 }
55 return (m_handler != nullptr);
56}
57
59{
60 // Hardcoded for now
61 return {QByteArrayLiteral("pkm"), QByteArrayLiteral("ktx"), QByteArrayLiteral("astc")};
62}
63
64bool QTextureFileReader::init()
65{
66 if (!m_device)
67 return false;
68 return m_device->isReadable();
69}
70
IOBluetoothDevice * device
static bool canRead(const QByteArray &suffix, const QByteArray &block)
\inmodule QtCore
Definition qbytearray.h:57
QByteArray toLower() const &
Definition qbytearray.h:254
\inmodule QtCore \reentrant
Definition qiodevice.h:34
bool isReadable() const
Returns true if data can be read from the device; otherwise returns false.
qint64 peek(char *data, qint64 maxlen)
static bool canRead(const QByteArray &suffix, const QByteArray &block)
static bool canRead(const QByteArray &suffix, const QByteArray &block)
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
virtual ~QTextureFileHandler()
virtual QTextureFileData read()=0
QTextureFileReader(QIODevice *device, const QString &fileName=QString())
QTextureFileData read()
static QList< QByteArray > supportedFileFormats()
Combined button and popup list for selecting options.
#define QByteArrayLiteral(str)
Definition qbytearray.h:52