OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qmldesigner / designercore / model / modelrewriter.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 MODELREWRITER_H
34 #define MODELREWRITER_H
35
36 #include <QtCore/QByteArray>
37 #include <QtCore/QMimeData>
38 #include <QtCore/QObject>
39 #include <QtCore/QUrl>
40
41 #include "anchorline.h"
42 #include "import.h"
43 #include "modeltotextmerger.h"
44 #include "model.h"
45 #include "modelnode.h"
46 #include "modificationgrouptoken.h"
47 #include "subcomponentmanager.h"
48 #include "texttomodelmerger.h"
49
50 namespace QmlDesigner {
51 class TextModifier;
52
53 namespace Internal {
54
55 class ModelPrivate;
56
57 class ModelRewriter: public QObject
58 {
59     Q_OBJECT
60
61 public:
62     ModelRewriter(Model* model, TextModifier* textModifier);
63
64     TextModifier *textModifier() const { return m_textModifier; }
65
66     bool load(const QUrl &url, QList<QmlError> *errors = 0);
67     bool reloadAndMerge(QList<QmlError> *errors = 0);
68     void setFileUrl(const QUrl& url);
69
70     ModificationGroupToken beginModificationGroup();
71     void endModificationGroup(const ModificationGroupToken& token);
72
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);
77
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);
84
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);
90
91     // Anchors:
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);
95
96     bool lastRewriteFailed() const;
97
98     // Copy & Paste:
99     QMimeData* copy(const QList<InternalNodeState::Pointer> &nodeStates) const;
100     bool paste(QMimeData *transferData, const InternalNode::Pointer &intoNode);
101
102     // Imports:
103     void addImport(const Import &import);
104     void removeImport(const Import &import);
105
106 public slots:
107     void mergeChanges();
108
109 signals:
110     void errorDuringRewrite(const QList<QmlError> &errors);
111
112 private:
113     bool modificationGroupActive() const { return !m_activeModificationGroups.isEmpty(); }
114
115 private:
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;
123 };
124
125 }
126 }
127
128 #endif //MODELREWRITER_H