1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
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.
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.
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.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #ifndef MODELREWRITER_H
34 #define MODELREWRITER_H
36 #include <QtCore/QByteArray>
37 #include <QtCore/QMimeData>
38 #include <QtCore/QObject>
39 #include <QtCore/QUrl>
41 #include "anchorline.h"
43 #include "modeltotextmerger.h"
45 #include "modelnode.h"
46 #include "modificationgrouptoken.h"
47 #include "subcomponentmanager.h"
48 #include "texttomodelmerger.h"
50 namespace QmlDesigner {
57 class ModelRewriter: public QObject
62 ModelRewriter(Model* model, TextModifier* textModifier);
64 TextModifier *textModifier() const { return m_textModifier; }
66 bool load(const QUrl &url, QList<QmlError> *errors = 0);
67 bool reloadAndMerge(QList<QmlError> *errors = 0);
68 void setFileUrl(const QUrl& url);
70 ModificationGroupToken beginModificationGroup();
71 void endModificationGroup(const ModificationGroupToken& token);
73 // Property change actions:
74 void addProperty(const InternalNodeState::Pointer& state, const QString& name, const QVariant& value);
75 void changePropertyValue(const InternalNodeState::Pointer& state, const QString& name, const QVariant& value);
76 void removeProperty(const InternalNodeState::Pointer& state, const QString& name);
78 // Node change actions:
79 void addNode(const InternalNodePointer& newNode, const InternalNodePointer& parentNode);
80 void reparentNode(const InternalNodePointer &child, const InternalNodePointer &newParent);
81 void removeNode(const InternalNodePointer &node);
82 void changeNodeId(const InternalNodePointer& node, const QString& id);
83 void moveNodeBefore(const InternalNodePointer& node, const InternalNodePointer& beforeNode);
85 // State change actions:
86 void addModelState(const InternalModelState::Pointer &state);
87 void removeModelState(const InternalModelState::Pointer &state);
88 void setStateName(const InternalModelStatePointer &state, const QString &name);
89 void setStateWhenCondition(const InternalModelStatePointer &state, const QString &whenCondition);
92 void setAnchor(const InternalNodeState::Pointer &state, const QString &propertyName, const QVariant &value);
93 void removeAnchor(const InternalNodeState::Pointer &state, const QString &propertyName);
94 void setAnchorMargin(const InternalNodeState::Pointer &state, const QString &propertyName, const QVariant &value);
96 bool lastRewriteFailed() const;
99 QMimeData* copy(const QList<InternalNodeState::Pointer> &nodeStates) const;
100 bool paste(QMimeData *transferData, const InternalNode::Pointer &intoNode);
103 void addImport(const Import &import);
104 void removeImport(const Import &import);
110 void errorDuringRewrite(const QList<QmlError> &errors);
113 bool modificationGroupActive() const { return !m_activeModificationGroups.isEmpty(); }
116 SubComponentManager m_subcomponentManager;
117 QByteArray m_lastCorrectData;
118 QList<ModificationGroupToken> m_activeModificationGroups;
119 TextModifier* m_textModifier;
120 ModelToTextMerger m_modelToTextMerger;
121 TextToModelMerger m_textToModelMerger;
122 bool m_lastRewriteFailed;
128 #endif //MODELREWRITER_H