1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #include "propertycontainer.h"
34 #include "propertyparser.h"
44 namespace QmlDesigner {
46 using namespace QmlDesigner::Internal;
49 // Creates invalid PropertyContainer
50 PropertyContainer::PropertyContainer()
54 PropertyContainer::PropertyContainer(const QString &name, const QString &type, const QVariant &value)
55 : m_name(name), m_type(type), m_value(value)
57 Q_ASSERT_X(!name.isEmpty(), Q_FUNC_INFO, "Name of property cannot be empty");
58 Q_ASSERT_X(!type.isEmpty(), Q_FUNC_INFO, "Type of property cannot be empty");
61 void PropertyContainer::set(const QString &name, const QString &type, const QVariant &value)
68 bool PropertyContainer::isValid() const
70 return !m_name.isEmpty() && m_value.isValid();
73 QString PropertyContainer::name() const
78 QVariant PropertyContainer::value() const
80 if (m_value.type() == QVariant::String)
81 m_value = PropertyParser::read(m_type, m_value.toString());
86 void PropertyContainer::setValue(const QVariant &value)
91 QString PropertyContainer::type() const
96 QDataStream &operator<<(QDataStream &stream, const PropertyContainer &propertyContainer)
98 Q_ASSERT(!propertyContainer.name().isEmpty());
99 Q_ASSERT(!propertyContainer.type().isEmpty());
100 Q_ASSERT(propertyContainer.value().isValid());
101 stream << propertyContainer.name();
102 stream << propertyContainer.type();
103 stream << propertyContainer.value();
109 QDataStream &operator>>(QDataStream &stream, PropertyContainer &propertyContainer)
112 stream >> propertyContainer.m_name;
113 stream >> propertyContainer.m_type;
114 stream >> propertyContainer.m_value;
116 Q_ASSERT(!propertyContainer.name().isEmpty());
121 QDataStream &operator<<(QDataStream &stream, const QList<PropertyContainer> &propertyContainerList)
123 stream << propertyContainerList.count();
124 foreach (const PropertyContainer &propertyContainer, propertyContainerList)
125 stream << propertyContainer;
130 QDataStream &operator>>(QDataStream &stream, QList<PropertyContainer> &propertyContainerList)
134 Q_ASSERT(count >= 0);
135 for( int i = 0; i < count; i++) {
136 PropertyContainer propertyContainer;
137 stream >> propertyContainer;
138 propertyContainerList.append(propertyContainer);
145 } //namespace QmlDesigner