summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Bodson <yann.bodson@nokia.com>2009-08-24 23:16:40 (GMT)
committerYann Bodson <yann.bodson@nokia.com>2009-08-24 23:16:40 (GMT)
commite1081c88616fea20fed343e258c98da2a669d9f1 (patch)
treee10d4130cd2bde2c30436d34fdd817b3a5a9ca55
parent70564bdb1856243640d11611515a83d339bb4f2f (diff)
parent6d57d71824ba67cfed07bcb27ab62349ee7d4c6e (diff)
downloadQt-e1081c88616fea20fed343e258c98da2a669d9f1.zip
Qt-e1081c88616fea20fed343e258c98da2a669d9f1.tar.gz
Qt-e1081c88616fea20fed343e258c98da2a669d9f1.tar.bz2
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
-rw-r--r--examples/declarative/dial/DialLibrary/Dial.qml4
-rw-r--r--src/declarative/QmlChanges.txt1
-rw-r--r--src/declarative/fx/qfxitem.cpp17
-rw-r--r--src/declarative/fx/qfxlistview.cpp55
-rw-r--r--src/declarative/fx/qfxlistview.h5
-rw-r--r--src/declarative/fx/qfxmouseregion_p.h11
-rw-r--r--src/declarative/qml/qmlcompositetypemanager.cpp19
-rw-r--r--src/declarative/qml/qmldom.cpp150
-rw-r--r--src/declarative/qml/qmldom.h16
-rw-r--r--src/declarative/qml/qmlengine.cpp111
-rw-r--r--src/declarative/qml/qmlengine_p.h18
-rw-r--r--src/declarative/qml/qmlparser.cpp2
-rw-r--r--src/declarative/qml/qmlparser_p.h5
-rw-r--r--src/declarative/qml/qmlscriptparser.cpp12
-rw-r--r--tests/auto/declarative/qmldom/tst_qmldom.cpp2
-rw-r--r--tests/auto/declarative/qmlparser/FailingComponent.qml5
-rw-r--r--tests/auto/declarative/qmlparser/failingComponent.qml8
-rw-r--r--tests/auto/declarative/qmlparser/failingComponentTest.qml4
-rw-r--r--tests/auto/declarative/qmlparser/tst_qmlparser.cpp2
19 files changed, 234 insertions, 213 deletions
diff --git a/examples/declarative/dial/DialLibrary/Dial.qml b/examples/declarative/dial/DialLibrary/Dial.qml
index 08308fa..f53b25e 100644
--- a/examples/declarative/dial/DialLibrary/Dial.qml
+++ b/examples/declarative/dial/DialLibrary/Dial.qml
@@ -1,6 +1,7 @@
import Qt 4.6
Item {
+ id: Root
property real value : 0
width: 210; height: 210
@@ -26,9 +27,10 @@ Item {
origin.x: 7; origin.y: 65
angle: -130
angle: Follow {
+id: MyFollow
spring: 1.4
damping: .15
- source: Math.min(Math.max(-130, value*2.2 - 130), 133)
+ source: Math.min(Math.max(-130, Root.value*2.2 - 130), 133)
}
}
}
diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt
index f886466..e01b9af 100644
--- a/src/declarative/QmlChanges.txt
+++ b/src/declarative/QmlChanges.txt
@@ -28,6 +28,7 @@ SetAnchors -> AnchorChanges
SetPropertyAction -> PropertyAction
RunScriptAction -> ScriptAction
ParentChangeAction -> ParentAction
+VisualModel -> VisualDataModel
Renamed properties:
MouseRegion: xmin -> minimumX
diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp
index d78e096..feb4e8c 100644
--- a/src/declarative/fx/qfxitem.cpp
+++ b/src/declarative/fx/qfxitem.cpp
@@ -611,7 +611,7 @@ class QFxKeysAttachedPrivate : public QObjectPrivate
public:
QFxKeysAttachedPrivate() : QObjectPrivate(), enabled(true) {}
- bool isConnected(int idx);
+ bool isConnected(const char *signalName);
bool enabled;
};
@@ -740,16 +740,9 @@ const QFxKeysAttached::SigMap QFxKeysAttached::sigMap[] = {
QHash<QObject*, QFxKeysAttached*> QFxKeysAttached::attachedProperties;
-bool QFxKeysAttachedPrivate::isConnected(int idx)
+bool QFxKeysAttachedPrivate::isConnected(const char *signalName)
{
- if (idx < 32) {
- quint32 mask = 1 << idx;
- return connectedSignals[0] & mask;
- } else if (idx < 64) {
- quint32 mask = 1 << (idx-32);
- return connectedSignals[1] & mask;
- }
- return false;
+ return isSignalConnected(signalIndex(signalName));
}
QFxKeysAttached::QFxKeysAttached(QObject *parent)
@@ -777,10 +770,10 @@ void QFxKeysAttached::keyPressed(QKeyEvent *event)
QByteArray keySignal = keyToSignal(event->key());
if (!keySignal.isEmpty()) {
keySignal += "(QFxKeyEvent*)";
- int idx = QFxKeysAttached::staticMetaObject.indexOfSignal(keySignal);
- if (d->isConnected(idx)) {
+ if (d->isConnected(keySignal)) {
// If we specifically handle a key then default to accepted
ke.setAccepted(true);
+ int idx = QFxKeysAttached::staticMetaObject.indexOfSignal(keySignal);
metaObject()->method(idx).invoke(this, Q_ARG(QFxKeysAttached, &ke));
}
}
diff --git a/src/declarative/fx/qfxlistview.cpp b/src/declarative/fx/qfxlistview.cpp
index 04fc3bd..4b28462 100644
--- a/src/declarative/fx/qfxlistview.cpp
+++ b/src/declarative/fx/qfxlistview.cpp
@@ -174,7 +174,7 @@ public:
, visiblePos(0), visibleIndex(0)
, averageSize(100), currentIndex(-1), requestedIndex(-1)
, currItemMode(QFxListView::Free), snapPos(0), highlightComponent(0), highlight(0), trackedItem(0)
- , moveReason(Other), buffer(0), highlightPosAnimator(0), highlightSizeAnimator(0)
+ , moveReason(Other), buffer(0), highlightPosAnimator(0), highlightSizeAnimator(0), spacing(0)
, ownModel(false), wrap(false), autoHighlight(true)
, fixCurrentVisibility(false) {}
@@ -212,8 +212,11 @@ public:
qreal startPosition() const {
qreal pos = 0;
- if (!visibleItems.isEmpty())
- pos = visibleItems.first()->position() - visibleIndex * averageSize;
+ if (!visibleItems.isEmpty()) {
+ pos = visibleItems.first()->position();
+ if (visibleIndex > 0)
+ pos -= visibleIndex * (averageSize + spacing) - spacing;
+ }
return pos;
}
@@ -227,7 +230,7 @@ public:
break;
}
}
- pos = visibleItems.last()->endPosition() + invisibleCount * averageSize;
+ pos = visibleItems.last()->endPosition() + invisibleCount * (averageSize + spacing);
}
return pos;
}
@@ -238,7 +241,7 @@ public:
if (!visibleItems.isEmpty()) {
if (modelIndex < visibleIndex) {
int count = visibleIndex - modelIndex;
- return visibleItems.first()->position() - count * averageSize;
+ return visibleItems.first()->position() - count * (averageSize + spacing);
} else {
int idx = visibleItems.count() - 1;
while (idx >= 0 && visibleItems.at(idx)->index == -1)
@@ -248,7 +251,7 @@ public:
else
idx = visibleItems.at(idx)->index;
int count = modelIndex - idx - 1;
- return visibleItems.last()->endPosition() + count * averageSize + 1;
+ return visibleItems.last()->endPosition() + spacing + count * (averageSize + spacing) + 1;
}
}
return 0;
@@ -382,6 +385,7 @@ public:
QmlFollow *highlightSizeAnimator;
QString sectionExpression;
QString currentSection;
+ int spacing;
int ownModel : 1;
int wrap : 1;
@@ -480,7 +484,7 @@ void QFxListViewPrivate::refill(qreal from, qreal to)
qreal itemEnd = visiblePos-1;
if (!visibleItems.isEmpty()) {
visiblePos = visibleItems.first()->position();
- itemEnd = visibleItems.last()->endPosition();
+ itemEnd = visibleItems.last()->endPosition() + spacing;
int i = visibleItems.count() - 1;
while (i > 0 && visibleItems.at(i)->index == -1)
--i;
@@ -495,7 +499,7 @@ void QFxListViewPrivate::refill(qreal from, qreal to)
if (!(item = createItem(modelIndex)))
break;
item->setPosition(pos);
- pos += item->size();
+ pos += item->size() + spacing;
visibleItems.append(item);
++modelIndex;
changed = true;
@@ -505,7 +509,7 @@ void QFxListViewPrivate::refill(qreal from, qreal to)
if (!(item = createItem(visibleIndex-1)))
break;
--visibleIndex;
- visiblePos -= item->size();
+ visiblePos -= item->size() + spacing;
item->setPosition(visiblePos);
visibleItems.prepend(item);
changed = true;
@@ -547,11 +551,11 @@ void QFxListViewPrivate::layout()
Q_Q(QFxListView);
if (!visibleItems.isEmpty()) {
int oldEnd = visibleItems.last()->endPosition();
- int pos = visibleItems.first()->endPosition() + 1;
+ int pos = visibleItems.first()->endPosition() + spacing + 1;
for (int i=1; i < visibleItems.count(); ++i) {
FxListItem *item = visibleItems.at(i);
item->setPosition(pos);
- pos += item->size();
+ pos += item->size() + spacing;
}
// move current item if it is after the visible items.
if (currentItem && currentIndex > lastVisibleIndex())
@@ -661,7 +665,7 @@ void QFxListViewPrivate::createHighlight()
highlightPosAnimator->setTarget(QmlMetaProperty(highlight->item, posProp));
highlightPosAnimator->setEpsilon(0.25);
highlightPosAnimator->setSpring(2.5);
- highlightPosAnimator->setDamping(0.3);
+ highlightPosAnimator->setDamping(0.35);
highlightPosAnimator->setEnabled(autoHighlight);
const QLatin1String sizeProp(orient == Qt::Vertical ? "height" : "width");
highlightSizeAnimator = new QmlFollow(q);
@@ -755,7 +759,7 @@ void QFxListViewPrivate::updateCurrent(int modelIndex)
if (currentItem) {
if (modelIndex == visibleIndex - 1) {
// We can calculate exact postion in this case
- currentItem->setPosition(visibleItems.first()->position() - currentItem->size());
+ currentItem->setPosition(visibleItems.first()->position() - currentItem->size() - spacing);
} else {
// Create current item now and position as best we can.
// Its position will be corrected when it becomes visible.
@@ -1136,6 +1140,27 @@ void QFxListView::setSnapPosition(int pos)
}
/*!
+ \qmlproperty int ListView::spacing
+
+ This property holds the spacing to leave between items.
+*/
+int QFxListView::spacing() const
+{
+ Q_D(const QFxListView);
+ return d->spacing;
+}
+
+void QFxListView::setSpacing(int spacing)
+{
+ Q_D(QFxListView);
+ if (spacing != d->spacing) {
+ d->spacing = spacing;
+ d->layout();
+ emit spacingChanged();
+ }
+}
+
+/*!
\qmlproperty enumeration ListView::orientation
This property holds the orientation of the list.
@@ -1452,7 +1477,7 @@ void QFxListView::itemsInserted(int modelIndex, int count)
int to = d->buffer+d->position()+d->size()-1;
// index can be the next item past the end of the visible items list (i.e. appended)
int pos = index < d->visibleItems.count() ? d->visibleItems.at(index)->position()
- : d->visibleItems.at(index-1)->endPosition()+1;
+ : d->visibleItems.at(index-1)->endPosition()+d->spacing+1;
int initialPos = pos;
QList<FxListItem*> added;
for (int i = 0; i < count && pos <= to; ++i) {
@@ -1460,7 +1485,7 @@ void QFxListView::itemsInserted(int modelIndex, int count)
d->visibleItems.insert(index, item);
item->setPosition(pos);
added.append(item);
- pos += item->size();
+ pos += item->size() + d->spacing;
++index;
}
if (d->currentIndex >= modelIndex) {
diff --git a/src/declarative/fx/qfxlistview.h b/src/declarative/fx/qfxlistview.h
index e6898f6..858e5ed 100644
--- a/src/declarative/fx/qfxlistview.h
+++ b/src/declarative/fx/qfxlistview.h
@@ -69,6 +69,7 @@ class Q_DECLARATIVE_EXPORT QFxListView : public QFxFlickable
Q_PROPERTY(bool autoHighlight READ autoHighlight WRITE setAutoHighlight)
Q_PROPERTY(CurrentItemPositioning currentItemPositioning READ currentItemPositioning WRITE setCurrentItemPositioning)
Q_PROPERTY(int snapPosition READ snapPosition WRITE setSnapPosition)
+ Q_PROPERTY(int spacing READ spacing WRITE setSpacing NOTIFY spacingChanged)
Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation)
Q_PROPERTY(bool wrap READ isWrapEnabled WRITE setWrapEnabled)
Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer)
@@ -104,6 +105,9 @@ public:
int snapPosition() const;
void setSnapPosition(int pos);
+ int spacing() const;
+ void setSpacing(int spacing);
+
Qt::Orientation orientation() const;
void setOrientation(Qt::Orientation);
@@ -121,6 +125,7 @@ public:
Q_SIGNALS:
void countChanged();
+ void spacingChanged();
void currentIndexChanged();
void currentSectionChanged();
void sectionExpressionChanged();
diff --git a/src/declarative/fx/qfxmouseregion_p.h b/src/declarative/fx/qfxmouseregion_p.h
index 70df8d1..caed2ab 100644
--- a/src/declarative/fx/qfxmouseregion_p.h
+++ b/src/declarative/fx/qfxmouseregion_p.h
@@ -85,15 +85,8 @@ public:
bool isConnected(const char *signal) {
Q_Q(QFxMouseRegion);
- int idx = QFxMouseRegion::staticMetaObject.indexOfSignal(signal);
- if (idx < 32) {
- quint32 mask = 1 << idx;
- return QObjectPrivate::get(q)->connectedSignals[0] & mask;
- } else if (idx < 64) {
- quint32 mask = 1 << (idx-32);
- return QObjectPrivate::get(q)->connectedSignals[1] & mask;
- }
- return false;
+ int idx = QObjectPrivate::get(q)->signalIndex(signal);
+ return QObjectPrivate::get(q)->isSignalConnected(idx);
}
bool absorb : 1;
diff --git a/src/declarative/qml/qmlcompositetypemanager.cpp b/src/declarative/qml/qmlcompositetypemanager.cpp
index 0fb6c86..5bf2dc0 100644
--- a/src/declarative/qml/qmlcompositetypemanager.cpp
+++ b/src/declarative/qml/qmlcompositetypemanager.cpp
@@ -327,8 +327,23 @@ void QmlCompositeTypeManager::compile(QmlCompositeTypeData *unit)
}
QUrl url;
- if (!QmlEnginePrivate::get(engine)->resolveType(unit->imports, typeName, &ref.type, &url)) {
- // XXX could produce error message here.
+ QmlEnginePrivate::ImportedNamespace *s;
+ QByteArray localTypeName;
+
+ QmlEnginePrivate::get(engine)->resolveNamespace(unit->imports, typeName, &s, &localTypeName);
+ if (QmlEnginePrivate::get(engine)->resolveTypeInNamespace(s, localTypeName, &ref.type, &url)) {
+ int majorVersion;
+ int minorVersion;
+ if (s->getTypeInfo(localTypeName, 0, &majorVersion, &minorVersion)) {
+ foreach (QmlParser::Object *obj, parserRef->refObjects) {
+ // store namespace for DOM
+ obj->majorVersion = majorVersion;
+ obj->minorVersion = minorVersion;
+ }
+ }
+ } else {
+ // try base url
+ url = unit->imports.baseUrl().resolved(QUrl(QLatin1String(typeName + ".qml")));
}
if (ref.type) {
diff --git a/src/declarative/qml/qmldom.cpp b/src/declarative/qml/qmldom.cpp
index 22a8e49..2aaf492 100644
--- a/src/declarative/qml/qmldom.cpp
+++ b/src/declarative/qml/qmldom.cpp
@@ -76,15 +76,11 @@ QmlDomDocumentPrivate::~QmlDomDocumentPrivate()
\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
- single file. Each document has a version number, accessible through
- QmlDomDocument::version(), and a root object, accessible through
+ single file. Each document has a root object, accessible through
QmlDomDocument::rootObject().
- The QmlDomDocument class allows the programmer to load a QML document, by
- calling QmlDomDocument::load(), manipulate it and save it to textual form
- by calling QmlDomDocument::save(). By using the QML DOM API, editors can
- non-destructively modify a QML document even if they only understand a
- subset of the total QML functionality.
+ The QmlDomDocument class allows the programmer to inspect a QML document by
+ calling QmlDomDocument::load().
The following example loads a QML file from disk, and prints out its root
object type and the properties assigned in the root object.
@@ -136,15 +132,6 @@ QmlDomDocument &QmlDomDocument::operator=(const QmlDomDocument &other)
}
/*!
- Return the version number of the Qml document. Currently only version
- 1 exists.
-*/
-int QmlDomDocument::version() const
-{
- return 1;
-}
-
-/*!
Returns all import statements in qml.
*/
QList<QmlDomImport> QmlDomDocument::imports() const
@@ -157,7 +144,7 @@ QList<QmlDomImport> QmlDomDocument::imports() const
data. On success, true is returned. If the \a data is malformed, false
is returned and QmlDomDocument::loadError() contains an error description.
- \sa QmlDomDocument::save() QmlDomDocument::loadError()
+ \sa QmlDomDocument::loadError()
*/
bool QmlDomDocument::load(QmlEngine *engine, const QByteArray &data, const QUrl &url)
{
@@ -224,17 +211,6 @@ QList<QmlError> QmlDomDocument::errors() const
}
/*!
- Return a saved copy of the QmlDomDocument. The returned data will be valid
- QML XML data.
-
- \sa load()
-*/
-QByteArray QmlDomDocument::save() const
-{
- return QByteArray();
-}
-
-/*!
Returns the document's root object, or an invalid QmlDomObject if the
document has no root.
@@ -417,15 +393,6 @@ QmlDomValue QmlDomProperty::value() const
}
/*!
- Sets the QmlDomValue that is assigned to this property to \a value.
-*/
-void QmlDomProperty::setValue(const QmlDomValue &value)
-{
- Q_UNUSED(value);
- qWarning("QmlDomProperty::setValue(const QmlDomValue &): Not Implemented");
-}
-
-/*!
Returns the position in the input data where the property ID startd, or -1 if
the property is invalid.
*/
@@ -689,11 +656,6 @@ QGraphicsWidget {
"opacity" and "size". Obviously QGraphicsWidget has many more properties than just
these two, but the QML DOM representation only contains those assigned
values (or bindings) in the QML file.
-
- The DOM tree can be modified to include new property assignments by calling
- QmlDomObject::addProperty(). Existing property assignments can be modified
- through the QmlDomProperty::setValue() method, or removed entirely by
- calling QmlDomObject::removeProperty().
*/
/*!
@@ -776,6 +738,21 @@ QByteArray QmlDomObject::objectClassName() const
return QByteArray();
}
+int QmlDomObject::objectTypeMajorVersion() const
+{
+ if (d->object)
+ return d->object->majorVersion;
+ else
+ return -1;
+}
+
+int QmlDomObject::objectTypeMinorVersion() const
+{
+ if (d->object)
+ return d->object->minorVersion;
+ else
+ return -1;
+}
/*!
Returns the QML id assigned to this object, or an empty QByteArray if no id
@@ -793,17 +770,6 @@ QString QmlDomObject::objectId() const
}
/*!
- Set the object \a id. If any other object within the DOM tree has the same
- id, the other object's id will be cleared.
-*/
-void QmlDomObject::setObjectId(const QByteArray &id)
-{
- Q_UNUSED(id);
- qWarning("QmlDomObject::setObjectId(const QByteArray &): Not implemented");
-}
-
-
-/*!
Returns the list of assigned properties on this object.
In the following example, "text" and "x" properties would be returned.
@@ -863,27 +829,6 @@ QmlDomProperty QmlDomObject::property(const QByteArray &name) const
return QmlDomProperty();
}
-/*!
- Remove the property \a name from this object, if it exists. Otherwise does
- nothing.
-*/
-void QmlDomObject::removeProperty(const QByteArray &name)
-{
- Q_UNUSED(name);
- qWarning("QmlDomObject::removeProperty(const QByteArray &): Not implemented");
-}
-
-/*!
- Adds the property \a name with the specified \a value to this object. If
- a property by \a name already exists, it will be removed.
-*/
-void QmlDomObject::addProperty(const QByteArray &name, const QmlDomValue &value)
-{
- Q_UNUSED(name);
- Q_UNUSED(value);
- qWarning("QmlDomObject::addProperty(const QByteArray &, const QmlDomValue &): Not implemented");
-}
-
QList<QmlDomDynamicProperty> QmlDomObject::dynamicProperties() const
{
QList<QmlDomDynamicProperty> properties;
@@ -935,18 +880,6 @@ bool QmlDomObject::isCustomType() const
}
/*!
- Sets the custom type \a data. If this type is not a custom type, this
- method does nothing.
-
- \sa QmlDomObject::isCustomType() QmlDomObject::customTypeData()
-*/
-void QmlDomObject::setCustomTypeData(const QByteArray &data)
-{
- Q_UNUSED(data);
- qWarning("QmlDomObject::setCustomTypeData(const QByteArray &): Not implemented");
-}
-
-/*!
If this object represents a custom type, returns the data associated with
the custom type, otherwise returns an empty QByteArray().
QmlDomObject::isCustomType() can be used to check if this object represents
@@ -1101,15 +1034,6 @@ QString QmlDomValueLiteral::literal() const
}
/*!
- Sets the literal \a value.
-*/
-void QmlDomValueLiteral::setLiteral(const QString &value)
-{
- Q_UNUSED(value);
- qWarning("QmlDomValueLiteral::setLiteral(const QString &): Not implemented");
-}
-
-/*!
\class QmlDomValueBinding
\internal
\brief The QmlDomValueBinding class represents a property binding.
@@ -1171,15 +1095,6 @@ QString QmlDomValueBinding::binding() const
}
/*!
- Sets the binding \a expression.
-*/
-void QmlDomValueBinding::setBinding(const QString &expression)
-{
- Q_UNUSED(expression);
- qWarning("QmlDomValueBinding::setBinding(const QString &): Not implemented");
-}
-
-/*!
\class QmlDomValueValueSource
\internal
\brief The QmlDomValueValueSource class represents a value source assignment value.
@@ -1259,14 +1174,6 @@ QmlDomObject QmlDomValueValueSource::object() const
return rv;
}
-/*!
- Sets the value source \a object.
-*/
-void QmlDomValueValueSource::setObject(const QmlDomObject &object)
-{
- Q_UNUSED(object);
- qWarning("QmlDomValueValueSource::setObject(const QmlDomObject &): Not implemented");
-}
QmlDomValuePrivate::QmlDomValuePrivate()
: property(0), value(0)
@@ -1644,15 +1551,6 @@ QList<QmlDomValue> QmlDomList::values() const
}
/*!
- Set the list of QmlDomValue's to \a values.
-*/
-void QmlDomList::setValues(const QList<QmlDomValue> &values)
-{
- Q_UNUSED(values);
- qWarning("QmlDomList::setValues(const QList<QmlDomValue> &): Not implemented");
-}
-
-/*!
Returns the position in the input data where the list started, or -1 if
the property is invalid.
*/
@@ -1778,16 +1676,6 @@ QmlDomObject QmlDomComponent::componentRoot() const
return rv;
}
-/*!
- Set the component's \a root object.
-*/
-void QmlDomComponent::setComponentRoot(const QmlDomObject &root)
-{
- Q_UNUSED(root);
- qWarning("QmlDomComponent::setComponentRoot(const QmlDomObject &): Not implemented");
-}
-
-
QmlDomImportPrivate::QmlDomImportPrivate()
: type(File)
{
diff --git a/src/declarative/qml/qmldom.h b/src/declarative/qml/qmldom.h
index 32ed2da..f344bb2 100644
--- a/src/declarative/qml/qmldom.h
+++ b/src/declarative/qml/qmldom.h
@@ -72,12 +72,10 @@ public:
~QmlDomDocument();
QmlDomDocument &operator=(const QmlDomDocument &);
- int version() const;
QList<QmlDomImport> imports() const;
QList<QmlError> errors() const;
bool load(QmlEngine *, const QByteArray &, const QUrl & = QUrl());
- QByteArray save() const;
QmlDomObject rootObject() const;
@@ -100,7 +98,6 @@ public:
bool isDefaultProperty() const;
QmlDomValue value() const;
- void setValue(const QmlDomValue &);
int position() const;
int length() const;
@@ -152,21 +149,19 @@ public:
QByteArray objectType() const;
QByteArray objectClassName() const;
+ int objectTypeMajorVersion() const;
+ int objectTypeMinorVersion() const;
+
QString objectId() const;
- void setObjectId(const QByteArray &);
QList<QmlDomProperty> properties() const;
QmlDomProperty property(const QByteArray &) const;
- void removeProperty(const QByteArray &);
- void addProperty(const QByteArray &, const QmlDomValue &);
-
QList<QmlDomDynamicProperty> dynamicProperties() const;
QmlDomDynamicProperty dynamicProperty(const QByteArray &) const;
bool isCustomType() const;
QByteArray customTypeData() const;
- void setCustomTypeData(const QByteArray &);
bool isComponent() const;
QmlDomComponent toComponent() const;
@@ -194,7 +189,6 @@ public:
QmlDomValueLiteral &operator=(const QmlDomValueLiteral &);
QString literal() const;
- void setLiteral(const QString &);
private:
friend class QmlDomValue;
@@ -210,7 +204,6 @@ public:
QmlDomValueBinding &operator=(const QmlDomValueBinding &);
QString binding() const;
- void setBinding(const QString &);
private:
friend class QmlDomValue;
@@ -226,7 +219,6 @@ public:
QmlDomValueValueSource &operator=(const QmlDomValueValueSource &);
QmlDomObject object() const;
- void setObject(const QmlDomObject &);
private:
friend class QmlDomValue;
@@ -242,7 +234,6 @@ public:
QmlDomComponent &operator=(const QmlDomComponent &);
QmlDomObject componentRoot() const;
- void setComponentRoot(const QmlDomObject &);
};
class Q_DECLARATIVE_EXPORT QmlDomValue
@@ -295,7 +286,6 @@ public:
QmlDomList &operator=(const QmlDomList &);
QList<QmlDomValue> values() const;
- void setValues(const QList<QmlDomValue> &);
int position() const;
int length() const;
diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp
index 351bd8a..fd18b26 100644
--- a/src/declarative/qml/qmlengine.cpp
+++ b/src/declarative/qml/qmlengine.cpp
@@ -1072,7 +1072,7 @@ void QmlObjectScriptClass::setProperty(QScriptValue &object,
}
-struct QmlEnginePrivate::ImportedNamespace {
+struct QmlImportedNamespacePrivate {
QStringList urls;
QList<int> majversions;
QList<int> minversions;
@@ -1177,10 +1177,10 @@ public:
} else {
url = base.resolved(QUrl(url)).toString();
}
- s->urls.append(url);
- s->majversions.append(vmaj);
- s->minversions.append(vmin);
- s->isLibrary.append(importType == QmlScriptParser::Import::Library);
+ s->d->urls.append(url);
+ s->d->majversions.append(vmaj);
+ s->d->minversions.append(vmin);
+ s->d->isLibrary.append(importType == QmlScriptParser::Import::Library);
return true;
}
@@ -1202,7 +1202,7 @@ public:
}
QString unqualifiedtype = type.mid(slash+1);
if (s)
- return s->find(unqualifiedtype);
+ return s->d->find(unqualifiedtype);
else
return QUrl();
}
@@ -1226,16 +1226,37 @@ public:
}
QByteArray unqualifiedtype = slash < 0 ? type : type.mid(slash+1); // common-case opt (QString::mid works fine, but slower)
if (s)
- return s->findBuiltin(unqualifiedtype,found);
+ return s->d->findBuiltin(unqualifiedtype,found);
else
return 0;
- }
+ }
QmlEnginePrivate::ImportedNamespace *findNamespace(const QString& type)
{
return set.value(type);
}
+ void resolveNamespace(const QByteArray &type, QmlEnginePrivate::ImportedNamespace **ns, QByteArray *unqualifiedType)
+ {
+ QmlEnginePrivate::ImportedNamespace *s = 0;
+ int slash = type.indexOf('/');
+ if (slash >= 0) {
+ while (!s) {
+ s = set.value(QString::fromLatin1(type.left(slash)));
+ int nslash = type.indexOf('/',slash+1);
+ if (nslash > 0)
+ slash = nslash;
+ else
+ break;
+ }
+ } else {
+ s = &unqualifiedset;
+ }
+
+ *ns = s;
+ *unqualifiedType = slash < 0 ? type : type.mid(slash+1); // common-case opt (QString::mid works fine, but slower)
+ }
+
private:
QmlEnginePrivate::ImportedNamespace unqualifiedset;
QHash<QString,QmlEnginePrivate::ImportedNamespace* > set;
@@ -1258,6 +1279,37 @@ void QmlEnginePrivate::Imports::setBaseUrl(const QUrl& url)
base = url;
}
+QmlEnginePrivate::ImportedNamespace::ImportedNamespace()
+ : d(new QmlImportedNamespacePrivate)
+{
+}
+
+QmlEnginePrivate::ImportedNamespace::~ImportedNamespace()
+{
+ delete d;
+}
+
+bool QmlEnginePrivate::ImportedNamespace::getTypeInfo(const QByteArray &typeName, QString *uri, int *majorVersion, int *minorVersion)
+{
+ for (int i=0; i<d->urls.count(); ++i) {
+ int vmaj = d->majversions.at(i);
+ int vmin = d->minversions.at(i);
+ QByteArray qt = d->urls.at(i).toLatin1();
+ qt += "/";
+ qt += typeName;
+ if (QmlMetaType::qmlType(qt,vmaj,vmin)) {
+ if (uri)
+ *uri = d->urls.at(i);
+ if (majorVersion)
+ *majorVersion = d->majversions.at(i);
+ if (minorVersion)
+ *minorVersion = d->minversions.at(i);
+ return true;
+ }
+ }
+ return false;
+}
+
/*!
Adds \a path as a directory where installed QML components are
defined in a URL-based directory structure.
@@ -1312,11 +1364,6 @@ bool QmlEnginePrivate::addToImport(Imports* imports, const QString& uri, const Q
*/
bool QmlEnginePrivate::resolveType(const Imports& imports, const QByteArray& type, QmlType** type_return, QUrl* url_return, ImportedNamespace** ns_return) const
{
- if (ns_return) {
- *ns_return = imports.d->findNamespace(QLatin1String(type));
- if (*ns_return)
- return true;
- }
if (type_return) {
QmlType* t = imports.d->findBuiltin(type);
if (!t) t = QmlMetaType::qmlType(type,0,0); // Try global namespace
@@ -1339,6 +1386,11 @@ bool QmlEnginePrivate::resolveType(const Imports& imports, const QByteArray& typ
return true;
}
}
+ if (ns_return) {
+ *ns_return = imports.d->findNamespace(QLatin1String(type));
+ if (*ns_return)
+ return true;
+ }
if (qmlImportTrace())
qDebug() << "QmlEngine::resolveType" << type << " not found";
return false;
@@ -1347,6 +1399,16 @@ bool QmlEnginePrivate::resolveType(const Imports& imports, const QByteArray& typ
/*!
\internal
+ Splits a fully qualified type name into the namespace and the unqualified type name.
+*/
+void QmlEnginePrivate::resolveNamespace(const Imports& imports, const QByteArray &type, ImportedNamespace **ns, QByteArray *unqualifiedType) const
+{
+ imports.d->resolveNamespace(type, ns, unqualifiedType);
+}
+
+/*!
+ \internal
+
Searching \e only in the namespace \a ns (previously returned in a call to
resolveType(), \a type is found and returned to either
a QmlType stored at \a type_return, or
@@ -1354,14 +1416,31 @@ bool QmlEnginePrivate::resolveType(const Imports& imports, const QByteArray& typ
If either return pointer is 0, the corresponding search is not done.
*/
-void QmlEnginePrivate::resolveTypeInNamespace(ImportedNamespace* ns, const QByteArray& type, QmlType** type_return, QUrl* url_return ) const
+bool QmlEnginePrivate::resolveTypeInNamespace(ImportedNamespace* ns, const QByteArray& type, QmlType** type_return, QUrl* url_return ) const
{
+ if (!ns)
+ return false;
+
if (type_return) {
- *type_return = ns->findBuiltin(type);
+ QmlType* t = ns->d->findBuiltin(type);
+ if (!t) t = QmlMetaType::qmlType(type,0,0); // Try global namespace
+ if (t) {
+ *type_return = t;
+ if (qmlImportTrace())
+ qDebug() << "QmlEngine::resolveTypeInNamespace" << type << "= (builtin)";
+ return true;
+ }
}
if (url_return) {
- *url_return = ns->find(QLatin1String(type));
+ QUrl url = ns->d->find(QLatin1String(type));
+ if (url.isValid()) {
+ if (url_return) *url_return = url;
+ if (qmlImportTrace())
+ qDebug() << "QmlEngine::resolveType" << type << "=" << url;
+ return true;
+ }
}
+ return false;
}
QT_END_NAMESPACE
diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h
index 4142872..c84b3b5 100644
--- a/src/declarative/qml/qmlengine_p.h
+++ b/src/declarative/qml/qmlengine_p.h
@@ -195,10 +195,24 @@ public:
QUrl base;
QmlImportsPrivate *d;
};
- struct ImportedNamespace;
+
+ struct ImportedNamespace {
+ ImportedNamespace();
+ ~ImportedNamespace();
+
+ bool getTypeInfo(const QByteArray &typeName, QString *uri, int *vmaj, int *vmin);
+ private:
+ friend class QmlImportsPrivate;
+ friend class QmlEnginePrivate;
+ class QmlImportedNamespacePrivate *d;
+ };
+
bool addToImport(Imports*, const QString& uri, const QString& prefix, int vmaj, int vmin, QmlScriptParser::Import::Type importType) const;
+
bool resolveType(const Imports&, const QByteArray& type, QmlType** type_return, QUrl* url_return, ImportedNamespace** ns_return=0) const;
- void resolveTypeInNamespace(ImportedNamespace*, const QByteArray& type, QmlType** type_return, QUrl* url_return ) const;
+
+ void resolveNamespace(const Imports& imports, const QByteArray &type, ImportedNamespace **s, QByteArray *unqualifiedType) const;
+ bool resolveTypeInNamespace(ImportedNamespace*, const QByteArray& type, QmlType** type_return, QUrl* url_return ) const;
static QScriptValue qmlScriptObject(QObject*, QmlEngine*);
diff --git a/src/declarative/qml/qmlparser.cpp b/src/declarative/qml/qmlparser.cpp
index 2a67c92..0f2a282 100644
--- a/src/declarative/qml/qmlparser.cpp
+++ b/src/declarative/qml/qmlparser.cpp
@@ -61,7 +61,7 @@ QT_BEGIN_NAMESPACE
using namespace QmlParser;
QmlParser::Object::Object()
-: type(-1), idIndex(-1), metatype(0), defaultProperty(0), parserStatusCast(-1)
+: type(-1), majorVersion(-1), minorVersion(-1), idIndex(-1), metatype(0), defaultProperty(0), parserStatusCast(-1)
{
}
diff --git a/src/declarative/qml/qmlparser_p.h b/src/declarative/qml/qmlparser_p.h
index 120af75..8a92a9f 100644
--- a/src/declarative/qml/qmlparser_p.h
+++ b/src/declarative/qml/qmlparser_p.h
@@ -115,6 +115,11 @@ namespace QmlParser
int type;
// The url of this object if it is an external type. Used by the DOM
QUrl url;
+
+ // version information if type is defined in library or C++
+ int majorVersion;
+ int minorVersion;
+
// The fully-qualified name of this type
QByteArray typeName;
// The class name
diff --git a/src/declarative/qml/qmlscriptparser.cpp b/src/declarative/qml/qmlscriptparser.cpp
index 187f640..ca2d295 100644
--- a/src/declarative/qml/qmlscriptparser.cpp
+++ b/src/declarative/qml/qmlscriptparser.cpp
@@ -432,8 +432,17 @@ bool ProcessAST::visit(AST::UiImport *node)
AST::SourceLocation startLoc = node->importToken;
AST::SourceLocation endLoc = node->semicolonToken;
- if (node->importId)
+ if (node->importId) {
import.qualifier = node->importId->asString();
+ if (!import.qualifier.at(0).isUpper()) {
+ QmlError error;
+ error.setDescription(QLatin1String("Invalid import qualifier ID"));
+ error.setLine(node->importIdToken.startLine);
+ error.setColumn(node->importIdToken.startColumn);
+ _parser->_errors << error;
+ return false;
+ }
+ }
if (node->versionToken.isValid())
import.version = textAt(node->versionToken);
@@ -831,6 +840,7 @@ void QmlScriptParser::clear()
root->release();
root = 0;
}
+ _imports.clear();
qDeleteAll(_refTypes);
_refTypes.clear();
_errors.clear();
diff --git a/tests/auto/declarative/qmldom/tst_qmldom.cpp b/tests/auto/declarative/qmldom/tst_qmldom.cpp
index dd02bce..e1419cc 100644
--- a/tests/auto/declarative/qmldom/tst_qmldom.cpp
+++ b/tests/auto/declarative/qmldom/tst_qmldom.cpp
@@ -41,6 +41,8 @@ void tst_qmldom::loadSimple()
QVERIFY(!rootObject.isComponent());
QVERIFY(!rootObject.isCustomType());
QVERIFY(rootObject.objectType() == "Qt/Item");
+ QVERIFY(rootObject.objectTypeMajorVersion() == 4);
+ QVERIFY(rootObject.objectTypeMinorVersion() == 6);
}
void tst_qmldom::loadProperties()
diff --git a/tests/auto/declarative/qmlparser/FailingComponent.qml b/tests/auto/declarative/qmlparser/FailingComponent.qml
deleted file mode 100644
index 1c01e3d..0000000
--- a/tests/auto/declarative/qmlparser/FailingComponent.qml
+++ /dev/null
@@ -1,5 +0,0 @@
-import Qt 4.6
-
-Object {
- a: 10
-}
diff --git a/tests/auto/declarative/qmlparser/failingComponent.qml b/tests/auto/declarative/qmlparser/failingComponent.qml
index bc21243..1c01e3d 100644
--- a/tests/auto/declarative/qmlparser/failingComponent.qml
+++ b/tests/auto/declarative/qmlparser/failingComponent.qml
@@ -1,5 +1,5 @@
-import Test 1.0
-MyContainer {
- FailingComponent {}
-}
+import Qt 4.6
+Object {
+ a: 10
+}
diff --git a/tests/auto/declarative/qmlparser/failingComponentTest.qml b/tests/auto/declarative/qmlparser/failingComponentTest.qml
new file mode 100644
index 0000000..74a6acf
--- /dev/null
+++ b/tests/auto/declarative/qmlparser/failingComponentTest.qml
@@ -0,0 +1,4 @@
+import Test 1.0
+MyContainer {
+ FailingComponent {}
+}
diff --git a/tests/auto/declarative/qmlparser/tst_qmlparser.cpp b/tests/auto/declarative/qmlparser/tst_qmlparser.cpp
index 0bac946..a9c4351 100644
--- a/tests/auto/declarative/qmlparser/tst_qmlparser.cpp
+++ b/tests/auto/declarative/qmlparser/tst_qmlparser.cpp
@@ -143,7 +143,7 @@ void tst_qmlparser::errors_data()
QTest::newRow("unregisteredObject") << "unregisteredObject.qml" << "unregisteredObject.errors.txt" << false;
QTest::newRow("empty") << "empty.qml" << "empty.errors.txt" << false;
QTest::newRow("missingObject") << "missingObject.qml" << "missingObject.errors.txt" << false;
- QTest::newRow("failingComponent") << "failingComponent.qml" << "failingComponent.errors.txt" << false;
+ QTest::newRow("failingComponent") << "failingComponentTest.qml" << "failingComponent.errors.txt" << false;
QTest::newRow("missingSignal") << "missingSignal.qml" << "missingSignal.errors.txt" << false;
QTest::newRow("finalOverride") << "finalOverride.qml" << "finalOverride.errors.txt" << false;
}