OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qmldesigner / designercore / model / propertycontainer.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
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.
18 **
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.
22 **
23 ** Other Usage
24 **
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.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #include "propertycontainer.h"
34 #include "propertyparser.h"
35 #include <QVariant>
36 #include <QString>
37 #include <QRegExp>
38 #include <QSize>
39 #include <QSizeF>
40 #include <QPoint>
41 #include <QPointF>
42 #include <QtDebug>
43
44 namespace QmlDesigner {
45
46 using namespace QmlDesigner::Internal;
47
48
49 // Creates invalid PropertyContainer
50 PropertyContainer::PropertyContainer()
51 {
52 }
53
54 PropertyContainer::PropertyContainer(const QString &name, const QString &type, const QVariant &value)
55         : m_name(name), m_type(type), m_value(value)
56 {
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");
59 }
60
61 void PropertyContainer::set(const QString &name, const QString &type, const QVariant &value)
62 {
63     m_name = name;
64     m_type = type;
65     m_value = value;
66 }
67
68 bool PropertyContainer::isValid() const
69 {
70     return !m_name.isEmpty() && m_value.isValid();
71 }
72
73 QString PropertyContainer::name() const
74 {
75     return m_name;
76 }
77
78 QVariant PropertyContainer::value() const
79 {
80     if (m_value.type() == QVariant::String)
81         m_value = PropertyParser::read(m_type, m_value.toString());
82     return m_value;
83 }
84
85
86 void PropertyContainer::setValue(const QVariant &value)
87 {
88     m_value = value;
89 }
90
91 QString PropertyContainer::type() const
92 {
93     return m_type;
94 }
95
96 QDataStream &operator<<(QDataStream &stream, const PropertyContainer &propertyContainer)
97 {
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();
104
105
106     return stream;
107 }
108
109 QDataStream &operator>>(QDataStream &stream, PropertyContainer &propertyContainer)
110 {
111
112     stream >> propertyContainer.m_name;
113     stream >> propertyContainer.m_type;
114     stream >> propertyContainer.m_value;
115
116     Q_ASSERT(!propertyContainer.name().isEmpty());
117
118     return stream;
119 }
120
121 QDataStream &operator<<(QDataStream &stream, const QList<PropertyContainer> &propertyContainerList)
122 {
123     stream << propertyContainerList.count();
124     foreach (const PropertyContainer &propertyContainer, propertyContainerList)
125         stream << propertyContainer;
126
127     return stream;
128 }
129
130 QDataStream &operator>>(QDataStream &stream, QList<PropertyContainer> &propertyContainerList)
131 {
132     int count;
133     stream >> count;
134     Q_ASSERT(count >= 0);
135     for( int i = 0; i < count; i++) {
136         PropertyContainer propertyContainer;
137         stream >> propertyContainer;
138         propertyContainerList.append(propertyContainer);
139     }
140
141     return stream;
142 }
143
144
145 } //namespace QmlDesigner
146