diff options
Diffstat (limited to 'src/declarative')
52 files changed, 1586 insertions, 227 deletions
diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt index 34e4834..4951cb3 100644 --- a/src/declarative/QmlChanges.txt +++ b/src/declarative/QmlChanges.txt @@ -12,6 +12,7 @@ Connection: syntax and rename: Connection { sender: a; signal: bar(); script: yyy } becomes: Connections { target: a; onFoo: xxx; onBar: yyy } +Using WebView now requires "import org.webkit 1.0" QmlView ------- @@ -52,6 +53,16 @@ matchProperties and matchTargets have been renamed back to properties and target The semantics are explained in the PropertyAnimation::properties documentation and the animation overview documentation. +Behavior and Animation syntax +----------------------------- + +Previously animations and behaviors could be "assigned" to properties like this: + Item { x: Behavior {}; y: NumberAnimation {} } +To make it more obvious that these are not regular value assignments a new "on" +syntax has been introduced: + Item { Behavior on x {}; NumberAnimation on y {} } +Only the syntax has changed, the behavior is identical. + ============================================================================= The changes below are pre-4.6.0 release. diff --git a/src/declarative/declarative.pro b/src/declarative/declarative.pro index 4287e25..a7ec18e 100644 --- a/src/declarative/declarative.pro +++ b/src/declarative/declarative.pro @@ -1,29 +1,5 @@ -TARGET = QtDeclarative -QPRO_PWD = $$PWD -QT = core gui xml script network -contains(QT_CONFIG, svg): QT += svg -contains(QT_CONFIG, opengl): QT += opengl -DEFINES += QT_BUILD_DECLARATIVE_LIB QT_NO_URL_CAST_FROM_STRING -win32-msvc*|win32-icc:QMAKE_LFLAGS += /BASE:0x66000000 -solaris-cc*:QMAKE_CXXFLAGS_RELEASE -= -O2 +TEMPLATE = subdirs -unix:QMAKE_PKGCONFIG_REQUIRES = QtCore QtGui QtXml +SUBDIRS = libdeclarative.pro imports -exists("qdeclarative_enable_gcov") { - QMAKE_CXXFLAGS = -fprofile-arcs -ftest-coverage -fno-elide-constructors - LIBS += -lgcov -} -include(../qbase.pri) - -#INCLUDEPATH -= $$QMAKE_INCDIR_QT/$$TARGET -#DESTDIR=. - -#modules -include(3rdparty/3rdparty.pri) -include(util/util.pri) -include(graphicsitems/graphicsitems.pri) -include(qml/qml.pri) -include(debugger/debugger.pri) - -symbian:TARGET.UID3=0x2001E623 diff --git a/src/declarative/graphicsitems/graphicsitems.pri b/src/declarative/graphicsitems/graphicsitems.pri index 7a85f00..3ff92b1 100644 --- a/src/declarative/graphicsitems/graphicsitems.pri +++ b/src/declarative/graphicsitems/graphicsitems.pri @@ -84,10 +84,3 @@ SOURCES += \ $$PWD/qdeclarativegraphicsobjectcontainer.cpp \ $$PWD/qdeclarativeparticles.cpp \ $$PWD/qdeclarativelayoutitem.cpp \ - -contains(QT_CONFIG, webkit) { - QT+=webkit - SOURCES += $$PWD/qdeclarativewebview.cpp - HEADERS += $$PWD/qdeclarativewebview_p.h - HEADERS += $$PWD/qdeclarativewebview_p_p.h -} diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index b43b30b..090c46d 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -45,6 +45,7 @@ #include "qdeclarativeflickable_p_p.h" #include <qdeclarativeeasefollow_p.h> +#include <qdeclarativeguard_p.h> #include <qlistmodelinterface_p.h> #include <QKeyEvent> @@ -251,7 +252,7 @@ public: } } - QGuard<QDeclarativeVisualModel> model; + QDeclarativeGuard<QDeclarativeVisualModel> model; QVariant modelVariant; QList<FxGridItem*> visibleItems; QHash<QDeclarativeItem*,int> unrequestedItems; @@ -618,7 +619,7 @@ void QDeclarativeGridViewPrivate::createHighlight() } } if (changed) - emit q->highlightChanged(); + emit q->highlightItemChanged(); } void QDeclarativeGridViewPrivate::updateHighlight() @@ -784,6 +785,8 @@ QVariant QDeclarativeGridView::model() const void QDeclarativeGridView::setModel(const QVariant &model) { Q_D(QDeclarativeGridView); + if (d->modelVariant == model) + return; if (d->model) { disconnect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); disconnect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); @@ -828,6 +831,7 @@ void QDeclarativeGridView::setModel(const QVariant &model) connect(d->model, SIGNAL(destroyingItem(QDeclarativeItem*)), this, SLOT(destroyingItem(QDeclarativeItem*))); emit countChanged(); } + emit modelChanged(); } /*! @@ -871,6 +875,7 @@ void QDeclarativeGridView::setDelegate(QDeclarativeComponent *delegate) d->moveReason = QDeclarativeGridViewPrivate::SetIndex; d->updateCurrent(d->currentIndex); } + emit delegateChanged(); } } @@ -966,6 +971,7 @@ void QDeclarativeGridView::setHighlight(QDeclarativeComponent *highlight) if (highlight != d->highlightComponent) { d->highlightComponent = highlight; d->updateCurrent(d->currentIndex); + emit highlightChanged(); } } @@ -1039,6 +1045,7 @@ void QDeclarativeGridView::setFlow(Flow flow) d->updateGrid(); refill(); d->updateCurrent(d->currentIndex); + emit flowChanged(); } } @@ -1058,7 +1065,10 @@ bool QDeclarativeGridView::isWrapEnabled() const void QDeclarativeGridView::setWrapEnabled(bool wrap) { Q_D(QDeclarativeGridView); + if (d->wrap == wrap) + return; d->wrap = wrap; + emit keyNavigationWrapsChanged(); } /*! @@ -1082,6 +1092,7 @@ void QDeclarativeGridView::setCacheBuffer(int buffer) d->buffer = buffer; if (isComponentComplete()) refill(); + emit cacheBufferChanged(); } } diff --git a/src/declarative/graphicsitems/qdeclarativegridview_p.h b/src/declarative/graphicsitems/qdeclarativegridview_p.h index b488475..d463a46 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview_p.h +++ b/src/declarative/graphicsitems/qdeclarativegridview_p.h @@ -57,19 +57,19 @@ class Q_DECLARATIVE_EXPORT QDeclarativeGridView : public QDeclarativeFlickable Q_OBJECT Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeGridView) - Q_PROPERTY(QVariant model READ model WRITE setModel) - Q_PROPERTY(QDeclarativeComponent *delegate READ delegate WRITE setDelegate) + Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged) + Q_PROPERTY(QDeclarativeComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged) Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) Q_PROPERTY(QDeclarativeItem *currentItem READ currentItem NOTIFY currentIndexChanged) Q_PROPERTY(int count READ count NOTIFY countChanged) - Q_PROPERTY(QDeclarativeComponent *highlight READ highlight WRITE setHighlight) - Q_PROPERTY(QDeclarativeItem *highlightItem READ highlightItem NOTIFY highlightChanged) + Q_PROPERTY(QDeclarativeComponent *highlight READ highlight WRITE setHighlight NOTIFY highlightChanged) + Q_PROPERTY(QDeclarativeItem *highlightItem READ highlightItem NOTIFY highlightItemChanged) Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem) - Q_PROPERTY(Flow flow READ flow WRITE setFlow) - Q_PROPERTY(bool keyNavigationWraps READ isWrapEnabled WRITE setWrapEnabled) - Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer) + Q_PROPERTY(Flow flow READ flow WRITE setFlow NOTIFY flowChanged) + Q_PROPERTY(bool keyNavigationWraps READ isWrapEnabled WRITE setWrapEnabled NOTIFY keyNavigationWrapsChanged) + Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer NOTIFY cacheBufferChanged) Q_PROPERTY(int cellWidth READ cellWidth WRITE setCellWidth NOTIFY cellWidthChanged) Q_PROPERTY(int cellHeight READ cellHeight WRITE setCellHeight NOTIFY cellHeightChanged) Q_CLASSINFO("DefaultProperty", "data") @@ -129,6 +129,12 @@ Q_SIGNALS: void cellWidthChanged(); void cellHeightChanged(); void highlightChanged(); + void highlightItemChanged(); + void modelChanged(); + void delegateChanged(); + void flowChanged(); + void keyNavigationWrapsChanged(); + void cacheBufferChanged(); protected: virtual void viewportMoved(); diff --git a/src/declarative/graphicsitems/qdeclarativeimage.cpp b/src/declarative/graphicsitems/qdeclarativeimage.cpp index 99ab053..2739ab8 100644 --- a/src/declarative/graphicsitems/qdeclarativeimage.cpp +++ b/src/declarative/graphicsitems/qdeclarativeimage.cpp @@ -232,6 +232,16 @@ qreal QDeclarativeImage::paintedHeight() const \o Error - an error occurred while loading the image \endlist + Note that a change in the status property does not cause anything to happen + (although it reflects what has happened with the image internally). If you wish + to react to the change in status you need to do it yourself, for example in one + of the following ways: + \list + \o Create a state, so that a state change occurs, e.g. State{name: 'loaded'; when: image.status = Image.Ready;} + \o Do something inside the onStatusChanged signal handler, e.g. Image{id: image; onStatusChanged: if(image.status == Image.Ready) console.log('Loaded');} + \o Bind to the status variable somewhere, e.g. Text{text: if(image.status!=Image.Ready){'Not Loaded';}else{'Loaded';}} + \endlist + \sa progress */ diff --git a/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp b/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp index f3b9385..e0ae2eb 100644 --- a/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp @@ -139,9 +139,6 @@ void QDeclarativeItemModule::defineModule() QML_REGISTER_TYPE(Qt,4,6,VisibleArea,QDeclarativeFlickableVisibleArea); QML_REGISTER_TYPE(Qt,4,6,VisualDataModel,QDeclarativeVisualDataModel); QML_REGISTER_TYPE(Qt,4,6,VisualItemModel,QDeclarativeVisualItemModel); -#ifdef QT_WEBKIT_LIB - QML_REGISTER_TYPE(Qt,4,6,WebView,QDeclarativeWebView); -#endif QML_REGISTER_NOCREATE_TYPE(QDeclarativeAnchors); QML_REGISTER_NOCREATE_TYPE(QGraphicsEffect); diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 03303a0..a05e638 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -47,6 +47,7 @@ #include <qdeclarativeeasefollow_p.h> #include <qdeclarativeexpression.h> #include <qdeclarativeengine.h> +#include <qdeclarativeguard_p.h> #include <qlistmodelinterface_p.h> #include <QKeyEvent> @@ -429,7 +430,7 @@ public: virtual void flickX(qreal velocity); virtual void flickY(qreal velocity); - QGuard<QDeclarativeVisualModel> model; + QDeclarativeGuard<QDeclarativeVisualModel> model; QVariant modelVariant; QList<FxListItem*> visibleItems; QHash<QDeclarativeItem*,int> unrequestedItems; @@ -816,7 +817,7 @@ void QDeclarativeListViewPrivate::createHighlight() } } if (changed) - emit q->highlightChanged(); + emit q->highlightItemChanged(); } void QDeclarativeListViewPrivate::updateHighlight() @@ -1473,6 +1474,8 @@ QVariant QDeclarativeListView::model() const void QDeclarativeListView::setModel(const QVariant &model) { Q_D(QDeclarativeListView); + if (d->modelVariant == model) + return; if (d->model) { disconnect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); disconnect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); @@ -1517,6 +1520,7 @@ void QDeclarativeListView::setModel(const QVariant &model) connect(d->model, SIGNAL(destroyingItem(QDeclarativeItem*)), this, SLOT(destroyingItem(QDeclarativeItem*))); emit countChanged(); } + emit modelChanged(); } /*! @@ -1563,6 +1567,7 @@ void QDeclarativeListView::setDelegate(QDeclarativeComponent *delegate) d->updateCurrent(d->currentIndex); } } + emit delegateChanged(); } /*! @@ -1663,6 +1668,7 @@ void QDeclarativeListView::setHighlight(QDeclarativeComponent *highlight) d->createHighlight(); if (d->currentItem) d->updateHighlight(); + emit highlightChanged(); } } @@ -1700,6 +1706,7 @@ void QDeclarativeListView::setHighlightFollowsCurrentItem(bool autoHighlight) d->highlightSizeAnimator->setEnabled(d->autoHighlight); } d->updateHighlight(); + emit highlightFollowsCurrentItemChanged(); } } @@ -1745,8 +1752,11 @@ qreal QDeclarativeListView::preferredHighlightBegin() const void QDeclarativeListView::setPreferredHighlightBegin(qreal start) { Q_D(QDeclarativeListView); + if (d->highlightRangeStart == start) + return; d->highlightRangeStart = start; d->haveHighlightRange = d->highlightRange != NoHighlightRange && d->highlightRangeStart <= d->highlightRangeEnd; + emit preferredHighlightBeginChanged(); } qreal QDeclarativeListView::preferredHighlightEnd() const @@ -1758,8 +1768,11 @@ qreal QDeclarativeListView::preferredHighlightEnd() const void QDeclarativeListView::setPreferredHighlightEnd(qreal end) { Q_D(QDeclarativeListView); + if (d->highlightRangeEnd == end) + return; d->highlightRangeEnd = end; d->haveHighlightRange = d->highlightRange != NoHighlightRange && d->highlightRangeStart <= d->highlightRangeEnd; + emit preferredHighlightEndChanged(); } QDeclarativeListView::HighlightRangeMode QDeclarativeListView::highlightRangeMode() const @@ -1771,8 +1784,11 @@ QDeclarativeListView::HighlightRangeMode QDeclarativeListView::highlightRangeMod void QDeclarativeListView::setHighlightRangeMode(HighlightRangeMode mode) { Q_D(QDeclarativeListView); + if (d->highlightRange == mode) + return; d->highlightRange = mode; d->haveHighlightRange = d->highlightRange != NoHighlightRange && d->highlightRangeStart <= d->highlightRangeEnd; + emit highlightRangeModeChanged(); } /*! @@ -1848,7 +1864,10 @@ bool QDeclarativeListView::isWrapEnabled() const void QDeclarativeListView::setWrapEnabled(bool wrap) { Q_D(QDeclarativeListView); + if (d->wrap == wrap) + return; d->wrap = wrap; + emit keyNavigationWrapsChanged(); } /*! @@ -1874,6 +1893,7 @@ void QDeclarativeListView::setCacheBuffer(int b) d->bufferMode = QDeclarativeListViewPrivate::BufferBefore | QDeclarativeListViewPrivate::BufferAfter; refill(); } + emit cacheBufferChanged(); } } @@ -1998,6 +2018,7 @@ void QDeclarativeListView::setSnapMode(SnapMode mode) Q_D(QDeclarativeListView); if (d->snapMode != mode) { d->snapMode = mode; + emit snapModeChanged(); } } @@ -2020,6 +2041,7 @@ void QDeclarativeListView::setFooter(QDeclarativeComponent *footer) d->maxExtentDirty = true; d->updateFooter(); d->updateViewport(); + emit footerChanged(); } } @@ -2043,6 +2065,7 @@ void QDeclarativeListView::setHeader(QDeclarativeComponent *header) d->updateHeader(); d->updateFooter(); d->updateViewport(); + emit headerChanged(); } } diff --git a/src/declarative/graphicsitems/qdeclarativelistview_p.h b/src/declarative/graphicsitems/qdeclarativelistview_p.h index 5e3edb0..f9b7b50 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview_p.h +++ b/src/declarative/graphicsitems/qdeclarativelistview_p.h @@ -91,33 +91,33 @@ class Q_DECLARATIVE_EXPORT QDeclarativeListView : public QDeclarativeFlickable Q_OBJECT Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeListView) - Q_PROPERTY(QVariant model READ model WRITE setModel) - Q_PROPERTY(QDeclarativeComponent *delegate READ delegate WRITE setDelegate) + Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged) + Q_PROPERTY(QDeclarativeComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged) Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) Q_PROPERTY(QDeclarativeItem *currentItem READ currentItem NOTIFY currentIndexChanged) Q_PROPERTY(int count READ count NOTIFY countChanged) - Q_PROPERTY(QDeclarativeComponent *highlight READ highlight WRITE setHighlight) - Q_PROPERTY(QDeclarativeItem *highlightItem READ highlightItem NOTIFY highlightChanged) - Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem) + Q_PROPERTY(QDeclarativeComponent *highlight READ highlight WRITE setHighlight NOTIFY highlightChanged) + Q_PROPERTY(QDeclarativeItem *highlightItem READ highlightItem NOTIFY highlightItemChanged) + Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem NOTIFY highlightFollowsCurrentItemChanged) Q_PROPERTY(qreal highlightMoveSpeed READ highlightMoveSpeed WRITE setHighlightMoveSpeed NOTIFY highlightMoveSpeedChanged) Q_PROPERTY(qreal highlightResizeSpeed READ highlightResizeSpeed WRITE setHighlightResizeSpeed NOTIFY highlightResizeSpeedChanged) - Q_PROPERTY(qreal preferredHighlightBegin READ preferredHighlightBegin WRITE setPreferredHighlightBegin) - Q_PROPERTY(qreal preferredHighlightEnd READ preferredHighlightEnd WRITE setPreferredHighlightEnd) - Q_PROPERTY(HighlightRangeMode highlightRangeMode READ highlightRangeMode WRITE setHighlightRangeMode) + Q_PROPERTY(qreal preferredHighlightBegin READ preferredHighlightBegin WRITE setPreferredHighlightBegin NOTIFY preferredHighlightBeginChanged) + Q_PROPERTY(qreal preferredHighlightEnd READ preferredHighlightEnd WRITE setPreferredHighlightEnd NOTIFY preferredHighlightEndChanged) + Q_PROPERTY(HighlightRangeMode highlightRangeMode READ highlightRangeMode WRITE setHighlightRangeMode NOTIFY highlightRangeModeChanged) Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing NOTIFY spacingChanged) Q_PROPERTY(Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged) - Q_PROPERTY(bool keyNavigationWraps READ isWrapEnabled WRITE setWrapEnabled) - Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer) + Q_PROPERTY(bool keyNavigationWraps READ isWrapEnabled WRITE setWrapEnabled NOTIFY keyNavigationWrapsChanged) + Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer NOTIFY cacheBufferChanged) Q_PROPERTY(QDeclarativeViewSection *section READ sectionCriteria CONSTANT) Q_PROPERTY(QString currentSection READ currentSection NOTIFY currentSectionChanged) - Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode) + Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged) - Q_PROPERTY(QDeclarativeComponent *header READ header WRITE setHeader) - Q_PROPERTY(QDeclarativeComponent *footer READ footer WRITE setFooter) + Q_PROPERTY(QDeclarativeComponent *header READ header WRITE setHeader NOTIFY headerChanged) + Q_PROPERTY(QDeclarativeComponent *footer READ footer WRITE setFooter NOTIFY footerChanged) Q_ENUMS(HighlightRangeMode) Q_ENUMS(Orientation) @@ -205,6 +205,18 @@ Q_SIGNALS: void highlightMoveSpeedChanged(); void highlightResizeSpeedChanged(); void highlightChanged(); + void highlightItemChanged(); + void modelChanged(); + void delegateChanged(); + void highlightFollowsCurrentItemChanged(); + void preferredHighlightBeginChanged(); + void preferredHighlightEndChanged(); + void highlightRangeModeChanged(); + void keyNavigationWrapsChanged(); + void cacheBufferChanged(); + void snapModeChanged(); + void headerChanged(); + void footerChanged(); protected: virtual void viewportMoved(); diff --git a/src/declarative/graphicsitems/qdeclarativeloader.cpp b/src/declarative/graphicsitems/qdeclarativeloader.cpp index bd89321..b0499d7 100644 --- a/src/declarative/graphicsitems/qdeclarativeloader.cpp +++ b/src/declarative/graphicsitems/qdeclarativeloader.cpp @@ -320,6 +320,15 @@ void QDeclarativeLoaderPrivate::_q_sourceLoaded() \o Error - an error occurred while loading the QML source \endlist + Note that a change in the status property does not cause anything to happen + (although it reflects what has happened to the loader internally). If you wish + to react to the change in status you need to do it yourself, for example in one + of the following ways: + \list + \o Create a state, so that a state change occurs, e.g. State{name: 'loaded'; when: loader.status = Loader.Ready;} + \o Do something inside the onStatusChanged signal handler, e.g. Loader{id: loader; onStatusChanged: if(loader.status == Loader.Ready) console.log('Loaded');} + \o Bind to the status variable somewhere, e.g. Text{text: if(loader.status!=Loader.Ready){'Not Loaded';}else{'Loaded';}} + \endlist \sa progress */ diff --git a/src/declarative/graphicsitems/qdeclarativepath.cpp b/src/declarative/graphicsitems/qdeclarativepath.cpp index 48f112a..80586b8 100644 --- a/src/declarative/graphicsitems/qdeclarativepath.cpp +++ b/src/declarative/graphicsitems/qdeclarativepath.cpp @@ -114,7 +114,10 @@ qreal QDeclarativePath::startX() const void QDeclarativePath::setStartX(qreal x) { Q_D(QDeclarativePath); + if (qFuzzyCompare(x, d->startX)) + return; d->startX = x; + emit startXChanged(); } qreal QDeclarativePath::startY() const @@ -126,7 +129,10 @@ qreal QDeclarativePath::startY() const void QDeclarativePath::setStartY(qreal y) { Q_D(QDeclarativePath); + if (qFuzzyCompare(y, d->startY)) + return; d->startY = y; + emit startYChanged(); } /*! @@ -522,7 +528,10 @@ QString QDeclarativePathAttribute::name() const void QDeclarativePathAttribute::setName(const QString &name) { - _name = name; + if (_name == name) + return; + _name = name; + emit nameChanged(); } /*! diff --git a/src/declarative/graphicsitems/qdeclarativepath_p.h b/src/declarative/graphicsitems/qdeclarativepath_p.h index b3139f8..d7cfca1 100644 --- a/src/declarative/graphicsitems/qdeclarativepath_p.h +++ b/src/declarative/graphicsitems/qdeclarativepath_p.h @@ -67,7 +67,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativePathAttribute : public QDeclarativePathEl { Q_OBJECT - Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY changed) public: QDeclarativePathAttribute(QObject *parent=0) : QDeclarativePathElement(parent), _value(0) {} @@ -79,6 +79,9 @@ public: qreal value() const; void setValue(qreal value); +Q_SIGNALS: + void nameChanged(); + private: QString _name; qreal _value; @@ -190,8 +193,8 @@ class Q_DECLARATIVE_EXPORT QDeclarativePath : public QObject, public QDeclarativ Q_INTERFACES(QDeclarativeParserStatus) Q_PROPERTY(QDeclarativeListProperty<QDeclarativePathElement> pathElements READ pathElements) - Q_PROPERTY(qreal startX READ startX WRITE setStartX) - Q_PROPERTY(qreal startY READ startY WRITE setStartY) + Q_PROPERTY(qreal startX READ startX WRITE setStartX NOTIFY startXChanged) + Q_PROPERTY(qreal startY READ startY WRITE setStartY NOTIFY startYChanged) Q_PROPERTY(bool closed READ isClosed NOTIFY changed) Q_CLASSINFO("DefaultProperty", "pathElements") Q_INTERFACES(QDeclarativeParserStatus) @@ -216,6 +219,8 @@ public: Q_SIGNALS: void changed(); + void startXChanged(); + void startYChanged(); protected: virtual void componentComplete(); diff --git a/src/declarative/graphicsitems/qdeclarativepathview.cpp b/src/declarative/graphicsitems/qdeclarativepathview.cpp index f1b0213..50aa9ef 100644 --- a/src/declarative/graphicsitems/qdeclarativepathview.cpp +++ b/src/declarative/graphicsitems/qdeclarativepathview.cpp @@ -203,6 +203,9 @@ QVariant QDeclarativePathView::model() const void QDeclarativePathView::setModel(const QVariant &model) { Q_D(QDeclarativePathView); + if (d->modelVariant == model) + return; + if (d->model) { disconnect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); disconnect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); @@ -242,6 +245,7 @@ void QDeclarativePathView::setModel(const QVariant &model) d->pathOffset = 0; d->regenerate(); d->fixOffset(); + emit modelChanged(); } /*! @@ -269,9 +273,12 @@ QDeclarativePath *QDeclarativePathView::path() const void QDeclarativePathView::setPath(QDeclarativePath *path) { Q_D(QDeclarativePathView); + if (d->path == path) + return; d->path = path; connect(d->path, SIGNAL(changed()), this, SLOT(refill())); d->regenerate(); + emit pathChanged(); } /*! @@ -333,7 +340,7 @@ void QDeclarativePathViewPrivate::setOffset(qreal o) /*! \qmlproperty real PathView::snapPosition - This property determines the position (0-100) the nearest item will snap to. + This property determines the position (0.0-1.0) the nearest item will snap to. */ qreal QDeclarativePathView::snapPosition() const { @@ -344,8 +351,12 @@ qreal QDeclarativePathView::snapPosition() const void QDeclarativePathView::setSnapPosition(qreal pos) { Q_D(QDeclarativePathView); - d->snapPos = pos/100; + qreal normalizedPos = pos - int(pos); + if (qFuzzyCompare(normalizedPos, d->snapPos)) + return; + d->snapPos = normalizedPos; d->fixOffset(); + emit snapPositionChanged(); } /*! @@ -365,7 +376,10 @@ qreal QDeclarativePathView::dragMargin() const void QDeclarativePathView::setDragMargin(qreal dragMargin) { Q_D(QDeclarativePathView); + if (d->dragMargin == dragMargin) + return; d->dragMargin = dragMargin; + emit dragMarginChanged(); } /*! @@ -392,16 +406,19 @@ QDeclarativeComponent *QDeclarativePathView::delegate() const return 0; } -void QDeclarativePathView::setDelegate(QDeclarativeComponent *c) +void QDeclarativePathView::setDelegate(QDeclarativeComponent *delegate) { Q_D(QDeclarativePathView); + if (delegate == this->delegate()) + return; if (!d->ownModel) { d->model = new QDeclarativeVisualDataModel(qmlContext(this)); d->ownModel = true; } if (QDeclarativeVisualDataModel *dataModel = qobject_cast<QDeclarativeVisualDataModel*>(d->model)) { - dataModel->setDelegate(c); + dataModel->setDelegate(delegate); d->regenerate(); + emit delegateChanged(); } } @@ -422,6 +439,7 @@ void QDeclarativePathView::setPathItemCount(int i) return; d->pathItems = i; d->regenerate(); + pathItemCountChanged(); } QPointF QDeclarativePathViewPrivate::pointNear(const QPointF &point, qreal *nearPercent) const diff --git a/src/declarative/graphicsitems/qdeclarativepathview_p.h b/src/declarative/graphicsitems/qdeclarativepathview_p.h index 709a4fc..df9c6ae 100644 --- a/src/declarative/graphicsitems/qdeclarativepathview_p.h +++ b/src/declarative/graphicsitems/qdeclarativepathview_p.h @@ -56,15 +56,15 @@ class Q_DECLARATIVE_EXPORT QDeclarativePathView : public QDeclarativeItem { Q_OBJECT - Q_PROPERTY(QVariant model READ model WRITE setModel) - Q_PROPERTY(QDeclarativePath *path READ path WRITE setPath) + Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged) + Q_PROPERTY(QDeclarativePath *path READ path WRITE setPath NOTIFY pathChanged) Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) Q_PROPERTY(qreal offset READ offset WRITE setOffset NOTIFY offsetChanged) - Q_PROPERTY(qreal snapPosition READ snapPosition WRITE setSnapPosition) - Q_PROPERTY(qreal dragMargin READ dragMargin WRITE setDragMargin) + Q_PROPERTY(qreal snapPosition READ snapPosition WRITE setSnapPosition NOTIFY snapPositionChanged) + Q_PROPERTY(qreal dragMargin READ dragMargin WRITE setDragMargin NOTIFY dragMarginChanged) Q_PROPERTY(int count READ count) - Q_PROPERTY(QDeclarativeComponent *delegate READ delegate WRITE setDelegate) - Q_PROPERTY(int pathItemCount READ pathItemCount WRITE setPathItemCount) + Q_PROPERTY(QDeclarativeComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged) + Q_PROPERTY(int pathItemCount READ pathItemCount WRITE setPathItemCount NOTIFY pathItemCountChanged) public: QDeclarativePathView(QDeclarativeItem *parent=0); @@ -101,6 +101,12 @@ public: Q_SIGNALS: void currentIndexChanged(); void offsetChanged(); + void modelChanged(); + void pathChanged(); + void dragMarginChanged(); + void snapPositionChanged(); + void delegateChanged(); + void pathItemCountChanged(); protected: void mousePressEvent(QGraphicsSceneMouseEvent *event); diff --git a/src/declarative/graphicsitems/qdeclarativepathview_p_p.h b/src/declarative/graphicsitems/qdeclarativepathview_p_p.h index ca50910..6344a8a 100644 --- a/src/declarative/graphicsitems/qdeclarativepathview_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativepathview_p_p.h @@ -60,6 +60,7 @@ #include <qdeclarative.h> #include <qdeclarativeanimation_p_p.h> +#include <qdeclarativeguard_p.h> #include <qdatetime.h> @@ -132,7 +133,7 @@ public: int pathOffset; int requestedIndex; QList<QDeclarativeItem *> items; - QGuard<QDeclarativeVisualModel> model; + QDeclarativeGuard<QDeclarativeVisualModel> model; QVariant modelVariant; enum MovementReason { Other, Key, Mouse }; MovementReason moveReason; diff --git a/src/declarative/graphicsitems/qdeclarativetextedit.cpp b/src/declarative/graphicsitems/qdeclarativetextedit.cpp index 8e44b26..be73b39 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextedit.cpp @@ -613,6 +613,11 @@ void QDeclarativeTextEdit::setPersistentSelection(bool on) emit persistentSelectionChanged(d->persistentSelection); } +/* + \qmlproperty number TextEdit::textMargin + + The margin, in pixels, around the text in the TextEdit. +*/ qreal QDeclarativeTextEdit::textMargin() const { Q_D(const QDeclarativeTextEdit); diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp index cd72ef9..a0aed46 100644 --- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp @@ -53,6 +53,7 @@ #include <qdeclarativedeclarativedata_p.h> #include <qdeclarativepropertycache_p.h> #include <qdeclarativeguard_p.h> +#include <qdeclarativeglobal_p.h> #include <qlistmodelinterface_p.h> #include <qhash.h> @@ -80,6 +81,14 @@ public: static_cast<QDeclarativeVisualItemModelPrivate *>(prop->data)->emitChildrenChanged(); } + static int children_count(QDeclarativeListProperty<QDeclarativeItem> *prop) { + return static_cast<QDeclarativeVisualItemModelPrivate *>(prop->data)->children.count(); + } + + static QDeclarativeItem *children_at(QDeclarativeListProperty<QDeclarativeItem> *prop, int index) { + return static_cast<QDeclarativeVisualItemModelPrivate *>(prop->data)->children.at(index); + } + void itemAppended() { Q_Q(QDeclarativeVisualItemModel); QDeclarativeVisualItemModelAttached *attached = QDeclarativeVisualItemModelAttached::properties(children.last()); @@ -135,7 +144,8 @@ QDeclarativeVisualItemModel::QDeclarativeVisualItemModel() QDeclarativeListProperty<QDeclarativeItem> QDeclarativeVisualItemModel::children() { Q_D(QDeclarativeVisualItemModel); - return QDeclarativeListProperty<QDeclarativeItem>(this, d, QDeclarativeVisualItemModelPrivate::children_append); + return QDeclarativeListProperty<QDeclarativeItem>(this, d, d->children_append, + d->children_count, d->children_at); } /*! @@ -984,8 +994,8 @@ QDeclarativeItem *QDeclarativeVisualDataModel::item(int index, const QByteArray if (complete) d->m_delegate->completeCreate(); if (nobj) { - ctxt->setParent(nobj); - data->setParent(nobj); + QDeclarative_setParent_noEvent(ctxt, nobj); + QDeclarative_setParent_noEvent(data, nobj); d->m_cache.insertItem(index, nobj); if (QDeclarativePackage *package = qobject_cast<QDeclarativePackage *>(nobj)) emit createdPackage(index, package); @@ -1268,7 +1278,6 @@ void QDeclarativeVisualDataModel::_q_dataChanged(const QModelIndex &begin, const void QDeclarativeVisualDataModel::_q_modelReset() { - Q_D(QDeclarativeVisualDataModel); emit modelReset(); } diff --git a/src/declarative/imports/imports.pro b/src/declarative/imports/imports.pro new file mode 100644 index 0000000..f874644 --- /dev/null +++ b/src/declarative/imports/imports.pro @@ -0,0 +1,7 @@ +TEMPLATE = subdirs + +SUBDIRS += widgets + +contains(QT_CONFIG, multimedia): SUBDIRS += multimedia +contains(QT_CONFIG, webkit): SUBDIRS += webkit + diff --git a/src/declarative/imports/multimedia/multimedia.cpp b/src/declarative/imports/multimedia/multimedia.cpp new file mode 100644 index 0000000..8becbf3 --- /dev/null +++ b/src/declarative/imports/multimedia/multimedia.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtDeclarative/qdeclarativeextensionplugin.h> +#include <QtDeclarative/qdeclarative.h> +#include <QtMultimedia/multimediadeclarative.h> + +QT_BEGIN_NAMESPACE + +class QMultimediaQmlModule : public QDeclarativeExtensionPlugin +{ + Q_OBJECT +public: + virtual void registerTypes(const char *uri) + { + QtMultimedia::qRegisterDeclarativeElements(uri); + } +}; + +QT_END_NAMESPACE + +#include "multimedia.moc" + +Q_EXPORT_PLUGIN2(qmultimediaqmlmodule, QT_PREPEND_NAMESPACE(QMultimediaQmlModule)); + diff --git a/src/declarative/imports/multimedia/multimedia.pro b/src/declarative/imports/multimedia/multimedia.pro new file mode 100644 index 0000000..d601d2e --- /dev/null +++ b/src/declarative/imports/multimedia/multimedia.pro @@ -0,0 +1,15 @@ +TARGET = multimedia +include(../qimportbase.pri) + +QT += multimedia declarative + +SOURCES += multimedia.cpp + +QTDIR_build:DESTDIR = $$QT_BUILD_TREE/imports/Qt/multimedia +target.path = $$[QT_INSTALL_IMPORTS]/Qt/multimedia + +qmldir.files += $$QT_BUILD_TREE/imports/Qt/multimedia/qmldir +qmldir.path += $$[QT_INSTALL_IMPORTS]/Qt/multimedia + +INSTALLS += target qmldir + diff --git a/src/declarative/imports/qimportbase.pri b/src/declarative/imports/qimportbase.pri new file mode 100644 index 0000000..5b0a4e2 --- /dev/null +++ b/src/declarative/imports/qimportbase.pri @@ -0,0 +1,16 @@ +TEMPLATE = lib +CONFIG += qt plugin + +win32|mac:!wince*:!win32-msvc:!macx-xcode:CONFIG += debug_and_release +TARGET = $$qtLibraryTarget($$TARGET) +contains(QT_CONFIG, reduce_exports):CONFIG += hide_symbols + +include(../../qt_targets.pri) + +wince*:LIBS += $$QMAKE_LIBS_GUI + +symbian: { + TARGET.EPOCALLOWDLLDATA=1 + TARGET.CAPABILITY = All -Tcb + load(armcc_warnings) +} diff --git a/src/declarative/imports/webkit/plugin.cpp b/src/declarative/imports/webkit/plugin.cpp new file mode 100644 index 0000000..2f6205d --- /dev/null +++ b/src/declarative/imports/webkit/plugin.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtDeclarative/qdeclarativeextensionplugin.h> +#include <QtDeclarative/qdeclarative.h> + +#include "qdeclarativewebview_p.h" +#include "qdeclarativewebview_p_p.h" + +QT_BEGIN_NAMESPACE + +class WebKitQmlPlugin : public QDeclarativeExtensionPlugin +{ + Q_OBJECT +public: + virtual void registerTypes(const char *uri) + { + Q_ASSERT(QLatin1String(uri) == QLatin1String("org.webkit")); + qmlRegisterType<QDeclarativeWebView>(uri,1,0,"WebView"); + } +}; + +QT_END_NAMESPACE + +#include "plugin.moc" + +Q_EXPORT_PLUGIN2(webkitqmlplugin, QT_PREPEND_NAMESPACE(WebKitQmlPlugin)); + diff --git a/src/declarative/graphicsitems/qdeclarativewebview.cpp b/src/declarative/imports/webkit/qdeclarativewebview.cpp index a2b16ba..733ac86 100644 --- a/src/declarative/graphicsitems/qdeclarativewebview.cpp +++ b/src/declarative/imports/webkit/qdeclarativewebview.cpp @@ -42,11 +42,11 @@ #include "qdeclarativewebview_p.h" #include "qdeclarativewebview_p_p.h" -#include "qdeclarativepainteditem_p_p.h" +#include <private/qdeclarativepainteditem_p_p.h> #include <qdeclarative.h> #include <qdeclarativeengine.h> -#include <qdeclarativestate_p.h> +#include <private/qdeclarativestate_p.h> #include <QDebug> #include <QPen> @@ -61,7 +61,7 @@ #include <QtWebKit/QWebFrame> #include <QtWebKit/QWebElement> #include <QtWebKit/QWebSettings> -#include <qlistmodelinterface_p.h> +#include <private/qlistmodelinterface_p.h> QT_BEGIN_NAMESPACE @@ -128,6 +128,8 @@ public: usually laying out the web content to fit the preferredWidth. \qml + import org.webkit 1.0 + WebView { url: "http://www.nokia.com" width: 490 @@ -929,7 +931,7 @@ QWebPage *QDeclarativeWebView::page() const } \endqml */ -QDeclarativeWebSettings *QDeclarativeWebView::settingsObject() const +QObject *QDeclarativeWebView::settingsObject() const { Q_D(const QDeclarativeWebView); d->settings.s = page()->settings(); diff --git a/src/declarative/graphicsitems/qdeclarativewebview_p.h b/src/declarative/imports/webkit/qdeclarativewebview_p.h index a65aab3..0bb5d29 100644 --- a/src/declarative/graphicsitems/qdeclarativewebview_p.h +++ b/src/declarative/imports/webkit/qdeclarativewebview_p.h @@ -42,7 +42,7 @@ #ifndef QDECLARATIVEWEBVIEW_H #define QDECLARATIVEWEBVIEW_H -#include "qdeclarativepainteditem_p.h" +#include <private/qdeclarativepainteditem_p.h> #include <QtGui/QAction> #include <QtCore/QUrl> @@ -82,7 +82,6 @@ private: class QDeclarativeWebViewAttached; -class QDeclarativeWebSettings; //### TODO: browser plugins @@ -112,7 +111,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeWebView : public QDeclarativePaintedItem Q_PROPERTY(QAction* forward READ forwardAction CONSTANT) Q_PROPERTY(QAction* stop READ stopAction CONSTANT) - Q_PROPERTY(QDeclarativeWebSettings* settings READ settingsObject CONSTANT) + Q_PROPERTY(QObject* settings READ settingsObject CONSTANT) Q_PROPERTY(QDeclarativeListProperty<QObject> javaScriptWindowObjects READ javaScriptWindowObjects CONSTANT) @@ -169,7 +168,7 @@ public: QWebHistory *history() const; QWebSettings *settings() const; - QDeclarativeWebSettings *settingsObject() const; + QObject *settingsObject() const; bool renderingEnabled() const; void setRenderingEnabled(bool); diff --git a/src/declarative/graphicsitems/qdeclarativewebview_p_p.h b/src/declarative/imports/webkit/qdeclarativewebview_p_p.h index 258b472..258b472 100644 --- a/src/declarative/graphicsitems/qdeclarativewebview_p_p.h +++ b/src/declarative/imports/webkit/qdeclarativewebview_p_p.h diff --git a/src/declarative/imports/webkit/webkit.pro b/src/declarative/imports/webkit/webkit.pro new file mode 100644 index 0000000..7ad8564 --- /dev/null +++ b/src/declarative/imports/webkit/webkit.pro @@ -0,0 +1,18 @@ +TARGET = webkitqmlplugin +include(../qimportbase.pri) + +contains(QT_CONFIG, webkit) { + QT += webkit declarative + + SOURCES += qdeclarativewebview.cpp plugin.cpp + HEADERS += qdeclarativewebview_p.h + HEADERS += qdeclarativewebview_p_p.h + + QTDIR_build:DESTDIR = $$QT_BUILD_TREE/imports/org/webkit + target.path = $$[QT_INSTALL_IMPORTS]/org/webkit + + qmldir.files += $$QT_BUILD_TREE/imports/org/webkit/qmldir + qmldir.path += $$[QT_INSTALL_IMPORTS]/org/webkit + + INSTALLS += target qmldir +} diff --git a/src/declarative/imports/widgets/graphicslayouts.cpp b/src/declarative/imports/widgets/graphicslayouts.cpp new file mode 100644 index 0000000..fc15ad2 --- /dev/null +++ b/src/declarative/imports/widgets/graphicslayouts.cpp @@ -0,0 +1,260 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "graphicslayouts_p.h" + +#include <QtGui/qgraphicswidget.h> +#include <QtCore/qdebug.h> + +QT_BEGIN_NAMESPACE + +LinearLayoutAttached::LinearLayoutAttached(QObject *parent) +: QObject(parent), _stretch(1), _alignment(Qt::AlignCenter) +{ +} + +void LinearLayoutAttached::setStretchFactor(int f) +{ + if (_stretch == f) + return; + + _stretch = f; + emit stretchChanged(reinterpret_cast<QGraphicsLayoutItem*>(parent()), _stretch); +} + +void LinearLayoutAttached::setAlignment(Qt::Alignment a) +{ + if (_alignment == a) + return; + + _alignment = a; + emit alignmentChanged(reinterpret_cast<QGraphicsLayoutItem*>(parent()), _alignment); +} + +QGraphicsLinearLayoutStretchItemObject::QGraphicsLinearLayoutStretchItemObject(QObject *parent) + : QObject(parent) +{ +} + +QSizeF QGraphicsLinearLayoutStretchItemObject::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const +{ +Q_UNUSED(which); +Q_UNUSED(constraint); +return QSizeF(); +} + + +QGraphicsLinearLayoutObject::QGraphicsLinearLayoutObject(QObject *parent) +: QObject(parent) +{ +} + +QGraphicsLinearLayoutObject::~QGraphicsLinearLayoutObject() +{ +} + +void QGraphicsLinearLayoutObject::insertLayoutItem(int index, QGraphicsLayoutItem *item) +{ +insertItem(index, item); + +//connect attached properties +if (LinearLayoutAttached *obj = attachedProperties.value(item)) { + setStretchFactor(item, obj->stretchFactor()); + setAlignment(item, obj->alignment()); + QObject::connect(obj, SIGNAL(stretchChanged(QGraphicsLayoutItem*,int)), + this, SLOT(updateStretch(QGraphicsLayoutItem*,int))); + QObject::connect(obj, SIGNAL(alignmentChanged(QGraphicsLayoutItem*,Qt::Alignment)), + this, SLOT(updateAlignment(QGraphicsLayoutItem*,Qt::Alignment))); + //### need to disconnect when widget is removed? +} +} + +//### is there a better way to do this? +void QGraphicsLinearLayoutObject::clearChildren() +{ +for (int i = 0; i < count(); ++i) + removeAt(i); +} + +void QGraphicsLinearLayoutObject::updateStretch(QGraphicsLayoutItem *item, int stretch) +{ +QGraphicsLinearLayout::setStretchFactor(item, stretch); +} + +void QGraphicsLinearLayoutObject::updateAlignment(QGraphicsLayoutItem *item, Qt::Alignment alignment) +{ +QGraphicsLinearLayout::setAlignment(item, alignment); +} + +QHash<QGraphicsLayoutItem*, LinearLayoutAttached*> QGraphicsLinearLayoutObject::attachedProperties; +LinearLayoutAttached *QGraphicsLinearLayoutObject::qmlAttachedProperties(QObject *obj) +{ +// ### This is not allowed - you must attach to any object +if (!qobject_cast<QGraphicsLayoutItem*>(obj)) + return 0; +LinearLayoutAttached *rv = new LinearLayoutAttached(obj); +attachedProperties.insert(qobject_cast<QGraphicsLayoutItem*>(obj), rv); +return rv; +} + +////////////////////////////////////////////////////////////////////////////////////////////////////// +// QGraphicsGridLayout-related classes +////////////////////////////////////////////////////////////////////////////////////////////////////// +GridLayoutAttached::GridLayoutAttached(QObject *parent) +: QObject(parent), _row(-1), _column(-1), _rowspan(1), _colspan(1), _alignment(-1) +{ +} + +void GridLayoutAttached::setRow(int r) +{ + if (_row == r) + return; + + _row = r; + //emit rowChanged(reinterpret_cast<QGraphicsLayoutItem*>(parent()), _row); +} + +void GridLayoutAttached::setColumn(int c) +{ + if (_column == c) + return; + + _column = c; + //emit columnChanged(reinterpret_cast<QGraphicsLayoutItem*>(parent()), _column); +} + +void GridLayoutAttached::setRowSpan(int rs) +{ + if (_rowspan == rs) + return; + + _rowspan = rs; + //emit rowSpanChanged(reinterpret_cast<QGraphicsLayoutItem*>(parent()), _rowSpan); +} + +void GridLayoutAttached::setColumnSpan(int cs) +{ + if (_colspan == cs) + return; + + _colspan = cs; + //emit columnSpanChanged(reinterpret_cast<QGraphicsLayoutItem*>(parent()), _columnSpan); +} + +void GridLayoutAttached::setAlignment(Qt::Alignment a) +{ + if (_alignment == a) + return; + + _alignment = a; + //emit alignmentChanged(reinterpret_cast<QGraphicsLayoutItem*>(parent()), _alignment); +} + +QGraphicsGridLayoutObject::QGraphicsGridLayoutObject(QObject *parent) +: QObject(parent) +{ +} + +QGraphicsGridLayoutObject::~QGraphicsGridLayoutObject() +{ +} + +void QGraphicsGridLayoutObject::addWidget(QGraphicsWidget *wid) +{ +//use attached properties +if (QObject *obj = attachedProperties.value(qobject_cast<QGraphicsLayoutItem*>(wid))) { + int row = static_cast<GridLayoutAttached *>(obj)->row(); + int column = static_cast<GridLayoutAttached *>(obj)->column(); + int rowSpan = static_cast<GridLayoutAttached *>(obj)->rowSpan(); + int columnSpan = static_cast<GridLayoutAttached *>(obj)->columnSpan(); + if (row == -1 || column == -1) { + qWarning() << "Must set row and column for an item in a grid layout"; + return; + } + addItem(wid, row, column, rowSpan, columnSpan); +} +} + +void QGraphicsGridLayoutObject::addLayoutItem(QGraphicsLayoutItem *item) +{ +//use attached properties +if (GridLayoutAttached *obj = attachedProperties.value(item)) { + int row = obj->row(); + int column = obj->column(); + int rowSpan = obj->rowSpan(); + int columnSpan = obj->columnSpan(); + Qt::Alignment alignment = obj->alignment(); + if (row == -1 || column == -1) { + qWarning() << "Must set row and column for an item in a grid layout"; + return; + } + addItem(item, row, column, rowSpan, columnSpan); + if (alignment != -1) + setAlignment(item,alignment); +} +} + +//### is there a better way to do this? +void QGraphicsGridLayoutObject::clearChildren() +{ +for (int i = 0; i < count(); ++i) + removeAt(i); +} + +qreal QGraphicsGridLayoutObject::spacing() const +{ +if (verticalSpacing() == horizontalSpacing()) + return verticalSpacing(); +return -1; //### +} + +QHash<QGraphicsLayoutItem*, GridLayoutAttached*> QGraphicsGridLayoutObject::attachedProperties; +GridLayoutAttached *QGraphicsGridLayoutObject::qmlAttachedProperties(QObject *obj) +{ +// ### This is not allowed - you must attach to any object +if (!qobject_cast<QGraphicsLayoutItem*>(obj)) + return 0; +GridLayoutAttached *rv = new GridLayoutAttached(obj); +attachedProperties.insert(qobject_cast<QGraphicsLayoutItem*>(obj), rv); +return rv; +} + +QT_END_NAMESPACE diff --git a/src/declarative/imports/widgets/graphicslayouts_p.h b/src/declarative/imports/widgets/graphicslayouts_p.h new file mode 100644 index 0000000..f9b9ae8 --- /dev/null +++ b/src/declarative/imports/widgets/graphicslayouts_p.h @@ -0,0 +1,226 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef GRAPHICSLAYOUTS_H +#define GRAPHICSLAYOUTS_H + +#include "graphicswidgets_p.h" + +#include <QtGui/QGraphicsLinearLayout> +#include <QtGui/QGraphicsGridLayout> + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QGraphicsLinearLayoutStretchItemObject : public QObject, public QGraphicsLayoutItem +{ + Q_OBJECT + Q_INTERFACES(QGraphicsLayoutItem) +public: + QGraphicsLinearLayoutStretchItemObject(QObject *parent = 0); + + virtual QSizeF sizeHint(Qt::SizeHint, const QSizeF &) const; +}; + +class LinearLayoutAttached; +class QGraphicsLinearLayoutObject : public QObject, public QGraphicsLinearLayout +{ + Q_OBJECT + Q_INTERFACES(QGraphicsLayout QGraphicsLayoutItem) + + Q_PROPERTY(QDeclarativeListProperty<QGraphicsLayoutItem> children READ children) + Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation) + Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing) + Q_CLASSINFO("DefaultProperty", "children") +public: + QGraphicsLinearLayoutObject(QObject * = 0); + ~QGraphicsLinearLayoutObject(); + + QDeclarativeListProperty<QGraphicsLayoutItem> children() { return QDeclarativeListProperty<QGraphicsLayoutItem>(this, 0, children_append, children_count, children_at, children_clear); } + + static LinearLayoutAttached *qmlAttachedProperties(QObject *); + +private Q_SLOTS: + void updateStretch(QGraphicsLayoutItem*,int); + void updateAlignment(QGraphicsLayoutItem*,Qt::Alignment); + +private: + friend class LinearLayoutAttached; + void clearChildren(); + void insertLayoutItem(int, QGraphicsLayoutItem *); + static QHash<QGraphicsLayoutItem*, LinearLayoutAttached*> attachedProperties; + + static void children_append(QDeclarativeListProperty<QGraphicsLayoutItem> *prop, QGraphicsLayoutItem *item) { + static_cast<QGraphicsLinearLayoutObject*>(prop->object)->insertLayoutItem(-1, item); + } + + static void children_clear(QDeclarativeListProperty<QGraphicsLayoutItem> *prop) { + static_cast<QGraphicsLinearLayoutObject*>(prop->object)->clearChildren(); + } + + static int children_count(QDeclarativeListProperty<QGraphicsLayoutItem> *prop) { + return static_cast<QGraphicsLinearLayoutObject*>(prop->object)->count(); + } + + static QGraphicsLayoutItem *children_at(QDeclarativeListProperty<QGraphicsLayoutItem> *prop, int index) { + return static_cast<QGraphicsLinearLayoutObject*>(prop->object)->itemAt(index); + } +}; + +class GridLayoutAttached; +class QGraphicsGridLayoutObject : public QObject, public QGraphicsGridLayout +{ + Q_OBJECT + Q_INTERFACES(QGraphicsLayout QGraphicsLayoutItem) + + Q_PROPERTY(QDeclarativeListProperty<QGraphicsLayoutItem> children READ children) + Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing) + Q_PROPERTY(qreal verticalSpacing READ verticalSpacing WRITE setVerticalSpacing) + Q_PROPERTY(qreal horizontalSpacing READ horizontalSpacing WRITE setHorizontalSpacing) + Q_CLASSINFO("DefaultProperty", "children") +public: + QGraphicsGridLayoutObject(QObject * = 0); + ~QGraphicsGridLayoutObject(); + + QDeclarativeListProperty<QGraphicsLayoutItem> children() { return QDeclarativeListProperty<QGraphicsLayoutItem>(this, 0, children_append, children_count, children_at, children_clear); } + + qreal spacing() const; + + static GridLayoutAttached *qmlAttachedProperties(QObject *); + +private: + friend class GraphicsLayoutAttached; + void addWidget(QGraphicsWidget *); + void clearChildren(); + void addLayoutItem(QGraphicsLayoutItem *); + static QHash<QGraphicsLayoutItem*, GridLayoutAttached*> attachedProperties; + + static void children_append(QDeclarativeListProperty<QGraphicsLayoutItem> *prop, QGraphicsLayoutItem *item) { + static_cast<QGraphicsGridLayoutObject*>(prop->object)->addLayoutItem(item); + } + + static void children_clear(QDeclarativeListProperty<QGraphicsLayoutItem> *prop) { + static_cast<QGraphicsGridLayoutObject*>(prop->object)->clearChildren(); + } + + static int children_count(QDeclarativeListProperty<QGraphicsLayoutItem> *prop) { + return static_cast<QGraphicsGridLayoutObject*>(prop->object)->count(); + } + + static QGraphicsLayoutItem *children_at(QDeclarativeListProperty<QGraphicsLayoutItem> *prop, int index) { + return static_cast<QGraphicsGridLayoutObject*>(prop->object)->itemAt(index); + } +}; + +class LinearLayoutAttached : public QObject +{ + Q_OBJECT + + Q_PROPERTY(int stretchFactor READ stretchFactor WRITE setStretchFactor NOTIFY stretchChanged) + Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged) +public: + LinearLayoutAttached(QObject *parent); + + int stretchFactor() const { return _stretch; } + void setStretchFactor(int f); + Qt::Alignment alignment() const { return _alignment; } + void setAlignment(Qt::Alignment a); + +Q_SIGNALS: + void stretchChanged(QGraphicsLayoutItem*,int); + void alignmentChanged(QGraphicsLayoutItem*,Qt::Alignment); + +private: + int _stretch; + Qt::Alignment _alignment; +}; + +class GridLayoutAttached : public QObject +{ + Q_OBJECT + + Q_PROPERTY(int row READ row WRITE setRow) + Q_PROPERTY(int column READ column WRITE setColumn) + Q_PROPERTY(int rowSpan READ rowSpan WRITE setRowSpan) + Q_PROPERTY(int columnSpan READ columnSpan WRITE setColumnSpan) + Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment) +public: + GridLayoutAttached(QObject *parent); + + int row() const { return _row; } + void setRow(int r); + + int column() const { return _column; } + void setColumn(int c); + + int rowSpan() const { return _rowspan; } + void setRowSpan(int rs); + + int columnSpan() const { return _colspan; } + void setColumnSpan(int cs); + + Qt::Alignment alignment() const { return _alignment; } + void setAlignment(Qt::Alignment a); + +private: + int _row; + int _column; + int _rowspan; + int _colspan; + Qt::Alignment _alignment; +}; + +QT_END_NAMESPACE + +QML_DECLARE_INTERFACE(QGraphicsLayoutItem) +QML_DECLARE_INTERFACE(QGraphicsLayout) +QML_DECLARE_TYPE(QGraphicsLinearLayoutStretchItemObject) +QML_DECLARE_TYPE(QGraphicsLinearLayoutObject) +QML_DECLARE_TYPEINFO(QGraphicsLinearLayoutObject, QML_HAS_ATTACHED_PROPERTIES) +QML_DECLARE_TYPE(QGraphicsGridLayoutObject) +QML_DECLARE_TYPEINFO(QGraphicsGridLayoutObject, QML_HAS_ATTACHED_PROPERTIES) + +QT_END_HEADER + +#endif // GRAPHICSLAYOUTS_H diff --git a/src/declarative/imports/widgets/graphicswidgets.cpp b/src/declarative/imports/widgets/graphicswidgets.cpp new file mode 100644 index 0000000..062e516 --- /dev/null +++ b/src/declarative/imports/widgets/graphicswidgets.cpp @@ -0,0 +1,40 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ diff --git a/src/declarative/imports/widgets/graphicswidgets_p.h b/src/declarative/imports/widgets/graphicswidgets_p.h new file mode 100644 index 0000000..2c2b707 --- /dev/null +++ b/src/declarative/imports/widgets/graphicswidgets_p.h @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef GRAPHICSWIDGETS_H +#define GRAPHICSWIDGETS_H + +#include <qdeclarative.h> + +#include <QtGui/QGraphicsScene> +#include <QtGui/QGraphicsView> +#include <QtGui/QGraphicsWidget> +#include <QtGui/QGraphicsItem> + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QGraphicsView) +QML_DECLARE_TYPE_HASMETATYPE(QGraphicsScene) +QML_DECLARE_TYPE(QGraphicsWidget) +QML_DECLARE_TYPE(QGraphicsObject) +QML_DECLARE_INTERFACE_HASMETATYPE(QGraphicsItem) + +QT_END_HEADER + +#endif // GRAPHICSWIDGETS_H diff --git a/src/declarative/imports/widgets/widgets.cpp b/src/declarative/imports/widgets/widgets.cpp new file mode 100644 index 0000000..ec21cc4 --- /dev/null +++ b/src/declarative/imports/widgets/widgets.cpp @@ -0,0 +1,138 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtDeclarative/qdeclarativeextensionplugin.h> +#include <QtDeclarative/qdeclarative.h> + +#include "graphicslayouts_p.h" +#include "graphicswidgets_p.h" + +QT_BEGIN_NAMESPACE + +class QGraphicsViewDeclarativeUI : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QGraphicsScene *scene READ scene WRITE setScene) + Q_CLASSINFO("DefaultProperty", "scene") +public: + QGraphicsViewDeclarativeUI(QObject *other) : QObject(other) {} + + QGraphicsScene *scene() const { return static_cast<QGraphicsView *>(parent())->scene(); } + void setScene(QGraphicsScene *scene) + { + static_cast<QGraphicsView *>(parent())->setScene(scene); + } +}; + +class QGraphicsSceneDeclarativeUI : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QDeclarativeListProperty<QObject> children READ children) + Q_CLASSINFO("DefaultProperty", "children") +public: + QGraphicsSceneDeclarativeUI(QObject *other) : QObject(other) {} + + QDeclarativeListProperty<QObject> children() { return QDeclarativeListProperty<QObject>(this->parent(), 0, children_append); } + +private: + static void children_append(QDeclarativeListProperty<QObject> *prop, QObject *o) { + if (QGraphicsObject *go = qobject_cast<QGraphicsObject *>(o)) + static_cast<QGraphicsScene *>(prop->object)->addItem(go); + } +}; + +class QGraphicsWidgetDeclarativeUI : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QDeclarativeListProperty<QGraphicsItem> children READ children) + Q_PROPERTY(QGraphicsLayout *layout READ layout WRITE setLayout) + Q_CLASSINFO("DefaultProperty", "children") +public: + QGraphicsWidgetDeclarativeUI(QObject *other) : QObject(other) {} + + QDeclarativeListProperty<QGraphicsItem> children() { return QDeclarativeListProperty<QGraphicsItem>(this, 0, children_append); } + + QGraphicsLayout *layout() const { return static_cast<QGraphicsWidget *>(parent())->layout(); } + void setLayout(QGraphicsLayout *lo) + { + static_cast<QGraphicsWidget *>(parent())->setLayout(lo); + } + +private: + void setItemParent(QGraphicsItem *wid) + { + wid->setParentItem(static_cast<QGraphicsWidget *>(parent())); + } + + static void children_append(QDeclarativeListProperty<QGraphicsItem> *prop, QGraphicsItem *i) { + static_cast<QGraphicsWidgetDeclarativeUI*>(prop->object)->setItemParent(i); + } +}; + +class QWidgetsQmlModule : public QDeclarativeExtensionPlugin +{ + Q_OBJECT +public: + virtual void registerTypes(const char *uri) + { + Q_ASSERT(QLatin1String(uri) == QLatin1String("Qt.widgets")); + + QML_REGISTER_INTERFACE(QGraphicsLayoutItem); + QML_REGISTER_INTERFACE(QGraphicsLayout); + qmlRegisterType<QGraphicsLinearLayoutStretchItemObject>(uri,4,6,"QGraphicsLinearLayoutStretchItem"); + qmlRegisterType<QGraphicsLinearLayoutObject>(uri,4,6,"QGraphicsLinearLayout"); + qmlRegisterType<QGraphicsGridLayoutObject>(uri,4,6,"QGraphicsGridLayout"); + qmlRegisterExtendedType<QGraphicsView, QGraphicsViewDeclarativeUI>(uri,4,6,"QGraphicsView"); + qmlRegisterExtendedType<QGraphicsScene,QGraphicsSceneDeclarativeUI>(uri,4,6,"QGraphicsScene"); + qmlRegisterExtendedType<QGraphicsWidget,QGraphicsWidgetDeclarativeUI>(uri,4,6,"QGraphicsWidget"); + QML_REGISTER_INTERFACE(QGraphicsItem); + } +}; + +QT_END_NAMESPACE + +#include "widgets.moc" + +Q_EXPORT_PLUGIN2(qtwidgetsqmlmodule, QT_PREPEND_NAMESPACE(QWidgetsQmlModule)); + diff --git a/src/declarative/imports/widgets/widgets.pro b/src/declarative/imports/widgets/widgets.pro new file mode 100644 index 0000000..230d398 --- /dev/null +++ b/src/declarative/imports/widgets/widgets.pro @@ -0,0 +1,20 @@ +TARGET = widgets +include(../qimportbase.pri) + +QT += declarative + +SOURCES += \ + graphicslayouts.cpp \ + widgets.cpp + +HEADERS += \ + graphicswidgets_p.h \ + graphicslayouts_p.h + +QTDIR_build:DESTDIR = $$QT_BUILD_TREE/imports/Qt/widgets +target.path = $$[QT_INSTALL_IMPORTS]/Qt/widgets + +qmldir.files += $$QT_BUILD_TREE/imports/Qt/widgets/qmldir +qmldir.path += $$[QT_INSTALL_IMPORTS]/Qt/widgets + +INSTALLS += target qmldir diff --git a/src/declarative/libdeclarative.pro b/src/declarative/libdeclarative.pro new file mode 100644 index 0000000..4287e25 --- /dev/null +++ b/src/declarative/libdeclarative.pro @@ -0,0 +1,29 @@ +TARGET = QtDeclarative +QPRO_PWD = $$PWD +QT = core gui xml script network +contains(QT_CONFIG, svg): QT += svg +contains(QT_CONFIG, opengl): QT += opengl +DEFINES += QT_BUILD_DECLARATIVE_LIB QT_NO_URL_CAST_FROM_STRING +win32-msvc*|win32-icc:QMAKE_LFLAGS += /BASE:0x66000000 +solaris-cc*:QMAKE_CXXFLAGS_RELEASE -= -O2 + +unix:QMAKE_PKGCONFIG_REQUIRES = QtCore QtGui QtXml + +exists("qdeclarative_enable_gcov") { + QMAKE_CXXFLAGS = -fprofile-arcs -ftest-coverage -fno-elide-constructors + LIBS += -lgcov +} + +include(../qbase.pri) + +#INCLUDEPATH -= $$QMAKE_INCDIR_QT/$$TARGET +#DESTDIR=. + +#modules +include(3rdparty/3rdparty.pri) +include(util/util.pri) +include(graphicsitems/graphicsitems.pri) +include(qml/qml.pri) +include(debugger/debugger.pri) + +symbian:TARGET.UID3=0x2001E623 diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp index 5da207d..a9809c0 100644 --- a/src/declarative/qml/qdeclarativecompiler.cpp +++ b/src/declarative/qml/qdeclarativecompiler.cpp @@ -718,6 +718,7 @@ bool QDeclarativeCompiler::buildObject(Object *obj, const BindingContext &ctxt) BindingContext objCtxt(obj); // Create the synthesized meta object, ignoring aliases + COMPILE_CHECK(checkDynamicMeta(obj)); COMPILE_CHECK(mergeDynamicMetaProperties(obj)); COMPILE_CHECK(buildDynamicMeta(obj, IgnoreAliases)); @@ -1623,6 +1624,10 @@ void QDeclarativeCompiler::genPropertyAssignment(QDeclarativeParser::Property *p for (int ii = 0; ii < prop->values.count(); ++ii) { QDeclarativeParser::Value *v = prop->values.at(ii); + Q_ASSERT(v->type == Value::CreatedObject || + v->type == Value::PropertyBinding || + v->type == Value::Literal); + if (v->type == Value::CreatedObject) { genObject(v->object); @@ -1652,7 +1657,27 @@ void QDeclarativeCompiler::genPropertyAssignment(QDeclarativeParser::Property *p output->bytecode << store; } - } else if (v->type == Value::ValueSource) { + } else if (v->type == Value::PropertyBinding) { + + genBindingAssignment(v, prop, obj, valueTypeProperty); + + } else if (v->type == Value::Literal) { + + QMetaProperty mp = obj->metaObject()->property(prop->index); + genLiteralAssignment(mp, v); + + } + + } + + for (int ii = 0; ii < prop->onValues.count(); ++ii) { + + QDeclarativeParser::Value *v = prop->onValues.at(ii); + + Q_ASSERT(v->type == Value::ValueSource || + v->type == Value::ValueInterceptor); + + if (v->type == Value::ValueSource) { genObject(v->object); QDeclarativeInstruction store; @@ -1685,16 +1710,6 @@ void QDeclarativeCompiler::genPropertyAssignment(QDeclarativeParser::Property *p QDeclarativeType *valueType = toQmlType(v->object); store.assignValueInterceptor.castValue = valueType->propertyValueInterceptorCast(); output->bytecode << store; - - } else if (v->type == Value::PropertyBinding) { - - genBindingAssignment(v, prop, obj, valueTypeProperty); - - } else if (v->type == Value::Literal) { - - QMetaProperty mp = obj->metaObject()->property(prop->index); - genLiteralAssignment(mp, v); - } } @@ -1793,8 +1808,8 @@ bool QDeclarativeCompiler::buildAttachedProperty(QDeclarativeParser::Property *p // } // font is a nested property. pointSize and family are not. bool QDeclarativeCompiler::buildGroupedProperty(QDeclarativeParser::Property *prop, - QDeclarativeParser::Object *obj, - const BindingContext &ctxt) + QDeclarativeParser::Object *obj, + const BindingContext &ctxt) { Q_ASSERT(prop->type != 0); Q_ASSERT(prop->index != -1); @@ -1829,9 +1844,9 @@ bool QDeclarativeCompiler::buildGroupedProperty(QDeclarativeParser::Property *pr } bool QDeclarativeCompiler::buildValueTypeProperty(QObject *type, - QDeclarativeParser::Object *obj, - QDeclarativeParser::Object *baseObj, - const BindingContext &ctxt) + QDeclarativeParser::Object *obj, + QDeclarativeParser::Object *baseObj, + const BindingContext &ctxt) { if (obj->defaultProperty) COMPILE_EXCEPTION(obj, QCoreApplication::translate("QDeclarativeCompiler","Invalid property use")); @@ -1848,37 +1863,36 @@ bool QDeclarativeCompiler::buildValueTypeProperty(QObject *type, if (prop->value) COMPILE_EXCEPTION(prop, QCoreApplication::translate("QDeclarativeCompiler","Property assignment expected")); - if (prop->values.count() != 1) + if (prop->values.count() > 1) { COMPILE_EXCEPTION(prop, QCoreApplication::translate("QDeclarativeCompiler","Single property assignment expected")); + } else if (prop->values.count()) { + Value *value = prop->values.at(0); - Value *value = prop->values.at(0); - - if (value->object) { - bool isPropertyValue = output->types.at(value->object->type).type->propertyValueSourceCast() != -1; - bool isPropertyInterceptor = output->types.at(value->object->type).type->propertyValueInterceptorCast() != -1; - if (!isPropertyValue && !isPropertyInterceptor) { + if (value->object) { COMPILE_EXCEPTION(prop, QCoreApplication::translate("QDeclarativeCompiler","Unexpected object assignment")); - } else { - COMPILE_CHECK(buildObject(value->object, ctxt)); - - if (isPropertyInterceptor && baseObj->synthdata.isEmpty()) - buildDynamicMeta(baseObj, ForceCreation); - value->type = isPropertyValue ? Value::ValueSource : Value::ValueInterceptor; + } else if (value->value.isScript()) { + // ### Check for writability + BindingReference reference; + reference.expression = value->value; + reference.property = prop; + reference.value = value; + reference.bindingContext = ctxt; + reference.bindingContext.owner++; + addBindingReference(reference); + value->type = Value::PropertyBinding; + } else { + COMPILE_CHECK(testLiteralAssignment(p, value)); + value->type = Value::Literal; } - } else if (value->value.isScript()) { - // ### Check for writability - BindingReference reference; - reference.expression = value->value; - reference.property = prop; - reference.value = value; - reference.bindingContext = ctxt; - reference.bindingContext.owner++; - addBindingReference(reference); - value->type = Value::PropertyBinding; - } else { - COMPILE_CHECK(testLiteralAssignment(p, value)); - value->type = Value::Literal; } + + for (int ii = 0; ii < prop->onValues.count(); ++ii) { + Value *v = prop->onValues.at(ii); + Q_ASSERT(v->object); + + COMPILE_CHECK(buildPropertyOnAssignment(prop, obj, baseObj, v, ctxt)); + } + obj->addValueProperty(prop); } @@ -1886,13 +1900,11 @@ bool QDeclarativeCompiler::buildValueTypeProperty(QObject *type, } // Build assignments to QML lists. QML lists are properties of type -// QList<T *> * and QDeclarativeList<T *> *. -// -// QList<T *> * types can accept a list of objects, or a single binding -// QDeclarativeList<T *> * types can accept a list of objects +// QDeclarativeListProperty<T>. List properties can accept a list of +// objects, or a single binding. bool QDeclarativeCompiler::buildListProperty(QDeclarativeParser::Property *prop, - QDeclarativeParser::Object *obj, - const BindingContext &ctxt) + QDeclarativeParser::Object *obj, + const BindingContext &ctxt) { Q_ASSERT(QDeclarativeEnginePrivate::get(engine)->isList(prop->type)); @@ -1950,20 +1962,6 @@ bool QDeclarativeCompiler::buildScriptStringProperty(QDeclarativeParser::Propert } // Compile regular property assignments of the form "property: <value>" -// -// ### The following problems exist -// -// There is no distinction between how "lists" of values are specified. This -// Item { -// children: Item {} -// children: Item {} -// } -// is identical to -// Item { -// children: [ Item {}, Item {} ] -// } -// -// We allow assignming multiple values to single value properties bool QDeclarativeCompiler::buildPropertyAssignment(QDeclarativeParser::Property *prop, QDeclarativeParser::Object *obj, const BindingContext &ctxt) @@ -1983,14 +1981,21 @@ bool QDeclarativeCompiler::buildPropertyAssignment(QDeclarativeParser::Property } } + for (int ii = 0; ii < prop->onValues.count(); ++ii) { + Value *v = prop->onValues.at(ii); + + Q_ASSERT(v->object); + COMPILE_CHECK(buildPropertyOnAssignment(prop, obj, obj, v, ctxt)); + } + return true; } // Compile assigning a single object instance to a regular property bool QDeclarativeCompiler::buildPropertyObjectAssignment(QDeclarativeParser::Property *prop, - QDeclarativeParser::Object *obj, - QDeclarativeParser::Value *v, - const BindingContext &ctxt) + QDeclarativeParser::Object *obj, + QDeclarativeParser::Value *v, + const BindingContext &ctxt) { Q_ASSERT(prop->index != -1); Q_ASSERT(v->object->type != -1); @@ -2019,15 +2024,6 @@ bool QDeclarativeCompiler::buildPropertyObjectAssignment(QDeclarativeParser::Pro v->object->metatype = output->types.at(v->object->type).metaObject(); Q_ASSERT(v->object->metaObject()); - // Will be true if the assigned type inherits QDeclarativePropertyValueSource - bool isPropertyValue = false; - // Will be true if the assigned type inherits QDeclarativePropertyValueInterceptor - bool isPropertyInterceptor = false; - if (QDeclarativeType *valueType = toQmlType(v->object)) { - isPropertyValue = valueType->propertyValueSourceCast() != -1; - isPropertyInterceptor = valueType->propertyValueInterceptorCast() != -1; - } - // We want to raw metaObject here as the raw metaobject is the // actual property type before we applied any extensions that might // effect the properties on the type, but don't effect assignability @@ -2063,13 +2059,6 @@ bool QDeclarativeCompiler::buildPropertyObjectAssignment(QDeclarativeParser::Pro component->getDefaultProperty()->addValue(componentValue); v->object = component; COMPILE_CHECK(buildPropertyObjectAssignment(prop, obj, v, ctxt)); - } else if (isPropertyValue || isPropertyInterceptor) { - // Assign as a property value source - COMPILE_CHECK(buildObject(v->object, ctxt)); - - if (isPropertyInterceptor && prop->parent->synthdata.isEmpty()) - buildDynamicMeta(prop->parent, ForceCreation); - v->type = isPropertyValue ? Value::ValueSource : Value::ValueInterceptor; } else { COMPILE_EXCEPTION(v->object, QCoreApplication::translate("QDeclarativeCompiler","Cannot assign object to property")); } @@ -2078,6 +2067,55 @@ bool QDeclarativeCompiler::buildPropertyObjectAssignment(QDeclarativeParser::Pro return true; } +// Compile assigning a single object instance to a regular property using the "on" syntax. +// +// For example: +// Item { +// NumberAnimation on x { } +// } +bool QDeclarativeCompiler::buildPropertyOnAssignment(QDeclarativeParser::Property *prop, + QDeclarativeParser::Object *obj, + QDeclarativeParser::Object *baseObj, + QDeclarativeParser::Value *v, + const BindingContext &ctxt) +{ + Q_ASSERT(prop->index != -1); + Q_ASSERT(v->object->type != -1); + + if (!obj->metaObject()->property(prop->index).isWritable()) + COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler","Invalid property assignment: \"%1\" is a read-only property").arg(QString::fromUtf8(prop->name))); + + + // Normally buildObject() will set this up, but we need the static + // meta object earlier to test for assignability. It doesn't matter + // that there may still be outstanding synthesized meta object changes + // on this type, as they are not relevant for assignability testing + v->object->metatype = output->types.at(v->object->type).metaObject(); + Q_ASSERT(v->object->metaObject()); + + // Will be true if the assigned type inherits QDeclarativePropertyValueSource + bool isPropertyValue = false; + // Will be true if the assigned type inherits QDeclarativePropertyValueInterceptor + bool isPropertyInterceptor = false; + if (QDeclarativeType *valueType = toQmlType(v->object)) { + isPropertyValue = valueType->propertyValueSourceCast() != -1; + isPropertyInterceptor = valueType->propertyValueInterceptorCast() != -1; + } + + if (isPropertyValue || isPropertyInterceptor) { + // Assign as a property value source + COMPILE_CHECK(buildObject(v->object, ctxt)); + + if (isPropertyInterceptor && prop->parent->synthdata.isEmpty()) + buildDynamicMeta(baseObj, ForceCreation); + v->type = isPropertyValue ? Value::ValueSource : Value::ValueInterceptor; + } else { + COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler","\"%1\" cannot operate on \"%2\"").arg(v->object->typeName.constData()).arg(prop->name.constData())); + } + + return true; +} + // Compile assigning a literal or binding to a regular property bool QDeclarativeCompiler::buildPropertyLiteralAssignment(QDeclarativeParser::Property *prop, QDeclarativeParser::Object *obj, @@ -2203,10 +2241,13 @@ bool QDeclarativeCompiler::mergeDynamicMetaProperties(QDeclarativeParser::Object continue; Property *property = 0; - if (p.isDefaultProperty) + if (p.isDefaultProperty) { property = obj->getDefaultProperty(); - else + } else { property = obj->getProperty(p.name); + if (!property->values.isEmpty()) + COMPILE_EXCEPTION(property, QCoreApplication::translate("QDeclarativeCompiler","Property value set multiple times")); + } if (property->value) COMPILE_EXCEPTION(property, QCoreApplication::translate("QDeclarativeCompiler","Invalid property nesting")); @@ -2233,8 +2274,6 @@ bool QDeclarativeCompiler::buildDynamicMeta(QDeclarativeParser::Object *obj, Dyn obj->dynamicSlots.isEmpty()) return true; - COMPILE_CHECK(checkDynamicMeta(obj)); - QByteArray dynamicData(sizeof(QDeclarativeVMEMetaData), (char)0); QByteArray newClassName = obj->metatype->className(); diff --git a/src/declarative/qml/qdeclarativecompiler_p.h b/src/declarative/qml/qdeclarativecompiler_p.h index 2ea3366..93a3f83 100644 --- a/src/declarative/qml/qdeclarativecompiler_p.h +++ b/src/declarative/qml/qdeclarativecompiler_p.h @@ -219,6 +219,11 @@ private: QDeclarativeParser::Object *obj, QDeclarativeParser::Value *value, const BindingContext &ctxt); + bool buildPropertyOnAssignment(QDeclarativeParser::Property *prop, + QDeclarativeParser::Object *obj, + QDeclarativeParser::Object *baseObj, + QDeclarativeParser::Value *value, + const BindingContext &ctxt); bool buildPropertyLiteralAssignment(QDeclarativeParser::Property *prop, QDeclarativeParser::Object *obj, QDeclarativeParser::Value *value, diff --git a/src/declarative/qml/qdeclarativecomponent.cpp b/src/declarative/qml/qdeclarativecomponent.cpp index 6a2d2d1..d6bb216 100644 --- a/src/declarative/qml/qdeclarativecomponent.cpp +++ b/src/declarative/qml/qdeclarativecomponent.cpp @@ -437,6 +437,13 @@ void QDeclarativeComponent::loadUrl(const QUrl &url) else d->url = url; + if (url.isEmpty()) { + QDeclarativeError error; + error.setDescription(tr("Invalid empty URL")); + d->state.errors << error; + return; + } + QDeclarativeCompositeTypeData *data = QDeclarativeEnginePrivate::get(d->engine)->typeManager.get(d->url); diff --git a/src/declarative/qml/qdeclarativedeclarativedata_p.h b/src/declarative/qml/qdeclarativedeclarativedata_p.h index 2c92419..a7a73bc 100644 --- a/src/declarative/qml/qdeclarativedeclarativedata_p.h +++ b/src/declarative/qml/qdeclarativedeclarativedata_p.h @@ -103,7 +103,10 @@ public: static QDeclarativeDeclarativeData *get(const QObject *object, bool create = false) { QObjectPrivate *priv = QObjectPrivate::get(const_cast<QObject *>(object)); - if (priv->declarativeData) { + if (priv->wasDeleted) { + Q_ASSERT(!create); + return 0; + } else if (priv->declarativeData) { return static_cast<QDeclarativeDeclarativeData *>(priv->declarativeData); } else if (create) { priv->declarativeData = new QDeclarativeDeclarativeData; diff --git a/src/declarative/qml/qdeclarativedom.cpp b/src/declarative/qml/qdeclarativedom.cpp index 6c81f34..5b43109 100644 --- a/src/declarative/qml/qdeclarativedom.cpp +++ b/src/declarative/qml/qdeclarativedom.cpp @@ -374,7 +374,10 @@ QDeclarativeDomValue QDeclarativeDomProperty::value() const QDeclarativeDomValue rv; if (d->property) { rv.d->property = d->property; - rv.d->value = d->property->values.at(0); + if (d->property->values.count()) + rv.d->value = d->property->values.at(0); + else + rv.d->value = d->property->onValues.at(0); rv.d->property->addref(); rv.d->value->addref(); } @@ -1346,7 +1349,7 @@ QDeclarativeDomValue::Type QDeclarativeDomValue::type() const { if (d->property) if (QDeclarativeMetaType::isList(d->property->type) || - (d->property && d->property->values.count() > 1)) + (d->property && (d->property->values.count() + d->property->onValues.count()) > 1)) return List; QDeclarativeParser::Value *value = d->value; @@ -1628,6 +1631,13 @@ QList<QDeclarativeDomValue> QDeclarativeDomList::values() const rv << v; } + for (int ii = 0; ii < d->property->onValues.count(); ++ii) { + QDeclarativeDomValue v; + v.d->value = d->property->onValues.at(ii); + v.d->value->addref(); + rv << v; + } + return rv; } diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index af75e98..ecaea61 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -1687,6 +1687,7 @@ QString QDeclarativeEngine::offlineStoragePath() const \internal Returns the result of the merge of \a baseName with \a dir, \a suffixes, and \a prefix. + The \a prefix must contain the dot. */ QString QDeclarativeEnginePrivate::resolvePlugin(const QDir &dir, const QString &baseName, const QStringList &suffixes, @@ -1696,7 +1697,6 @@ QString QDeclarativeEnginePrivate::resolvePlugin(const QDir &dir, const QString QString pluginFileName = prefix; pluginFileName += baseName; - pluginFileName += QLatin1Char('.'); pluginFileName += suffix; QFileInfo fileInfo(dir, pluginFileName); @@ -1728,14 +1728,26 @@ QString QDeclarativeEnginePrivate::resolvePlugin(const QDir &dir, const QString QString QDeclarativeEnginePrivate::resolvePlugin(const QDir &dir, const QString &baseName) { #if defined(Q_OS_WIN32) || defined(Q_OS_WINCE) - return resolvePlugin(dir, baseName, QStringList(QLatin1String("dll"))); + return resolvePlugin(dir, baseName, + QStringList() +# ifdef QT_DEBUG + << QLatin1String("d.dll") // try a qmake-style debug build first +# endif + << QLatin1String(".dll")); #elif defined(Q_OS_SYMBIAN) - return resolvePlugin(dir, baseName, QStringList() << QLatin1String("dll") << QLatin1String("qtplugin")); + return resolvePlugin(dir, baseName, + QStringList() + << QLatin1String(".dll") + << QLatin1String(".qtplugin")); #else # if defined(Q_OS_DARWIN) - return resolvePlugin(dir, baseName, QStringList() << QLatin1String("dylib") << QLatin1String("so") << QLatin1String("bundle"), + return resolvePlugin(dir, baseName, + QStringList() + << QLatin1String(".dylib") + << QLatin1String(".so") + << QLatin1String(".bundle"), QLatin1String("lib")); # else // Generic Unix QStringList validSuffixList; @@ -1746,14 +1758,14 @@ QString QDeclarativeEnginePrivate::resolvePlugin(const QDir &dir, const QString "In PA-RISC (PA-32 and PA-64) shared libraries are suffixed with .sl. In IPF (32-bit and 64-bit), the shared libraries are suffixed with .so. For compatibility, the IPF linker also supports the .sl suffix." */ - validSuffixList << QLatin1String("sl"); + validSuffixList << QLatin1String(".sl"); # if defined __ia64 - validSuffixList << QLatin1String("so"); + validSuffixList << QLatin1String(".so"); # endif # elif defined(Q_OS_AIX) - validSuffixList << QLatin1String("a") << QLatin1String("so"); + validSuffixList << QLatin1String(".a") << QLatin1String(".so"); # elif defined(Q_OS_UNIX) - validSuffixList << QLatin1String("so"); + validSuffixList << QLatin1String(".so"); # endif // Examples of valid library names: diff --git a/src/declarative/qml/qdeclarativeengine_p.h b/src/declarative/qml/qdeclarativeengine_p.h index 0359f98..d3eb583 100644 --- a/src/declarative/qml/qdeclarativeengine_p.h +++ b/src/declarative/qml/qdeclarativeengine_p.h @@ -238,7 +238,8 @@ public: QHash<const QMetaObject *, QDeclarativePropertyCache *> propertyCache; QDeclarativePropertyCache *cache(QObject *obj) { Q_Q(QDeclarativeEngine); - if (!obj || QObjectPrivate::get(obj)->metaObject) return 0; + if (!obj || QObjectPrivate::get(obj)->metaObject || + QObjectPrivate::get(obj)->wasDeleted) return 0; const QMetaObject *mo = obj->metaObject(); QDeclarativePropertyCache *rv = propertyCache.value(mo); if (!rv) { diff --git a/src/declarative/qml/qdeclarativelist.h b/src/declarative/qml/qdeclarativelist.h index 8d59384..eac4967 100644 --- a/src/declarative/qml/qdeclarativelist.h +++ b/src/declarative/qml/qdeclarativelist.h @@ -53,7 +53,7 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) class QObject; -class QMetaObject; +struct QMetaObject; template<typename T> struct QDeclarativeListProperty { typedef void (*AppendFunction)(QDeclarativeListProperty<T> *, T*); diff --git a/src/declarative/qml/qdeclarativeparser.cpp b/src/declarative/qml/qdeclarativeparser.cpp index 5ac49d5..0e3d856 100644 --- a/src/declarative/qml/qdeclarativeparser.cpp +++ b/src/declarative/qml/qdeclarativeparser.cpp @@ -221,6 +221,8 @@ QDeclarativeParser::Property::~Property() { foreach(Value *value, values) value->release(); + foreach(Value *value, onValues) + value->release(); if (value) value->release(); } @@ -235,9 +237,14 @@ void QDeclarativeParser::Property::addValue(Value *v) values << v; } +void QDeclarativeParser::Property::addOnValue(Value *v) +{ + onValues << v; +} + bool QDeclarativeParser::Property::isEmpty() const { - return !value && values.isEmpty(); + return !value && values.isEmpty() && onValues.isEmpty(); } QDeclarativeParser::Value::Value() diff --git a/src/declarative/qml/qdeclarativeparser_p.h b/src/declarative/qml/qdeclarativeparser_p.h index aae507e..d0d7de1 100644 --- a/src/declarative/qml/qdeclarativeparser_p.h +++ b/src/declarative/qml/qdeclarativeparser_p.h @@ -320,6 +320,7 @@ namespace QDeclarativeParser Object *getValue(); void addValue(Value *v); + void addOnValue(Value *v); // The QVariant::Type of the property, or 0 (QVariant::Invalid) if // unknown. @@ -333,6 +334,8 @@ namespace QDeclarativeParser // The list of values assigned to this property. Content in values // and value are mutually exclusive QList<Value *> values; + // The list of values assigned to this property using the "on" syntax + QList<Value *> onValues; // The accessed property. This is used to represent dot properties. // Content in value and values are mutually exclusive. Object *value; diff --git a/src/declarative/qml/qdeclarativepropertycache.cpp b/src/declarative/qml/qdeclarativepropertycache.cpp index 08b47b7..fea59e5 100644 --- a/src/declarative/qml/qdeclarativepropertycache.cpp +++ b/src/declarative/qml/qdeclarativepropertycache.cpp @@ -155,9 +155,9 @@ QDeclarativePropertyCache::Data QDeclarativePropertyCache::create(const QMetaObj int parenIdx = methodName.indexOf(QLatin1Char('(')); Q_ASSERT(parenIdx != -1); - methodName = methodName.left(parenIdx); + QStringRef methodNameRef = methodName.leftRef(parenIdx); - if (methodName == property) { + if (methodNameRef == property) { rv.load(m); return rv; } diff --git a/src/declarative/qml/qdeclarativescriptparser.cpp b/src/declarative/qml/qdeclarativescriptparser.cpp index f4c9cdd..a4b3668 100644 --- a/src/declarative/qml/qdeclarativescriptparser.cpp +++ b/src/declarative/qml/qdeclarativescriptparser.cpp @@ -106,12 +106,12 @@ public: void operator()(const QString &code, AST::Node *node); protected: - Object *defineObjectBinding(AST::UiQualifiedId *propertyName, + Object *defineObjectBinding(AST::UiQualifiedId *propertyName, bool onAssignment, AST::UiQualifiedId *objectTypeName, LocationSpan location, AST::UiObjectInitializer *initializer = 0); - Object *defineObjectBinding_helper(AST::UiQualifiedId *propertyName, + Object *defineObjectBinding_helper(AST::UiQualifiedId *propertyName, bool onAssignment, const QString &objectType, AST::SourceLocation typeLocation, LocationSpan location, @@ -243,6 +243,7 @@ QString ProcessAST::asString(AST::UiQualifiedId *node) const Object * ProcessAST::defineObjectBinding_helper(AST::UiQualifiedId *propertyName, + bool onAssignment, const QString &objectType, AST::SourceLocation typeLocation, LocationSpan location, @@ -254,10 +255,19 @@ ProcessAST::defineObjectBinding_helper(AST::UiQualifiedId *propertyName, (lastTypeDot >= 0 && objectType.at(lastTypeDot+1).isUpper())); int propertyCount = 0; - for (; propertyName; propertyName = propertyName->next){ + for (AST::UiQualifiedId *name = propertyName; name; name = name->next){ ++propertyCount; - _stateStack.pushProperty(propertyName->name->asString(), - this->location(propertyName)); + _stateStack.pushProperty(name->name->asString(), + this->location(name)); + } + + if (!onAssignment && propertyCount && currentProperty() && currentProperty()->values.count()) { + QDeclarativeError error; + error.setDescription(QCoreApplication::translate("QDeclarativeParser","Property value set multiple times")); + error.setLine(this->location(propertyName).start.line); + error.setColumn(this->location(propertyName).start.column); + _parser->_errors << error; + return 0; } if (!isType) { @@ -327,7 +337,10 @@ ProcessAST::defineObjectBinding_helper(AST::UiQualifiedId *propertyName, Value *v = new Value; v->object = obj; v->location = obj->location; - prop->addValue(v); + if (onAssignment) + prop->addOnValue(v); + else + prop->addValue(v); while (propertyCount--) _stateStack.pop(); @@ -363,7 +376,7 @@ ProcessAST::defineObjectBinding_helper(AST::UiQualifiedId *propertyName, } } -Object *ProcessAST::defineObjectBinding(AST::UiQualifiedId *qualifiedId, +Object *ProcessAST::defineObjectBinding(AST::UiQualifiedId *qualifiedId, bool onAssignment, AST::UiQualifiedId *objectTypeName, LocationSpan location, AST::UiObjectInitializer *initializer) @@ -395,7 +408,7 @@ Object *ProcessAST::defineObjectBinding(AST::UiQualifiedId *qualifiedId, } - return defineObjectBinding_helper(qualifiedId, objectType, typeLocation, location, initializer); + return defineObjectBinding_helper(qualifiedId, onAssignment, objectType, typeLocation, location, initializer); } LocationSpan ProcessAST::location(AST::UiQualifiedId *id) @@ -623,7 +636,7 @@ bool ProcessAST::visit(AST::UiObjectDefinition *node) LocationSpan l = location(node->firstSourceLocation(), node->lastSourceLocation()); - defineObjectBinding(/*propertyName = */ 0, + defineObjectBinding(/*propertyName = */ 0, false, node->qualifiedTypeNameId, l, node->initializer); @@ -638,7 +651,7 @@ bool ProcessAST::visit(AST::UiObjectBinding *node) LocationSpan l = location(node->qualifiedTypeNameId->identifierToken, node->initializer->rbraceToken); - defineObjectBinding(node->qualifiedId, + defineObjectBinding(node->qualifiedId, node->hasOnToken, node->qualifiedTypeNameId, l, node->initializer); @@ -674,14 +687,23 @@ bool ProcessAST::visit(AST::UiScriptBinding *node) { int propertyCount = 0; AST::UiQualifiedId *propertyName = node->qualifiedId; - for (; propertyName; propertyName = propertyName->next){ + for (AST::UiQualifiedId *name = propertyName; name; name = name->next){ ++propertyCount; - _stateStack.pushProperty(propertyName->name->asString(), - location(propertyName)); + _stateStack.pushProperty(name->name->asString(), + location(name)); } Property *prop = currentProperty(); + if (prop->values.count()) { + QDeclarativeError error; + error.setDescription(QCoreApplication::translate("QDeclarativeParser","Property value set multiple times")); + error.setLine(this->location(propertyName).start.line); + error.setColumn(this->location(propertyName).start.column); + _parser->_errors << error; + return 0; + } + QDeclarativeParser::Variant primitive; if (AST::ExpressionStatement *stmt = AST::cast<AST::ExpressionStatement *>(node->statement)) { @@ -724,16 +746,26 @@ bool ProcessAST::visit(AST::UiArrayBinding *node) { int propertyCount = 0; AST::UiQualifiedId *propertyName = node->qualifiedId; - for (; propertyName; propertyName = propertyName->next){ + for (AST::UiQualifiedId *name = propertyName; name; name = name->next){ ++propertyCount; - _stateStack.pushProperty(propertyName->name->asString(), - location(propertyName)); + _stateStack.pushProperty(name->name->asString(), + location(name)); + } + + Property* prop = currentProperty(); + + if (prop->values.count()) { + QDeclarativeError error; + error.setDescription(QCoreApplication::translate("QDeclarativeParser","Property value set multiple times")); + error.setLine(this->location(propertyName).start.line); + error.setColumn(this->location(propertyName).start.column); + _parser->_errors << error; + return 0; } accept(node->members); // For the DOM, store the position of the T_LBRACKET upto the T_RBRACKET as the range: - Property* prop = currentProperty(); prop->listValueRange.offset = node->lbracketToken.offset; prop->listValueRange.length = node->rbracketToken.offset + node->rbracketToken.length - node->lbracketToken.offset; diff --git a/src/declarative/qml/qdeclarativeworkerscript.cpp b/src/declarative/qml/qdeclarativeworkerscript.cpp index 03151e4..c1d090e 100644 --- a/src/declarative/qml/qdeclarativeworkerscript.cpp +++ b/src/declarative/qml/qdeclarativeworkerscript.cpp @@ -841,6 +841,41 @@ bool QDeclarativeWorkerListModelAgent::event(QEvent *e) return QObject::event(e); } +/*! + \qmlclass WorkerListModel QDeclarativeWorkerListModel + \brief The WorkerListModel element provides a threaded list model. + + Use WorkerListModel together with WorkerScript to define a list model + that is controlled by a separate thread. This is useful if list modification + operations are synchronous and take some time: using WorkerListModel + moves these operations to a different thread and avoids blocking of the + main GUI thread. + + The thread that creates the WorkerListModel can modify the model for any + initial set-up requirements. However, once the model has been modified by + the associated WorkerScript, the model can only be modified by that worker + script and becomes read-only to all other threads. + + Here is an example application that uses WorkerScript to append the + current time to a WorkerListModel: + + \snippet examples/declarative/workerlistmodel/timedisplay.qml 0 + + The included file, \tt dataloader.js, looks like this: + + \snippet examples/declarative/workerlistmodel/dataloader.js 0 + + The application's \tt Timer object periodically sends a message to the + worker script by calling \tt WorkerScript::sendMessage(). When this message + is received, \tt WorkerScript.onMessage() is invoked in + \tt dataloader.js, which appends the current time to the worker list + model. + + Note that unlike ListModel, WorkerListModel does not have \tt move() and + \tt setProperty() methods. + + \sa WorkerScript, ListModel +*/ QDeclarativeWorkerListModel::QDeclarativeWorkerListModel(QObject *parent) : QListModelInterface(parent), m_agent(0) { @@ -854,6 +889,14 @@ QDeclarativeWorkerListModel::~QDeclarativeWorkerListModel() } } +/*! + \qmlmethod WorkerListModel::clear() + + Deletes all content from the model. The properties are cleared such that + different properties may be set on subsequent additions. + + \sa append() remove() +*/ void QDeclarativeWorkerListModel::clear() { if (m_agent) { @@ -869,6 +912,13 @@ void QDeclarativeWorkerListModel::clear() } } +/*! + \qmlmethod WorkerListModel::remove(int index) + + Deletes the content at \a index from the model. + + \sa clear() +*/ void QDeclarativeWorkerListModel::remove(int index) { if (m_agent) { @@ -884,6 +934,18 @@ void QDeclarativeWorkerListModel::remove(int index) emit countChanged(); } +/*! + \qmlmethod WorkerListModel::append(jsobject dict) + + Adds a new item to the end of the list model, with the + values in \a dict. + + \code + FruitModel.append({"cost": 5.95, "name":"Pizza"}) + \endcode + + \sa set() remove() +*/ void QDeclarativeWorkerListModel::append(const QScriptValue &value) { if (m_agent) { @@ -914,6 +976,21 @@ void QDeclarativeWorkerListModel::append(const QScriptValue &value) emit countChanged(); } +/*! + \qmlmethod WorkerListModel::insert(int index, jsobject dict) + + Adds a new item to the list model at position \a index, with the + values in \a dict. + + \code + FruitModel.insert(2, {"cost": 5.95, "name":"Pizza"}) + \endcode + + The \a index must be to an existing item in the list, or one past + the end of the list (equivalent to append). + + \sa set() append() +*/ void QDeclarativeWorkerListModel::insert(int index, const QScriptValue &value) { if (m_agent) { @@ -946,6 +1023,30 @@ void QDeclarativeWorkerListModel::insert(int index, const QScriptValue &value) emit countChanged(); } +/*! + \qmlmethod object ListModel::get(int index) + + Returns the item at \a index in the list model. + + \code + FruitModel.append({"cost": 5.95, "name":"Jackfruit"}) + FruitModel.get(0).cost + \endcode + + The \a index must be an element in the list. + + Note that properties of the returned object that are themselves objects + will also be models, and this get() method is used to access elements: + + \code + FruitModel.append(..., "attributes": + [{"name":"spikes","value":"7mm"}, + {"name":"color","value":"green"}]); + FruitModel.get(0).attributes.get(1).value; // == "green" + \endcode + + \sa append() +*/ QScriptValue QDeclarativeWorkerListModel::get(int index) const { QDeclarativeEngine *engine = qmlEngine(this); @@ -962,6 +1063,21 @@ QScriptValue QDeclarativeWorkerListModel::get(int index) const return rv; } +/*! + \qmlmethod WorkerListModel::set(int index, jsobject dict) + + Changes the item at \a index in the list model with the + values in \a dict. Properties not appearing in \a valuemap + are left unchanged. + + \code + FruitModel.set(3, {"cost": 5.95, "name":"Pizza"}) + \endcode + + The \a index must be an element in the list. + + \sa append() +*/ void QDeclarativeWorkerListModel::set(int index, const QScriptValue &value) { if (m_agent) { @@ -995,6 +1111,22 @@ void QDeclarativeWorkerListModel::set(int index, const QScriptValue &value) } } +/*! + \qmlmethod WorkerListModel::sync() + + Writes any unsaved changes to the list model. This must be called after + changes have been made to the list model in the worker script. + + Note that this method can only be called from the associated worker script. +*/ +void QDeclarativeWorkerListModel::sync() +{ + // This is really a dummy method to make it look like sync() exists in + // WorkerListModel (and not QDeclarativeWorkerListModelAgent) and to let + // us document sync(). + qmlInfo(this) << "sync() can only be called from a WorkerScript"; +} + QDeclarativeWorkerListModelAgent *QDeclarativeWorkerListModel::agent() { if (!m_agent) @@ -1013,6 +1145,10 @@ QString QDeclarativeWorkerListModel::toString(int role) const return m_roles.value(role); } +/*! + \qmlproperty int ListModel::count + The number of data entries in the model. +*/ int QDeclarativeWorkerListModel::count() const { return m_values.count(); @@ -1038,4 +1174,3 @@ QT_END_NAMESPACE #include "qdeclarativeworkerscript.moc" - diff --git a/src/declarative/qml/qdeclarativeworkerscript_p.h b/src/declarative/qml/qdeclarativeworkerscript_p.h index 8ebd2c1..912eac9 100644 --- a/src/declarative/qml/qdeclarativeworkerscript_p.h +++ b/src/declarative/qml/qdeclarativeworkerscript_p.h @@ -61,8 +61,12 @@ #include <QtScript/qscriptvalue.h> #include <QtCore/qurl.h> +QT_BEGIN_HEADER + QT_BEGIN_NAMESPACE +QT_MODULE(Declarative) + class QDeclarativeWorkerScript; class QDeclarativeWorkerScriptEnginePrivate; class QDeclarativeWorkerScriptEngine : public QThread @@ -84,7 +88,7 @@ private: QDeclarativeWorkerScriptEnginePrivate *d; }; -class QDeclarativeWorkerScript : public QObject, public QDeclarativeParserStatus +class Q_DECLARATIVE_EXPORT QDeclarativeWorkerScript : public QObject, public QDeclarativeParserStatus { Q_OBJECT Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) @@ -115,7 +119,7 @@ private: }; class QDeclarativeWorkerListModelAgent; -class QDeclarativeWorkerListModel : public QListModelInterface +class Q_DECLARATIVE_EXPORT QDeclarativeWorkerListModel : public QListModelInterface { Q_OBJECT Q_PROPERTY(int count READ count NOTIFY countChanged) @@ -130,6 +134,7 @@ public: Q_INVOKABLE void insert(int index, const QScriptValue&); Q_INVOKABLE QScriptValue get(int index) const; Q_INVOKABLE void set(int index, const QScriptValue &); + Q_INVOKABLE void sync(); QDeclarativeWorkerListModelAgent *agent(); @@ -157,4 +162,6 @@ QT_END_NAMESPACE QML_DECLARE_TYPE(QDeclarativeWorkerScript); QML_DECLARE_TYPE(QDeclarativeWorkerListModel); +QT_END_HEADER + #endif // QDECLARATIVEWORKERSCRIPT_P_H diff --git a/src/declarative/util/qdeclarativeanimation.cpp b/src/declarative/util/qdeclarativeanimation.cpp index 10230d3..ebf1a20 100644 --- a/src/declarative/util/qdeclarativeanimation.cpp +++ b/src/declarative/util/qdeclarativeanimation.cpp @@ -1573,7 +1573,8 @@ QDeclarativeSequentialAnimation::QDeclarativeSequentialAnimation(QObject *parent QDeclarativeAnimationGroup(parent) { Q_D(QDeclarativeAnimationGroup); - d->ag = new QSequentialAnimationGroup(this); + d->ag = new QSequentialAnimationGroup; + QDeclarative_setParent_noEvent(d->ag, this); } QDeclarativeSequentialAnimation::~QDeclarativeSequentialAnimation() @@ -1638,7 +1639,8 @@ QDeclarativeParallelAnimation::QDeclarativeParallelAnimation(QObject *parent) : QDeclarativeAnimationGroup(parent) { Q_D(QDeclarativeAnimationGroup); - d->ag = new QParallelAnimationGroup(this); + d->ag = new QParallelAnimationGroup; + QDeclarative_setParent_noEvent(d->ag, this); } QDeclarativeParallelAnimation::~QDeclarativeParallelAnimation() @@ -1797,7 +1799,7 @@ QDeclarativePropertyAnimation::~QDeclarativePropertyAnimation() void QDeclarativePropertyAnimationPrivate::init() { Q_Q(QDeclarativePropertyAnimation); - va = new QDeclarativeTimeLineValueAnimator; + va = new QDeclarativeBulkValueAnimator; QDeclarative_setParent_noEvent(va, q); } @@ -2213,7 +2215,7 @@ QAbstractAnimation *QDeclarativePropertyAnimation::qtAnimation() return d->va; } -struct PropertyUpdater : public QDeclarativeTimeLineValue +struct PropertyUpdater : public QDeclarativeBulkValueUpdater { QDeclarativeStateActions actions; int interpolatorType; //for Number/ColorAnimation @@ -2231,7 +2233,6 @@ struct PropertyUpdater : public QDeclarativeTimeLineValue wasDeleted = &deleted; if (reverse) //QVariantAnimation sends us 1->0 when reversed, but we are expecting 0->1 v = 1 - v; - QDeclarativeTimeLineValue::setValue(v); for (int ii = 0; ii < actions.count(); ++ii) { QDeclarativeAction &action = actions[ii]; diff --git a/src/declarative/util/qdeclarativeanimation_p_p.h b/src/declarative/util/qdeclarativeanimation_p_p.h index e582066..ae82a90 100644 --- a/src/declarative/util/qdeclarativeanimation_p_p.h +++ b/src/declarative/util/qdeclarativeanimation_p_p.h @@ -149,14 +149,21 @@ private: bool running; }; -//animates QDeclarativeTimeLineValue (assumes start and end values will be reals or compatible) -class QDeclarativeTimeLineValueAnimator : public QVariantAnimation +class QDeclarativeBulkValueUpdater +{ +public: + virtual ~QDeclarativeBulkValueUpdater() {} + virtual void setValue(qreal value) = 0; +}; + +//animates QDeclarativeBulkValueUpdater (assumes start and end values will be reals or compatible) +class QDeclarativeBulkValueAnimator : public QVariantAnimation { Q_OBJECT public: - QDeclarativeTimeLineValueAnimator(QObject *parent = 0) : QVariantAnimation(parent), animValue(0), fromSourced(0), policy(KeepWhenStopped) {} - ~QDeclarativeTimeLineValueAnimator() { if (policy == DeleteWhenStopped) { delete animValue; animValue = 0; } } - void setAnimValue(QDeclarativeTimeLineValue *value, DeletionPolicy p) + QDeclarativeBulkValueAnimator(QObject *parent = 0) : QVariantAnimation(parent), animValue(0), fromSourced(0), policy(KeepWhenStopped) {} + ~QDeclarativeBulkValueAnimator() { if (policy == DeleteWhenStopped) { delete animValue; animValue = 0; } } + void setAnimValue(QDeclarativeBulkValueUpdater *value, DeletionPolicy p) { if (state() == Running) stop(); @@ -193,7 +200,7 @@ protected: } private: - QDeclarativeTimeLineValue *animValue; + QDeclarativeBulkValueUpdater *animValue; bool *fromSourced; DeletionPolicy policy; }; @@ -352,7 +359,7 @@ public: int interpolatorType; QVariantAnimation::Interpolator interpolator; - QDeclarativeTimeLineValueAnimator *va; + QDeclarativeBulkValueAnimator *va; static QVariant interpolateVariant(const QVariant &from, const QVariant &to, qreal progress); static void convertVariant(QVariant &variant, int type); diff --git a/src/declarative/util/qdeclarativefontloader.cpp b/src/declarative/util/qdeclarativefontloader.cpp index 4d12ae1..8f5f537 100644 --- a/src/declarative/util/qdeclarativefontloader.cpp +++ b/src/declarative/util/qdeclarativefontloader.cpp @@ -189,6 +189,16 @@ void QDeclarativeFontLoader::setName(const QString &name) \o Loading - the font is currently being loaded \o Error - an error occurred while loading the font \endlist + + Note that a change in the status property does not cause anything to happen + (although it reflects what has happened to the font loader internally). If you wish + to react to the change in status you need to do it yourself, for example in one + of the following ways: + \list + \o Create a state, so that a state change occurs, e.g. State{name: 'loaded'; when: loader.status = FontLoader.Ready;} + \o Do something inside the onStatusChanged signal handler, e.g. FontLoader{id: loader; onStatusChanged: if(loader.status == FontLoader.Ready) console.log('Loaded');} + \o Bind to the status variable somewhere, e.g. Text{text: if(loader.status!=FontLoader.Ready){'Not Loaded';}else{'Loaded';}} + \endlist */ QDeclarativeFontLoader::Status QDeclarativeFontLoader::status() const { diff --git a/src/declarative/util/qdeclarativeview.cpp b/src/declarative/util/qdeclarativeview.cpp index 6fe5bf3..f08e634 100644 --- a/src/declarative/util/qdeclarativeview.cpp +++ b/src/declarative/util/qdeclarativeview.cpp @@ -51,6 +51,7 @@ #include <qdeclarativedebug_p.h> #include <qdeclarativedebugservice_p.h> #include <qdeclarativeglobal_p.h> +#include <qdeclarativeguard_p.h> #include <qscriptvalueiterator.h> #include <qdebug.h> @@ -136,8 +137,8 @@ public: QDeclarativeView *q; - QGuard<QGraphicsObject> root; - QGuard<QDeclarativeItem> qmlRoot; + QDeclarativeGuard<QGraphicsObject> root; + QDeclarativeGuard<QDeclarativeItem> qmlRoot; QUrl source; @@ -282,13 +283,14 @@ QDeclarativeView::~QDeclarativeView() /*! Sets the source to the \a url, loads the QML component and instantiates it. + + Calling this methods multiple times with the same url will result + in the QML being reloaded. */ void QDeclarativeView::setSource(const QUrl& url) { - if (url != d->source) { - d->source = url; - d->execute(); - } + d->source = url; + d->execute(); } /*! diff --git a/src/declarative/util/qdeclarativexmllistmodel.cpp b/src/declarative/util/qdeclarativexmllistmodel.cpp index 162a669..d260ada 100644 --- a/src/declarative/util/qdeclarativexmllistmodel.cpp +++ b/src/declarative/util/qdeclarativexmllistmodel.cpp @@ -647,11 +647,21 @@ void QDeclarativeXmlListModel::setNamespaceDeclarations(const QString &declarati This property holds the status of data source loading. It can be one of: \list \o Null - no data source has been set - \o Ready - nthe data source has been loaded + \o Ready - the data source has been loaded \o Loading - the data source is currently being loaded \o Error - an error occurred while loading the data source \endlist + Note that a change in the status property does not cause anything to happen + (although it reflects what has happened to the XmlListModel internally). If you wish + to react to the change in status you need to do it yourself, for example in one + of the following ways: + \list + \o Create a state, so that a state change occurs, e.g. State{name: 'loaded'; when: xmlListModel.status = XmlListModel.Ready;} + \o Do something inside the onStatusChanged signal handler, e.g. XmlListModel{id: xmlListModel; onStatusChanged: if(xmlListModel.status == XmlListModel.Ready) console.log('Loaded');} + \o Bind to the status variable somewhere, e.g. Text{text: if(xmlListModel.status!=XmlListModel.Ready){'Not Loaded';}else{'Loaded';}} + \endlist + \sa progress */ |