From b4954701093739e7a4e54a0669f306922d0d4605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pasi=20Kera=CC=88nen?= Date: Thu, 6 Jun 2019 16:22:02 +0300 Subject: Long live the slayer! MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Initial commit of OpenGL Runtime to repository. Based on SHA1 61823aaccc6510699a54b34a2fe3f7523dab3b4e of qt3dstudio repository. Task-number: QT3DS-3600 Change-Id: Iaeb80237399f0e5656a19ebec9d1ab3a681d8832 Reviewed-by: Pasi Keränen --- src/dm/systems/Qt3DSDMValue.cpp | 178 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 src/dm/systems/Qt3DSDMValue.cpp (limited to 'src/dm/systems/Qt3DSDMValue.cpp') diff --git a/src/dm/systems/Qt3DSDMValue.cpp b/src/dm/systems/Qt3DSDMValue.cpp new file mode 100644 index 0000000..94c5a59 --- /dev/null +++ b/src/dm/systems/Qt3DSDMValue.cpp @@ -0,0 +1,178 @@ +/**************************************************************************** +** +** Copyright (C) 1993-2009 NVIDIA Corporation. +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt 3D Studio. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** 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 General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** 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-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "Qt3DSDMPrefix.h" +#include "Qt3DSDMValue.h" + +#include +#include +#include + +using namespace qt3dsdm; + +SValue::SValue(const QVariant &inData) +{ + switch (inData.type()) { + case QVariant::Bool: + { + *this = inData.toBool(); + break; + } + case QVariant::Color: + { + const QColor c = inData.value(); + *this = qt3dsdm::SFloat4(c.redF(), c.greenF(), c.blueF(), c.alphaF()); + break; + } + case QVariant::String: + { + const QString q = inData.toString(); + const int count = q.size() + 1; +#ifdef __INTEGRITY + wchar_t* tempBuf = reinterpret_cast(malloc(count * sizeof(wchar_t))); +#else + wchar_t* tempBuf = reinterpret_cast(alloca(count * sizeof(wchar_t))); +#endif + tempBuf[count - 1] = 0; + q.toWCharArray(tempBuf); + *this = std::make_shared(tempBuf); +#ifdef __INTEGRITY + free(tempBuf); +#endif + break; + } + case QVariant::Int: { + *this = inData.toInt(); + break; + } + case QVariant::Double: { + *this = inData.toFloat(); + break; + } + + case QVariant::Vector2D: { + const auto v = inData.value(); + *this = qt3dsdm::SFloat2(v.x(), v.y()); + break; + } + + case QVariant::Vector3D: { + const auto v = inData.value(); + *this = qt3dsdm::SFloat3(v.x(), v.y(), v.z()); + break; + } + + default: + qDebug() << "Add a handler for QVariant::type" << inData.type(); + throw std::runtime_error("Cannot transform this QVariant into SValue"); + } +} + +QVariant SValue::toQVariant() const +{ + switch (getType()) { + case DataModelDataType::String: + case DataModelDataType::StringRef: + { + return get(*this); + } + case DataModelDataType::Float: { + return get(*this); + } + case DataModelDataType::Float2: { + return QVariant::fromValue(get(*this)); + } + case DataModelDataType::Float3: { + return QVariant::fromValue(get(*this)); + } + case DataModelDataType::Float4: { + return QVariant::fromValue(get >(*this)); + } + case DataModelDataType::Long: { + return QVariant::fromValue(get(*this)); + } + case DataModelDataType::Bool: { + return get(*this); + } + case DataModelDataType::FloatList: { + //KDAB_TODO + qDebug() << "Add a handler for type DataModelDataType::FloatList"; + return {}; + } + case DataModelDataType::Long4: { + return QVariant::fromValue(get >(*this)); + } + case DataModelDataType::ObjectRef: { + const SObjectRefType &theRef(get(*this)); + switch (theRef.GetReferenceType()) { + case ObjectReferenceType::Absolute: + return SValue(get(theRef.m_Value)).toQVariant(); + break; + case ObjectReferenceType::Relative: + return SValue(get(theRef.m_Value)).toQVariant(); + break; + case ObjectReferenceType::Unknown: + return QVariant::fromValue(QVector()); + break; + } + } + case DataModelDataType::StringOrInt: { + const SStringOrInt &theData(get(*this)); + if (theData.GetType() == SStringOrIntTypes::Int) { + return QVariant::fromValue(get(theData.m_Value)); + } else if (theData.GetType() == SStringOrIntTypes::String) { + auto wideStr = get(theData.m_Value)->GetData(); + return QString::fromWCharArray(wideStr); + } else { + return {}; + } + + } + case DataModelDataType::None: + return {}; + default: + break; + } + return {}; +} + +SInternValue::SInternValue(const SValue &inValue, IStringTable &inStringTable) +{ + if (GetValueType(inValue) == DataModelDataType::StringRef) { + const SStringRef ¤t = get(inValue); + SStringRef newId = inStringTable.RegisterStr(current.m_Id); + m_Value = SValue(newId); + } else { + m_Value = inValue; + } +} + +SInternValue::SInternValue(const SInternValue &inOther) + : m_Value(inOther.m_Value) +{ +} -- cgit v1.2.3