1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
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
16 ** GNU Lesser General Public License Usage
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.
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.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #ifndef REWRITERVIEW_H
35 #define REWRITERVIEW_H
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>
44 #include <QWeakPointer>
45 #include <QtCore/QHash>
47 #include <modelnode.h>
48 #include <QScopedPointer>
52 class DiagnosticMessage;
58 namespace QmlDesigner {
60 class CORESHARED_EXPORT TextModifier;
64 class TextToModelMerger;
65 class ModelToTextMerger;
66 class ModelNodePositionStorage;
70 class CORESHARED_EXPORT RewriterView : public AbstractView
75 enum DifferenceHandling {
90 Error(const QmlJS::DiagnosticMessage &qmlError, const QUrl &document);
91 Error(const QString &shortDescription);
92 Error(Exception *exception);
103 QString description() const
104 { return m_description; }
109 QString toString() const;
115 QString m_description;
120 RewriterView(DifferenceHandling differenceHandling, QObject *parent);
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);
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);
148 void rewriterBeginTransaction();
149 void rewriterEndTransaction();
151 void actualStateChanged(const ModelNode &node);
153 void importAdded(const Import &import);
154 void importRemoved(const Import &import);
155 void importsChanged(const QList<Import> &addedImports, const QList<Import> &removedImports);
157 void fileUrlChanged(const QUrl &oldUrl, const QUrl &newUrl);
159 void selectedNodesChanged(const QList<ModelNode> &selectedNodeList, const QList<ModelNode> &lastSelectedNodeList);
161 TextModifier *textModifier() const;
162 void setTextModifier(TextModifier *textModifier);
163 QString textModifierContent() const;
165 Internal::ModelNodePositionStorage *positionStorage() const
166 { return m_positionStorage; }
168 QList<Error> errors() const;
170 void setErrors(const QList<Error> &errors);
171 void addError(const Error &error);
173 void enterErrorState(const QString &errorMessage);
174 bool inErrorState() const { return !m_rewritingErrorMessage.isEmpty(); }
175 void leaveErrorState() { m_rewritingErrorMessage.clear(); }
176 void resetToLastCorrectQml();
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();
185 bool renameId(const QString& oldId, const QString& newId);
187 QmlJS::LookupContext *lookupContext() const;
188 QmlJS::Document *document() const;
190 bool checkSemanticErrors() const
191 { return m_checkErrors; }
193 void setCheckSemanticErrors(bool b)
194 { m_checkErrors = b; }
197 void errorsChanged(const QList<RewriterView::Error> &errors);
200 void qmlTextChanged();
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();
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;
227 #endif // REWRITERVIEW_H