]>
vaikene.ee Git - evaf/blob - libs/Common/util.cpp
2 * @file Common/util.cpp
3 * @brief Global utility functions for eVaf
6 * Copyright (c) 2011 Enar Vaikene
8 * This file is part of the eVaf C++ cross-platform application development framework.
10 * This file can be used under the terms of the GNU General Public License
11 * version 3.0 as published by the Free Software Foundation and appearing in
12 * the file LICENSE included in the packaging of this file. Please review the
13 * the following information to ensure the GNU General Public License version
14 * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
16 * Alternatively, this file may be used in accordance with the Commercial License
17 * Agreement provided with the Software.
23 //-------------------------------------------------------------------
25 QVariant
eVaf::Common::toVariant(QString
const & value
, QVariant
const & defaultValue
)
27 // If the default value is not valid, return the string value without conversions
28 if (!defaultValue
.isValid())
29 return QVariant(value
);
31 // Convert to the expected type
32 switch (defaultValue
.type()) {
33 case QVariant::UInt
: {
35 uint v
= value
.toUInt(&ok
, 0);
44 int v
= value
.toInt(&ok
, 0);
51 case QVariant::Double
: {
53 double v
= value
.toDouble(&ok
);
60 case QVariant::Bool
: {
62 uint v
= value
.toUInt(&ok
, 0);
63 if (eVaf::Common::isTrue(value
))
64 return QVariant(true);
65 else if (eVaf::Common::isFalse(value
))
66 return QVariant(false);
71 case QVariant::Char
: {
73 return QVariant(value
.at(0));
79 return QVariant(value
);