File indexing completed on 2024-06-30 05:51:25

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_SINTDATAINFORMATION_HPP
0010 #define KASTEN_SINTDATAINFORMATION_HPP
0011 
0012 #include "primitivedatainformation.hpp"
0013 #include "structureviewpreferences.hpp"
0014 #include "../../allprimitivetypes.hpp"
0015 
0016 template <typename T>
0017 class SIntDataInformationMethods
0018 {
0019 public:
0020     static PrimitiveDataType staticType();
0021     static T fromVariant(const QVariant& value, bool* ok);
0022     static QScriptValue asScriptValue(T value, QScriptEngine* engine, ScriptHandlerInfo* handler);
0023     static QString staticValueString(T val, int base = Kasten::StructureViewPreferences::signedDisplayBase());
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 SIntDataInformationMethods<qint8>::staticType()
0033 {
0034     return PrimitiveDataType::Int8;
0035 }
0036 template <>
0037 inline PrimitiveDataType SIntDataInformationMethods<qint16>::staticType()
0038 {
0039     return PrimitiveDataType::Int16;
0040 }
0041 template <>
0042 inline PrimitiveDataType SIntDataInformationMethods<qint32>::staticType()
0043 {
0044     return PrimitiveDataType::Int32;
0045 }
0046 template <>
0047 inline PrimitiveDataType SIntDataInformationMethods<qint64>::staticType()
0048 {
0049     return PrimitiveDataType::Int64;
0050 }
0051 
0052 template <typename T>
0053 inline QVariant SIntDataInformationMethods<T>::staticToQVariant(T value)
0054 {
0055     return QVariant(value);
0056 }
0057 
0058 template <typename T>
0059 inline T SIntDataInformationMethods<T>::fromVariant(const QVariant& value, bool* ok)
0060 {
0061     Q_CHECK_PTR(ok);
0062     qint64 val = value.toLongLong(ok);
0063     T result = T(val);
0064     if (val != qint64(result)) {
0065         *ok = false;
0066     }
0067     return result;
0068 }
0069 
0070 #endif // KASTEN_SINTDATAINFORMATION_HPP