From f7573945387671cafaff14924905859e296b47f7 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 5 May 2009 12:46:41 +1000 Subject: QmlError doc --- src/declarative/qml/qmlcomponent.cpp | 4 +++ src/declarative/qml/qmlerror.cpp | 47 ++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/src/declarative/qml/qmlcomponent.cpp b/src/declarative/qml/qmlcomponent.cpp index 3b4d7b3..66440f5 100644 --- a/src/declarative/qml/qmlcomponent.cpp +++ b/src/declarative/qml/qmlcomponent.cpp @@ -351,6 +351,10 @@ void QmlComponent::loadUrl(const QUrl &url) emit statusChanged(status()); } +/*! + Return the list of errors that occured during the last compile or create + operation. An empty list is returned if isError() is not set. +*/ QList QmlComponent::errors() const { Q_D(const QmlComponent); diff --git a/src/declarative/qml/qmlerror.cpp b/src/declarative/qml/qmlerror.cpp index 66c834f..2ed3500 100644 --- a/src/declarative/qml/qmlerror.cpp +++ b/src/declarative/qml/qmlerror.cpp @@ -46,6 +46,10 @@ QT_BEGIN_NAMESPACE +/*! + \class QmlError + \brief The QmlError class encapsulates a QML error +*/ class QmlErrorPrivate { public: @@ -62,17 +66,26 @@ QmlErrorPrivate::QmlErrorPrivate() { } +/*! + Create an empty error object. +*/ QmlError::QmlError() : d(new QmlErrorPrivate) { } +/*! + Create a copy of \a other. +*/ QmlError::QmlError(const QmlError &other) : d(new QmlErrorPrivate) { *this = other; } +/*! + Assign \a other to this error object. +*/ QmlError &QmlError::operator=(const QmlError &other) { d->url = other.d->url; @@ -82,51 +95,85 @@ QmlError &QmlError::operator=(const QmlError &other) return *this; } +/*! + \internal +*/ QmlError::~QmlError() { delete d; d = 0; } +/*! + Return the url for the file that caused this error. +*/ QUrl QmlError::url() const { return d->url; } +/*! + Set the \a url for the file that caused this error. +*/ void QmlError::setUrl(const QUrl &url) { d->url = url; } +/*! + Return the error description. +*/ QString QmlError::description() const { return d->description; } +/*! + Set the error \a description. +*/ void QmlError::setDescription(const QString &description) { d->description = description; } +/*! + Return the error line number. +*/ int QmlError::line() const { return d->line; } +/*! + Set the error \a line number. +*/ void QmlError::setLine(int line) { d->line = line; } +/*! + Return the error column number. +*/ int QmlError::column() const { return d->column; } +/*! + Set the error \a column number. +*/ void QmlError::setColumn(int column) { d->column = column; } +/*! + \relates QmlError + \fn QDebug operator<<(QDebug debug, const QmlError &error) + + Output a human readable version of \a error to \a debug. +*/ + QDebug operator<<(QDebug debug, const QmlError &error) { QUrl url = error.url(); -- cgit v0.12 From caa1832f8dd6012ed3d44d7b822c500485ffb5ec Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 5 May 2009 12:49:26 +1000 Subject: Mark DOM API as internal for now --- src/declarative/qml/qmldom.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/declarative/qml/qmldom.cpp b/src/declarative/qml/qmldom.cpp index 3942375..08755b1 100644 --- a/src/declarative/qml/qmldom.cpp +++ b/src/declarative/qml/qmldom.cpp @@ -70,6 +70,7 @@ QmlDomDocumentPrivate::~QmlDomDocumentPrivate() /*! \class QmlDomDocument + \internal \brief The QmlDomDocument class represents the root of a QML document A QML document is a self-contained snippet of QML, usually contained in a @@ -251,6 +252,7 @@ QmlDomPropertyPrivate::~QmlDomPropertyPrivate() /*! \class QmlDomProperty + \internal \brief The QmlDomProperty class represents one property assignment in the QML DOM tree @@ -452,6 +454,7 @@ QmlDomObjectPrivate::properties(QmlParser::Property *property) const /*! \class QmlDomObject + \internal \brief The QmlDomObject class represents an object instantiation. Each object instantiated in a QML file has a corresponding QmlDomObject @@ -736,6 +739,7 @@ QmlDomBasicValuePrivate::~QmlDomBasicValuePrivate() /*! \class QmlDomValueLiteral + \internal \brief The QmlDomValueLiteral class represents a literal value. A literal value is a simple value, written inline with the QML. In the @@ -808,6 +812,7 @@ void QmlDomValueLiteral::setLiteral(const QString &value) /*! \class QmlDomValueBinding + \internal \brief The QmlDomValueBinding class represents a property binding. A property binding is an ECMAScript expression assigned to a property. In @@ -877,6 +882,7 @@ void QmlDomValueBinding::setBinding(const QString &expression) /*! \class QmlDomValueValueSource + \internal \brief The QmlDomValueValueSource class represents a value source assignment value. In QML, value sources are special value generating types that may be @@ -985,6 +991,7 @@ QmlDomValuePrivate::~QmlDomValuePrivate() /*! \class QmlDomValue + \internal \brief The QmlDomValue class represents a generic Qml value. QmlDomValue's can be assigned to QML \l {QmlDomProperty}{properties}. In @@ -1236,6 +1243,7 @@ QmlDomList QmlDomValue::toList() const /*! \class QmlDomList + \internal \brief The QmlDomList class represents a list of values assigned to a QML property. Lists of values can be assigned to properties. For example, the following @@ -1325,6 +1333,7 @@ void QmlDomList::setValues(const QList &values) /*! \class QmlDomComponent + \internal \brief The QmlDomComponent class represents sub-component within a QML document. Sub-components are QmlComponents defined within a QML document. The -- cgit v0.12 From ca737861c5b6459a3f5f33cafbbe371da5c113c4 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Tue, 5 May 2009 13:17:20 +1000 Subject: Minehunt switched to KDE smiley faces Minehunt example now meets minimum aesthetic requirements. --- examples/declarative/minehunt/minehunt.qml | 6 +++--- examples/declarative/minehunt/pics/face-sad.png | Bin 0 -> 14844 bytes examples/declarative/minehunt/pics/face-smile-big.png | Bin 0 -> 13810 bytes examples/declarative/minehunt/pics/face-smile.png | Bin 0 -> 15408 bytes examples/declarative/minehunt/pics/frown.png | Bin 1036 -> 0 bytes examples/declarative/minehunt/pics/glee.png | Bin 1082 -> 0 bytes examples/declarative/minehunt/pics/smile.png | Bin 1028 -> 0 bytes 7 files changed, 3 insertions(+), 3 deletions(-) create mode 100644 examples/declarative/minehunt/pics/face-sad.png create mode 100644 examples/declarative/minehunt/pics/face-smile-big.png create mode 100644 examples/declarative/minehunt/pics/face-smile.png delete mode 100644 examples/declarative/minehunt/pics/frown.png delete mode 100644 examples/declarative/minehunt/pics/glee.png delete mode 100644 examples/declarative/minehunt/pics/smile.png diff --git a/examples/declarative/minehunt/minehunt.qml b/examples/declarative/minehunt/minehunt.qml index 58397b0..bf31c3d 100644 --- a/examples/declarative/minehunt/minehunt.qml +++ b/examples/declarative/minehunt/minehunt.qml @@ -148,9 +148,9 @@ Item { text: numFlags } Image { - x: 240 - y: 0 - source: if(isPlaying==true){'pics/smile.png'}else{if(hasWon==true){'pics/glee.png'}else{'pics/frown.png'}} + x: 280 + y: 10 + source: if(isPlaying==true){'pics/face-smile.png'}else{if(hasWon==true){'pics/face-smile-big.png'}else{'pics/face-sad.png'}} MouseRegion { anchors.fill: parent onClicked: { reset() } diff --git a/examples/declarative/minehunt/pics/face-sad.png b/examples/declarative/minehunt/pics/face-sad.png new file mode 100644 index 0000000..cf00aaf Binary files /dev/null and b/examples/declarative/minehunt/pics/face-sad.png differ diff --git a/examples/declarative/minehunt/pics/face-smile-big.png b/examples/declarative/minehunt/pics/face-smile-big.png new file mode 100644 index 0000000..f9c2335 Binary files /dev/null and b/examples/declarative/minehunt/pics/face-smile-big.png differ diff --git a/examples/declarative/minehunt/pics/face-smile.png b/examples/declarative/minehunt/pics/face-smile.png new file mode 100644 index 0000000..3d66d72 Binary files /dev/null and b/examples/declarative/minehunt/pics/face-smile.png differ diff --git a/examples/declarative/minehunt/pics/frown.png b/examples/declarative/minehunt/pics/frown.png deleted file mode 100644 index 52684b3..0000000 Binary files a/examples/declarative/minehunt/pics/frown.png and /dev/null differ diff --git a/examples/declarative/minehunt/pics/glee.png b/examples/declarative/minehunt/pics/glee.png deleted file mode 100644 index 59ea583..0000000 Binary files a/examples/declarative/minehunt/pics/glee.png and /dev/null differ diff --git a/examples/declarative/minehunt/pics/smile.png b/examples/declarative/minehunt/pics/smile.png deleted file mode 100644 index ccd52cd..0000000 Binary files a/examples/declarative/minehunt/pics/smile.png and /dev/null differ -- cgit v0.12 From d02cc90ec24fd30d1440e06eb443eafb221cdbe7 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 5 May 2009 13:25:46 +1000 Subject: Fix QmlComponent::isError() after QmlComponent::create() --- src/declarative/qml/qmlcomponent.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/declarative/qml/qmlcomponent.cpp b/src/declarative/qml/qmlcomponent.cpp index 66440f5..1e167d5 100644 --- a/src/declarative/qml/qmlcomponent.cpp +++ b/src/declarative/qml/qmlcomponent.cpp @@ -190,10 +190,10 @@ QmlComponent::Status QmlComponent::status() const if (d->typeData) return Loading; - else if (d->engine && d->cc) - return Ready; else if (!d->errors.isEmpty()) return Error; + else if (d->engine && d->cc) + return Ready; else return Null; } -- cgit v0.12 From 6089208e78bdcb0091c0ba0bc2fbd2a4fc0806de Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 5 May 2009 13:48:29 +1000 Subject: Remove QML XML support --- src/declarative/qml/qml.pri | 2 - src/declarative/qml/qmlcomponent.cpp | 11 - src/declarative/qml/qmlcomponent_p.h | 1 - src/declarative/qml/qmlscriptparser.cpp | 19 -- src/declarative/qml/qmlxmlparser.cpp | 391 -------------------------- src/declarative/qml/qmlxmlparser_p.h | 89 ------ tools/qmlconv/qmlconv.cpp | 482 -------------------------------- tools/qmlconv/qmlconv.pro | 10 - 8 files changed, 1005 deletions(-) delete mode 100644 src/declarative/qml/qmlxmlparser.cpp delete mode 100644 src/declarative/qml/qmlxmlparser_p.h delete mode 100644 tools/qmlconv/qmlconv.cpp delete mode 100644 tools/qmlconv/qmlconv.pro 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 -#include -#include -#include "qmlparser_p.h" -#include -#include - -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 -{ - 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("'); - --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 pt; -#endif - - QString fileDisplayName; - if (url.isEmpty()) { - fileDisplayName = QLatin1String(""); - } 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(); - - // - - 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 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 -#include -#include - -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 nameSpacePaths() const; - QStringList types() const; - - QmlParser::Object *tree() const; - QmlParser::Object *takeTree(); - - void clear(); - -private: - QMap _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 -#include -#include -#include -#include -#include - - -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 StringPair; - QList 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 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 -- cgit v0.12 From f062be7569804461dad94d5b80dc0b87298fd5eb Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 5 May 2009 14:00:03 +1000 Subject: Remove XML custom parser support --- .../phonebrowser/dummydata/PhonesModel.qml | 2 +- .../declarative/pathview/dummydata/MenuModel.qml | 2 +- .../contacts/dummydata/contactModel.qml | 2 +- examples/declarative/easing/easing.qml | 2 +- .../declarative/listview/dummydata/MyPetsModel.qml | 2 +- .../declarative/listview/dummydata/Recipies.qml | 2 +- examples/declarative/velocity/velocity.qml | 2 +- src/declarative/qml/qmlcompiler.cpp | 26 +-- src/declarative/qml/qmlcustomparser_p.h | 17 -- src/declarative/qml/qmlinstruction.cpp | 3 - src/declarative/qml/qmlinstruction_p.h | 5 - src/declarative/qml/qmlvme.cpp | 21 --- src/declarative/util/qmllistmodel.cpp | 180 +-------------------- 13 files changed, 17 insertions(+), 249 deletions(-) diff --git a/demos/declarative/phonebrowser/dummydata/PhonesModel.qml b/demos/declarative/phonebrowser/dummydata/PhonesModel.qml index eb68fdb..8d9ed97 100644 --- a/demos/declarative/phonebrowser/dummydata/PhonesModel.qml +++ b/demos/declarative/phonebrowser/dummydata/PhonesModel.qml @@ -1,4 +1,4 @@ -ListModel2 { +ListModel { id: "PhonesModel" ListElement { diff --git a/doc/src/snippets/declarative/pathview/dummydata/MenuModel.qml b/doc/src/snippets/declarative/pathview/dummydata/MenuModel.qml index 5b973d7..44cdaf0 100644 --- a/doc/src/snippets/declarative/pathview/dummydata/MenuModel.qml +++ b/doc/src/snippets/declarative/pathview/dummydata/MenuModel.qml @@ -1,4 +1,4 @@ -ListModel2 { +ListModel { id: MenuModel ListElement { name: "Bill Jones" diff --git a/examples/declarative/contacts/dummydata/contactModel.qml b/examples/declarative/contacts/dummydata/contactModel.qml index 48b2fd9..53f6b7b 100644 --- a/examples/declarative/contacts/dummydata/contactModel.qml +++ b/examples/declarative/contacts/dummydata/contactModel.qml @@ -1,4 +1,4 @@ -ListModel2 { +ListModel { ListElement { firstName: "Aaron" lastName: "Kennedy" diff --git a/examples/declarative/easing/easing.qml b/examples/declarative/easing/easing.qml index 32c1b9b..af675d1 100644 --- a/examples/declarative/easing/easing.qml +++ b/examples/declarative/easing/easing.qml @@ -4,7 +4,7 @@ Rect { height: Layout.height color: "white" - ListModel2 { + ListModel { id: EasingTypes ListElement { type: "easeLinear" } ListElement { type: "easeInQuad" } diff --git a/examples/declarative/listview/dummydata/MyPetsModel.qml b/examples/declarative/listview/dummydata/MyPetsModel.qml index 1c96b7f..4d76ff4 100644 --- a/examples/declarative/listview/dummydata/MyPetsModel.qml +++ b/examples/declarative/listview/dummydata/MyPetsModel.qml @@ -1,6 +1,6 @@ // ListModel allows free form list models to be defined and populated. // Be sure to name the file the same as the id. -ListModel2 { +ListModel { id: MyListElementsModel ListElement { name: "Polly" diff --git a/examples/declarative/listview/dummydata/Recipies.qml b/examples/declarative/listview/dummydata/Recipies.qml index 8f464da..3f2ab48 100644 --- a/examples/declarative/listview/dummydata/Recipies.qml +++ b/examples/declarative/listview/dummydata/Recipies.qml @@ -1,4 +1,4 @@ -ListModel2 { +ListModel { id: Recipies ListElement { title: "Pancakes" diff --git a/examples/declarative/velocity/velocity.qml b/examples/declarative/velocity/velocity.qml index ff95527..786f364 100644 --- a/examples/declarative/velocity/velocity.qml +++ b/examples/declarative/velocity/velocity.qml @@ -2,7 +2,7 @@ Rect { color: "lightSteelBlue" width: 800 height: 600 - ListModel2 { + ListModel { id: List ListElement { name: "Sunday" diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp index 37d7fa1..ec5903e 100644 --- a/src/declarative/qml/qmlcompiler.cpp +++ b/src/declarative/qml/qmlcompiler.cpp @@ -569,25 +569,13 @@ bool QmlCompiler::compileObject(Object *obj, int ctxt) } int createInstrIdx = output->bytecode.count(); - if (obj->type != -1 && output->types.at(obj->type).parser) { - QByteArray data = obj->custom; - int ref = output->indexForByteArray(data); - - QmlInstruction create; - create.type = QmlInstruction::CreateCustomObject; - create.line = obj->line; - create.createCustom.type = obj->type; - create.createCustom.data = ref; - output->bytecode << create; - } else { - // Create the object - QmlInstruction create; - create.type = QmlInstruction::CreateObject; - create.line = obj->line; - create.create.data = -1; - create.create.type = obj->type; - output->bytecode << create; - } + // Create the object + QmlInstruction create; + create.type = QmlInstruction::CreateObject; + create.line = obj->line; + create.create.data = -1; + create.create.type = obj->type; + output->bytecode << create; COMPILE_CHECK(compileDynamicPropertiesAndSignals(obj)); diff --git a/src/declarative/qml/qmlcustomparser_p.h b/src/declarative/qml/qmlcustomparser_p.h index 0e6a619..e4e6089 100644 --- a/src/declarative/qml/qmlcustomparser_p.h +++ b/src/declarative/qml/qmlcustomparser_p.h @@ -98,26 +98,9 @@ class Q_DECLARATIVE_EXPORT QmlCustomParser public: virtual ~QmlCustomParser() {} - virtual QByteArray compile(QXmlStreamReader&, bool *ok)=0; virtual QByteArray compile(const QList &, bool *ok); - virtual QVariant create(const QByteArray &)=0; virtual void setCustomData(QObject *, const QByteArray &); - - struct Register { - Register(const char *name, QmlCustomParser *parser) { - qmlRegisterCustomParser(name, parser); - } - }; - template - struct Define { - static Register instance; - }; }; -#define QML_DEFINE_CUSTOM_PARSER(name, parserClass) \ - template<> QmlCustomParser::Register QmlCustomParser::Define::instance(# name, new parserClass); -#define QML_DEFINE_CUSTOM_PARSER_NS(namespacestring, name, parserClass) \ - template<> QmlCustomParser::Register QmlCustomParser::Define::instance(namespacestring "/" # name, new parserClass); - #define QML_DEFINE_CUSTOM_TYPE(TYPE, NAME, CUSTOMTYPE) \ template<> QmlPrivate::InstanceType QmlPrivate::Define::instance(qmlRegisterCustomType(#NAME, #TYPE, new CUSTOMTYPE)); diff --git a/src/declarative/qml/qmlinstruction.cpp b/src/declarative/qml/qmlinstruction.cpp index 82924c8..52677c2 100644 --- a/src/declarative/qml/qmlinstruction.cpp +++ b/src/declarative/qml/qmlinstruction.cpp @@ -58,9 +58,6 @@ void QmlCompiledComponent::dump(QmlInstruction *instr, int idx) case QmlInstruction::CreateObject: qWarning() << idx << "\t" << line << "\t" << "CREATE\t\t\t" << instr->create.type << "\t\t\t" << types.at(instr->create.type).className; break; - case QmlInstruction::CreateCustomObject: - qWarning() << idx << "\t" << line << "\t" << "CREATE_CUSTOM\t\t" << instr->createCustom.type << "\t" << instr->createCustom.data << "\t\t" << types.at(instr->create.type).className; - break; case QmlInstruction::SetId: qWarning() << idx << "\t" << line << "\t" << "SETID\t\t\t" << instr->setId.value << "\t" << instr->setId.save << "\t\t" << primitives.at(instr->setId.value); break; diff --git a/src/declarative/qml/qmlinstruction_p.h b/src/declarative/qml/qmlinstruction_p.h index 922fc61..462f9e4 100644 --- a/src/declarative/qml/qmlinstruction_p.h +++ b/src/declarative/qml/qmlinstruction_p.h @@ -63,7 +63,6 @@ public: // top of the stack. Init, /* init */ CreateObject, /* create */ - CreateCustomObject, /* createCustom */ SetId, /* setId */ SetDefault, CreateComponent, /* createComponent */ @@ -180,10 +179,6 @@ public: int data; } storeMeta; struct { - int type; - int data; - } createCustom; - struct { int value; int save; } setId; diff --git a/src/declarative/qml/qmlvme.cpp b/src/declarative/qml/qmlvme.cpp index a3bfd62..ad3d1d5 100644 --- a/src/declarative/qml/qmlvme.cpp +++ b/src/declarative/qml/qmlvme.cpp @@ -277,27 +277,6 @@ QObject *QmlVME::run(QmlContext *ctxt, QmlCompiledComponent *comp, int start, in } break; - case QmlInstruction::CreateCustomObject: - { -#ifdef Q_ENABLE_PERFORMANCE_LOG - QFxCompilerTimer cc; -#endif - QVariant v = - types.at(instr.createCustom.type).parser->create(datas.at(instr.createCustom.data)); - // XXX - QObject *o = QmlMetaType::toQObject(v); - if (!o) - VME_EXCEPTION("Unable to create" << types.at(instr.create.type).className); - QmlEngine::setContextForObject(o, QmlContext::activeContext()); - - if (!stack.isEmpty()) { - QObject *parent = stack.top(); - o->setParent(parent); - } - stack.push(o); - } - break; - case QmlInstruction::SetId: { #ifdef Q_ENABLE_PERFORMANCE_LOG diff --git a/src/declarative/util/qmllistmodel.cpp b/src/declarative/util/qmllistmodel.cpp index 4837180..6ad0cb9 100644 --- a/src/declarative/util/qmllistmodel.cpp +++ b/src/declarative/util/qmllistmodel.cpp @@ -190,8 +190,6 @@ ModelObject::ModelObject(ModelNode *node) { } -QML_DECLARE_TYPE(ListModel); -QML_DEFINE_TYPE(ListModel,ListModel); ListModel::ListModel(QObject *parent) : QListModelInterface(parent), _rolesOk(false), _root(0) { @@ -304,14 +302,10 @@ int ListModel::count() const class ListModelParser : public QmlCustomParser { public: - virtual QByteArray compile(QXmlStreamReader& reader, bool *); QByteArray compile(const QList &, bool *ok); - virtual QVariant create(const QByteArray &); - bool compileProperty(const QmlCustomParserProperty &prop, QList &instr, QByteArray &data); void setCustomData(QObject *, const QByteArray &); }; -QML_DEFINE_CUSTOM_PARSER(ListModel, ListModelParser); bool ListModelParser::compileProperty(const QmlCustomParserProperty &prop, QList &instr, QByteArray &data) { @@ -462,13 +456,10 @@ void ListModelParser::setCustomData(QObject *obj, const QByteArray &d) } } -class ListModel2 : public ListModel -{ -Q_OBJECT -}; -QML_DECLARE_TYPE(ListModel2); -QML_DEFINE_CUSTOM_TYPE(ListModel2, ListModel2, ListModelParser); +QML_DECLARE_TYPE(ListModel); +QML_DEFINE_CUSTOM_TYPE(ListModel, ListModel, ListModelParser); +// ### FIXME class ListElement : public QObject { Q_OBJECT @@ -512,170 +503,5 @@ ModelNode::~ModelNode() if (modelCache) { delete modelCache; modelCache = 0; } } -QByteArray ListModelParser::compile(QXmlStreamReader& reader, bool *ok) -{ - *ok = true; - - QByteArray data; - QList instr; - int depth=0; - - while(!reader.atEnd() && depth >= 0) { - switch(reader.readNext()) { - case QXmlStreamReader::StartElement: - { - QStringRef name = reader.name(); - bool isType = name.at(0).isUpper(); - - if (isType) { - ListInstruction li; - li.type = ListInstruction::Push; - li.dataIdx = -1; - instr << li; - - for (int i = 0; i < reader.attributes().count(); ++i) { - const QXmlStreamAttribute &attr = reader.attributes().at(i); - QStringRef attrName = attr.name(); - QStringRef attrValue = attr.value(); - - ListInstruction li; - int ref = data.count(); - data.append(attrName.toString().toLatin1()); - data.append('\0'); - li.type = ListInstruction::Set; - li.dataIdx = ref; - instr << li; - - ref = data.count(); - data.append(attrValue.toString().toLatin1()); - data.append('\0'); - li.type = ListInstruction::Value; - li.dataIdx = ref; - instr << li; - - li.type = ListInstruction::Pop; - li.dataIdx = -1; - instr << li; - } - } else { - ListInstruction li; - int ref = data.count(); - data.append(name.toString().toLatin1()); - data.append('\0'); - li.type = ListInstruction::Set; - li.dataIdx = ref; - instr << li; - } - } - ++depth; - break; - case QXmlStreamReader::EndElement: - { - ListInstruction li; - li.type = ListInstruction::Pop; - li.dataIdx = -1; - instr << li; - --depth; - } - break; - case QXmlStreamReader::Characters: - if (!reader.isWhitespace()) { - int ref = data.count(); - QByteArray d = reader.text().toString().toLatin1(); - d.append('\0'); - data.append(d); - - ListInstruction li; - li.type = ListInstruction::Value; - li.dataIdx = ref; - instr << li; - } - break; - - case QXmlStreamReader::Invalid: - case QXmlStreamReader::NoToken: - case QXmlStreamReader::StartDocument: - case QXmlStreamReader::EndDocument: - case QXmlStreamReader::Comment: - case QXmlStreamReader::DTD: - case QXmlStreamReader::EntityReference: - case QXmlStreamReader::ProcessingInstruction: - break; - } - } - - if (reader.hasError()) - *ok = true; - - if (!*ok) - return QByteArray(); - - int size = sizeof(ListModelData) + - instr.count() * sizeof(ListInstruction) + - data.count(); - - QByteArray rv; - rv.resize(size); - - ListModelData *lmd = (ListModelData *)rv.data(); - lmd->dataOffset = sizeof(ListModelData) + - instr.count() * sizeof(ListInstruction); - lmd->instrCount = instr.count(); - for (int ii = 0; ii < instr.count(); ++ii) - lmd->instructions()[ii] = instr.at(ii); - ::memcpy(rv.data() + lmd->dataOffset, data.constData(), data.count()); - - return rv; -} - -QVariant ListModelParser::create(const QByteArray &d) -{ - ListModel *rv = new ListModel; - ModelNode *root = new ModelNode; - rv->_root = root; - QStack nodes; - nodes << root; - - const ListModelData *lmd = (const ListModelData *)d.constData(); - const char *data = ((const char *)lmd) + lmd->dataOffset; - - for (int ii = 0; ii < lmd->instrCount; ++ii) { - const ListInstruction &instr = lmd->instructions()[ii]; - - switch(instr.type) { - case ListInstruction::Push: - { - ModelNode *n = nodes.top(); - ModelNode *n2 = new ModelNode; - n->values << qVariantFromValue(n2); - nodes.push(n2); - } - break; - - case ListInstruction::Pop: - nodes.pop(); - break; - - case ListInstruction::Value: - { - ModelNode *n = nodes.top(); - n->values.append(QByteArray(data + instr.dataIdx)); - } - break; - - case ListInstruction::Set: - { - ModelNode *n = nodes.top(); - ModelNode *n2 = new ModelNode; - n->properties.insert(QLatin1String(data + instr.dataIdx), n2); - nodes.push(n2); - } - break; - } - } - - return QVariant::fromValue(rv); -} - QT_END_NAMESPACE #include "qmllistmodel.moc" -- cgit v0.12 From d778d86065e08cf55fdf70a491f17c61ff93705c Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 5 May 2009 14:05:03 +1000 Subject: Remove magic "properties" and "signals" property support New properties and signals should be defined using the QML syntax: [default] property [: ] signal --- src/declarative/qml/qmlcompiler.cpp | 238 +----------------------------------- src/declarative/qml/qmlcompiler_p.h | 5 - src/declarative/qml/qmlparser.cpp | 5 +- src/declarative/qml/qmlparser_p.h | 4 - 4 files changed, 3 insertions(+), 249 deletions(-) diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp index ec5903e..b8f3921 100644 --- a/src/declarative/qml/qmlcompiler.cpp +++ b/src/declarative/qml/qmlcompiler.cpp @@ -64,17 +64,6 @@ #include "qmlscriptparser_p.h" QT_BEGIN_NAMESPACE -/* - New properties and signals can be added to any QObject type from QML. - - - - metatype && obj->metatype->indexOfProperty(PROPERTIES_NAME) != -1) - ignoreProperties = true; - if (obj->metatype && obj->metatype->indexOfProperty(SIGNALS_NAME) != -1) - ignoreSignals = true; - - Property *propertiesProperty = ignoreProperties?0:obj->getProperty(PROPERTIES_NAME, false); - Property *signalsProperty = ignoreSignals?0:obj->getProperty(SIGNALS_NAME, false); - - if (propertiesProperty) { - obj->dynamicPropertiesProperty = propertiesProperty; - obj->properties.remove(PROPERTIES_NAME); - } - if (signalsProperty) { - obj->dynamicSignalsProperty = signalsProperty; - obj->properties.remove(SIGNALS_NAME); - } - int createInstrIdx = output->bytecode.count(); // Create the object QmlInstruction create; @@ -602,9 +570,7 @@ bool QmlCompiler::compileObject(Object *obj, int ctxt) QList customProps; foreach(Property *prop, obj->properties) { - if (!ignoreProperties && prop->name == PROPERTIES_NAME) { - } else if (!ignoreSignals && prop->name == SIGNALS_NAME) { - } else if (prop->name.length() >= 3 && prop->name.startsWith("on") && + if (prop->name.length() >= 3 && prop->name.startsWith("on") && ('A' <= prop->name.at(2) && 'Z' >= prop->name.at(2))) { if (!isCustomParser) { COMPILE_CHECK(compileSignal(prop, obj)); @@ -1246,209 +1212,9 @@ bool QmlCompiler::compilePropertyLiteralAssignment(QmlParser::Property *prop, return true; } -bool QmlCompiler::findDynamicProperties(QmlParser::Property *prop, - QmlParser::Object *obj) -{ - QList definedProperties; - - struct TypeNameToType { - const char *name; - Object::DynamicProperty::Type type; - } propTypeNameToTypes[] = { - { "", Object::DynamicProperty::Variant }, - { "int", Object::DynamicProperty::Int }, - { "bool", Object::DynamicProperty::Bool }, - { "double", Object::DynamicProperty::Real }, - { "real", Object::DynamicProperty::Real }, - { "string", Object::DynamicProperty::String }, - { "color", Object::DynamicProperty::Color }, - { "date", Object::DynamicProperty::Date }, - { "variant", Object::DynamicProperty::Variant } - }; - const int propTypeNameToTypesCount = sizeof(propTypeNameToTypes) / - sizeof(propTypeNameToTypes[0]); - - - if (prop->value) - COMPILE_EXCEPTION("Invalid property specification"); - - bool seenDefault = false; - for (int ii = 0; ii < prop->values.count(); ++ii) { - QmlParser::Value *val = prop->values.at(ii); - if (!val->object) - COMPILE_EXCEPTION("Invalid property specification"); - - QmlParser::Object *obj = val->object; - if (obj->type == -1 || output->types.at(obj->type).className != "Property") - COMPILE_EXCEPTION("Use Property tag to specify properties"); - - - enum Seen { None = 0, Name = 0x01, - Type = 0x02, Value = 0x04, - ValueChanged = 0x08, - Default = 0x10 } seen = None; - - Object::DynamicProperty propDef; - - for (QHash::ConstIterator iter = - obj->properties.begin(); - iter != obj->properties.end(); - ++iter) { - - QmlParser::Property *property = *iter; - if (property->name == "name") { - if (seen & Name) - COMPILE_EXCEPTION("May only specify Property name once"); - seen = (Seen)(seen | Name); - - if (property->value || property->values.count() != 1 || - property->values.at(0)->object) - COMPILE_EXCEPTION("Invalid Property name"); - - propDef.name = property->values.at(0)->primitive.toLatin1(); - - } else if (property->name == "type") { - if (seen & Type) - COMPILE_EXCEPTION("May only specify Property type once"); - seen = (Seen)(seen | Type); - - if (property->value || property->values.count() != 1 || - property->values.at(0)->object) - COMPILE_EXCEPTION("Invalid Property type"); - - QString type = property->values.at(0)->primitive.toLower(); - bool found = false; - for (int ii = 0; !found && ii < propTypeNameToTypesCount; ++ii) { - if (type == QLatin1String(propTypeNameToTypes[ii].name)){ - found = true; - propDef.type = propTypeNameToTypes[ii].type; - } - - } - - if (!found) - COMPILE_EXCEPTION("Invalid Property type"); - - } else if (property->name == "value") { - if (seen & Value) - COMPILE_EXCEPTION("May only specify Property value once"); - seen = (Seen)(seen | Value); - - propDef.defaultValue = property; - } else if (property->name == "onValueChanged") { - if (seen & ValueChanged) - COMPILE_EXCEPTION("May only specify Property onValueChanged once"); - seen = (Seen)(seen | ValueChanged); - - if (property->value || property->values.count() != 1 || - property->values.at(0)->object) - COMPILE_EXCEPTION("Invalid Property onValueChanged"); - - propDef.onValueChanged = property->values.at(0)->primitive; - - } else if (property->name == "default") { - if (seen & Default) - COMPILE_EXCEPTION("May only specify Property default once"); - seen = (Seen)(seen | Default); - if (property->value || property->values.count() != 1 || - property->values.at(0)->object) - COMPILE_EXCEPTION("Invalid Property default"); - - bool defaultValue = - QmlStringConverters::boolFromString(property->values.at(0)->primitive); - propDef.isDefaultProperty = defaultValue; - if (defaultValue) { - if (seenDefault) - COMPILE_EXCEPTION("Only one property may be the default"); - seenDefault = true; - } - - } else { - COMPILE_EXCEPTION("Invalid Property property"); - } - - } - if (obj->defaultProperty) { - if (seen & Value) - COMPILE_EXCEPTION("May only specify Property value once"); - - seen = (Seen)(seen | Value); - propDef.defaultValue = obj->defaultProperty; - } - - if (!(seen & Name)) - COMPILE_EXCEPTION("Must specify Property name"); - - definedProperties << propDef; - } - - obj->dynamicProperties << definedProperties; - return true; -} - -bool QmlCompiler::findDynamicSignals(QmlParser::Property *sigs, - QmlParser::Object *obj) -{ - QList definedSignals; - - if (sigs->value) - COMPILE_EXCEPTION("Invalid signal specification"); - - for (int ii = 0; ii < sigs->values.count(); ++ii) { - QmlParser::Value *val = sigs->values.at(ii); - if (!val->object) - COMPILE_EXCEPTION("Invalid signal specification"); - - QmlParser::Object *obj = val->object; - if (obj->type == -1 || output->types.at(obj->type).className != "Signal") - COMPILE_EXCEPTION("Use Signal tag to specify signals"); - - enum Seen { None = 0, Name = 0x01 } seen = None; - Object::DynamicSignal sigDef; - - for (QHash::ConstIterator iter = - obj->properties.begin(); - iter != obj->properties.end(); - ++iter) { - - QmlParser::Property *property = *iter; - if (property->name == "name") { - if (seen & Name) - COMPILE_EXCEPTION("May only specify Signal name once"); - seen = (Seen)(seen | Name); - - if (property->value || property->values.count() != 1 || - property->values.at(0)->object) - COMPILE_EXCEPTION("Invalid Signal name"); - - sigDef.name = property->values.at(0)->primitive.toLatin1(); - - } else { - COMPILE_EXCEPTION("Invalid Signal property"); - } - - } - - if (obj->defaultProperty) - COMPILE_EXCEPTION("Invalid Signal property"); - - if (!(seen & Name)) - COMPILE_EXCEPTION("Must specify Signal name"); - - definedSignals << sigDef; - } - - obj->dynamicSignals << definedSignals; - return true; -} - bool QmlCompiler::compileDynamicPropertiesAndSignals(QmlParser::Object *obj) { - if (obj->dynamicPropertiesProperty) - findDynamicProperties(obj->dynamicPropertiesProperty, obj); - if (obj->dynamicSignalsProperty) - findDynamicSignals(obj->dynamicSignalsProperty, obj); - + // ### FIXME - Check that there is only one default property etc. if (obj->dynamicProperties.isEmpty() && obj->dynamicSignals.isEmpty()) return true; diff --git a/src/declarative/qml/qmlcompiler_p.h b/src/declarative/qml/qmlcompiler_p.h index cc1a9e9..4acdcfa 100644 --- a/src/declarative/qml/qmlcompiler_p.h +++ b/src/declarative/qml/qmlcompiler_p.h @@ -163,11 +163,6 @@ private: QmlParser::Value *value, int ctxt); - bool findDynamicProperties(QmlParser::Property *prop, - QmlParser::Object *obj); - bool findDynamicSignals(QmlParser::Property *sigs, - QmlParser::Object *obj); - bool compileDynamicPropertiesAndSignals(QmlParser::Object *obj); void compileBinding(const QString &, QmlParser::Property *prop, int ctxt, const QMetaObject *, qint64); diff --git a/src/declarative/qml/qmlparser.cpp b/src/declarative/qml/qmlparser.cpp index 87c8434..d862315 100644 --- a/src/declarative/qml/qmlparser.cpp +++ b/src/declarative/qml/qmlparser.cpp @@ -63,8 +63,7 @@ QT_BEGIN_NAMESPACE using namespace QmlParser; QmlParser::Object::Object() -: type(-1), metatype(0), extObject(0), defaultProperty(0), line(-1), column(-1), - dynamicPropertiesProperty(0), dynamicSignalsProperty(0) +: type(-1), metatype(0), extObject(0), defaultProperty(0), line(-1), column(-1) { } @@ -73,8 +72,6 @@ QmlParser::Object::~Object() if (defaultProperty) defaultProperty->release(); foreach(Property *prop, properties) prop->release(); - if (dynamicPropertiesProperty) dynamicPropertiesProperty->release(); - if (dynamicSignalsProperty) dynamicSignalsProperty->release(); } const QMetaObject *Object::metaObject() const diff --git a/src/declarative/qml/qmlparser_p.h b/src/declarative/qml/qmlparser_p.h index 17b367d6..aeacee8 100644 --- a/src/declarative/qml/qmlparser_p.h +++ b/src/declarative/qml/qmlparser_p.h @@ -124,10 +124,6 @@ namespace QmlParser QByteArray name; }; - // The "properties" property - Property *dynamicPropertiesProperty; - // The "signals" property - Property *dynamicSignalsProperty; // The list of dynamic properties described in the "properties" property QList dynamicProperties; // The list of dynamic signals described in the "signals" property -- cgit v0.12 From 0725ca189ad30ec54a2a7a054404a50f20e2bfed Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 5 May 2009 14:55:09 +1000 Subject: Add warning text --- src/declarative/qml/qmlscriptparser.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/declarative/qml/qmlscriptparser.cpp b/src/declarative/qml/qmlscriptparser.cpp index d0051ac..81315c3 100644 --- a/src/declarative/qml/qmlscriptparser.cpp +++ b/src/declarative/qml/qmlscriptparser.cpp @@ -522,7 +522,11 @@ bool ProcessAST::visit(AST::UiSourceElement *node) { QmlParser::Object *obj = currentObject(); if (! (obj && obj->typeName == "Script")) { - // ### warning + QmlError error; + error.setDescription("JavaScript declaration outside Script element"); + error.setLine(node->firstSourceLocation().startLine); + error.setColumn(node->firstSourceLocation().startColumn); + _parser->_errors << error; return false; } -- cgit v0.12