OSDN Git Service

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