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 //static void testMessageOutput(QtMsgType type, const char *msg)
37 //#ifdef QDEBUG_IN_TESTS
38 // std::fprintf(stderr, "Debug: %s\n", msg);
39 //#endif // QDEBUG_IN_TESTS
42 //#ifdef WARNINGS_IN_TESTS
43 // std::fprintf(stderr, "Warning: %s\n", msg);
44 //#endif // WARNINGS_IN_TESTS
46 // case QtCriticalMsg:
47 // std::fprintf(stderr, "Critical: %s\n", msg);
50 // std::fprintf(stderr, "Fatal: %s\n", msg);
55 static ModelNode addNodeListChild(const ModelNode &parentNode, const QString &typeName, int major, int minor, const QString &parentProperty)
57 ModelNode newNode = parentNode.view()->createModelNode(typeName, major, minor);
58 parentNode.nodeListProperty(parentProperty).reparentHere(newNode);
62 static ModelNode addNodeChild(const ModelNode &parentNode, const QString &typeName, int major, int minor, const QString &parentProperty)
64 ModelNode newNode = parentNode.view()->createModelNode(typeName, major, minor);
65 parentNode.nodeProperty(parentProperty).reparentHere(newNode);
69 static QString bareTemplate("import Qt 4.6\n"
70 "Item { id: parentItem;"
73 static QString contentsTemplate(bareTemplate.arg("Text { id: textChild; x:10; y: 10; text: \"%1\"; %2 }"));
76 void printErrors(const QList<QDeclarativeError> &errors, const QString &fileName)
81 qDebug() << "Error loading file \"" << fileName << "\":";
83 foreach (const QDeclarativeError &error, errors) {
84 qDebug() << error.line() << ":" << error.column() << ": " << error.description();
88 // TODO: this need to e updated for states
89 static bool compareProperty(const AbstractProperty &property1, const AbstractProperty &property2)
91 return (property1.name() == property2.name());
92 // && (property1.value().type() == property2.value().type());
93 // && (property1.value() == property2.value()));
96 // TODO: this need to e updated for states
97 static bool compareTree(const ModelNode &node1, const ModelNode &node2)
99 if (!node1.isValid() || !node2.isValid()) {
103 if (node1.type() != node2.type()) {
107 // Compare properties
109 const QList<AbstractProperty> propList1 = node1.properties();
110 const QList<AbstractProperty> propList2 = node2.properties();
112 QList<AbstractProperty>::const_iterator iter1 = propList1.constBegin();
113 QList<AbstractProperty>::const_iterator iter2 = propList2.constBegin();
115 iter1 != propList1.constEnd() && iter2 != propList2.constEnd();
117 if (!compareProperty(*iter1, *iter2))
121 if (iter1 != propList1.constEnd() || iter2 != propList2.constEnd())
125 // Compare list of children
127 const QList<ModelNode> childList1 = node1.allDirectSubModelNodes();
128 const QList<ModelNode> childList2 = node2.allDirectSubModelNodes();
130 QList<ModelNode>::const_iterator iter1;
131 QList<ModelNode>::const_iterator iter2;
132 for (iter1 = childList1.constBegin(), iter2 = childList2.constBegin();
133 iter1 != childList1.constEnd() && iter2 != childList2.constEnd();
135 if (!compareTree((*iter1), (*iter2)))
139 if (iter1 != childList1.constEnd() || iter2 != childList2.constEnd())
145 //void load(const QString &data, Model *&model, ByteArrayModifier *&modifier)
148 // QByteArray bytes = data.toLatin1();
149 // QBuffer file(&bytes, 0);
150 // QVERIFY(file.open(QIODevice::ReadOnly));
151 // QList<QDeclarativeError> errors;
152 // QString fileText(file.readAll());
153 // modifier = ByteArrayModifier::create(QString(fileText));
154 // model = Model::create(modifier, QUrl(), &errors);
156 // if (!errors.isEmpty()) {
157 // printErrors(errors, "<inline>");
163 //void reload(const QString &data, ByteArrayModifier *modifier)
165 // modifier->setText(data);
168 //static Model* create(const QString& document)
170 // ByteArrayModifier* modifier = 0;
173 // load(document, model, modifier);
175 // if (modifier && model)
176 // modifier->setParent(model);