diff options
-rw-r--r-- | src/declarative/qml/qml.pri | 2 | ||||
-rw-r--r-- | src/declarative/qml/qmlcomponent.cpp | 11 | ||||
-rw-r--r-- | src/declarative/qml/qmlcomponent_p.h | 1 | ||||
-rw-r--r-- | src/declarative/qml/qmlscriptparser.cpp | 19 | ||||
-rw-r--r-- | src/declarative/qml/qmlxmlparser.cpp | 391 | ||||
-rw-r--r-- | src/declarative/qml/qmlxmlparser_p.h | 89 | ||||
-rw-r--r-- | tools/qmlconv/qmlconv.cpp | 482 | ||||
-rw-r--r-- | tools/qmlconv/qmlconv.pro | 10 |
8 files changed, 0 insertions, 1005 deletions
diff --git a/src/declarative/qml/qml.pri b/src/declarative/qml/qml.pri index 69a1461..5198264 100644 --- a/src/declarative/qml/qml.pri +++ b/src/declarative/qml/qml.pri @@ -8,7 +8,6 @@ SOURCES += qml/qmlparser.cpp \ qml/qmlcontext.cpp \ qml/qmlcustomparser.cpp \ qml/qmlpropertyvaluesource.cpp \ - qml/qmlxmlparser.cpp \ qml/qmlproxymetaobject.cpp \ qml/qmlvme.cpp \ qml/qmlcompiler.cpp \ @@ -37,7 +36,6 @@ HEADERS += qml/qmlparser_p.h \ qml/qmlcustomparser_p_p.h \ qml/qmlpropertyvaluesource.h \ qml/qmlboundsignal_p.h \ - qml/qmlxmlparser_p.h \ qml/qmlparserstatus.h \ qml/qmlproxymetaobject_p.h \ qml/qmlcompiledcomponent_p.h \ diff --git a/src/declarative/qml/qmlcomponent.cpp b/src/declarative/qml/qmlcomponent.cpp index 1e167d5..b1beb9c 100644 --- a/src/declarative/qml/qmlcomponent.cpp +++ b/src/declarative/qml/qmlcomponent.cpp @@ -60,17 +60,6 @@ QT_BEGIN_NAMESPACE class QByteArray; -bool QmlComponentPrivate::isXml(const QByteArray &ba) -{ - for (int i = 0; i < ba.size(); ++i) { - char c = ba.at(i); - if (c == ' ' || c == '\n' || c == '\r' || c == '\t') - continue; - return (c == '<'); - } - return true; -} - /*! \class QmlComponent \brief The QmlComponent class encapsulates a QML component description. diff --git a/src/declarative/qml/qmlcomponent_p.h b/src/declarative/qml/qmlcomponent_p.h index 0507958..6a5345e 100644 --- a/src/declarative/qml/qmlcomponent_p.h +++ b/src/declarative/qml/qmlcomponent_p.h @@ -82,7 +82,6 @@ public: QmlEngine *engine; void clear(); - static bool isXml(const QByteArray &); }; #endif // QMLCOMPONENT_P_H diff --git a/src/declarative/qml/qmlscriptparser.cpp b/src/declarative/qml/qmlscriptparser.cpp index 618eb2e..d0051ac 100644 --- a/src/declarative/qml/qmlscriptparser.cpp +++ b/src/declarative/qml/qmlscriptparser.cpp @@ -1,6 +1,5 @@ #include "qmlscriptparser_p.h" -#include "qmlxmlparser_p.h" #include "qmlparser_p.h" #include "parser/javascriptengine_p.h" @@ -562,24 +561,6 @@ QmlScriptParser::~QmlScriptParser() bool QmlScriptParser::parse(const QByteArray &data, const QUrl &url) { - if (QmlComponentPrivate::isXml(data)) { - // parse using the XML parser. - QmlXmlParser xmlParser; - if (xmlParser.parse(data, url)) { - _nameSpacePaths = xmlParser.nameSpacePaths(); - root = xmlParser.takeTree(); - _typeNames = xmlParser.types(); - return true; - } - - QmlError error; - error.setUrl(url); - error.setDescription(xmlParser.errorDescription()); - _errors << error; - - return false; - } - const QString fileName = url.toString(); QTextStream stream(data, QIODevice::ReadOnly); diff --git a/src/declarative/qml/qmlxmlparser.cpp b/src/declarative/qml/qmlxmlparser.cpp deleted file mode 100644 index 35d2c0e..0000000 --- a/src/declarative/qml/qmlxmlparser.cpp +++ /dev/null @@ -1,391 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qmlxmlparser_p.h" -#include "qmlcustomparser_p.h" -#include <qfxperf.h> -#include <QXmlStreamReader> -#include <QStack> -#include "qmlparser_p.h" -#include <private/qmlparser_p.h> -#include <QtCore/qdebug.h> - -QT_BEGIN_NAMESPACE -using namespace QmlParser; - -struct QmlXmlParserState { - QmlXmlParserState() : object(0), property(0) {} - QmlXmlParserState(Object *o) : object(o), property(0) {} - QmlXmlParserState(Object *o, Property *p) : object(o), property(p) {} - - Object *object; - Property *property; -}; - -struct QmlXmlParserStateStack : public QStack<QmlXmlParserState> -{ - void pushObject(Object *obj) - { - push(QmlXmlParserState(obj)); - } - - void pushProperty(const QString &name, int lineNumber) - { - const QmlXmlParserState &state = top(); - if (state.property) { - QmlXmlParserState s(state.property->getValue(), - state.property->getValue()->getProperty(name.toLatin1())); - s.property->line = lineNumber; - push(s); - } else { - QmlXmlParserState s(state.object, - state.object->getProperty(name.toLatin1())); - s.property->line = lineNumber; - push(s); - } - } -}; - -QmlXmlParser::~QmlXmlParser() -{ - if (root) - root->release(); -} - -QmlXmlParser::QmlXmlParser() -: root(0) -{ -} - -static QString flatXml(QXmlStreamReader& reader) -{ - QString result; - int depth=0; - QStringRef ns = reader.namespaceUri(); - while (depth>=0) { - switch (reader.tokenType()) { - case QXmlStreamReader::StartElement: - result += QLatin1Char('<'); - result += reader.name(); - if (reader.namespaceUri() != ns || depth==0) { - result += QLatin1String(" xmlns=\""); - result += reader.namespaceUri(); - result += QLatin1Char('"'); - } - foreach(QXmlStreamAttribute attr, reader.attributes()) { - result += QLatin1Char(' '); - result += attr.name(); - result += QLatin1String("=\""); - result += attr.value(); // XXX escape - result += QLatin1Char('"'); - } - result += QLatin1Char('>'); - ++depth; - break; - case QXmlStreamReader::EndElement: - result += QLatin1String("</"); - result += reader.name(); - result += QLatin1Char('>'); - --depth; - break; - case QXmlStreamReader::Characters: - result += reader.text(); - break; - default: - reader.raiseError(QLatin1String("Only StartElement, EndElement, and Characters permitted")); - break; - } - if (depth>=0) - reader.readNext(); - } - return result; -} - -bool QmlXmlParser::parse(const QByteArray &data, const QUrl &url) -{ -#ifdef Q_ENABLE_PERFORMANCE_LOG - QFxPerfTimer<QFxPerf::XmlParsing> pt; -#endif - - QString fileDisplayName; - if (url.isEmpty()) { - fileDisplayName = QLatin1String("<unspecified file>"); - } else if (url.scheme() == QLatin1String("file")) { - fileDisplayName = url.toLocalFile(); - } else { - fileDisplayName = url.toString(); - } - if (data.isEmpty()) { - _error = QLatin1String("No Qml was specified for parsing @") + fileDisplayName; - return false; - } - - QmlXmlParserStateStack states; - - QXmlStreamReader reader; - reader.addData(data); - - while(!reader.atEnd()) { - switch(reader.readNext()) { - case QXmlStreamReader::Invalid: - case QXmlStreamReader::NoToken: - case QXmlStreamReader::StartDocument: - case QXmlStreamReader::EndDocument: - break; - - case QXmlStreamReader::StartElement: - { - QString name = reader.name().toString(); - QString nameSpace = reader.namespaceUri().toString(); - int line = reader.lineNumber(); - bool isType = name.at(0).isUpper() && !name.contains(QLatin1Char('.')); - QString qualifiedname; - if (!nameSpace.isEmpty()) { - qualifiedname = nameSpace; - qualifiedname += QLatin1Char('/'); - } - qualifiedname += name; - QByteArray qualifiednameL1 = qualifiedname.toLatin1(); - QXmlStreamAttributes attrs = reader.attributes(); - - if (isType) { - // Class - int typeId = _typeNames.indexOf(qualifiedname); - if (typeId == -1) { - typeId = _typeNames.count(); - _typeNames.append(qualifiedname); - } - - Object *obj = new Object; - obj->type = typeId; - obj->typeName = qualifiednameL1; - obj->line = line; - - QmlCustomParser *customparser = QmlMetaType::customParser(qualifiednameL1); - if (customparser) { - bool ok; - obj->custom = customparser->compile(reader, &ok); - if (reader.tokenType() != QXmlStreamReader::EndElement) { - reader.raiseError(QLatin1String("Parser for ") + qualifiedname + QLatin1String(" did not end on end element")); - ok = false; - } - if (!ok) { - delete obj; - break; - } - } - - - if (!root) { - root = obj; - states.pushObject(obj); - } else { - const QmlXmlParserState &state = states.top(); - Value *v = new Value; - v->object = obj; - v->line = line; - if (state.property) - state.property->addValue(v); - else - state.object->getDefaultProperty()->addValue(v); - states.pushObject(obj); - } - } else { - // Property - if (!root) { - reader.raiseError(QLatin1String("Can't have a property with no object")); - break; - } - QStringList str = name.split(QLatin1Char('.')); - for (int ii = 0; ii < str.count(); ++ii) { - QString s = str.at(ii); - states.pushProperty(s, line); - } - if (!nameSpace.isEmpty()) { - // Pass non-QML as flat text property value - const QmlXmlParserState &state = states.top(); - Value *v = new Value; - v->primitive = flatXml(reader); - v->line = line; - state.property->addValue(v); - } - } - - // (even custom parsed content gets properties set) - foreach(QXmlStreamAttribute attr, attrs) { - QStringList str = attr.name().toString().split(QLatin1Char('.')); - - for (int ii = 0; ii < str.count(); ++ii) { - QString s = str.at(ii); - states.pushProperty(s, line); - } - - const QmlXmlParserState &state = states.top(); - Value *v = new Value; - v->primitive = attr.value().toString(); - v->line = reader.lineNumber(); - state.property->addValue(v); - - for (int ii = str.count() - 1; ii >= 0; --ii) - states.pop(); - } - } - - // Custom parsers and namespaced properties move - // the reader to the end element, so we handle that - // BEFORE continuing. - // - if (reader.tokenType()!=QXmlStreamReader::EndElement) - break; - // ELSE fallthrough to EndElement... - case QXmlStreamReader::EndElement: - { - QString name = reader.name().toString(); - Q_ASSERT(!name.isEmpty()); - if (name.at(0).isUpper() && !name.contains(QLatin1Char('.'))) { - // Class - states.pop(); - } else { - // Property - QStringList str = name.split(QLatin1Char('.')); - for (int ii = 0; ii < str.count(); ++ii) - states.pop(); - } - } - break; - case QXmlStreamReader::Characters: - if (!reader.isWhitespace()) { - const QmlXmlParserState &state = states.top(); - Value *v = new Value; - v->primitive = reader.text().toString(); - v->line = reader.lineNumber(); - if (state.property) - state.property->addValue(v); - else - state.object->getDefaultProperty()->addValue(v); - } - break; - - case QXmlStreamReader::Comment: - case QXmlStreamReader::DTD: - case QXmlStreamReader::EntityReference: - break; - case QXmlStreamReader::ProcessingInstruction: - if (reader.processingInstructionTarget() == QLatin1String("qtfx")) { - QString str = reader.processingInstructionData().toString(); - QString token, data; - int idx = str.indexOf(QLatin1Char(':')); - if (-1 != idx) { - token = str.left(idx); - data = str.mid(idx + 1); - } else { - token = str; - } - token = token.trimmed(); - data = data.trimmed(); - - // <?qtfx namespacepath: namespace=path> - - if (token == QLatin1String("namespacepath")) { - int eq=data.indexOf(QLatin1Char('=')); - if (eq>=0) { - _nameSpacePaths.insertMulti(data.left(eq),data.mid(eq+1)); - } - } else { - str = str.trimmed(); - qWarning().nospace() << "Unknown processing instruction " << str.toLatin1().constData() << " @" << fileDisplayName.toLatin1().constData() << ":" << reader.lineNumber(); - } - } - break; - } - } - - if (reader.hasError()) { - if (root) { - root->release(); - root = 0; - } - _error = reader.errorString() + QLatin1String(" @") + fileDisplayName + - QLatin1String(":") + QString::number(reader.lineNumber()); - } - - return root != 0; -} - -QMap<QString,QString> QmlXmlParser::nameSpacePaths() const -{ - return _nameSpacePaths; -} - -QStringList QmlXmlParser::types() const -{ - return _typeNames; -} - -QmlParser::Object *QmlXmlParser::tree() const -{ - return root; -} - -QmlParser::Object *QmlXmlParser::takeTree() -{ - QmlParser::Object *r = root; - root = 0; - return r; -} - -QString QmlXmlParser::errorDescription() const -{ - return _error; -} - -void QmlXmlParser::clear() -{ - if (root) { - root->release(); - root = 0; - } - _nameSpacePaths.clear(); - _typeNames.clear(); - _error.clear(); -} - -QT_END_NAMESPACE diff --git a/src/declarative/qml/qmlxmlparser_p.h b/src/declarative/qml/qmlxmlparser_p.h deleted file mode 100644 index 9b45e28..0000000 --- a/src/declarative/qml/qmlxmlparser_p.h +++ /dev/null @@ -1,89 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMLXMLPARSER_P_H -#define QMLXMLPARSER_P_H - -#include <QList> -#include <QUrl> -#include <qml.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -namespace QmlParser { - class Object; -} - -class QByteArray; -class QmlXmlParser -{ -public: - QmlXmlParser(); - ~QmlXmlParser(); - - bool parse(const QByteArray &data, const QUrl &url=QUrl()); - QString errorDescription() const; - - QMap<QString,QString> nameSpacePaths() const; - QStringList types() const; - - QmlParser::Object *tree() const; - QmlParser::Object *takeTree(); - - void clear(); - -private: - QMap<QString,QString> _nameSpacePaths; - QmlParser::Object *root; - QStringList _typeNames; - QString _error; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QMLXMLPARSER_P_H - diff --git a/tools/qmlconv/qmlconv.cpp b/tools/qmlconv/qmlconv.cpp deleted file mode 100644 index 6e89530..0000000 --- a/tools/qmlconv/qmlconv.cpp +++ /dev/null @@ -1,482 +0,0 @@ -#include <QtCore/QCoreApplication> -#include <QtCore/QFile> -#include <QtCore/QXmlStreamReader> -#include <QtCore/QStack> -#include <QtCore/QStringList> -#include <QtCore/QDebug> - - -static bool optionInPlace = false; - -class Reader -{ - QString outString; - QTextStream out; - QXmlStreamReader xml; - int depth; - bool supressIndent; - - QStringList knownListProperties; - inline QString depthString() {if (supressIndent) { supressIndent = false; return QString(); } - return QString(depth*4, QLatin1Char(' '));} - -public: - Reader(QIODevice *in) - :xml(in) { - - knownListProperties << "states" << "transitions" << "children" << "resources" - << "transform" << "notes"; - depth = 0; - supressIndent = false; - - out.setString(&outString); - - loop(); - - out.flush(); - - if (! optionInPlace) { - QTextStream print(stdout); - print << outString; - } - } - - QString output() const - { - return outString; - } - - void comment() - { - if (xml.isComment()) { - out << depthString() << "// " - << xml.text().toString().trimmed().replace(QRegExp("\n\\s*"),"\n"+depthString()+"// ") - << endl; - } - } - - void emptyLoop() { - while (!xml.atEnd()) { - xml.readNext(); - comment(); - if (xml.tokenType() == QXmlStreamReader::EndElement) - return; - } - } - - void loop() - { - while (!xml.atEnd()) { - xml.readNext(); - if (xml.tokenType() == QXmlStreamReader::EndElement) - return; - else if (xml.tokenType() == QXmlStreamReader::StartElement) - startElement(); - else if (xml.tokenType() == QXmlStreamReader::ProcessingInstruction) { - if (xml.processingInstructionTarget() == QLatin1String("qtfx")) { - QString data = xml.processingInstructionData().toString().trimmed(); - if (data.startsWith(QLatin1String("namespacepath:="))) { - outString.prepend( QLatin1String("import \"") + data.mid(data.indexOf(QLatin1Char('='))+1) + QLatin1String("\"\n")); - } - } - } - comment(); - } - } - - void startElement() { - - if (!propertyChangeSet.isEmpty() - && xml.name() != "SetProperties" - && xml.name() != "SetProperty") { - clearPropertyChangeSet(); - } - - if (false && xml.name() == "properties") - startDeclareProperties(); - else if (false && xml.name() == "signals") - startDeclareSignals(); - else if (false && xml.name() == "states") - loop(); // ignore - else if (false && xml.name() == "transitions") - loop(); // ignore - else if (knownListProperties.contains(xml.name().toString())) - startList(); - else if (false && xml.name() == "SetProperties") - startSetProperties(); - else if (false && xml.name() == "SetProperty") - startSetProperty(); - else if (false && xml.name() == "ParentChange") - startParentChange(); - else if (true && xml.name() == "Connection") - startConnection(); - else if (false && xml.name() == "Script") - startScript(); - else if (xml.name().at(0).isLower() && xml.attributes().isEmpty()) - startObjectProperty(); - else - startItem(); - } - - static void possiblyRemoveBraces(QString *s) { - if (s->startsWith('{') && s->endsWith('}')) - *s = s->mid(1, s->length() - 2); - } - - static bool isNumber(const QString &s) { - bool ok = true; - s.toFloat(&ok); - return ok; - } - - static bool isSignalHandler(const QString &s) { - return s.size() > 3 - && s.startsWith("on") - && s.at(2).isUpper(); - } - - static bool isEnum(const QString &property, const QString &value) { - return !value.contains(' ') && (property == "vAlign" || property == "hAlign" - || property == "style"); - } - - static bool isIdentifier(const QString &s) { - if (s.isEmpty()) - return false; - if (!s.at(1).isLetter()) - return false; - for (int i = 1; i < s.size(); ++i) { - QChar c = s.at(i); - if (c.isLetterOrNumber() - || c == QLatin1Char('_') - || c == QLatin1Char('-')) - continue; - return false; - } - return true; - } - - - void setProperty(const QString &property, const QString &value, bool newline = true) { - QString v = value.trimmed(); - if (v.startsWith('{')) { - possiblyRemoveBraces(&v); - } else if (v == "true" - || v == "false" - || isNumber(v) - || property == "id" - || isEnum(property, value) - ) { - ; - } else if (isSignalHandler(property)) { - // if not a function name, create an anonymous function - if (!isIdentifier(v)) { - v.prepend("{ "); - v.append(" }"); - } - } else - - // if (property == "text" || property == "name" || value.contains(' ') - // || value.contains("/") || value.startsWith('#') - // || property == "filename" || property == "source" || property == "src" - // || property == "title" || property == "movieTitle" || property == "movieDescription" - // || property == "properties" || property == "fromState" || property == "toState" - // ) - { - v.prepend('\"'); - v.append('\"'); - } - -// QByteArray semiColon = ";"; -// if (v.endsWith(QLatin1Char('}')) || v.endsWith(QLatin1Char(';'))) -// semiColon.clear(); - - if (!newline) - out << property << ": " << v /* << semiColon.constData() */; - else - out << depthString() << property << ": " << v /* << semiColon.constData() */ << endl; - } - - - typedef QPair<QString,QString> StringPair; - QList<StringPair> propertyChangeSet; - void startItem(bool inList = false) { - - QString name = xml.name().toString(); - - out << depthString() << name << " {" << endl; - ++depth; - - foreach (QXmlStreamAttribute attribute, xml.attributes()) { - setProperty(attribute.name().toString(), attribute.value().toString()); - } - - if (name == "Script") { - QString text = xml.readElementText(); - if (!text.trimmed().isEmpty()) { - out << text << endl; - } - } else { - loop(); - } - - if (name == "State") - clearPropertyChangeSet(); - - --depth; - out << depthString() << "}"; - if (!inList) - out << endl; - } - - void clearPropertyChangeSet() { - if (propertyChangeSet.isEmpty()) - return; - - out << depthString() << "PropertyChangeSet" << " {" << endl; - ++depth; - foreach(StringPair pair, propertyChangeSet) - setProperty(pair.first, pair.second); - --depth; - out << depthString() << "}" << endl; - propertyChangeSet.clear(); - } - - void startObjectProperty() { - - QString name = xml.name().toString(); - bool hasElements = false; - while (!xml.atEnd()) { - xml.readNext(); - if (xml.tokenType() == QXmlStreamReader::EndElement) - break; - if (xml.tokenType() == QXmlStreamReader::StartElement) { - hasElements = true; - out << depthString() << name << ": "; - supressIndent = true; - startElement(); - } else if (!hasElements && xml.tokenType() == QXmlStreamReader::Characters) { - if (!xml.text().toString().trimmed().isEmpty()) { - setProperty(name, xml.text().toString()); - } - } - comment(); - } - } - - void startDeclareProperty() { - out << depthString() << "public property "; - - if (xml.attributes().hasAttribute("type")) - out << "/* " << xml.attributes().value("type").toString() << " */ "; - - QString name = xml.attributes().value("name").toString(); - - if (xml.attributes().hasAttribute("value")) - setProperty(name, xml.attributes().value("value").toString(), false); - else out << name; - - QMap<QString, QString> attributes; - foreach (QXmlStreamAttribute attribute, xml.attributes()) { - if (attribute.name() == "name" || attribute.name() == "value") - continue; - attributes.insert(attribute.name().toString(), attribute.value().toString()); - } - out << endl; - emptyLoop(); - } - - void startDeclareProperties() { - while (!xml.atEnd()) { - xml.readNext(); - if (xml.tokenType() == QXmlStreamReader::EndElement) - return; - if (xml.tokenType() == QXmlStreamReader::StartElement) { - if (xml.name() == "Property") - startDeclareProperty(); - } - comment(); - } - } - - void startDeclareSignal() { - out << depthString() << "public signal " << xml.attributes().value("name").toString() << endl; - emptyLoop(); - } - - void startDeclareSignals() { - while (!xml.atEnd()) { - xml.readNext(); - if (xml.tokenType() == QXmlStreamReader::EndElement) - return; - if (xml.tokenType() == QXmlStreamReader::StartElement) { - if (xml.name() == "Signal") - startDeclareSignal(); - } - comment(); - } - } - - - void startSetProperties() { - QString target = xml.attributes().value("target").toString(); - possiblyRemoveBraces(&target); - foreach (QXmlStreamAttribute attribute, xml.attributes()) { - if (attribute.name() == "target") - continue; - propertyChangeSet += StringPair(target + "." + attribute.name().toString(), attribute.value().toString()); - } - emptyLoop(); - } - - void startSetProperty() { - QString target = xml.attributes().value("target").toString(); - possiblyRemoveBraces(&target); - propertyChangeSet += StringPair(target + "." + xml.attributes().value("property").toString(), - xml.attributes().value("value").toString()); - - emptyLoop(); - } - - void startParentChange() { - QString target = xml.attributes().value("target").toString(); - possiblyRemoveBraces(&target); - - out << depthString() << "ParentChangeSet" << " {" << endl; - ++depth; - setProperty(target + ".parent", xml.attributes().value("parent").toString()); - --depth; - out << depthString() << "}" << endl; - -// propertyChangeSet += StringPair(target + ".moveToParent", xml.attributes().value("parent").toString()); - - emptyLoop(); - } - - void startConnection() { - QString sender = xml.attributes().value("sender").toString(); - possiblyRemoveBraces(&sender); - out << depthString() << "Connection {" << endl; - ++depth; - if (! sender.isEmpty()) - out << depthString() << "sender: " << sender << endl; - if (xml.attributes().hasAttribute("signal")) - out << depthString() << "signal: \"" << xml.attributes().value("signal").toString() << '"' << endl; - if (xml.attributes().hasAttribute("script")) { - out << depthString() << "script: { " << xml.attributes().value("script").toString() << " }" << endl; - --depth; - out << depthString() << "}" << endl; - } else { - QString text; - while (!xml.atEnd()) { - xml.readNext(); - if (xml.tokenType() == QXmlStreamReader::EndElement) - break; - else if (xml.tokenType() == QXmlStreamReader::Characters) - text.append(xml.text()); - } - - out << depthString() << "script: {" << endl; - foreach (QString line, text.split(QLatin1Char('\n'))) { - out << depthString() << line << endl; - } - out << depthString() << "}" << endl; - --depth; - out << depthString() << "}" << endl; - } - emptyLoop(); - } - - void startScript() { - if (xml.attributes().hasAttribute(QLatin1String("src"))) { - /* - QString import; - QTextStream ts(&import); - ts << "import \""; - ts << xml.attributes().value(QLatin1String("src")).toString(); - ts << "\"" << endl; - ts.flush(); - outString.prepend(import); - */ - } - QString text = xml.readElementText(); - if (!text.trimmed().isEmpty()) { - out << text << endl; - } - if (xml.tokenType() != QXmlStreamReader::EndElement) - emptyLoop(); - } - - void startList() - { - out << depthString() << xml.name().toString() << ": [" << endl; - ++depth; - bool needComma = false; - - while (!xml.atEnd()) { - xml.readNext(); - if (xml.tokenType() == QXmlStreamReader::EndElement) - break; - if (xml.tokenType() == QXmlStreamReader::StartElement) { - if (needComma) - out << "," << endl; - startItem(true); - needComma = true; - } - comment(); - } - - out << endl; - --depth; - out << depthString() << "]" << endl; - } - -}; - - - -int main(int argc, char *argv[]) -{ - QCoreApplication a(argc, argv); - - QStringList args = a.arguments(); - args.removeFirst(); - - if (!args.isEmpty() && args.first() == QLatin1String("-i")) { - optionInPlace = true; - args.removeFirst(); - } - - if (args.isEmpty() && optionInPlace) { - qWarning() << "Usage: qmlconv [ [-i] filename ]"; - exit(1); - } - - const QString fileName = args.isEmpty() ? QString("-") : args.first(); - - QFile file(fileName); - if (fileName == "-") { - file.open(0,QIODevice::ReadOnly); - } else { - if (! file.open(QIODevice::ReadOnly)) { - qWarning() << "qmlconv: no input file"; - exit(1); - } - } - - Reader r(&file); - file.close(); - - if (optionInPlace) { - if (! file.open(QFile::WriteOnly)) { - qWarning() << "qmlconv: cannot open file" << qPrintable(fileName); - exit(1); - } - - QTextStream out(&file); - out << r.output(); - file.close(); - } - - return 0; -} diff --git a/tools/qmlconv/qmlconv.pro b/tools/qmlconv/qmlconv.pro deleted file mode 100644 index 331f4ee..0000000 --- a/tools/qmlconv/qmlconv.pro +++ /dev/null @@ -1,10 +0,0 @@ -DESTDIR = ../../bin -QT -= gui -# Input -SOURCES += qmlconv.cpp - -target.path=$$[QT_INSTALL_BINS] -INSTALLS += target - -CONFIG += console -macx:CONFIG -= app_bundle |