OSDN Git Service

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