1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "variantparser.h"
35 #include <private/qdeclarativevaluetype_p.h>
45 #include <QEasingCurve>
46 #include <QMetaProperty>
48 namespace QmlDesigner {
51 VariantParser::VariantParser(const QVariant &value) : m_valueType(QDeclarativeValueTypeFactory::valueType(value.type()))
54 m_valueType->setValue(value);
55 if (!m_valueType->value().isValid())
56 qWarning("VariantParser::VariantParser: value not valid");
60 VariantParser::~VariantParser()
66 QVariant VariantParser::value() const
68 return m_valueType->value();
71 QVariant VariantParser::property(QString name) const
75 return m_valueType->property(name.toLatin1());
78 bool VariantParser::setProperty(const QString &name, const QVariant &value)
82 if (name == "pixelSize" && value.toInt() < 1)
83 return false; //this check we have to harcode
84 return m_valueType->setProperty(name.toLatin1(), value);
87 bool VariantParser::isValueType(const QString &type)
89 return VariantParser::create(type).isValid();
92 QStringList VariantParser::properties()
96 QStringList propertyList;
97 for (int i=1; i < m_valueType->metaObject()->propertyCount(); i++) {
98 QMetaProperty metaProperty = m_valueType->metaObject()->property(i);
99 propertyList.append(metaProperty.name());
104 VariantParser VariantParser::create(const QString &type)
107 return VariantParser(QVariant(QFont()));
108 if (type == "QPoint")
109 return VariantParser(QVariant(QPoint()));
110 if (type == "QPointF")
111 return VariantParser(QVariant(QPointF()));
113 return VariantParser(QVariant(QSize()));
114 if (type == "QSizeF")
115 return VariantParser(QVariant(QSizeF()));
117 return VariantParser(QVariant(QRect()));
118 if (type == "QRectF")
119 return VariantParser(QVariant(QRectF()));
120 if (type == "QVector3D")
121 return VariantParser(QVariant(QVector3D()));
122 if (type == "QEasingCurve")
123 return VariantParser(QVariant(QEasingCurve()));
125 return VariantParser(QVariant());
128 void VariantParser::init(const QString &type)
131 m_valueType = QDeclarativeValueTypeFactory::valueType(QVariant::Font);
132 if (type == "QPoint")
133 m_valueType = QDeclarativeValueTypeFactory::valueType(QVariant::Point);
134 if (type == "QPointF")
135 m_valueType = QDeclarativeValueTypeFactory::valueType(QVariant::PointF);
137 m_valueType = QDeclarativeValueTypeFactory::valueType(QVariant::Size);
138 if (type == "QSizeF")
139 m_valueType = QDeclarativeValueTypeFactory::valueType(QVariant::SizeF);
141 m_valueType = QDeclarativeValueTypeFactory::valueType(QVariant::Rect);
142 if (type == "QRectF")
143 m_valueType = QDeclarativeValueTypeFactory::valueType(QVariant::RectF);
144 if (type == "QVector3D")
145 m_valueType = QDeclarativeValueTypeFactory::valueType(QVariant::Vector3D);
146 if (type == "QEasingCurve")
147 m_valueType = QDeclarativeValueTypeFactory::valueType(QVariant::EasingCurve);
150 bool VariantParser::isValid()
152 return m_valueType && m_valueType->value().isValid();
155 } // namespace Internal
156 } // namespace QmlDesigner