diff options
author | David Boddie <dboddie@trolltech.com> | 2010-08-27 16:32:49 (GMT) |
---|---|---|
committer | David Boddie <dboddie@trolltech.com> | 2010-08-27 16:32:49 (GMT) |
commit | 3ca305cf25033477b73121aa6622f8c9115285ec (patch) | |
tree | 59edd09384ffca0b5e68a777a032a9aa3f65a9df /src/declarative | |
parent | 2cac8ca88c9b5b2f9d3040b1543d88ecee52da99 (diff) | |
parent | d3b898e973662707f9644b4fe5f8d18849929723 (diff) | |
download | Qt-3ca305cf25033477b73121aa6622f8c9115285ec.zip Qt-3ca305cf25033477b73121aa6622f8c9115285ec.tar.gz Qt-3ca305cf25033477b73121aa6622f8c9115285ec.tar.bz2 |
Merge branch '4.7' into qmldocs
Diffstat (limited to 'src/declarative')
34 files changed, 255 insertions, 116 deletions
diff --git a/src/declarative/debugger/qdeclarativedebug.cpp b/src/declarative/debugger/qdeclarativedebug.cpp index 154df51..1ffe441 100644 --- a/src/declarative/debugger/qdeclarativedebug.cpp +++ b/src/declarative/debugger/qdeclarativedebug.cpp @@ -340,6 +340,8 @@ void QDeclarativeEngineDebugPrivate::message(const QByteArray &data) if (!watch) return; emit watch->valueChanged(name, value); + } else if (type == "OBJECT_CREATED") { + emit q_func()->newObjects(); } } diff --git a/src/declarative/debugger/qdeclarativedebug_p.h b/src/declarative/debugger/qdeclarativedebug_p.h index 2e79c5d..f0fc488 100644 --- a/src/declarative/debugger/qdeclarativedebug_p.h +++ b/src/declarative/debugger/qdeclarativedebug_p.h @@ -99,6 +99,9 @@ public: bool resetBindingForObject(int objectDebugId, const QString &propertyName); bool setMethodBody(int objectDebugId, const QString &methodName, const QString &methodBody); +Q_SIGNALS: + void newObjects(); + private: Q_DECLARE_PRIVATE(QDeclarativeEngineDebug) }; diff --git a/src/declarative/graphicsitems/qdeclarativeflickable.cpp b/src/declarative/graphicsitems/qdeclarativeflickable.cpp index 7fee44e..a710190 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable.cpp +++ b/src/declarative/graphicsitems/qdeclarativeflickable.cpp @@ -54,7 +54,7 @@ QT_BEGIN_NAMESPACE static const int FlickThreshold = 20; // Really slow flicks can be annoying. -static const int minimumFlickVelocity = 200; +static const int MinimumFlickVelocity = 75; QDeclarativeFlickableVisibleArea::QDeclarativeFlickableVisibleArea(QDeclarativeFlickable *parent) : QObject(parent), flickable(parent), m_xPosition(0.), m_widthRatio(0.) @@ -653,6 +653,8 @@ void QDeclarativeFlickablePrivate::handleMousePressEvent(QGraphicsSceneMouseEven timeline.clear(); hData.velocity = 0; vData.velocity = 0; + hData.dragStartOffset = 0; + vData.dragStartOffset = 0; lastPos = QPoint(); QDeclarativeItemPrivate::start(lastPosTime); pressPos = event->pos(); @@ -675,7 +677,9 @@ void QDeclarativeFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent if (q->yflick()) { int dy = int(event->pos().y() - pressPos.y()); if (qAbs(dy) > QApplication::startDragDistance() || QDeclarativeItemPrivate::elapsed(pressTime) > 200) { - qreal newY = dy + vData.pressPos; + if (!vMoved) + vData.dragStartOffset = dy; + qreal newY = dy + vData.pressPos - vData.dragStartOffset; const qreal minY = q->minYExtent(); const qreal maxY = q->maxYExtent(); if (newY > minY) @@ -705,7 +709,9 @@ void QDeclarativeFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent if (q->xflick()) { int dx = int(event->pos().x() - pressPos.x()); if (qAbs(dx) > QApplication::startDragDistance() || QDeclarativeItemPrivate::elapsed(pressTime) > 200) { - qreal newX = dx + hData.pressPos; + if (!hMoved) + hData.dragStartOffset = dx; + qreal newX = dx + hData.pressPos - hData.dragStartOffset; const qreal minX = q->minXExtent(); const qreal maxX = q->maxXExtent(); if (newX > minX) @@ -779,23 +785,15 @@ void QDeclarativeFlickablePrivate::handleMouseReleaseEvent(QGraphicsSceneMouseEv } vTime = timeline.time(); - if (qAbs(vData.velocity) > 10 && qAbs(event->pos().y() - pressPos.y()) > FlickThreshold) { - qreal velocity = vData.velocity; - if (qAbs(velocity) < minimumFlickVelocity) // Minimum velocity to avoid annoyingly slow flicks. - velocity = velocity < 0 ? -minimumFlickVelocity : minimumFlickVelocity; - flickY(velocity); - } else { + if (qAbs(vData.velocity) > MinimumFlickVelocity && qAbs(event->pos().y() - pressPos.y()) > FlickThreshold) + flickY(vData.velocity); + else fixupY(); - } - if (qAbs(hData.velocity) > 10 && qAbs(event->pos().x() - pressPos.x()) > FlickThreshold) { - qreal velocity = hData.velocity; - if (qAbs(velocity) < minimumFlickVelocity) // Minimum velocity to avoid annoyingly slow flicks. - velocity = velocity < 0 ? -minimumFlickVelocity : minimumFlickVelocity; - flickX(velocity); - } else { + if (qAbs(hData.velocity) > MinimumFlickVelocity && qAbs(event->pos().x() - pressPos.x()) > FlickThreshold) + flickX(hData.velocity); + else fixupX(); - } lastPosTime.invalidate(); diff --git a/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h b/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h index b919e1b..c398faa 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h @@ -96,6 +96,7 @@ public: QDeclarativeTimeLineValueProxy<QDeclarativeFlickablePrivate> move; qreal viewSize; qreal pressPos; + qreal dragStartOffset; qreal velocity; qreal flickTarget; QDeclarativeFlickablePrivate::Velocity smoothVelocity; diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index d67e69a..a0faf14 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -64,7 +64,7 @@ public: FxGridItem(QDeclarativeItem *i, QDeclarativeGridView *v) : item(i), view(v) { attached = static_cast<QDeclarativeGridViewAttached*>(qmlAttachedPropertiesObject<QDeclarativeGridView>(item)); if (attached) - attached->m_view = view; + attached->setView(view); } ~FxGridItem() {} @@ -2212,7 +2212,7 @@ void QDeclarativeGridView::trackedPositionChanged() if (trackedPos < d->startPosition() + d->highlightRangeStart) { pos = d->startPosition(); } else if (d->trackedItem->endRowPos() > d->endPosition() - d->size() + d->highlightRangeEnd) { - pos = d->endPosition() - d->size(); + pos = d->endPosition() - d->size() + 1; if (pos < d->startPosition()) pos = d->startPosition(); } else { @@ -2226,14 +2226,14 @@ void QDeclarativeGridView::trackedPositionChanged() } else { if (trackedPos < viewPos && d->currentItem->rowPos() < viewPos) { pos = d->currentItem->rowPos() < trackedPos ? trackedPos : d->currentItem->rowPos(); - } else if (d->trackedItem->endRowPos() > viewPos + d->size() - && d->currentItem->endRowPos() > viewPos + d->size()) { - if (d->trackedItem->endRowPos() < d->currentItem->endRowPos()) { - pos = d->trackedItem->endRowPos() - d->size(); + } else if (d->trackedItem->endRowPos() >= viewPos + d->size() + && d->currentItem->endRowPos() >= viewPos + d->size()) { + if (d->trackedItem->endRowPos() <= d->currentItem->endRowPos()) { + pos = d->trackedItem->endRowPos() - d->size() + 1; if (d->rowSize() > d->size()) pos = trackedPos; } else { - pos = d->currentItem->endRowPos() - d->size(); + pos = d->currentItem->endRowPos() - d->size() + 1; if (d->rowSize() > d->size()) pos = d->currentItem->rowPos(); } diff --git a/src/declarative/graphicsitems/qdeclarativegridview_p.h b/src/declarative/graphicsitems/qdeclarativegridview_p.h index d6bbaf3..ee632b1 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview_p.h +++ b/src/declarative/graphicsitems/qdeclarativegridview_p.h @@ -43,6 +43,7 @@ #define QDECLARATIVEGRIDVIEW_H #include "private/qdeclarativeflickable_p.h" +#include "private/qdeclarativeguard_p.h" QT_BEGIN_HEADER @@ -220,8 +221,14 @@ public: : QObject(parent), m_view(0), m_isCurrent(false), m_delayRemove(false) {} ~QDeclarativeGridViewAttached() {} - Q_PROPERTY(QDeclarativeGridView *view READ view CONSTANT) + Q_PROPERTY(QDeclarativeGridView *view READ view NOTIFY viewChanged) QDeclarativeGridView *view() { return m_view; } + void setView(QDeclarativeGridView *view) { + if (view != m_view) { + m_view = view; + emit viewChanged(); + } + } Q_PROPERTY(bool isCurrentItem READ isCurrentItem NOTIFY currentItemChanged) bool isCurrentItem() const { return m_isCurrent; } @@ -249,9 +256,10 @@ Q_SIGNALS: void delayRemoveChanged(); void add(); void remove(); + void viewChanged(); public: - QDeclarativeGridView *m_view; + QDeclarativeGuard<QDeclarativeGridView> m_view; bool m_isCurrent : 1; bool m_delayRemove : 1; }; diff --git a/src/declarative/graphicsitems/qdeclarativeimage.cpp b/src/declarative/graphicsitems/qdeclarativeimage.cpp index eb8b00e..405a74a 100644 --- a/src/declarative/graphicsitems/qdeclarativeimage.cpp +++ b/src/declarative/graphicsitems/qdeclarativeimage.cpp @@ -343,7 +343,7 @@ qreal QDeclarativeImage::paintedHeight() const Unlike the \l {Item::}{width} and \l {Item::}{height} properties, which scale the painting of the image, this property sets the actual number of pixels stored for the loaded image so that large images do not use more - memory than necessary. For example, this ensures the image is memory is no + memory than necessary. For example, this ensures the image in memory is no larger than 1024x1024 pixels, regardless of the Image's \l {Item::}{width} and \l {Item::}{height} values: diff --git a/src/declarative/graphicsitems/qdeclarativeimagebase.cpp b/src/declarative/graphicsitems/qdeclarativeimagebase.cpp index ba40443..d6b935b 100644 --- a/src/declarative/graphicsitems/qdeclarativeimagebase.cpp +++ b/src/declarative/graphicsitems/qdeclarativeimagebase.cpp @@ -147,10 +147,15 @@ void QDeclarativeImageBase::load() setImplicitWidth(0); setImplicitHeight(0); emit statusChanged(d->status); + d->sourcesize.setWidth(0); + d->sourcesize.setHeight(0); + emit sourceSizeChanged(); pixmapChange(); update(); } else { + d->status = Loading; + emit statusChanged(d->status); d->pix.load(qmlEngine(this), d->url, d->sourcesize, d->async); @@ -169,53 +174,34 @@ void QDeclarativeImageBase::load() d->pix.connectDownloadProgress(this, thisRequestProgress); } else { - QSize impsize = d->pix.implicitSize(); - setImplicitWidth(impsize.width()); - setImplicitHeight(impsize.height()); - - if (d->pix.isReady()) { - d->status = Ready; - - if (!d->sourcesize.isValid()) - emit sourceSizeChanged(); - - } else { - d->status = Error; - qmlInfo(this) << d->pix.error(); - } - d->progress = 1.0; - emit statusChanged(d->status); - emit progressChanged(d->progress); - pixmapChange(); - update(); + requestFinished(); } - } - - emit statusChanged(d->status); } void QDeclarativeImageBase::requestFinished() { Q_D(QDeclarativeImageBase); - QSize impsize = d->pix.implicitSize(); - if (d->pix.isError()) { d->status = Error; qmlInfo(this) << d->pix.error(); + } else { + d->status = Ready; } + emit statusChanged(d->status); - setImplicitWidth(impsize.width()); - setImplicitHeight(impsize.height()); + setImplicitWidth(d->pix.width()); + setImplicitHeight(d->pix.height()); - if (d->status == Loading) - d->status = Ready; d->progress = 1.0; - emit statusChanged(d->status); - emit progressChanged(1.0); - if (!d->sourcesize.isValid()) + emit progressChanged(d->progress); + + if (d->sourcesize.width() != d->pix.width() || d->sourcesize.height() != d->pix.height()) { + d->sourcesize.setWidth(d->pix.width()); + d->sourcesize.setHeight(d->pix.height()); emit sourceSizeChanged(); + } pixmapChange(); update(); } diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index ec1b6cf..d3d46f7 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -96,7 +96,7 @@ public: FxListItem(QDeclarativeItem *i, QDeclarativeListView *v) : item(i), section(0), view(v) { attached = static_cast<QDeclarativeListViewAttached*>(qmlAttachedPropertiesObject<QDeclarativeListView>(item)); if (attached) - attached->m_view = view; + attached->setView(view); } ~FxListItem() {} qreal position() const { @@ -983,7 +983,7 @@ void QDeclarativeListViewPrivate::updateSections() void QDeclarativeListViewPrivate::updateCurrentSection() { if (!sectionCriteria || visibleItems.isEmpty()) { - currentSection = QString(); + currentSection.clear(); return; } int index = 0; @@ -2652,7 +2652,7 @@ void QDeclarativeListView::trackedPositionChanged() if (trackedPos < d->startPosition() + d->highlightRangeStart) { pos = d->startPosition(); } else if (d->trackedItem->endPosition() > d->endPosition() - d->size() + d->highlightRangeEnd) { - pos = d->endPosition() - d->size(); + pos = d->endPosition() - d->size() + 1; if (pos < d->startPosition()) pos = d->startPosition(); } else { @@ -2666,14 +2666,14 @@ void QDeclarativeListView::trackedPositionChanged() } else { if (trackedPos < viewPos && d->currentItem->position() < viewPos) { pos = d->currentItem->position() < trackedPos ? trackedPos : d->currentItem->position(); - } else if (d->trackedItem->endPosition() > viewPos + d->size() - && d->currentItem->endPosition() > viewPos + d->size()) { - if (d->trackedItem->endPosition() < d->currentItem->endPosition()) { - pos = d->trackedItem->endPosition() - d->size(); - if (d->trackedItem->size() > d->size()) + } else if (d->trackedItem->endPosition() >= viewPos + d->size() + && d->currentItem->endPosition() >= viewPos + d->size()) { + if (d->trackedItem->endPosition() <= d->currentItem->endPosition()) { + pos = d->trackedItem->endPosition() - d->size() + 1; + if (d->trackedItem->size() > d->size()) pos = trackedPos; } else { - pos = d->currentItem->endPosition() - d->size(); + pos = d->currentItem->endPosition() - d->size() + 1; if (d->currentItem->size() > d->size()) pos = d->currentItem->position(); } diff --git a/src/declarative/graphicsitems/qdeclarativelistview_p.h b/src/declarative/graphicsitems/qdeclarativelistview_p.h index b264861..8fbff49 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview_p.h +++ b/src/declarative/graphicsitems/qdeclarativelistview_p.h @@ -43,6 +43,7 @@ #define QDECLARATIVELISTVIEW_H #include "private/qdeclarativeflickable_p.h" +#include "private/qdeclarativeguard_p.h" QT_BEGIN_HEADER @@ -268,8 +269,14 @@ public: : QObject(parent), m_view(0), m_isCurrent(false), m_delayRemove(false) {} ~QDeclarativeListViewAttached() {} - Q_PROPERTY(QDeclarativeListView *view READ view CONSTANT) + Q_PROPERTY(QDeclarativeListView *view READ view NOTIFY viewChanged) QDeclarativeListView *view() { return m_view; } + void setView(QDeclarativeListView *view) { + if (view != m_view) { + m_view = view; + emit viewChanged(); + } + } Q_PROPERTY(bool isCurrentItem READ isCurrentItem NOTIFY currentItemChanged) bool isCurrentItem() const { return m_isCurrent; } @@ -327,9 +334,10 @@ Q_SIGNALS: void delayRemoveChanged(); void add(); void remove(); + void viewChanged(); public: - QDeclarativeListView *m_view; + QDeclarativeGuard<QDeclarativeListView> m_view; mutable QString m_section; QString m_prevSection; QString m_nextSection; diff --git a/src/declarative/graphicsitems/qdeclarativepath.cpp b/src/declarative/graphicsitems/qdeclarativepath.cpp index 62e03e7..0c069ce 100644 --- a/src/declarative/graphicsitems/qdeclarativepath.cpp +++ b/src/declarative/graphicsitems/qdeclarativepath.cpp @@ -893,6 +893,7 @@ void QDeclarativePathPercent::setValue(qreal value) { if (_value != value) { _value = value; + emit valueChanged(); emit changed(); } } diff --git a/src/declarative/graphicsitems/qdeclarativepath_p.h b/src/declarative/graphicsitems/qdeclarativepath_p.h index 195057c..21e1b24 100644 --- a/src/declarative/graphicsitems/qdeclarativepath_p.h +++ b/src/declarative/graphicsitems/qdeclarativepath_p.h @@ -190,13 +190,16 @@ private: class Q_AUTOTEST_EXPORT QDeclarativePathPercent : public QDeclarativePathElement { Q_OBJECT - Q_PROPERTY(qreal value READ value WRITE setValue) + Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged) public: QDeclarativePathPercent(QObject *parent=0) : QDeclarativePathElement(parent) {} qreal value() const; void setValue(qreal value); +signals: + void valueChanged(); + private: qreal _value; }; diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp index 51d6e8f..b8d5ce6 100644 --- a/src/declarative/graphicsitems/qdeclarativetext.cpp +++ b/src/declarative/graphicsitems/qdeclarativetext.cpp @@ -1046,10 +1046,10 @@ QPixmap QDeclarativeTextPrivate::richTextImage(bool drawStyle) QAbstractTextDocumentLayout::PaintContext context; + QTextOption oldOption(doc->defaultTextOption()); if (drawStyle) { context.palette.setColor(QPalette::Text, styleColor); - // ### Do we really want this? - QTextOption colorOption; + QTextOption colorOption(doc->defaultTextOption()); colorOption.setFlags(QTextOption::SuppressColors); doc->setDefaultTextOption(colorOption); } else { @@ -1057,7 +1057,7 @@ QPixmap QDeclarativeTextPrivate::richTextImage(bool drawStyle) } doc->documentLayout()->draw(&p, context); if (drawStyle) - doc->setDefaultTextOption(QTextOption()); + doc->setDefaultTextOption(oldOption); return img; } @@ -1217,7 +1217,7 @@ void QDeclarativeText::mousePressEvent(QGraphicsSceneMouseEvent *event) if (!d->richText || !d->doc || d->doc->documentLayout()->anchorAt(event->pos()).isEmpty()) { event->setAccepted(false); - d->activeLink = QString(); + d->activeLink.clear(); } else { d->activeLink = d->doc->documentLayout()->anchorAt(event->pos()); } diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp index 50a0a33..b4e8bda 100644 --- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp @@ -714,6 +714,7 @@ void QDeclarativeVisualDataModel::setModel(const QVariant &model) QObject::disconnect(d->m_abstractItemModel, SIGNAL(rowsMoved(const QModelIndex&,int,int,const QModelIndex&,int)), this, SLOT(_q_rowsMoved(const QModelIndex&,int,int,const QModelIndex&,int))); QObject::disconnect(d->m_abstractItemModel, SIGNAL(modelReset()), this, SLOT(_q_modelReset())); + QObject::disconnect(d->m_abstractItemModel, SIGNAL(layoutChanged()), this, SLOT(_q_layoutChanged())); d->m_abstractItemModel = 0; } else if (d->m_visualItemModel) { QObject::disconnect(d->m_visualItemModel, SIGNAL(itemsInserted(int,int)), @@ -761,6 +762,7 @@ void QDeclarativeVisualDataModel::setModel(const QVariant &model) QObject::connect(d->m_abstractItemModel, SIGNAL(rowsMoved(const QModelIndex&,int,int,const QModelIndex&,int)), this, SLOT(_q_rowsMoved(const QModelIndex&,int,int,const QModelIndex&,int))); QObject::connect(d->m_abstractItemModel, SIGNAL(modelReset()), this, SLOT(_q_modelReset())); + QObject::connect(d->m_abstractItemModel, SIGNAL(layoutChanged()), this, SLOT(_q_layoutChanged())); d->m_metaDataCacheable = true; return; } @@ -966,7 +968,7 @@ QDeclarativeVisualDataModel::ReleaseFlags QDeclarativeVisualDataModel::release(Q Q_ASSERT(p->declarativeData); QDeclarativeData *d = static_cast<QDeclarativeData*>(p->declarativeData); if (d->ownContext && d->context) - d->context->clearExpressions(); + d->context->clearContext(); if (inPackage) { emit destroyingPackage(qobject_cast<QDeclarativePackage*>(obj)); @@ -1332,6 +1334,12 @@ void QDeclarativeVisualDataModel::_q_dataChanged(const QModelIndex &begin, const _q_itemsChanged(begin.row(), end.row() - begin.row() + 1, d->m_roles); } +void QDeclarativeVisualDataModel::_q_layoutChanged() +{ + Q_D(QDeclarativeVisualDataModel); + _q_itemsChanged(0, count(), d->m_roles); +} + void QDeclarativeVisualDataModel::_q_modelReset() { emit modelReset(); diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel_p.h b/src/declarative/graphicsitems/qdeclarativevisualitemmodel_p.h index 50d2c53..e159786 100644 --- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel_p.h +++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel_p.h @@ -194,6 +194,7 @@ private Q_SLOTS: void _q_rowsRemoved(const QModelIndex &,int,int); void _q_rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int); void _q_dataChanged(const QModelIndex&,const QModelIndex&); + void _q_layoutChanged(); void _q_modelReset(); void _q_createdPackage(int index, QDeclarativePackage *package); void _q_destroyingPackage(QDeclarativePackage *package); diff --git a/src/declarative/qml/parser/qdeclarativejslexer.cpp b/src/declarative/qml/parser/qdeclarativejslexer.cpp index 65a6af2..cd08658 100644 --- a/src/declarative/qml/parser/qdeclarativejslexer.cpp +++ b/src/declarative/qml/parser/qdeclarativejslexer.cpp @@ -120,7 +120,7 @@ Lexer::~Lexer() void Lexer::setCode(const QString &c, int lineno) { - errmsg = QString(); + errmsg.clear(); yylineno = lineno; yycolumn = 1; restrKeyword = false; diff --git a/src/declarative/qml/qdeclarativecomponent.cpp b/src/declarative/qml/qdeclarativecomponent.cpp index 15cef16..d2d1f19 100644 --- a/src/declarative/qml/qdeclarativecomponent.cpp +++ b/src/declarative/qml/qdeclarativecomponent.cpp @@ -54,6 +54,7 @@ #include "private/qdeclarativeglobal_p.h" #include "private/qdeclarativescriptparser_p.h" #include "private/qdeclarativedebugtrace_p.h" +#include "private/qdeclarativeenginedebug_p.h" #include <QStack> #include <QStringList> @@ -765,8 +766,11 @@ QDeclarativeComponentPrivate::beginCreate(QDeclarativeContextData *context, cons QObject *rv = begin(ctxt, ep, cc, start, count, &state, bindings); - if (rv && !context->isInternal && ep->isDebugging) - context->asQDeclarativeContextPrivate()->instances.append(rv); + if (ep->isDebugging && rv) { + if (!context->isInternal) + context->asQDeclarativeContextPrivate()->instances.append(rv); + QDeclarativeEngineDebugServer::instance()->objectCreated(engine, rv); + } return rv; } diff --git a/src/declarative/qml/qdeclarativecompositetypemanager.cpp b/src/declarative/qml/qdeclarativecompositetypemanager.cpp index 26b2a9b..2e77534 100644 --- a/src/declarative/qml/qdeclarativecompositetypemanager.cpp +++ b/src/declarative/qml/qdeclarativecompositetypemanager.cpp @@ -544,7 +544,7 @@ int QDeclarativeCompositeTypeManager::resolveTypes(QDeclarativeCompositeTypeData } - foreach (QDeclarativeScriptParser::Import imp, unit->data.imports()) { + foreach (const QDeclarativeScriptParser::Import &imp, unit->data.imports()) { QDeclarativeDirComponents qmldircomponentsnetwork; if (imp.type == QDeclarativeScriptParser::Import::Script) continue; diff --git a/src/declarative/qml/qdeclarativecontext.cpp b/src/declarative/qml/qdeclarativecontext.cpp index a58dc6c..a3b16d9 100644 --- a/src/declarative/qml/qdeclarativecontext.cpp +++ b/src/declarative/qml/qdeclarativecontext.cpp @@ -533,8 +533,21 @@ void QDeclarativeContextData::invalidate() parent = 0; } -void QDeclarativeContextData::clearExpressions() +void QDeclarativeContextData::clearContext() { + if (engine) { + while (componentAttached) { + QDeclarativeComponentAttached *a = componentAttached; + componentAttached = a->next; + if (componentAttached) componentAttached->prev = &componentAttached; + + a->next = 0; + a->prev = 0; + + emit a->destruction(); + } + } + QDeclarativeAbstractExpression *expression = expressions; while (expression) { QDeclarativeAbstractExpression *nextExpression = expression->m_nextExpression; @@ -555,7 +568,7 @@ void QDeclarativeContextData::destroy() if (engine) invalidate(); - clearExpressions(); + clearContext(); while (contextObjects) { QDeclarativeData *co = contextObjects; diff --git a/src/declarative/qml/qdeclarativecontext_p.h b/src/declarative/qml/qdeclarativecontext_p.h index c5a039a..6c14feb 100644 --- a/src/declarative/qml/qdeclarativecontext_p.h +++ b/src/declarative/qml/qdeclarativecontext_p.h @@ -113,7 +113,7 @@ class Q_AUTOTEST_EXPORT QDeclarativeContextData public: QDeclarativeContextData(); QDeclarativeContextData(QDeclarativeContext *); - void clearExpressions(); + void clearContext(); void destroy(); void invalidate(); diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index cedf9d5..c5a5c18 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -438,8 +438,6 @@ void QDeclarativeEnginePrivate::clear(SimpleList<QDeclarativeParserStatus> &pss) pss.clear(); } -Q_GLOBAL_STATIC(QDeclarativeEngineDebugServer, qmlEngineDebugServer); - void QDeclarativePrivate::qdeclarativeelement_destructor(QObject *o) { QObjectPrivate *p = QObjectPrivate::get(o); @@ -481,9 +479,8 @@ void QDeclarativeEnginePrivate::init() if (QCoreApplication::instance()->thread() == q->thread() && QDeclarativeEngineDebugServer::isDebuggingEnabled()) { - qmlEngineDebugServer(); isDebugging = true; - QDeclarativeEngineDebugServer::addEngine(q); + QDeclarativeEngineDebugServer::instance()->addEngine(q); } } @@ -547,7 +544,7 @@ QDeclarativeEngine::~QDeclarativeEngine() { Q_D(QDeclarativeEngine); if (d->isDebugging) - QDeclarativeEngineDebugServer::remEngine(this); + QDeclarativeEngineDebugServer::instance()->remEngine(this); } /*! \fn void QDeclarativeEngine::quit() @@ -2079,7 +2076,7 @@ void QDeclarativeEnginePrivate::registerCompositeType(QDeclarativeCompiledData * QByteArray name = data->root->className(); QByteArray ptr = name + '*'; - QByteArray lst = "QDeclarativeListProperty<" + name + ">"; + QByteArray lst = "QDeclarativeListProperty<" + name + '>'; int ptr_type = QMetaType::registerType(ptr.constData(), voidptr_destructor, voidptr_constructor); diff --git a/src/declarative/qml/qdeclarativeenginedebug.cpp b/src/declarative/qml/qdeclarativeenginedebug.cpp index 688e0fc..ed28185 100644 --- a/src/declarative/qml/qdeclarativeenginedebug.cpp +++ b/src/declarative/qml/qdeclarativeenginedebug.cpp @@ -58,7 +58,13 @@ QT_BEGIN_NAMESPACE -QList<QDeclarativeEngine *> QDeclarativeEngineDebugServer::m_engines; +Q_GLOBAL_STATIC(QDeclarativeEngineDebugServer, qmlEngineDebugServer); + +QDeclarativeEngineDebugServer *QDeclarativeEngineDebugServer::instance() +{ + return qmlEngineDebugServer(); +} + QDeclarativeEngineDebugServer::QDeclarativeEngineDebugServer(QObject *parent) : QDeclarativeDebugService(QLatin1String("QDeclarativeEngine"), parent), m_watch(new QDeclarativeWatcher(this)) @@ -598,4 +604,19 @@ void QDeclarativeEngineDebugServer::remEngine(QDeclarativeEngine *engine) m_engines.removeAll(engine); } +void QDeclarativeEngineDebugServer::objectCreated(QDeclarativeEngine *engine, QObject *object) +{ + Q_ASSERT(engine); + Q_ASSERT(m_engines.contains(engine)); + + int engineId = QDeclarativeDebugService::idForObject(engine); + int objectId = QDeclarativeDebugService::idForObject(object); + + QByteArray reply; + QDataStream rs(&reply, QIODevice::WriteOnly); + + rs << QByteArray("OBJECT_CREATED") << engineId << objectId; + sendMessage(reply); +} + QT_END_NAMESPACE diff --git a/src/declarative/qml/qdeclarativeenginedebug_p.h b/src/declarative/qml/qdeclarativeenginedebug_p.h index aa450f3..613f1fe 100644 --- a/src/declarative/qml/qdeclarativeenginedebug_p.h +++ b/src/declarative/qml/qdeclarativeenginedebug_p.h @@ -92,8 +92,11 @@ public: bool hasNotifySignal; }; - static void addEngine(QDeclarativeEngine *); - static void remEngine(QDeclarativeEngine *); + void addEngine(QDeclarativeEngine *); + void remEngine(QDeclarativeEngine *); + void objectCreated(QDeclarativeEngine *, QObject *); + + static QDeclarativeEngineDebugServer *instance(); protected: virtual void messageReceived(const QByteArray &); @@ -111,7 +114,7 @@ private: void resetBinding(int objectId, const QString &propertyName); void setMethodBody(int objectId, const QString &method, const QString &body); - static QList<QDeclarativeEngine *> m_engines; + QList<QDeclarativeEngine *> m_engines; QDeclarativeWatcher *m_watch; }; Q_DECLARATIVE_EXPORT QDataStream &operator<<(QDataStream &, const QDeclarativeEngineDebugServer::QDeclarativeObjectData &); diff --git a/src/declarative/qml/qdeclarativeimport.cpp b/src/declarative/qml/qdeclarativeimport.cpp index 8d81b34..5c21ebc 100644 --- a/src/declarative/qml/qdeclarativeimport.cpp +++ b/src/declarative/qml/qdeclarativeimport.cpp @@ -338,7 +338,7 @@ QString QDeclarativeImportsPrivate::resolvedUri(const QString &dir_arg, QDeclara qSort(paths.begin(), paths.end(), greaterThan); // Ensure subdirs preceed their parents. QString stableRelativePath = dir; - foreach( QString path, paths) { + foreach(const QString &path, paths) { if (dir.startsWith(path)) { stableRelativePath = dir.mid(path.length()+1); break; diff --git a/src/declarative/qml/qdeclarativescriptparser.cpp b/src/declarative/qml/qdeclarativescriptparser.cpp index 0657f49..0b3b35f 100644 --- a/src/declarative/qml/qdeclarativescriptparser.cpp +++ b/src/declarative/qml/qdeclarativescriptparser.cpp @@ -543,7 +543,7 @@ bool ProcessAST::visit(AST::UiPublicMember *node) QString typemodifier; if(node->typeModifier) typemodifier = node->typeModifier->asString(); - if (typemodifier == QString()) { + if (typemodifier.isEmpty()) { type = Object::DynamicProperty::Custom; } else if(typemodifier == QLatin1String("list")) { type = Object::DynamicProperty::CustomList; diff --git a/src/declarative/qml/qdeclarativexmlhttprequest.cpp b/src/declarative/qml/qdeclarativexmlhttprequest.cpp index ff1a0e9..d832638 100644 --- a/src/declarative/qml/qdeclarativexmlhttprequest.cpp +++ b/src/declarative/qml/qdeclarativexmlhttprequest.cpp @@ -965,8 +965,9 @@ public: QScriptValue send(QScriptValue *me, const QByteArray &); QScriptValue abort(QScriptValue *me); - QString responseBody() const; + QString responseBody(); const QByteArray & rawResponseBody() const; + bool receivedXml() const; private slots: void downloadProgress(qint64); void error(QNetworkReply::NetworkError); @@ -989,6 +990,15 @@ private: HeadersList m_headersList; void fillHeadersList(); + bool m_gotXml; + QByteArray m_mime; + QByteArray m_charset; + QTextCodec *m_textCodec; +#ifndef QT_NO_TEXTCODEC + QTextCodec* findTextCodec() const; +#endif + void readEncoding(); + QScriptValue m_me; // Set to the data object while a send() is ongoing (to access the callback) QScriptValue dispatchCallback(QScriptValue *me); @@ -1006,7 +1016,7 @@ private: QDeclarativeXMLHttpRequest::QDeclarativeXMLHttpRequest(QNetworkAccessManager *manager) : m_state(Unsent), m_errorFlag(false), m_sendFlag(false), - m_redirectCount(0), m_network(0), m_nam(manager) + m_redirectCount(0), m_gotXml(false), m_textCodec(0), m_network(0), m_nam(manager) { } @@ -1277,6 +1287,7 @@ void QDeclarativeXMLHttpRequest::finished() if (cbv.isError()) printError(cbv); } m_responseEntityBody.append(m_network->readAll()); + readEncoding(); if (xhrDump()) { qWarning().nospace() << "XMLHttpRequest: RESPONSE " << qPrintable(m_url.toString()); @@ -1302,15 +1313,72 @@ void QDeclarativeXMLHttpRequest::finished() } -QString QDeclarativeXMLHttpRequest::responseBody() const +void QDeclarativeXMLHttpRequest::readEncoding() +{ + foreach (const HeaderPair &header, m_headersList) { + if (header.first == "content-type") { + int separatorIdx = header.second.indexOf(';'); + if (separatorIdx == -1) { + m_mime == header.second; + } else { + m_mime = header.second.mid(0, separatorIdx); + int charsetIdx = header.second.indexOf("charset="); + if (charsetIdx != -1) { + charsetIdx += 8; + separatorIdx = header.second.indexOf(';', charsetIdx); + m_charset = header.second.mid(charsetIdx, separatorIdx >= 0 ? separatorIdx : header.second.length()); + } + } + break; + } + } + + if (m_mime.isEmpty() || m_mime == "text/xml" || m_mime == "application/xml" || m_mime.endsWith("+xml")) + m_gotXml = true; +} + +bool QDeclarativeXMLHttpRequest::receivedXml() const +{ + return m_gotXml; +} + + +#ifndef QT_NO_TEXTCODEC +QTextCodec* QDeclarativeXMLHttpRequest::findTextCodec() const +{ + QTextCodec *codec = 0; + + if (!m_charset.isEmpty()) + codec = QTextCodec::codecForName(m_charset); + + if (!codec && m_gotXml) { + QXmlStreamReader reader(m_responseEntityBody); + reader.readNext(); + codec = QTextCodec::codecForName(reader.documentEncoding().toString().toUtf8()); + } + + if (!codec && m_mime == "text/html") + codec = QTextCodec::codecForHtml(m_responseEntityBody, 0); + + if (!codec) + codec = QTextCodec::codecForUtfText(m_responseEntityBody, 0); + + if (!codec) + codec = QTextCodec::codecForName("UTF-8"); + return codec; +} +#endif + + +QString QDeclarativeXMLHttpRequest::responseBody() { - QXmlStreamReader reader(m_responseEntityBody); - reader.readNext(); #ifndef QT_NO_TEXTCODEC - QTextCodec *codec = QTextCodec::codecForName(reader.documentEncoding().toString().toUtf8()); - if (codec) - return codec->toUnicode(m_responseEntityBody); + if (!m_textCodec) + m_textCodec = findTextCodec(); + if (m_textCodec) + return m_textCodec->toUnicode(m_responseEntityBody); #endif + return QString::fromUtf8(m_responseEntityBody); } @@ -1571,7 +1639,8 @@ static QScriptValue qmlxmlhttprequest_responseXML(QScriptContext *context, QScri if (!request) THROW_REFERENCE("Not an XMLHttpRequest object"); - if (request->readyState() != QDeclarativeXMLHttpRequest::Loading && + if (!request->receivedXml() || + request->readyState() != QDeclarativeXMLHttpRequest::Loading && request->readyState() != QDeclarativeXMLHttpRequest::Done) return engine->nullValue(); else diff --git a/src/declarative/qml/qmetaobjectbuilder.cpp b/src/declarative/qml/qmetaobjectbuilder.cpp index 6e4d7b8..0954248 100644 --- a/src/declarative/qml/qmetaobjectbuilder.cpp +++ b/src/declarative/qml/qmetaobjectbuilder.cpp @@ -1142,7 +1142,7 @@ static QByteArray buildParameterNames if (!parameterNames.isEmpty()) { QByteArray names; bool first = true; - foreach (QByteArray name, parameterNames) { + foreach (const QByteArray &name, parameterNames) { if (first) first = false; else diff --git a/src/declarative/util/qdeclarativefontloader.cpp b/src/declarative/util/qdeclarativefontloader.cpp index 291583c..1755855 100644 --- a/src/declarative/util/qdeclarativefontloader.cpp +++ b/src/declarative/util/qdeclarativefontloader.cpp @@ -130,6 +130,7 @@ void QDeclarativeFontLoader::setSource(const QUrl &url) d->status = Loading; emit statusChanged(); + emit sourceChanged(); #ifndef QT_NO_LOCALFILE_OPTIMIZED_QML QString lf = QDeclarativeEnginePrivate::urlToLocalFileOrQrc(d->url); if (!lf.isEmpty()) { diff --git a/src/declarative/util/qdeclarativefontloader_p.h b/src/declarative/util/qdeclarativefontloader_p.h index a5fbb8f..0344d99 100644 --- a/src/declarative/util/qdeclarativefontloader_p.h +++ b/src/declarative/util/qdeclarativefontloader_p.h @@ -60,7 +60,7 @@ class Q_AUTOTEST_EXPORT QDeclarativeFontLoader : public QObject Q_DECLARE_PRIVATE(QDeclarativeFontLoader) Q_ENUMS(Status) - Q_PROPERTY(QUrl source READ source WRITE setSource) + Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) Q_PROPERTY(Status status READ status NOTIFY statusChanged) @@ -82,6 +82,7 @@ private Q_SLOTS: void replyFinished(); Q_SIGNALS: + void sourceChanged(); void nameChanged(); void statusChanged(); }; diff --git a/src/declarative/util/qdeclarativelistmodel.cpp b/src/declarative/util/qdeclarativelistmodel.cpp index 8f9b725..60d8aa9 100644 --- a/src/declarative/util/qdeclarativelistmodel.cpp +++ b/src/declarative/util/qdeclarativelistmodel.cpp @@ -58,9 +58,6 @@ Q_DECLARE_METATYPE(QListModelInterface *) QT_BEGIN_NAMESPACE -#define DATA_ROLE_ID 1 -#define DATA_ROLE_NAME "data" - QDeclarativeListModelParser::ListInstruction *QDeclarativeListModelParser::ListModelData::instructions() const { return (QDeclarativeListModelParser::ListInstruction *)((char *)this + sizeof(ListModelData)); @@ -570,7 +567,7 @@ bool QDeclarativeListModelParser::compileProperty(const QDeclarativeCustomParser QList<QDeclarativeCustomParserProperty> props = node.properties(); for(int jj = 0; jj < props.count(); ++jj) { const QDeclarativeCustomParserProperty &nodeProp = props.at(jj); - if (nodeProp.name() == "") { + if (nodeProp.name().isEmpty()) { error(nodeProp, QDeclarativeListModel::tr("ListElement: cannot contain nested elements")); return false; } @@ -658,7 +655,7 @@ QByteArray QDeclarativeListModelParser::compile(const QList<QDeclarativeCustomPa for(int ii = 0; ii < customProps.count(); ++ii) { const QDeclarativeCustomParserProperty &prop = customProps.at(ii); - if(prop.name() != "") { // isn't default property + if(!prop.name().isEmpty()) { // isn't default property error(prop, QDeclarativeListModel::tr("ListModel: undefined property '%1'").arg(QString::fromUtf8(prop.name()))); return QByteArray(); } diff --git a/src/declarative/util/qdeclarativelistmodelworkeragent.cpp b/src/declarative/util/qdeclarativelistmodelworkeragent.cpp index 534c923..498de6d 100644 --- a/src/declarative/util/qdeclarativelistmodelworkeragent.cpp +++ b/src/declarative/util/qdeclarativelistmodelworkeragent.cpp @@ -187,12 +187,17 @@ void QDeclarativeListModelWorkerAgent::sync() s->data = data; s->list = m_copy; data.changes.clear(); + + mutex.lock(); QCoreApplication::postEvent(this, s); + syncDone.wait(&mutex); + mutex.unlock(); } bool QDeclarativeListModelWorkerAgent::event(QEvent *e) { if (e->type() == QEvent::User) { + QMutexLocker locker(&mutex); Sync *s = static_cast<Sync *>(e); const QList<Change> &changes = s->data.changes; @@ -202,13 +207,18 @@ bool QDeclarativeListModelWorkerAgent::event(QEvent *e) FlatListModel *orig = m_orig->m_flat; FlatListModel *copy = s->list->m_flat; - if (!orig || !copy) + if (!orig || !copy) { + syncDone.wakeAll(); return QObject::event(e); - + } + orig->m_roles = copy->m_roles; orig->m_strings = copy->m_strings; orig->m_values = copy->m_values; + syncDone.wakeAll(); + locker.unlock(); + for (int ii = 0; ii < changes.count(); ++ii) { const Change &change = changes.at(ii); switch (change.type) { @@ -229,6 +239,8 @@ bool QDeclarativeListModelWorkerAgent::event(QEvent *e) if (cc) emit m_orig->countChanged(); + } else { + syncDone.wakeAll(); } } diff --git a/src/declarative/util/qdeclarativelistmodelworkeragent_p.h b/src/declarative/util/qdeclarativelistmodelworkeragent_p.h index 1622144..01da374 100644 --- a/src/declarative/util/qdeclarativelistmodelworkeragent_p.h +++ b/src/declarative/util/qdeclarativelistmodelworkeragent_p.h @@ -57,6 +57,8 @@ #include <QtScript/qscriptvalue.h> #include <QtGui/qevent.h> +#include <QMutex> +#include <QWaitCondition> QT_BEGIN_HEADER @@ -142,6 +144,8 @@ private: QAtomicInt m_ref; QDeclarativeListModel *m_orig; QDeclarativeListModel *m_copy; + QMutex mutex; + QWaitCondition syncDone; }; QT_END_NAMESPACE diff --git a/src/declarative/util/qdeclarativestategroup.cpp b/src/declarative/util/qdeclarativestategroup.cpp index fc90baa..6d9563e 100644 --- a/src/declarative/util/qdeclarativestategroup.cpp +++ b/src/declarative/util/qdeclarativestategroup.cpp @@ -272,7 +272,7 @@ void QDeclarativeStateGroup::componentComplete() return; } else if (!d->currentState.isEmpty()) { QString cs = d->currentState; - d->currentState = QString(); + d->currentState.clear(); d->setCurrentStateInternal(cs, true); } } @@ -314,7 +314,7 @@ bool QDeclarativeStateGroupPrivate::updateAutoState() } } if (revert) { - bool rv = currentState != QString(); + bool rv = !currentState.isEmpty(); q->setState(QString()); return rv; } else { diff --git a/src/declarative/util/qdeclarativexmllistmodel.cpp b/src/declarative/util/qdeclarativexmllistmodel.cpp index 7b3d4a8..02bf370 100644 --- a/src/declarative/util/qdeclarativexmllistmodel.cpp +++ b/src/declarative/util/qdeclarativexmllistmodel.cpp @@ -466,8 +466,6 @@ public: QList<QDeclarativeXmlListModelRole *> roleObjects; static void append_role(QDeclarativeListProperty<QDeclarativeXmlListModelRole> *list, QDeclarativeXmlListModelRole *role); static void clear_role(QDeclarativeListProperty<QDeclarativeXmlListModelRole> *list); - static void removeAt_role(QDeclarativeListProperty<QDeclarativeXmlListModelRole> *list, int i); - static void insert_role(QDeclarativeListProperty<QDeclarativeXmlListModelRole> *list, int i, QDeclarativeXmlListModelRole *role); QList<QList<QVariant> > data; int redirectCount; }; |