File indexing completed on 2024-06-30 05:51:26
0001 /* 0002 This file is part of the Okteta Kasten Framework, made within the KDE community. 0003 0004 SPDX-FileCopyrightText: 2011 Alex Richardson <alex.richardson@gmx.de> 0005 0006 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0007 */ 0008 0009 #ifndef KASTEN_UINTDATAINFORMATION_HPP 0010 #define KASTEN_UINTDATAINFORMATION_HPP 0011 0012 #include "primitivedatainformation.hpp" 0013 #include "structureviewpreferences.hpp" 0014 #include "../../allprimitivetypes.hpp" 0015 0016 template <typename T> 0017 class UIntDataInformationMethods 0018 { 0019 public: 0020 static QScriptValue asScriptValue(T value, QScriptEngine* engine, ScriptHandlerInfo* handler); 0021 static QString staticValueString(T val, int base = Kasten::StructureViewPreferences::unsignedDisplayBase()); 0022 static PrimitiveDataType staticType(); 0023 static T fromVariant(const QVariant& value, bool* ok); 0024 static QVariant staticToQVariant(T value); 0025 0026 static QWidget* staticCreateEditWidget(QWidget* parent); 0027 static QVariant staticDataFromWidget(const QWidget* w); 0028 static void staticSetWidgetData(T value, QWidget* w); 0029 }; 0030 0031 template <> 0032 inline PrimitiveDataType UIntDataInformationMethods<quint8>::staticType() { return PrimitiveDataType::UInt8; } 0033 template <> 0034 inline PrimitiveDataType UIntDataInformationMethods<quint16>::staticType() { return PrimitiveDataType::UInt16; } 0035 template <> 0036 inline PrimitiveDataType UIntDataInformationMethods<quint32>::staticType() { return PrimitiveDataType::UInt32; } 0037 template <> 0038 inline PrimitiveDataType UIntDataInformationMethods<quint64>::staticType() { return PrimitiveDataType::UInt64; } 0039 0040 template <typename T> 0041 inline QVariant UIntDataInformationMethods<T>::staticToQVariant(T value) 0042 { 0043 return QVariant(value); 0044 } 0045 0046 template <typename T> 0047 inline T UIntDataInformationMethods<T>::fromVariant(const QVariant& value, bool* ok) 0048 { 0049 Q_CHECK_PTR(ok); 0050 quint64 val = value.toULongLong(ok); 0051 T result = T(val); 0052 if (val != quint64(result)) { 0053 *ok = false; 0054 } 0055 return result; 0056 } 0057 0058 #endif // KASTEN_UINTDATAINFORMATION_HPP