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: 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_FLOATDATAINFORMATION_HPP
0010 #define KASTEN_FLOATDATAINFORMATION_HPP
0011 
0012 #include "primitivedatainformation.hpp"
0013 
0014 class FloatDataInformationMethods
0015 {
0016 public:
0017     static PrimitiveDataType staticType();
0018     static QString staticValueString(float value);
0019     static QScriptValue asScriptValue(float value, QScriptEngine* engine, ScriptHandlerInfo* handler);
0020     static float fromVariant(const QVariant& value, bool* ok);
0021     static QVariant staticToQVariant(float value);
0022 
0023     static QWidget* staticCreateEditWidget(QWidget* parent);
0024     static QVariant staticDataFromWidget(const QWidget* w);
0025     static void staticSetWidgetData(float value, QWidget* w);
0026 };
0027 
0028 inline PrimitiveDataType FloatDataInformationMethods::staticType()
0029 {
0030     return PrimitiveDataType::Float;
0031 }
0032 
0033 inline QVariant FloatDataInformationMethods::staticToQVariant(float value)
0034 {
0035     return QVariant(value);
0036 }
0037 
0038 inline float FloatDataInformationMethods::fromVariant(const QVariant& value, bool* ok)
0039 {
0040     Q_CHECK_PTR(ok);
0041     float result = value.toFloat(ok);
0042     // result != result if value is NaN so check for that case too
0043     if (double(result) != value.toDouble() && result == result) {
0044         *ok = false;
0045     }
0046     return result;
0047 }
0048 
0049 #endif /* KASTEN_FLOATDATAINFORMATION_HPP */