File indexing completed on 2024-06-30 05:51:24
0001 /* 0002 This file is part of the Okteta Kasten Framework, made within the KDE community. 0003 0004 SPDX-FileCopyrightText: 2009, 2010, 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_CHARDATAINFORMATION_HPP 0010 #define KASTEN_CHARDATAINFORMATION_HPP 0011 0012 #include "primitivedatainformation.hpp" 0013 0014 class CharDataInformationMethods 0015 { 0016 public: 0017 static QString staticValueString(quint8 value); 0018 static quint8 fromVariant(const QVariant& value, bool* ok); 0019 static PrimitiveDataType staticType(); 0020 static QScriptValue asScriptValue(quint8 value, QScriptEngine* engine, ScriptHandlerInfo* handler); 0021 static QVariant staticToQVariant(quint8 value); 0022 0023 static QWidget* staticCreateEditWidget(QWidget* parent); 0024 static QVariant staticDataFromWidget(const QWidget* w); 0025 static void staticSetWidgetData(quint8 value, QWidget* w); 0026 }; 0027 0028 inline PrimitiveDataType CharDataInformationMethods::staticType() 0029 { 0030 return PrimitiveDataType::Char; 0031 } 0032 0033 inline QVariant CharDataInformationMethods::staticToQVariant(quint8 value) 0034 { 0035 return QVariant(value); 0036 } 0037 0038 inline quint8 CharDataInformationMethods::fromVariant(const QVariant& value, bool* ok) 0039 { 0040 Q_CHECK_PTR(ok); 0041 quint32 tmp = value.toUInt(ok); 0042 auto result = static_cast<quint8>(tmp); 0043 if (tmp != quint32(result)) { 0044 *ok = false; // out of bounds 0045 return 0; 0046 } 0047 return result; 0048 } 0049 0050 #endif /* KASTEN_CHARDATAINFORMATION_HPP */