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: 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_BOOLDATAINFORMATION_HPP
0010 #define KASTEN_BOOLDATAINFORMATION_HPP
0011 
0012 #include <QScriptValue>
0013 
0014 #include "uintdatainformation.hpp"
0015 
0016 template <typename T>
0017 class BoolDataInformationMethods
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 BoolDataInformationMethods<quint8>::staticType()
0033 {
0034     return PrimitiveDataType::Bool8;
0035 }
0036 template <>
0037 inline PrimitiveDataType BoolDataInformationMethods<quint16>::staticType()
0038 {
0039     return PrimitiveDataType::Bool16;
0040 }
0041 template <>
0042 inline PrimitiveDataType BoolDataInformationMethods<quint32>::staticType()
0043 {
0044     return PrimitiveDataType::Bool32;
0045 }
0046 template <>
0047 inline PrimitiveDataType BoolDataInformationMethods<quint64>::staticType()
0048 {
0049     return PrimitiveDataType::Bool64;
0050 }
0051 
0052 template <typename T>
0053 inline QScriptValue BoolDataInformationMethods<T>::asScriptValue(T value, QScriptEngine* engine,
0054                                                                  ScriptHandlerInfo* handler)
0055 {
0056     Q_UNUSED(engine);
0057     Q_UNUSED(handler);
0058     return {(value != 0)};
0059 }
0060 
0061 template <typename T>
0062 inline QVariant BoolDataInformationMethods<T>::staticToQVariant(T value)
0063 {
0064     return UIntDataInformationMethods<T>::staticToQVariant(value);
0065 }
0066 
0067 template <typename T>
0068 inline T BoolDataInformationMethods<T>::fromVariant(const QVariant& value, bool* ok)
0069 {
0070     return UIntDataInformationMethods<T>::fromVariant(value, ok);
0071 }
0072 
0073 #endif // KASTEN_BOOLDATAINFORMATION_HPP