OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qmldesigner / designercore / model / viewlogger.cpp
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 #include "viewlogger.h"
35 #include <QDebug>
36 #include <QTemporaryFile>
37 #include <QDir>
38 #include <variantproperty.h>
39 #include <bindingproperty.h>
40 #include <nodeabstractproperty.h>
41 #include <nodelistproperty.h>
42
43 namespace QmlDesigner {
44 namespace Internal {
45
46 static QString serialize(AbstractView::PropertyChangeFlags change)
47 {
48     QStringList tokenList;
49
50     if (change.testFlag(AbstractView::PropertiesAdded))
51         tokenList.append(QLatin1String("PropertiesAdded"));
52
53     if (change.testFlag(AbstractView::EmptyPropertiesRemoved))
54         tokenList.append(QLatin1String("EmptyPropertiesRemoved"));
55
56     return tokenList.join(" ");
57 }
58
59 static QString indent(const QString &name = QString()) {
60     return name.leftJustified(30, ' ');
61 }
62
63 QString ViewLogger::time() const
64 {
65     return QString::number(m_timer.elapsed()).leftJustified(7, ' ');
66 }
67
68 ViewLogger::ViewLogger(QObject *parent)
69     : AbstractView(parent)
70 {
71 #ifdef Q_OS_MAC
72     const QString tempPath = "/tmp";
73 #else
74     const QString tempPath = QDir::tempPath();
75 #endif
76
77     QTemporaryFile *temporaryFile = new QTemporaryFile(tempPath + QString("/qmldesigner-logger-%1-XXXXXX.txt").arg(QDateTime::currentDateTime().toString(Qt::ISODate).replace(":", "-")), this);
78
79     temporaryFile->setAutoRemove(false);
80     if (temporaryFile->open()) {
81         qDebug() << "QmlDesigner: Log file is:" << temporaryFile->fileName();
82         m_output.setDevice(temporaryFile);
83     } else {
84         qDebug() << "QmlDesigner: failed to open:" << temporaryFile->fileName();
85     }
86
87     m_timer.start();
88 }
89
90 void ViewLogger::modelAttached(Model *model)
91 {
92     m_output << time() << indent("modelAttached:") << model << endl;
93     AbstractView::modelAttached(model);
94 }
95
96 void ViewLogger::modelAboutToBeDetached(Model *model)
97 {
98     m_output << time() << indent("modelAboutToBeDetached:") << model << endl;
99     AbstractView::modelAboutToBeDetached(model);
100 }
101
102 void ViewLogger::nodeCreated(const ModelNode &createdNode)
103 {
104     m_output << time() << indent("nodeCreated:") << createdNode << endl;
105 }
106
107 void ViewLogger::nodeAboutToBeRemoved(const ModelNode &removedNode)
108 {
109     m_output << time() << indent("nodeAboutToBeRemoved:") << removedNode << endl;
110 }
111
112 void ViewLogger::nodeRemoved(const ModelNode &removedNode, const NodeAbstractProperty &parentProperty, PropertyChangeFlags propertyChange)
113 {
114     m_output << time() << indent("nodeRemoved:") << removedNode << parentProperty << serialize(propertyChange) << endl;
115 }
116
117 void ViewLogger::nodeAboutToBeReparented(const ModelNode &node, const NodeAbstractProperty &newPropertyParent, const NodeAbstractProperty &oldPropertyParent, AbstractView::PropertyChangeFlags propertyChange)
118 {
119     m_output << time() << indent("nodeAboutToBeReparented:") << node << "\t" << newPropertyParent << "\t" << oldPropertyParent << "\t" << serialize(propertyChange) << endl;
120 }
121
122
123 void ViewLogger::nodeReparented(const ModelNode &node, const NodeAbstractProperty &newPropertyParent, const NodeAbstractProperty &oldPropertyParent, AbstractView::PropertyChangeFlags propertyChange)
124 {
125     m_output << time() << indent("nodeReparented:") << node << "\t" << newPropertyParent << "\t" << oldPropertyParent << "\t" << serialize(propertyChange) << endl;
126 }
127
128 void ViewLogger::nodeIdChanged(const ModelNode& node, const QString& newId, const QString& oldId)
129 {
130     m_output << time() << indent("nodeIdChanged:") << node << "\t" << newId << "\t" << oldId << endl;
131 }
132
133 void ViewLogger::propertiesAboutToBeRemoved(const QList<AbstractProperty>& propertyList)
134 {
135     m_output << time() << indent("propertiesAboutToBeRemoved:") << endl;
136     foreach (const AbstractProperty &property, propertyList)
137         m_output << time() << indent() << property << endl;
138 }
139
140 void ViewLogger::propertiesRemoved(const QList<AbstractProperty> &propertyList)
141 {
142     m_output << time() << indent("propertiesRemoved:") << endl;
143     foreach (const AbstractProperty &property, propertyList)
144         m_output << time() << indent() << property << endl;
145 }
146
147 void ViewLogger::variantPropertiesChanged(const QList<VariantProperty>& propertyList, PropertyChangeFlags propertyChange)
148 {
149     m_output << time() << indent("variantPropertiesChanged:") << serialize(propertyChange) << endl;
150     foreach(const VariantProperty &property, propertyList)
151         m_output << time() << indent() << property << endl;
152 }
153
154 void ViewLogger::bindingPropertiesChanged(const QList<BindingProperty>& propertyList, PropertyChangeFlags propertyChange)
155 {
156     m_output << time() << indent("bindingPropertiesChanged:") << serialize(propertyChange) << endl;
157     foreach(const BindingProperty &property, propertyList)
158         m_output << time() << indent() << property << endl;
159 }
160
161 void ViewLogger::rootNodeTypeChanged(const QString &type, int majorVersion, int minorVersion)
162 {
163     m_output << time() << indent("rootNodeTypeChanged:") << rootModelNode() << type << majorVersion << minorVersion << endl;
164 }
165
166 void ViewLogger::selectedNodesChanged(const QList<ModelNode> &selectedNodeList,
167                                   const QList<ModelNode> &lastSelectedNodeList)
168 {
169     m_output << time() << indent("selectedNodesChanged:") << endl;
170     foreach(const ModelNode &node, selectedNodeList)
171         m_output << time() << indent("new: ") << node << endl;
172     foreach(const ModelNode &node, lastSelectedNodeList)
173         m_output << time() << indent("old: ") << node << endl;
174 }
175
176 void ViewLogger::fileUrlChanged(const QUrl &oldUrl, const QUrl &newUrl)
177 {
178     m_output << time() << indent("fileUrlChanged:") << oldUrl.toString() << "\t" << newUrl.toString() << endl;
179 }
180
181 void ViewLogger::nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &movedNode, int oldIndex)
182 {
183     m_output << time() << indent("nodeOrderChanged:") << listProperty << movedNode << oldIndex << endl;
184 }
185
186 void ViewLogger::importsChanged()
187 {
188     m_output << time() << indent("importsChanged:") << endl;
189 }
190
191 void ViewLogger::auxiliaryDataChanged(const ModelNode &node, const QString &name, const QVariant &data)
192 {
193     m_output << time() << indent("auxiliaryDataChanged:") << node << "\t" << name << "\t" << data.toString() << endl;
194 }
195
196 void ViewLogger::customNotification(const AbstractView *view, const QString &identifier, const QList<ModelNode> &nodeList, const QList<QVariant> &data)
197 {
198     m_output << time() << indent("customNotification:") << view << identifier << endl;
199     foreach(const ModelNode &node, nodeList)
200         m_output << time() << indent("node: ") << node << endl;
201     foreach(const QVariant &variant, data)
202         m_output << time() << indent("data: ") << variant.toString() << endl;
203 }
204
205 void ViewLogger::scriptFunctionsChanged(const ModelNode &node, const QStringList &/*scriptFunctionList*/)
206 {
207     m_output << time() << indent("function scripts changed:") << node << endl;
208 }
209
210 void ViewLogger::instancePropertyChange(const QList<QPair<ModelNode, QString> > &propertyList)
211 {
212     typedef QPair<ModelNode, QString> PropertyPair;
213     m_output << time() << indent("instancePropertyChange:") << endl;
214
215     foreach(const PropertyPair &propertyPair, propertyList)
216         m_output << time() << indent("property: ") << propertyPair.first << propertyPair.second << endl;
217 }
218
219 void ViewLogger::instancesCompleted(const QVector<ModelNode> &completedNodeList)
220 {
221      m_output << time() << indent("instancesCompleted:") << endl;
222
223      foreach(const ModelNode &node, completedNodeList)
224          m_output << time() << indent("node: ") << node << endl;
225
226 }
227
228 } // namespace Internal
229 } // namespace QmlDesigner