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 "propertycontainer.h"
35 #include "propertyparser.h"
45 namespace QmlDesigner {
47 using namespace QmlDesigner::Internal;
50 // Creates invalid PropertyContainer
51 PropertyContainer::PropertyContainer()
55 PropertyContainer::PropertyContainer(const QString &name, const QString &type, const QVariant &value)
56 : m_name(name), m_type(type), m_value(value)
58 Q_ASSERT_X(!name.isEmpty(), Q_FUNC_INFO, "Name of property cannot be empty");
59 Q_ASSERT_X(!type.isEmpty(), Q_FUNC_INFO, "Type of property cannot be empty");
62 void PropertyContainer::set(const QString &name, const QString &type, const QVariant &value)
69 bool PropertyContainer::isValid() const
71 return !m_name.isEmpty() && m_value.isValid();
74 QString PropertyContainer::name() const
79 QVariant PropertyContainer::value() const
81 if (m_value.type() == QVariant::String)
82 m_value = PropertyParser::read(m_type, m_value.toString());
87 void PropertyContainer::setValue(const QVariant &value)
92 QString PropertyContainer::type() const
97 QDataStream &operator<<(QDataStream &stream, const PropertyContainer &propertyContainer)
99 Q_ASSERT(!propertyContainer.name().isEmpty());
100 Q_ASSERT(!propertyContainer.type().isEmpty());
101 Q_ASSERT(propertyContainer.value().isValid());
102 stream << propertyContainer.name();
103 stream << propertyContainer.type();
104 stream << propertyContainer.value();
110 QDataStream &operator>>(QDataStream &stream, PropertyContainer &propertyContainer)
113 stream >> propertyContainer.m_name;
114 stream >> propertyContainer.m_type;
115 stream >> propertyContainer.m_value;
117 Q_ASSERT(!propertyContainer.name().isEmpty());
122 QDataStream &operator<<(QDataStream &stream, const QList<PropertyContainer> &propertyContainerList)
124 stream << propertyContainerList.count();
125 foreach (const PropertyContainer &propertyContainer, propertyContainerList)
126 stream << propertyContainer;
131 QDataStream &operator>>(QDataStream &stream, QList<PropertyContainer> &propertyContainerList)
135 Q_ASSERT(count >= 0);
136 for( int i = 0; i < count; i++) {
137 PropertyContainer propertyContainer;
138 stream >> propertyContainer;
139 propertyContainerList.append(propertyContainer);
146 } //namespace QmlDesigner