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 #include "viewlogger.h"
36 #include <QTemporaryFile>
38 #include <variantproperty.h>
39 #include <bindingproperty.h>
40 #include <nodeabstractproperty.h>
41 #include <nodelistproperty.h>
43 namespace QmlDesigner {
46 static QString serialize(AbstractView::PropertyChangeFlags change)
48 QStringList tokenList;
50 if (change.testFlag(AbstractView::PropertiesAdded))
51 tokenList.append(QLatin1String("PropertiesAdded"));
53 if (change.testFlag(AbstractView::EmptyPropertiesRemoved))
54 tokenList.append(QLatin1String("EmptyPropertiesRemoved"));
56 return tokenList.join(" ");
59 static QString indent(const QString &name = QString()) {
60 return name.leftJustified(30, ' ');
63 QString ViewLogger::time() const
65 return QString::number(m_timer.elapsed()).leftJustified(7, ' ');
68 ViewLogger::ViewLogger(QObject *parent)
69 : AbstractView(parent)
72 const QString tempPath = "/tmp";
74 const QString tempPath = QDir::tempPath();
77 QTemporaryFile *temporaryFile = new QTemporaryFile(tempPath + QString("/qmldesigner-logger-%1-XXXXXX.txt").arg(QDateTime::currentDateTime().toString(Qt::ISODate).replace(":", "-")), this);
79 temporaryFile->setAutoRemove(false);
80 if (temporaryFile->open()) {
81 qDebug() << "QmlDesigner: Log file is:" << temporaryFile->fileName();
82 m_output.setDevice(temporaryFile);
84 qDebug() << "QmlDesigner: failed to open:" << temporaryFile->fileName();
90 void ViewLogger::modelAttached(Model *model)
92 m_output << time() << indent("modelAttached:") << model << endl;
93 AbstractView::modelAttached(model);
96 void ViewLogger::modelAboutToBeDetached(Model *model)
98 m_output << time() << indent("modelAboutToBeDetached:") << model << endl;
99 AbstractView::modelAboutToBeDetached(model);
102 void ViewLogger::nodeCreated(const ModelNode &createdNode)
104 m_output << time() << indent("nodeCreated:") << createdNode << endl;
107 void ViewLogger::nodeAboutToBeRemoved(const ModelNode &removedNode)
109 m_output << time() << indent("nodeAboutToBeRemoved:") << removedNode << endl;
112 void ViewLogger::nodeRemoved(const ModelNode &removedNode, const NodeAbstractProperty &parentProperty, PropertyChangeFlags propertyChange)
114 m_output << time() << indent("nodeRemoved:") << removedNode << parentProperty << serialize(propertyChange) << endl;
117 void ViewLogger::nodeAboutToBeReparented(const ModelNode &node, const NodeAbstractProperty &newPropertyParent, const NodeAbstractProperty &oldPropertyParent, AbstractView::PropertyChangeFlags propertyChange)
119 m_output << time() << indent("nodeAboutToBeReparented:") << node << "\t" << newPropertyParent << "\t" << oldPropertyParent << "\t" << serialize(propertyChange) << endl;
123 void ViewLogger::nodeReparented(const ModelNode &node, const NodeAbstractProperty &newPropertyParent, const NodeAbstractProperty &oldPropertyParent, AbstractView::PropertyChangeFlags propertyChange)
125 m_output << time() << indent("nodeReparented:") << node << "\t" << newPropertyParent << "\t" << oldPropertyParent << "\t" << serialize(propertyChange) << endl;
128 void ViewLogger::nodeIdChanged(const ModelNode& node, const QString& newId, const QString& oldId)
130 m_output << time() << indent("nodeIdChanged:") << node << "\t" << newId << "\t" << oldId << endl;
133 void ViewLogger::propertiesAboutToBeRemoved(const QList<AbstractProperty>& propertyList)
135 m_output << time() << indent("propertiesAboutToBeRemoved:") << endl;
136 foreach (const AbstractProperty &property, propertyList)
137 m_output << time() << indent() << property << endl;
140 void ViewLogger::propertiesRemoved(const QList<AbstractProperty> &propertyList)
142 m_output << time() << indent("propertiesRemoved:") << endl;
143 foreach (const AbstractProperty &property, propertyList)
144 m_output << time() << indent() << property << endl;
147 void ViewLogger::variantPropertiesChanged(const QList<VariantProperty>& propertyList, PropertyChangeFlags propertyChange)
149 m_output << time() << indent("variantPropertiesChanged:") << serialize(propertyChange) << endl;
150 foreach(const VariantProperty &property, propertyList)
151 m_output << time() << indent() << property << endl;
154 void ViewLogger::bindingPropertiesChanged(const QList<BindingProperty>& propertyList, PropertyChangeFlags propertyChange)
156 m_output << time() << indent("bindingPropertiesChanged:") << serialize(propertyChange) << endl;
157 foreach(const BindingProperty &property, propertyList)
158 m_output << time() << indent() << property << endl;
161 void ViewLogger::rootNodeTypeChanged(const QString &type, int majorVersion, int minorVersion)
163 m_output << time() << indent("rootNodeTypeChanged:") << rootModelNode() << type << majorVersion << minorVersion << endl;
166 void ViewLogger::selectedNodesChanged(const QList<ModelNode> &selectedNodeList,
167 const QList<ModelNode> &lastSelectedNodeList)
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;
176 void ViewLogger::fileUrlChanged(const QUrl &oldUrl, const QUrl &newUrl)
178 m_output << time() << indent("fileUrlChanged:") << oldUrl.toString() << "\t" << newUrl.toString() << endl;
181 void ViewLogger::nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &movedNode, int oldIndex)
183 m_output << time() << indent("nodeOrderChanged:") << listProperty << movedNode << oldIndex << endl;
186 void ViewLogger::importsChanged()
188 m_output << time() << indent("importsChanged:") << endl;
191 void ViewLogger::auxiliaryDataChanged(const ModelNode &node, const QString &name, const QVariant &data)
193 m_output << time() << indent("auxiliaryDataChanged:") << node << "\t" << name << "\t" << data.toString() << endl;
196 void ViewLogger::customNotification(const AbstractView *view, const QString &identifier, const QList<ModelNode> &nodeList, const QList<QVariant> &data)
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;
205 void ViewLogger::scriptFunctionsChanged(const ModelNode &node, const QStringList &/*scriptFunctionList*/)
207 m_output << time() << indent("function scripts changed:") << node << endl;
210 void ViewLogger::instancePropertyChange(const QList<QPair<ModelNode, QString> > &propertyList)
212 typedef QPair<ModelNode, QString> PropertyPair;
213 m_output << time() << indent("instancePropertyChange:") << endl;
215 foreach(const PropertyPair &propertyPair, propertyList)
216 m_output << time() << indent("property: ") << propertyPair.first << propertyPair.second << endl;
219 void ViewLogger::instancesCompleted(const QVector<ModelNode> &completedNodeList)
221 m_output << time() << indent("instancesCompleted:") << endl;
223 foreach(const ModelNode &node, completedNodeList)
224 m_output << time() << indent("node: ") << node << endl;
228 } // namespace Internal
229 } // namespace QmlDesigner