OSDN Git Service

01969472ba068cae86820278bcf07e37cdab8aa7
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qmldesigner / designercore / include / rewriterview.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 REWRITERVIEW_H
35 #define REWRITERVIEW_H
36
37 #include "corelib_global.h"
38 #include "abstractview.h"
39 #include "exception.h"
40 #include <modelnodepositionstorage.h>
41 #include <QtCore/QHash>
42 #include <QtCore/QMap>
43 #include <QPointer>
44 #include <QWeakPointer>
45 #include <QtCore/QHash>
46
47 #include <modelnode.h>
48 #include <QScopedPointer>
49
50 namespace QmlJS {
51
52 class DiagnosticMessage;
53 class LookupContext;
54 class Document;
55 }
56
57
58 namespace QmlDesigner {
59
60 class CORESHARED_EXPORT TextModifier;
61
62 namespace Internal {
63
64 class TextToModelMerger;
65 class ModelToTextMerger;
66 class ModelNodePositionStorage;
67
68 } //Internal
69
70 class CORESHARED_EXPORT RewriterView : public AbstractView
71 {
72     Q_OBJECT
73
74 public:
75     enum DifferenceHandling {
76         Validate,
77         Amend
78     };
79
80     class Error {
81     public:
82         enum Type {
83             NoError = 0,
84             InternalError = 1,
85             ParseError = 2
86         };
87
88     public:
89         Error();
90         Error(const QmlJS::DiagnosticMessage &qmlError, const QUrl &document);
91         Error(const QString &shortDescription);
92         Error(Exception *exception);
93
94         Type type() const
95         { return m_type; }
96
97         int line() const
98         { return m_line; }
99
100         int column() const
101         { return m_column; }
102
103         QString description() const
104         { return m_description; }
105
106         QUrl url() const
107         { return m_url; }
108
109         QString toString() const;
110
111     private:
112         Type m_type;
113         int m_line;
114         int m_column;
115         QString m_description;
116         QUrl m_url;
117     };
118
119 public:
120     RewriterView(DifferenceHandling differenceHandling, QObject *parent);
121     ~RewriterView();
122
123     void modelAttached(Model *model);
124     void modelAboutToBeDetached(Model *model);
125     void nodeCreated(const ModelNode &createdNode);
126     void nodeAboutToBeRemoved(const ModelNode &removedNode);
127     void nodeRemoved(const ModelNode &removedNode, const NodeAbstractProperty &parentProperty, PropertyChangeFlags propertyChange);
128     void propertiesAdded(const ModelNode &node, const QList<AbstractProperty>& propertyList);
129     void propertiesAboutToBeRemoved(const QList<AbstractProperty>& propertyList);
130     void propertiesRemoved(const QList<AbstractProperty>& propertyList);
131     void variantPropertiesChanged(const QList<VariantProperty>& propertyList, PropertyChangeFlags propertyChange);
132     void bindingPropertiesChanged(const QList<BindingProperty>& propertyList, PropertyChangeFlags propertyChange);
133     void nodeAboutToBeReparented(const ModelNode &node, const NodeAbstractProperty &newPropertyParent, const NodeAbstractProperty &oldPropertyParent, AbstractView::PropertyChangeFlags propertyChange);
134     void nodeReparented(const ModelNode &node, const NodeAbstractProperty &newPropertyParent, const NodeAbstractProperty &oldPropertyParent, AbstractView::PropertyChangeFlags propertyChange);
135     void nodeIdChanged(const ModelNode& node, const QString& newId, const QString& oldId);
136     void nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &movedNode, int oldIndex);
137     void rootNodeTypeChanged(const QString &type, int majorVersion, int minorVersion);
138     void customNotification(const AbstractView *view, const QString &identifier, const QList<ModelNode> &nodeList, const QList<QVariant> &data);
139     void scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList);
140
141     void instancePropertyChange(const QList<QPair<ModelNode, QString> > &propertyList);
142     void instancesCompleted(const QVector<ModelNode> &completedNodeList);
143     void instanceInformationsChange(const QVector<ModelNode> &nodeList);
144     void instancesRenderImageChanged(const QVector<ModelNode> &nodeList);
145     void instancesPreviewImageChanged(const QVector<ModelNode> &nodeList);
146     void instancesChildrenChanged(const QVector<ModelNode> &nodeList);
147
148     void rewriterBeginTransaction();
149     void rewriterEndTransaction();
150
151     void actualStateChanged(const ModelNode &node);
152
153     void importAdded(const Import &import);
154     void importRemoved(const Import &import);
155     void importsChanged(const QList<Import> &addedImports, const QList<Import> &removedImports);
156
157     void fileUrlChanged(const QUrl &oldUrl, const QUrl &newUrl);
158
159     void selectedNodesChanged(const QList<ModelNode> &selectedNodeList, const QList<ModelNode> &lastSelectedNodeList);
160
161     TextModifier *textModifier() const;
162     void setTextModifier(TextModifier *textModifier);
163     QString textModifierContent() const;
164
165     Internal::ModelNodePositionStorage *positionStorage() const
166     { return m_positionStorage; }
167
168     QList<Error> errors() const;
169     void clearErrors();
170     void setErrors(const QList<Error> &errors);
171     void addError(const Error &error);
172
173     void enterErrorState(const QString &errorMessage);
174     bool inErrorState() const { return !m_rewritingErrorMessage.isEmpty(); }
175     void leaveErrorState() { m_rewritingErrorMessage.clear(); }
176     void resetToLastCorrectQml();
177
178     QMap<ModelNode, QString> extractText(const QList<ModelNode> &nodes) const;
179     int nodeOffset(const ModelNode &node) const;
180     int nodeLength(const ModelNode &node) const;
181     int firstDefinitionInsideOffset(const ModelNode &node) const;
182     int firstDefinitionInsideLength(const ModelNode &node) const;
183     bool modificationGroupActive();
184
185     bool renameId(const QString& oldId, const QString& newId);
186
187     QmlJS::LookupContext *lookupContext() const;
188     QmlJS::Document *document() const;
189
190     bool checkSemanticErrors() const
191     { return m_checkErrors; }
192
193     void setCheckSemanticErrors(bool b)
194     { m_checkErrors = b; }
195
196 signals:
197     void errorsChanged(const QList<RewriterView::Error> &errors);
198
199 public slots:
200     void qmlTextChanged();
201
202 protected: // functions
203     Internal::ModelToTextMerger *modelToTextMerger() const;
204     Internal::TextToModelMerger *textToModelMerger() const;
205     bool isModificationGroupActive() const;
206     void setModificationGroupActive(bool active);
207     void applyModificationGroupChanges();
208     void applyChanges();
209
210 private: //variables
211     DifferenceHandling m_differenceHandling;
212     bool m_modificationGroupActive;
213     Internal::ModelNodePositionStorage *m_positionStorage;
214     QScopedPointer<Internal::ModelToTextMerger> m_modelToTextMerger;
215     QScopedPointer<Internal::TextToModelMerger> m_textToModelMerger;
216     TextModifier *m_textModifier;
217     QList<Error> m_errors;
218     int transactionLevel;
219     RewriterTransaction m_removeDefaultPropertyTransaction;
220     QString m_rewritingErrorMessage;
221     QString lastCorrectQmlSource;
222     bool m_checkErrors;
223 };
224
225 } //QmlDesigner
226
227 #endif // REWRITERVIEW_H