summaryrefslogtreecommitdiffstats
path: root/src/gui/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/util')
-rw-r--r--src/gui/util/qdesktopservices.cpp28
-rw-r--r--src/gui/util/qktxhandler.cpp199
-rw-r--r--src/gui/util/qktxhandler_p.h78
-rw-r--r--src/gui/util/qpkmhandler.cpp126
-rw-r--r--src/gui/util/qpkmhandler_p.h70
-rw-r--r--src/gui/util/qshadergraphloader.cpp15
-rw-r--r--src/gui/util/qshadernodesloader.cpp8
-rw-r--r--src/gui/util/qshadernodesloader_p.h1
-rw-r--r--src/gui/util/qtexturefiledata.cpp280
-rw-r--r--src/gui/util/qtexturefiledata_p.h115
-rw-r--r--src/gui/util/qtexturefilehandler_p.h79
-rw-r--r--src/gui/util/qtexturefilereader.cpp102
-rw-r--r--src/gui/util/qtexturefilereader_p.h88
-rw-r--r--src/gui/util/qvalidator.cpp38
-rw-r--r--src/gui/util/util.pri13
15 files changed, 1213 insertions, 27 deletions
diff --git a/src/gui/util/qdesktopservices.cpp b/src/gui/util/qdesktopservices.cpp
index dfd190ddd0..b6eac91478 100644
--- a/src/gui/util/qdesktopservices.cpp
+++ b/src/gui/util/qdesktopservices.cpp
@@ -141,6 +141,10 @@ void QOpenUrlHandlerRegistry::handlerDestroyed(QObject *handler)
same argument, and it will try to open the URL using the
appropriate mechanism for the user's desktop environment.
+ Combined with platform specific settings, the schemes registered by the
+ openUrl() function can also be exposed to other applications, opening up
+ for application deep linking or a very basic URL-based IPC mechanism.
+
\note Since Qt 5, storageLocation() and displayName() are replaced by functionality
provided by the QStandardPaths class.
@@ -183,12 +187,7 @@ void QOpenUrlHandlerRegistry::handlerDestroyed(QObject *handler)
\l{https://developer.apple.com/documentation/uikit/uiapplication/1622952-canopenurl}{canOpenURL(_:)}.
For example, the following lines enable URLs with the HTTPS scheme:
- \code
- <key>LSApplicationQueriesSchemes</key>
- <array>
- <string>https</string>
- </array>
- \endcode
+ \snippet code/src_gui_util_qdesktopservices.cpp 3
\sa setUrlHandler()
*/
@@ -245,6 +244,14 @@ bool QDesktopServices::openUrl(const QUrl &url)
The provided method must be implemented as a slot that only accepts a single QUrl
argument.
+ To use this function for receiving data from other apps on iOS you also need to
+ add the custom scheme to the \c CFBundleURLSchemes list in your Info.plist file:
+
+ \snippet code/src_gui_util_qdesktopservices.cpp 4
+
+ For more information, see the Apple Developer Documentation for
+ \l{https://developer.apple.com/documentation/uikit/core_app/allowing_apps_and_websites_to_link_to_your_content/communicating_with_other_apps_using_custom_urls?language=objc}{Communicating with Other Apps Using Custom URLs}.
+
If setUrlHandler() is used to set a new handler for a scheme which already
has a handler, the existing handler is simply replaced with the new one.
Since QDesktopServices does not take ownership of handlers, no objects are
@@ -324,14 +331,9 @@ void QDesktopServices::unsetUrlHandler(const QString &scheme)
wasn't called, while in Qt 5 it defaults to the name of the executable.
Therefore, if you still need to access the Qt 4 path (for example for data migration to Qt 5), replace
- \code
- QDesktopServices::storageLocation(QDesktopServices::DataLocation)
- \endcode
+ \snippet code/src_gui_util_qdesktopservices.cpp 5
with
- \code
- QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) +
- "/data/organization/application"
- \endcode
+ \snippet code/src_gui_util_qdesktopservices.cpp 6
(assuming an organization name and an application name were set).
*/
diff --git a/src/gui/util/qktxhandler.cpp b/src/gui/util/qktxhandler.cpp
new file mode 100644
index 0000000000..7eda4c46fb
--- /dev/null
+++ b/src/gui/util/qktxhandler.cpp
@@ -0,0 +1,199 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qktxhandler_p.h"
+#include "qtexturefiledata_p.h"
+#include <QtEndian>
+#include <QSize>
+
+//#define KTX_DEBUG
+#ifdef KTX_DEBUG
+#include <QDebug>
+#include <QMetaEnum>
+#include <QOpenGLTexture>
+#endif
+
+QT_BEGIN_NAMESPACE
+
+#define KTX_IDENTIFIER_LENGTH 12
+static const char ktxIdentifier[KTX_IDENTIFIER_LENGTH] = { '\xAB', 'K', 'T', 'X', ' ', '1', '1', '\xBB', '\r', '\n', '\x1A', '\n' };
+static const quint32 platformEndianIdentifier = 0x04030201;
+static const quint32 inversePlatformEndianIdentifier = 0x01020304;
+
+struct KTXHeader {
+ quint8 identifier[KTX_IDENTIFIER_LENGTH]; // Must match ktxIdentifier
+ quint32 endianness; // Either platformEndianIdentifier or inversePlatformEndianIdentifier, other values not allowed.
+ quint32 glType;
+ quint32 glTypeSize;
+ quint32 glFormat;
+ quint32 glInternalFormat;
+ quint32 glBaseInternalFormat;
+ quint32 pixelWidth;
+ quint32 pixelHeight;
+ quint32 pixelDepth;
+ quint32 numberOfArrayElements;
+ quint32 numberOfFaces;
+ quint32 numberOfMipmapLevels;
+ quint32 bytesOfKeyValueData;
+};
+
+static const quint32 headerSize = sizeof(KTXHeader);
+
+// Currently unused, declared for future reference
+struct KTXKeyValuePairItem {
+ quint32 keyAndValueByteSize;
+ /*
+ quint8 keyAndValue[keyAndValueByteSize];
+ quint8 valuePadding[3 - ((keyAndValueByteSize + 3) % 4)];
+ */
+};
+
+struct KTXMipmapLevel {
+ quint32 imageSize;
+ /*
+ for each array_element in numberOfArrayElements*
+ for each face in numberOfFaces
+ for each z_slice in pixelDepth*
+ for each row or row_of_blocks in pixelHeight*
+ for each pixel or block_of_pixels in pixelWidth
+ Byte data[format-specific-number-of-bytes]**
+ end
+ end
+ end
+ Byte cubePadding[0-3]
+ end
+ end
+ quint8 mipPadding[3 - ((imageSize + 3) % 4)]
+ */
+};
+
+bool QKtxHandler::canRead(const QByteArray &suffix, const QByteArray &block)
+{
+ Q_UNUSED(suffix)
+
+ return (qstrncmp(block.constData(), ktxIdentifier, KTX_IDENTIFIER_LENGTH) == 0);
+}
+
+QTextureFileData QKtxHandler::read()
+{
+ if (!device())
+ return QTextureFileData();
+
+ QByteArray buf = device()->readAll();
+ const quint32 dataSize = quint32(buf.size());
+ if (dataSize < headerSize || !canRead(QByteArray(), buf)) {
+ qCDebug(lcQtGuiTextureIO, "Invalid KTX file %s", logName().constData());
+ return QTextureFileData();
+ }
+
+ const KTXHeader *header = reinterpret_cast<const KTXHeader *>(buf.constData());
+ if (!checkHeader(*header)) {
+ qCDebug(lcQtGuiTextureIO, "Unsupported KTX file format in %s", logName().constData());
+ return QTextureFileData();
+ }
+
+ QTextureFileData texData;
+ texData.setData(buf);
+
+ texData.setSize(QSize(decode(header->pixelWidth), decode(header->pixelHeight)));
+ texData.setGLFormat(decode(header->glFormat));
+ texData.setGLInternalFormat(decode(header->glInternalFormat));
+ texData.setGLBaseInternalFormat(decode(header->glBaseInternalFormat));
+
+ texData.setNumLevels(decode(header->numberOfMipmapLevels));
+ quint32 offset = headerSize + decode(header->bytesOfKeyValueData);
+ const int maxLevels = qMin(texData.numLevels(), 32); // Cap iterations in case of corrupt file.
+ for (int i = 0; i < maxLevels; i++) {
+ if (offset + sizeof(KTXMipmapLevel) > dataSize) // Corrupt file; avoid oob read
+ break;
+ const KTXMipmapLevel *level = reinterpret_cast<const KTXMipmapLevel *>(buf.constData() + offset);
+ quint32 levelLen = decode(level->imageSize);
+ texData.setDataOffset(offset + sizeof(KTXMipmapLevel::imageSize), i);
+ texData.setDataLength(levelLen, i);
+ offset += sizeof(KTXMipmapLevel::imageSize) + levelLen + (3 - ((levelLen + 3) % 4));
+ }
+
+ if (!texData.isValid()) {
+ qCDebug(lcQtGuiTextureIO, "Invalid values in header of KTX file %s", logName().constData());
+ return QTextureFileData();
+ }
+
+ texData.setLogName(logName());
+
+#ifdef KTX_DEBUG
+ qDebug() << "KTX file handler read" << texData;
+#endif
+
+ return texData;
+}
+
+bool QKtxHandler::checkHeader(const KTXHeader &header)
+{
+ if (header.endianness != platformEndianIdentifier && header.endianness != inversePlatformEndianIdentifier)
+ return false;
+ inverseEndian = (header.endianness == inversePlatformEndianIdentifier);
+#ifdef KTX_DEBUG
+ QMetaEnum tfme = QMetaEnum::fromType<QOpenGLTexture::TextureFormat>();
+ QMetaEnum ptme = QMetaEnum::fromType<QOpenGLTexture::PixelType>();
+ qDebug("Header of %s:", logName().constData());
+ qDebug(" glType: 0x%x (%s)", decode(header.glType), ptme.valueToKey(decode(header.glType)));
+ qDebug(" glTypeSize: %u", decode(header.glTypeSize));
+ qDebug(" glFormat: 0x%x (%s)", decode(header.glFormat), tfme.valueToKey(decode(header.glFormat)));
+ qDebug(" glInternalFormat: 0x%x (%s)", decode(header.glInternalFormat), tfme.valueToKey(decode(header.glInternalFormat)));
+ qDebug(" glBaseInternalFormat: 0x%x (%s)", decode(header.glBaseInternalFormat), tfme.valueToKey(decode(header.glBaseInternalFormat)));
+ qDebug(" pixelWidth: %u", decode(header.pixelWidth));
+ qDebug(" pixelHeight: %u", decode(header.pixelHeight));
+ qDebug(" pixelDepth: %u", decode(header.pixelDepth));
+ qDebug(" numberOfArrayElements: %u", decode(header.numberOfArrayElements));
+ qDebug(" numberOfFaces: %u", decode(header.numberOfFaces));
+ qDebug(" numberOfMipmapLevels: %u", decode(header.numberOfMipmapLevels));
+ qDebug(" bytesOfKeyValueData: %u", decode(header.bytesOfKeyValueData));
+#endif
+ return ((decode(header.glType) == 0) &&
+ (decode(header.glFormat) == 0) &&
+ (decode(header.pixelDepth) == 0) &&
+ (decode(header.numberOfFaces) == 1));
+}
+
+quint32 QKtxHandler::decode(quint32 val)
+{
+ return inverseEndian ? qbswap<quint32>(val) : val;
+}
+
+QT_END_NAMESPACE
diff --git a/src/gui/util/qktxhandler_p.h b/src/gui/util/qktxhandler_p.h
new file mode 100644
index 0000000000..19f7b0e79a
--- /dev/null
+++ b/src/gui/util/qktxhandler_p.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QKTXHANDLER_H
+#define QKTXHANDLER_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qtexturefilehandler_p.h"
+
+QT_BEGIN_NAMESPACE
+
+struct KTXHeader;
+
+class QKtxHandler : public QTextureFileHandler
+{
+public:
+ using QTextureFileHandler::QTextureFileHandler;
+
+ static bool canRead(const QByteArray &suffix, const QByteArray &block);
+
+ QTextureFileData read() override;
+
+private:
+ bool checkHeader(const KTXHeader &header);
+ quint32 decode(quint32 val);
+
+ bool inverseEndian = false;
+};
+
+QT_END_NAMESPACE
+
+#endif // QKTXHANDLER_H
diff --git a/src/gui/util/qpkmhandler.cpp b/src/gui/util/qpkmhandler.cpp
new file mode 100644
index 0000000000..e0c3b75efe
--- /dev/null
+++ b/src/gui/util/qpkmhandler.cpp
@@ -0,0 +1,126 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qpkmhandler_p.h"
+#include "qtexturefiledata_p.h"
+
+#include <QFile>
+#include <QDebug>
+#include <QSize>
+#include <qendian.h>
+
+//#define ETC_DEBUG
+
+QT_BEGIN_NAMESPACE
+
+static const int headerSize = 16;
+
+struct PkmType
+{
+ quint32 glFormat;
+ quint32 bytesPerBlock;
+};
+
+static PkmType typeMap[5] = {
+ { 0x8D64, 8 }, // GL_ETC1_RGB8_OES
+ { 0x9274, 8 }, // GL_COMPRESSED_RGB8_ETC2
+ { 0, 0 }, // unused (obsolete)
+ { 0x9278, 16}, // GL_COMPRESSED_RGBA8_ETC2_EAC
+ { 0x9276, 8 } // GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
+};
+
+bool QPkmHandler::canRead(const QByteArray &suffix, const QByteArray &block)
+{
+ Q_UNUSED(suffix)
+
+ return block.startsWith("PKM ");
+}
+
+QTextureFileData QPkmHandler::read()
+{
+ QTextureFileData texData;
+
+ if (!device())
+ return texData;
+
+ QByteArray fileData = device()->readAll();
+ if (fileData.size() < headerSize || !canRead(QByteArray(), fileData)) {
+ qCDebug(lcQtGuiTextureIO, "Invalid PKM file %s", logName().constData());
+ return QTextureFileData();
+ }
+ texData.setData(fileData);
+
+ const char *rawData = fileData.constData();
+
+ // ignore version (rawData + 4 & 5)
+
+ // texture type
+ quint16 type = qFromBigEndian<quint16>(rawData + 6);
+ if (type >= sizeof(typeMap)/sizeof(typeMap[0])) {
+ qCDebug(lcQtGuiTextureIO, "Unknown compression format in PKM file %s", logName().constData());
+ return QTextureFileData();
+ }
+ texData.setGLFormat(0); // 0 for compressed textures
+ texData.setGLInternalFormat(typeMap[type].glFormat);
+ //### setBaseInternalFormat
+
+ // texture size
+ texData.setNumLevels(1);
+ const int bpb = typeMap[type].bytesPerBlock;
+ QSize paddedSize(qFromBigEndian<quint16>(rawData + 8), qFromBigEndian<quint16>(rawData + 10));
+ texData.setDataLength((paddedSize.width() / 4) * (paddedSize.height() / 4) * bpb);
+ QSize texSize(qFromBigEndian<quint16>(rawData + 12), qFromBigEndian<quint16>(rawData + 14));
+ texData.setSize(texSize);
+
+ texData.setDataOffset(headerSize);
+
+ if (!texData.isValid()) {
+ qCDebug(lcQtGuiTextureIO, "Invalid values in header of PKM file %s", logName().constData());
+ return QTextureFileData();
+ }
+
+ texData.setLogName(logName());
+
+#ifdef ETC_DEBUG
+ qDebug() << "PKM file handler read" << texData;
+#endif
+ return texData;
+}
+
+QT_END_NAMESPACE
diff --git a/src/gui/util/qpkmhandler_p.h b/src/gui/util/qpkmhandler_p.h
new file mode 100644
index 0000000000..2f7618bc53
--- /dev/null
+++ b/src/gui/util/qpkmhandler_p.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QPKMHANDLER_H
+#define QPKMHANDLER_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qtexturefilehandler_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QPkmHandler : public QTextureFileHandler
+{
+public:
+ using QTextureFileHandler::QTextureFileHandler;
+
+ static bool canRead(const QByteArray &suffix, const QByteArray &block);
+
+ QTextureFileData read() override;
+};
+
+QT_END_NAMESPACE
+
+#endif // QPKMHANDLER_H
diff --git a/src/gui/util/qshadergraphloader.cpp b/src/gui/util/qshadergraphloader.cpp
index 8d92c73a5a..99a9f7869e 100644
--- a/src/gui/util/qshadergraphloader.cpp
+++ b/src/gui/util/qshadergraphloader.cpp
@@ -39,6 +39,8 @@
#include "qshadergraphloader_p.h"
+#include "qshadernodesloader_p.h"
+
#include <QtCore/qdebug.h>
#include <QtCore/qiodevice.h>
#include <QtCore/qjsonarray.h>
@@ -129,6 +131,19 @@ void QShaderGraphLoader::load()
bool hasError = false;
+ const auto prototypesValue = root.value(QStringLiteral("prototypes"));
+ if (!prototypesValue.isUndefined()) {
+ if (prototypesValue.isObject()) {
+ QShaderNodesLoader loader;
+ loader.load(prototypesValue.toObject());
+ m_prototypes.unite(loader.nodes());
+ } else {
+ qWarning() << "Invalid prototypes property, should be an object";
+ m_status = Error;
+ return;
+ }
+ }
+
const auto nodes = nodesValue.toArray();
for (const auto &nodeValue : nodes) {
if (!nodeValue.isObject()) {
diff --git a/src/gui/util/qshadernodesloader.cpp b/src/gui/util/qshadernodesloader.cpp
index db34b6d44d..692653ee44 100644
--- a/src/gui/util/qshadernodesloader.cpp
+++ b/src/gui/util/qshadernodesloader.cpp
@@ -99,11 +99,15 @@ void QShaderNodesLoader::load()
}
const auto root = document.object();
+ load(root);
+}
+void QShaderNodesLoader::load(const QJsonObject &prototypesObject)
+{
bool hasError = false;
- for (const auto &property : root.keys()) {
- const auto nodeValue = root.value(property);
+ for (const auto &property : prototypesObject.keys()) {
+ const auto nodeValue = prototypesObject.value(property);
if (!nodeValue.isObject()) {
qWarning() << "Invalid node found";
hasError = true;
diff --git a/src/gui/util/qshadernodesloader_p.h b/src/gui/util/qshadernodesloader_p.h
index 2696e958b6..0bec871857 100644
--- a/src/gui/util/qshadernodesloader_p.h
+++ b/src/gui/util/qshadernodesloader_p.h
@@ -78,6 +78,7 @@ public:
Q_GUI_EXPORT void setDevice(QIODevice *device) Q_DECL_NOTHROW;
Q_GUI_EXPORT void load();
+ Q_GUI_EXPORT void load(const QJsonObject &prototypesObject);
private:
Status m_status;
diff --git a/src/gui/util/qtexturefiledata.cpp b/src/gui/util/qtexturefiledata.cpp
new file mode 100644
index 0000000000..ebf46f8e4e
--- /dev/null
+++ b/src/gui/util/qtexturefiledata.cpp
@@ -0,0 +1,280 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qtexturefiledata_p.h"
+#include <QMetaEnum>
+#include <QSize>
+#if QT_CONFIG(opengl)
+#include <QOpenGLTexture>
+#endif
+
+QT_BEGIN_NAMESPACE
+
+Q_LOGGING_CATEGORY(lcQtGuiTextureIO, "qt.gui.textureio");
+
+class QTextureFileDataPrivate : public QSharedData
+{
+public:
+ QTextureFileDataPrivate()
+ {
+ }
+
+ QTextureFileDataPrivate(const QTextureFileDataPrivate &other)
+ : QSharedData(other),
+ logName(other.logName),
+ data(other.data),
+ offsets(other.offsets),
+ lengths(other.lengths),
+ size(other.size),
+ format(other.format)
+ {
+ }
+
+ ~QTextureFileDataPrivate()
+ {
+ }
+
+ void ensureLevels(int num, bool force = false)
+ {
+ const int newSize = force ? num : qMax(offsets.size(), num);
+ offsets.resize(newSize);
+ lengths.resize(newSize);
+ }
+
+ QByteArray logName;
+ QByteArray data;
+ QVector<int> offsets;
+ QVector<int> lengths;
+ QSize size;
+ quint32 format = 0;
+ quint32 internalFormat = 0;
+ quint32 baseInternalFormat = 0;
+};
+
+
+
+QTextureFileData::QTextureFileData()
+{
+}
+
+QTextureFileData::QTextureFileData(const QTextureFileData &other)
+ : d(other.d)
+{
+}
+
+QTextureFileData &QTextureFileData::operator=(const QTextureFileData &other)
+{
+ d = other.d;
+ return *this;
+}
+
+QTextureFileData::~QTextureFileData()
+{
+}
+
+bool QTextureFileData::isNull() const
+{
+ return !d;
+}
+
+bool QTextureFileData::isValid() const
+{
+ if (!d)
+ return false;
+
+ if (d->data.isEmpty() || d->size.isEmpty() || (!d->format && !d->internalFormat))
+ return false;
+
+ const int numChunks = d->offsets.size();
+ if (numChunks == 0 || (d->lengths.size() != numChunks))
+ return false;
+
+ const qint64 sz = d->data.size();
+ for (int i = 0; i < numChunks; i++) {
+ qint64 offi = d->offsets.at(i);
+ qint64 leni = d->lengths.at(i);
+ if (offi < 0 || offi >= sz || leni <= 0 || (offi + leni > sz))
+ return false;
+ }
+ return true;
+}
+
+void QTextureFileData::clear()
+{
+ d = nullptr;
+}
+
+QByteArray QTextureFileData::data() const
+{
+ return d ? d->data : QByteArray();
+}
+
+void QTextureFileData::setData(const QByteArray &data)
+{
+ if (!d.constData()) //### uh think about this design, this is the only way to create; should be constructor instead at least
+ d = new QTextureFileDataPrivate;
+
+ d->data = data;
+}
+
+int QTextureFileData::dataOffset(int level) const
+{
+ return (d && d->offsets.size() > level) ? d->offsets.at(level) : 0;
+}
+
+void QTextureFileData::setDataOffset(int offset, int level)
+{
+ if (d.constData() && level >= 0) {
+ d->ensureLevels(level + 1);
+ d->offsets[level] = offset;
+ }
+}
+
+int QTextureFileData::dataLength(int level) const
+{
+ return (d && d->lengths.size() > level) ? d->lengths.at(level) : 0;
+}
+
+void QTextureFileData::setDataLength(int length, int level)
+{
+ if (d.constData() && level >= 0) {
+ d->ensureLevels(level + 1);
+ d->lengths[level] = length;
+ }
+}
+
+int QTextureFileData::numLevels() const
+{
+ return d ? d->offsets.size() : 0;
+}
+
+void QTextureFileData::setNumLevels(int num)
+{
+ if (d && num >= 0)
+ d->ensureLevels(num, true);
+}
+
+QSize QTextureFileData::size() const
+{
+ return d ? d->size : QSize();
+}
+
+void QTextureFileData::setSize(const QSize &size)
+{
+ if (d.constData())
+ d->size = size;
+}
+
+quint32 QTextureFileData::glFormat() const
+{
+ return d ? d->format : 0;
+}
+
+void QTextureFileData::setGLFormat(quint32 format)
+{
+ if (d.constData())
+ d->format = format;
+}
+
+quint32 QTextureFileData::glInternalFormat() const
+{
+ return d ? d->internalFormat : 0;
+}
+
+void QTextureFileData::setGLInternalFormat(quint32 format)
+{
+ if (d.constData())
+ d->internalFormat = format;
+}
+
+quint32 QTextureFileData::glBaseInternalFormat() const
+{
+ return d ? d->baseInternalFormat : 0;
+}
+
+void QTextureFileData::setGLBaseInternalFormat(quint32 format)
+{
+ if (d.constData())
+ d->baseInternalFormat = format;
+}
+
+QByteArray QTextureFileData::logName() const
+{
+ return d ? d->logName : QByteArray();
+}
+
+void QTextureFileData::setLogName(const QByteArray &name)
+{
+ if (d.constData())
+ d->logName = name;
+}
+
+static QByteArray glFormatName(quint32 fmt)
+{
+ const char *id = 0;
+#if QT_CONFIG(opengl)
+ id = QMetaEnum::fromType<QOpenGLTexture::TextureFormat>().valueToKey(fmt);
+#endif
+ QByteArray res(id ? id : "(?)");
+ res += " [0x" + QByteArray::number(fmt, 16).rightJustified(4, '0') + ']';
+ return res;
+}
+
+QDebug operator<<(QDebug dbg, const QTextureFileData &d)
+{
+ QDebugStateSaver saver(dbg);
+
+ dbg.nospace() << "QTextureFileData(";
+ if (!d.isNull()) {
+ dbg.space() << d.logName() << d.size();
+ dbg << "glFormat:" << glFormatName(d.glFormat());
+ dbg << "glInternalFormat:" << glFormatName(d.glInternalFormat());
+ dbg << "glBaseInternalFormat:" << glFormatName(d.glBaseInternalFormat());
+ dbg.nospace() << "Levels: " << d.numLevels();
+ if (!d.isValid())
+ dbg << " {Invalid}";
+ dbg << ")";
+ } else {
+ dbg << "null)";
+ }
+
+ return dbg;
+}
+
+QT_END_NAMESPACE
diff --git a/src/gui/util/qtexturefiledata_p.h b/src/gui/util/qtexturefiledata_p.h
new file mode 100644
index 0000000000..2df23de33c
--- /dev/null
+++ b/src/gui/util/qtexturefiledata_p.h
@@ -0,0 +1,115 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QTEXTUREFILEDATA_P_H
+#define QTEXTUREFILEDATA_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtGui/qtguiglobal.h>
+#include <QSharedDataPointer>
+#include <QLoggingCategory>
+#include <QDebug>
+
+QT_BEGIN_NAMESPACE
+
+Q_DECLARE_LOGGING_CATEGORY(lcQtGuiTextureIO)
+
+class QTextureFileDataPrivate;
+
+class Q_GUI_EXPORT QTextureFileData
+{
+public:
+ QTextureFileData();
+ QTextureFileData(const QTextureFileData &other);
+ QTextureFileData &operator=(const QTextureFileData &other);
+ ~QTextureFileData();
+
+ bool isNull() const;
+ bool isValid() const;
+
+ void clear();
+
+ QByteArray data() const;
+ void setData(const QByteArray &data);
+
+ int dataOffset(int level = 0) const;
+ void setDataOffset(int offset, int level = 0);
+
+ int dataLength(int level = 0) const;
+ void setDataLength(int length, int level = 0);
+
+ int numLevels() const;
+ void setNumLevels(int num);
+
+ QSize size() const;
+ void setSize(const QSize &size);
+
+ quint32 glFormat() const;
+ void setGLFormat(quint32 format);
+
+ quint32 glInternalFormat() const;
+ void setGLInternalFormat(quint32 format);
+
+ quint32 glBaseInternalFormat() const;
+ void setGLBaseInternalFormat(quint32 format);
+
+ QByteArray logName() const;
+ void setLogName(const QByteArray &name);
+
+private:
+ QSharedDataPointer<QTextureFileDataPrivate> d;
+};
+
+Q_DECLARE_TYPEINFO(QTextureFileData, Q_MOVABLE_TYPE);
+
+Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QTextureFileData &d);
+
+QT_END_NAMESPACE
+
+#endif // QABSTRACTLAYOUTSTYLEINFO_P_H
diff --git a/src/gui/util/qtexturefilehandler_p.h b/src/gui/util/qtexturefilehandler_p.h
new file mode 100644
index 0000000000..b808d3e7db
--- /dev/null
+++ b/src/gui/util/qtexturefilehandler_p.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QTEXTUREFILEHANDLER_P_H
+#define QTEXTUREFILEHANDLER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qtexturefiledata_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QTextureFileHandler
+{
+public:
+ QTextureFileHandler(QIODevice *device, const QByteArray &logName = QByteArray())
+ : m_device(device)
+ {
+ m_logName = !logName.isEmpty() ? logName : QByteArrayLiteral("(unknown)");
+ }
+ virtual ~QTextureFileHandler() {}
+
+ virtual QTextureFileData read() = 0;
+ QIODevice *device() const { return m_device; }
+ QByteArray logName() const { return m_logName; }
+
+private:
+ QIODevice *m_device = nullptr;
+ QByteArray m_logName;
+};
+
+QT_END_NAMESPACE
+
+#endif // QTEXTUREFILEHANDLER_P_H
diff --git a/src/gui/util/qtexturefilereader.cpp b/src/gui/util/qtexturefilereader.cpp
new file mode 100644
index 0000000000..5d4bd600e0
--- /dev/null
+++ b/src/gui/util/qtexturefilereader.cpp
@@ -0,0 +1,102 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qtexturefilereader_p.h"
+
+#include "qpkmhandler_p.h"
+#include "qktxhandler_p.h"
+
+#include <QFileInfo>
+
+QT_BEGIN_NAMESPACE
+
+QTextureFileReader::QTextureFileReader(QIODevice *device, const QString &fileName)
+ : m_device(device), m_fileName(fileName)
+{
+}
+
+QTextureFileReader::~QTextureFileReader()
+{
+ delete m_handler;
+}
+
+QTextureFileData QTextureFileReader::read()
+{
+ if (!canRead())
+ return QTextureFileData();
+ return m_handler->read();
+}
+
+bool QTextureFileReader::canRead()
+{
+ if (!checked) {
+ checked = true;
+ if (!init())
+ return false;
+
+ QByteArray headerBlock = m_device->peek(64);
+ QFileInfo fi(m_fileName);
+ QByteArray suffix = fi.suffix().toLower().toLatin1();
+ QByteArray logName = fi.fileName().toUtf8();
+
+ // Currently the handlers are hardcoded; later maybe a list of plugins
+ if (QPkmHandler::canRead(suffix, headerBlock)) {
+ m_handler = new QPkmHandler(m_device, logName);
+ } else if (QKtxHandler::canRead(suffix, headerBlock)) {
+ m_handler = new QKtxHandler(m_device, logName);
+ }
+ // else if OtherHandler::canRead() ...etc.
+ }
+ return (m_handler != nullptr);
+}
+
+QList<QByteArray> QTextureFileReader::supportedFileFormats()
+{
+ // Hardcoded for now
+ return {QByteArrayLiteral("pkm"), QByteArrayLiteral("ktx")};
+}
+
+bool QTextureFileReader::init()
+{
+ if (!m_device)
+ return false;
+ return m_device->isReadable();
+}
+
+QT_END_NAMESPACE
diff --git a/src/gui/util/qtexturefilereader_p.h b/src/gui/util/qtexturefilereader_p.h
new file mode 100644
index 0000000000..2ec0b0cc49
--- /dev/null
+++ b/src/gui/util/qtexturefilereader_p.h
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QTEXTUREFILEREADER_H
+#define QTEXTUREFILEREADER_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qtexturefiledata_p.h"
+#include <QString>
+#include <QFileInfo>
+
+QT_BEGIN_NAMESPACE
+
+class QIODevice;
+class QTextureFileHandler;
+
+class Q_GUI_EXPORT QTextureFileReader
+{
+public:
+ QTextureFileReader(QIODevice *device, const QString &fileName = QString()); //### drop this logname thing?
+ ~QTextureFileReader();
+
+ bool canRead();
+ QTextureFileData read();
+
+ // TBD access function to params
+ // TBD ask for identified fmt
+
+ static QList<QByteArray> supportedFileFormats();
+
+private:
+ bool init();
+ QIODevice *m_device = nullptr;
+ QString m_fileName;
+ QTextureFileHandler *m_handler = nullptr;
+ bool checked = false;
+};
+
+QT_END_NAMESPACE
+
+
+#endif // QTEXTUREFILEREADER_H
diff --git a/src/gui/util/qvalidator.cpp b/src/gui/util/qvalidator.cpp
index 7982ad967e..2237b016e9 100644
--- a/src/gui/util/qvalidator.cpp
+++ b/src/gui/util/qvalidator.cpp
@@ -411,13 +411,15 @@ QValidator::State QIntValidator::validate(QString & input, int&) const
if (buff.isEmpty())
return Intermediate;
- if (b >= 0 && buff.startsWith('-'))
+ const bool startsWithMinus(buff[0] == '-');
+ if (b >= 0 && startsWithMinus)
return Invalid;
- if (t < 0 && buff.startsWith('+'))
+ const bool startsWithPlus(buff[0] == '+');
+ if (t < 0 && startsWithPlus)
return Invalid;
- if (buff.size() == 1 && (buff.at(0) == '+' || buff.at(0) == '-'))
+ if (buff.size() == 1 && (startsWithPlus || startsWithMinus))
return Intermediate;
bool ok;
@@ -433,7 +435,15 @@ QValidator::State QIntValidator::validate(QString & input, int&) const
if (entered >= 0) {
// the -entered < b condition is necessary to allow people to type
// the minus last (e.g. for right-to-left languages)
- return (entered > t && -entered < b) ? Invalid : Intermediate;
+ // The buffLength > tLength condition validates values consisting
+ // of a number of digits equal to or less than the max value as intermediate.
+
+ int buffLength = buff.size();
+ if (startsWithPlus)
+ buffLength--;
+ const int tLength = t != 0 ? static_cast<int>(std::log10(qAbs(t))) + 1 : 1;
+
+ return (entered > t && -entered < b && buffLength > tLength) ? Invalid : Intermediate;
} else {
return (entered < b) ? Invalid : Intermediate;
}
@@ -624,10 +634,10 @@ QDoubleValidator::~QDoubleValidator()
that is within the valid range and is in the correct format.
Returns \l Intermediate if \a input contains a double that is
- outside the range or is in the wrong format; e.g. with too many
- digits after the decimal point or is empty.
+ outside the range or is in the wrong format; e.g. is empty.
- Returns \l Invalid if the \a input is not a double.
+ Returns \l Invalid if the \a input is not a double or with too many
+ digits after the decimal point.
Note: If the valid range consists of just positive doubles (e.g. 0.0 to 100.0)
and \a input is a negative double then \l Invalid is returned. If notation()
@@ -690,8 +700,16 @@ QValidator::State QDoubleValidatorPrivate::validateWithLocale(QString &input, QL
if (notation == QDoubleValidator::StandardNotation) {
double max = qMax(qAbs(q->b), qAbs(q->t));
if (max < LLONG_MAX) {
- qlonglong n = pow10(numDigits(qlonglong(max))) - 1;
- if (qAbs(i) > n)
+ qlonglong n = pow10(numDigits(qlonglong(max)));
+ // In order to get the highest possible number in the intermediate
+ // range we need to get 10 to the power of the number of digits
+ // after the decimal's and subtract that from the top number.
+ //
+ // For example, where q->dec == 2 and with a range of 0.0 - 9.0
+ // then the minimum possible number is 0.00 and the maximum
+ // possible is 9.99. Therefore 9.999 and 10.0 should be seen as
+ // invalid.
+ if (qAbs(i) > (n - std::pow(10, -q->dec)))
return QValidator::Invalid;
}
}
@@ -1061,7 +1079,7 @@ void QRegularExpressionValidatorPrivate::setRegularExpression(const QRegularExpr
if (origRe != re) {
usedRe = origRe = re; // copies also the pattern options
- usedRe.setPattern(QLatin1String("\\A(?:") + re.pattern() + QLatin1String(")\\z"));
+ usedRe.setPattern(QRegularExpression::anchoredPattern(re.pattern()));
emit q->regularExpressionChanged(re);
emit q->changed();
}
diff --git a/src/gui/util/util.pri b/src/gui/util/util.pri
index cf3cbee48e..6324642505 100644
--- a/src/gui/util/util.pri
+++ b/src/gui/util/util.pri
@@ -14,7 +14,12 @@ HEADERS += \
util/qshaderlanguage_p.h \
util/qshadernode_p.h \
util/qshadernodeport_p.h \
- util/qshadernodesloader_p.h
+ util/qshadernodesloader_p.h \
+ util/qtexturefiledata_p.h \
+ util/qtexturefilereader_p.h \
+ util/qtexturefilehandler_p.h \
+ util/qpkmhandler_p.h \
+ util/qktxhandler_p.h
SOURCES += \
util/qdesktopservices.cpp \
@@ -29,4 +34,8 @@ SOURCES += \
util/qshaderlanguage.cpp \
util/qshadernode.cpp \
util/qshadernodeport.cpp \
- util/qshadernodesloader.cpp
+ util/qshadernodesloader.cpp \
+ util/qtexturefiledata.cpp \
+ util/qtexturefilereader.cpp \
+ util/qpkmhandler.cpp \
+ util/qktxhandler.cpp