OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qmldesigner / components / propertyeditor / propertyeditorvalue.h
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 #ifndef PROPERTYEDITORVALUE_H
35 #define PROPERTYEDITORVALUE_H
36
37 #include <QObject>
38 #include <QDeclarativePropertyMap>
39 #include <qdeclarative.h>
40 #include <modelnode.h>
41 #include <qmlitemnode.h>
42 #include <rewritertransaction.h>
43
44 class PropertyEditorValue;
45
46 class PropertyEditorNodeWrapper : public QObject {
47     Q_OBJECT
48
49     Q_PROPERTY(bool exists READ exists NOTIFY existsChanged)
50     Q_PROPERTY(QDeclarativePropertyMap* properties READ properties NOTIFY propertiesChanged)
51     Q_PROPERTY(QString type READ type NOTIFY typeChanged)
52
53 public:
54     PropertyEditorNodeWrapper(QObject *parent=0);
55     PropertyEditorNodeWrapper(PropertyEditorValue* parent);
56     bool exists();
57     QString type();
58     QDeclarativePropertyMap* properties();
59     QmlDesigner::ModelNode parentModelNode() const;
60     QString propertyName() const;
61
62 public slots:
63     void add(const QString &type = QString());
64     void remove();
65     void changeValue(const QString &name);
66     void update();
67
68 signals:
69     void existsChanged();
70     void propertiesChanged();
71     void typeChanged();
72
73 private:
74     void setup();
75
76     QmlDesigner::ModelNode m_modelNode;
77     QDeclarativePropertyMap m_valuesPropertyMap;
78     PropertyEditorValue* m_editorValue;
79 };
80
81 class PropertyEditorValue : public QObject
82 {
83     Q_OBJECT
84     Q_PROPERTY(QVariant value READ value WRITE setValueWithEmit NOTIFY valueChangedQml)
85     Q_PROPERTY(QString expression READ expression WRITE setExpressionWithEmit NOTIFY expressionChanged FINAL)
86     Q_PROPERTY(bool isInModel READ isInModel NOTIFY valueChangedQml FINAL)
87     Q_PROPERTY(bool isInSubState READ isInSubState NOTIFY valueChangedQml FINAL)
88     Q_PROPERTY(bool isBound READ isBound NOTIFY isBoundChanged FINAL)
89     Q_PROPERTY(bool isValid READ isValid NOTIFY isValidChanged FINAL)
90     Q_PROPERTY(QString name READ name FINAL)
91     Q_PROPERTY(PropertyEditorNodeWrapper* complexNode READ complexNode NOTIFY complexNodeChanged FINAL)
92
93 public:
94     PropertyEditorValue(QObject *parent=0);
95
96     QVariant value() const;
97     void setValueWithEmit(const QVariant &value);
98     void setValue(const QVariant &value);
99
100     QString expression() const;
101     void setExpressionWithEmit(const QString &expression);
102     void setExpression(const QString &expression);
103
104     bool isInSubState() const;
105
106     bool isInModel() const;
107
108     bool isBound() const;
109     bool isValid() const;
110
111     void setIsValid(bool valid);
112
113     QString name() const;
114     void setName(const QString &name);
115
116     QmlDesigner::ModelNode modelNode() const;
117     void setModelNode(const QmlDesigner::ModelNode &modelNode);
118
119     PropertyEditorNodeWrapper* complexNode();
120
121     static void registerDeclarativeTypes();
122
123 public slots:
124     void resetValue();
125
126 signals:
127     void valueChanged(const QString &name, const QVariant&);
128     void valueChangedQml();
129
130     void expressionChanged(const QString &name);
131
132     void modelStateChanged();
133     void modelNodeChanged();
134     void complexNodeChanged();
135     void isBoundChanged();
136     void isValidChanged();
137
138 private: //variables
139     QmlDesigner::ModelNode m_modelNode;
140     QVariant m_value;
141     QString m_expression;
142     QString m_name;
143     bool m_isInSubState;
144     bool m_isInModel;
145     bool m_isBound;
146     bool m_isValid; // if the property value belongs to a non-existing complexProperty it is invalid
147     PropertyEditorNodeWrapper *m_complexNode;
148 };
149
150 QML_DECLARE_TYPE(PropertyEditorValue)
151 QML_DECLARE_TYPE(PropertyEditorNodeWrapper)
152 QML_DECLARE_TYPE(QDeclarativePropertyMap)
153
154
155 #endif // PROPERTYEDITORVALUE_H