From 7b00e383231aee2866597031036389e6f11e2645 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 23 Jul 2009 16:34:37 +1000 Subject: Flesh out FolderListModel --- src/declarative/extra/qmlfolderlistmodel.cpp | 117 ++++++++++++++++++++++++++- src/declarative/extra/qmlfolderlistmodel.h | 10 +++ 2 files changed, 124 insertions(+), 3 deletions(-) diff --git a/src/declarative/extra/qmlfolderlistmodel.cpp b/src/declarative/extra/qmlfolderlistmodel.cpp index 4a71109..1c05a6d 100644 --- a/src/declarative/extra/qmlfolderlistmodel.cpp +++ b/src/declarative/extra/qmlfolderlistmodel.cpp @@ -49,18 +49,69 @@ QT_BEGIN_NAMESPACE class QmlFolderListModelPrivate : public QObjectPrivate { public: - QmlFolderListModelPrivate() : count(0) { + QmlFolderListModelPrivate() + : sortField(QmlFolderListModel::Name), sortReversed(false), count(0) { folder = QDir::currentPath(); nameFilters << QLatin1String("*"); } + void updateSorting() { + QDir::SortFlags flags = 0; + switch(sortField) { + case QmlFolderListModel::Unsorted: + flags |= QDir::Unsorted; + break; + case QmlFolderListModel::Name: + flags |= QDir::Name; + break; + case QmlFolderListModel::Time: + flags |= QDir::Time; + break; + case QmlFolderListModel::Size: + flags |= QDir::Size; + break; + case QmlFolderListModel::Type: + flags |= QDir::Type; + break; + } + + if (sortReversed) + flags |= QDir::Reversed; + + model.setSorting(flags); + } + QDirModel model; QString folder; QStringList nameFilters; QModelIndex folderIndex; + QmlFolderListModel::SortField sortField; + bool sortReversed; int count; }; +/*! + \qmlclass FolderListModel + \brief The FolderListModel provides a model of the contents of a folder in a filesystem. + + FolderListModel provides access to the local filesystem. The \e folder property + specifies the folder to list. + + Qt uses "/" as a universal directory separator in the same way that "/" is + used as a path separator in URLs. If you always use "/" as a directory + separator, Qt will translate your paths to conform to the underlying + operating system. + + The roles available are: + \list + \o fileName + \o filePath + \endlist + + Additionally a file entry can be differentiated from a folder entry + via the \l isFolder() method. +*/ + QmlFolderListModel::QmlFolderListModel(QObject *parent) : QListModelInterface(*(new QmlFolderListModelPrivate), parent) { @@ -73,6 +124,7 @@ QmlFolderListModel::QmlFolderListModel(QObject *parent) connect(&d->model, SIGNAL(dataChanged(const QModelIndex&,const QModelIndex&)) , this, SLOT(dataChanged(const QModelIndex&,const QModelIndex&))); connect(&d->model, SIGNAL(modelReset()), this, SLOT(refresh())); + connect(&d->model, SIGNAL(layoutChanged()), this, SLOT(refresh())); } QmlFolderListModel::~QmlFolderListModel() @@ -119,6 +171,11 @@ QString QmlFolderListModel::toString(int role) const return QString(); } +/*! + \qmlproperty string FolderListModel::folder + + The \a folder property holds the folder the model is currently providing. +*/ QString QmlFolderListModel::folder() const { Q_D(const QmlFolderListModel); @@ -138,6 +195,20 @@ void QmlFolderListModel::setFolder(const QString &folder) } } +/*! + \qmlproperty list FolderListModel::nameFilters + + The \a nameFilters property contains a list of filename filters. + The filters may include the ? and * wildcards. + + The example below filters on PNG and JPEG files: + + \code + FolderListModel { + nameFilters: [ "*.png", "*.jpg" ] + } + \endcode +*/ QStringList QmlFolderListModel::nameFilters() const { Q_D(const QmlFolderListModel); @@ -158,11 +229,50 @@ void QmlFolderListModel::classComplete() QMetaObject::invokeMethod(this, "refresh", Qt::QueuedConnection); } +QmlFolderListModel::SortField QmlFolderListModel::sortField() const +{ + Q_D(const QmlFolderListModel); + return d->sortField; +} + +void QmlFolderListModel::setSortField(SortField field) +{ + Q_D(QmlFolderListModel); + if (field != d->sortField) { + d->sortField = field; + d->updateSorting(); + } +} + +bool QmlFolderListModel::sortReversed() const +{ + Q_D(const QmlFolderListModel); + return d->sortReversed; +} + +void QmlFolderListModel::setSortReversed(bool rev) +{ + Q_D(QmlFolderListModel); + if (rev != d->sortReversed) { + d->sortReversed = rev; + d->updateSorting(); + } +} + +/*! + \qmlmethod bool FolderListModel::isFolder(int index) + + Returns true if the entry \a index is a folder; otherwise + returns false. +*/ bool QmlFolderListModel::isFolder(int index) const { Q_D(const QmlFolderListModel); - if (index != -1) - return d->model.isDir(d->model.index(index, 0, d->folderIndex)); + if (index != -1) { + QModelIndex idx = d->model.index(index, 0, d->folderIndex); + if (idx.isValid()) + return d->model.isDir(idx); + } return false; } @@ -203,6 +313,7 @@ void QmlFolderListModel::removed(const QModelIndex &index, int start, int end) void QmlFolderListModel::dataChanged(const QModelIndex &start, const QModelIndex &end) { Q_D(QmlFolderListModel); + qDebug() << "data changed"; if (start.parent() == d->folderIndex) emit itemsChanged(start.row(), end.row() - start.row() + 1, roles()); } diff --git a/src/declarative/extra/qmlfolderlistmodel.h b/src/declarative/extra/qmlfolderlistmodel.h index 8c99b22..8708d9a 100644 --- a/src/declarative/extra/qmlfolderlistmodel.h +++ b/src/declarative/extra/qmlfolderlistmodel.h @@ -62,6 +62,8 @@ class Q_DECLARATIVE_EXPORT QmlFolderListModel : public QListModelInterface, publ Q_PROPERTY(QString folder READ folder WRITE setFolder NOTIFY folderChanged) Q_PROPERTY(QStringList nameFilters READ nameFilters WRITE setNameFilters) + Q_PROPERTY(SortField sortField READ sortField WRITE setSortField) + Q_PROPERTY(bool sortReversed READ sortReversed WRITE setSortReversed) public: QmlFolderListModel(QObject *parent = 0); @@ -82,6 +84,14 @@ public: Q_INVOKABLE bool isFolder(int index) const; + enum SortField { Unsorted, Name, Time, Size, Type }; + SortField sortField() const; + void setSortField(SortField field); + Q_ENUMS(SortField) + + bool sortReversed() const; + void setSortReversed(bool rev); + Q_SIGNALS: void folderChanged(); -- cgit v0.12 From bb90cec43fbcc410dd357009a284f15c9208c0bf Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 23 Jul 2009 16:35:30 +1000 Subject: Better not to let animation get ahead of clock. --- src/declarative/util/qmlfollow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/util/qmlfollow.cpp b/src/declarative/util/qmlfollow.cpp index 63b6307..cfd2dde 100644 --- a/src/declarative/util/qmlfollow.cpp +++ b/src/declarative/util/qmlfollow.cpp @@ -104,7 +104,7 @@ void QmlFollowPrivate::tick(int time) return; // Real men solve the spring DEs using RK4. // We'll do something much simpler which gives a result that looks fine. - int count = (elapsed+8) / 16; + int count = elapsed / 16; for (int i = 0; i < count; ++i) { qreal diff = srcVal - currentValue; if (modulus != 0.0 && qAbs(diff) > modulus / 2) { -- cgit v0.12 From 05c1db3b28067336fcf14cce7909d1f09007998b Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Mon, 27 Jul 2009 01:43:22 +0200 Subject: Added formal parameters to the QML signals. --- src/declarative/qml/parser/qmljs.g | 52 +++++++++++++++ src/declarative/qml/parser/qmljsast.cpp | 25 ++++++++ src/declarative/qml/parser/qmljsast_p.h | 88 +++++++++++++++++++++++++- src/declarative/qml/parser/qmljsastfwd_p.h | 3 + src/declarative/qml/parser/qmljsastvisitor_p.h | 6 ++ src/declarative/qml/parser/qmljsparser.cpp | 40 ++++++++++++ src/declarative/qml/parser/qmljsparser_p.h | 3 + 7 files changed, 216 insertions(+), 1 deletion(-) diff --git a/src/declarative/qml/parser/qmljs.g b/src/declarative/qml/parser/qmljs.g index ccfe7fd..a1c4ba2 100644 --- a/src/declarative/qml/parser/qmljs.g +++ b/src/declarative/qml/parser/qmljs.g @@ -271,6 +271,9 @@ public: AST::UiObjectMemberList *UiObjectMemberList; AST::UiArrayMemberList *UiArrayMemberList; AST::UiQualifiedId *UiQualifiedId; + AST::UiSignature *UiSignature; + AST::UiFormalList *UiFormalList; + AST::UiFormal *UiFormal; }; public: @@ -880,13 +883,62 @@ case $rule_number: { ./ UiFormal: JsIdentifier ; +/. +case $rule_number: { + AST::UiFormal *node = makeAstNode(driver->nodePool(), sym(1).sval); + node->identifierToken = loc(1); + sym(1).UiFormal = node; +} break; +./ + UiFormal: JsIdentifier T_AS JsIdentifier ; +/. +case $rule_number: { + AST::UiFormal *node = makeAstNode(driver->nodePool(), + sym(1).sval, sym(3).sval); + node->identifierToken = loc(1); + node->asToken = loc(2); + node->aliasToken = loc(3); + sym(1).UiFormal = node; +} break; +./ UiFormalList: UiFormal ; +/. +case $rule_number: { + sym(1).UiFormalList = makeAstNode(driver->nodePool(), + sym(1).UiFormal); +} break; +./ + UiFormalList: UiFormalList T_COMMA UiFormal ; +/. +case $rule_number: { + sym(1).UiFormalList = makeAstNode(driver->nodePool(), + sym(1).UiFormalList, sym(3).UiFormal); +} break; +./ UiSignature: T_LPAREN T_RPAREN ; +/. +case $rule_number: { + AST::UiSignature *node = makeAstNode(driver->nodePool()); + node->lparenToken = loc(1); + node->rparenToken = loc(3); + sym(1).UiSignature = node; +} break; +./ + UiSignature: T_LPAREN UiFormalList T_RPAREN ; +/. +case $rule_number: { + AST::UiSignature *node = makeAstNode(driver->nodePool(), + sym(2).UiFormalList->finish()); + node->lparenToken = loc(1); + node->rparenToken = loc(3); + sym(1).UiSignature = node; +} break; +./ UiObjectMember: T_SIGNAL T_IDENTIFIER T_LPAREN UiParameterListOpt T_RPAREN T_AUTOMATIC_SEMICOLON ; UiObjectMember: T_SIGNAL T_IDENTIFIER T_LPAREN UiParameterListOpt T_RPAREN T_SEMICOLON ; diff --git a/src/declarative/qml/parser/qmljsast.cpp b/src/declarative/qml/parser/qmljsast.cpp index 52f19e2..1d7f09e 100644 --- a/src/declarative/qml/parser/qmljsast.cpp +++ b/src/declarative/qml/parser/qmljsast.cpp @@ -801,6 +801,31 @@ void UiProgram::accept0(Visitor *visitor) visitor->endVisit(this); } +void UiSignature::accept0(Visitor *visitor) +{ + if (visitor->visit(this)) { + acceptChild(formals, visitor); + } + visitor->endVisit(this); +} + +void UiFormalList::accept0(Visitor *visitor) +{ + if (visitor->visit(this)) { + for (UiFormalList *it = this; it; it = it->next) { + acceptChild(it->formal, visitor); + } + } + visitor->endVisit(this); +} + +void UiFormal::accept0(Visitor *visitor) +{ + if (visitor->visit(this)) { + } + visitor->endVisit(this); +} + void UiPublicMember::accept0(Visitor *visitor) { if (visitor->visit(this)) { diff --git a/src/declarative/qml/parser/qmljsast_p.h b/src/declarative/qml/parser/qmljsast_p.h index eba9202..9745153 100644 --- a/src/declarative/qml/parser/qmljsast_p.h +++ b/src/declarative/qml/parser/qmljsast_p.h @@ -213,7 +213,10 @@ public: Kind_UiPublicMember, Kind_UiQualifiedId, Kind_UiScriptBinding, - Kind_UiSourceElement + Kind_UiSourceElement, + Kind_UiFormal, + Kind_UiFormalList, + Kind_UiSignature }; inline Node() @@ -269,6 +272,89 @@ public: virtual SourceLocation lastSourceLocation() const = 0; }; +class UiFormal: public Node +{ +public: + QMLJS_DECLARE_AST_NODE(UiFormal) + + UiFormal(NameId *name, NameId *alias = 0) + : name(name), alias(alias) + { } + + virtual SourceLocation firstSourceLocation() const + { return SourceLocation(); } + + virtual SourceLocation lastSourceLocation() const + { return SourceLocation(); } + + virtual void accept0(Visitor *visitor); + +// attributes + NameId *name; + NameId *alias; + SourceLocation identifierToken; + SourceLocation asToken; + SourceLocation aliasToken; +}; + +class UiFormalList: public Node +{ +public: + QMLJS_DECLARE_AST_NODE(UiFormalList) + + UiFormalList(UiFormal *formal) + : formal(formal), next(this) {} + + UiFormalList(UiFormalList *previous, UiFormal *formal) + : formal(formal) + { + next = previous->next; + previous->next = this; + } + + UiFormalList *finish() + { + UiFormalList *head = next; + next = 0; + return head; + } + + virtual SourceLocation firstSourceLocation() const + { return SourceLocation(); } + + virtual SourceLocation lastSourceLocation() const + { return SourceLocation(); } + + virtual void accept0(Visitor *visitor); + +// attributes + UiFormal *formal; + UiFormalList *next; +}; + +class UiSignature: public Node +{ +public: + QMLJS_DECLARE_AST_NODE(UiSignature) + + UiSignature(UiFormalList *formals = 0) + : formals(formals) + { } + + virtual SourceLocation firstSourceLocation() const + { return SourceLocation(); } + + virtual SourceLocation lastSourceLocation() const + { return SourceLocation(); } + + virtual void accept0(Visitor *visitor); + +// attributes + SourceLocation lparenToken; + UiFormalList *formals; + SourceLocation rparenToken; +}; + class NestedExpression: public ExpressionNode { public: diff --git a/src/declarative/qml/parser/qmljsastfwd_p.h b/src/declarative/qml/parser/qmljsastfwd_p.h index 339bea4..f79cfc2 100644 --- a/src/declarative/qml/parser/qmljsastfwd_p.h +++ b/src/declarative/qml/parser/qmljsastfwd_p.h @@ -176,6 +176,9 @@ class UiObjectMember; class UiObjectMemberList; class UiArrayMemberList; class UiQualifiedId; +class UiFormalList; +class UiFormal; +class UiSignature; } } // namespace AST diff --git a/src/declarative/qml/parser/qmljsastvisitor_p.h b/src/declarative/qml/parser/qmljsastvisitor_p.h index 3677b1a..237640f 100644 --- a/src/declarative/qml/parser/qmljsastvisitor_p.h +++ b/src/declarative/qml/parser/qmljsastvisitor_p.h @@ -82,6 +82,9 @@ public: virtual bool visit(UiObjectMemberList *) { return true; } virtual bool visit(UiArrayMemberList *) { return true; } virtual bool visit(UiQualifiedId *) { return true; } + virtual bool visit(UiSignature *) { return true; } + virtual bool visit(UiFormalList *) { return true; } + virtual bool visit(UiFormal *) { return true; } virtual void endVisit(UiProgram *) {} virtual void endVisit(UiImportList *) {} @@ -96,6 +99,9 @@ public: virtual void endVisit(UiObjectMemberList *) {} virtual void endVisit(UiArrayMemberList *) {} virtual void endVisit(UiQualifiedId *) {} + virtual void endVisit(UiSignature *) {} + virtual void endVisit(UiFormalList *) {} + virtual void endVisit(UiFormal *) {} // QmlJS virtual bool visit(ThisExpression *) { return true; } diff --git a/src/declarative/qml/parser/qmljsparser.cpp b/src/declarative/qml/parser/qmljsparser.cpp index 22f3820..9bd6e6f 100644 --- a/src/declarative/qml/parser/qmljsparser.cpp +++ b/src/declarative/qml/parser/qmljsparser.cpp @@ -419,6 +419,46 @@ case 47: { sym(1).Node = node; } break; +case 48: { + AST::UiFormal *node = makeAstNode(driver->nodePool(), sym(1).sval); + node->identifierToken = loc(1); + sym(1).UiFormal = node; +} break; + +case 49: { + AST::UiFormal *node = makeAstNode(driver->nodePool(), + sym(1).sval, sym(3).sval); + node->identifierToken = loc(1); + node->asToken = loc(2); + node->aliasToken = loc(3); + sym(1).UiFormal = node; +} break; + +case 50: { + sym(1).UiFormalList = makeAstNode(driver->nodePool(), + sym(1).UiFormal); +} break; + +case 51: { + sym(1).UiFormalList = makeAstNode(driver->nodePool(), + sym(1).UiFormalList, sym(3).UiFormal); +} break; + +case 52: { + AST::UiSignature *node = makeAstNode(driver->nodePool()); + node->lparenToken = loc(1); + node->rparenToken = loc(3); + sym(1).UiSignature = node; +} break; + +case 53: { + AST::UiSignature *node = makeAstNode(driver->nodePool(), + sym(2).UiFormalList->finish()); + node->lparenToken = loc(1); + node->rparenToken = loc(3); + sym(1).UiSignature = node; +} break; + case 55: { AST::UiPublicMember *node = makeAstNode (driver->nodePool(), (NameId *)0, sym(2).sval); node->type = AST::UiPublicMember::Signal; diff --git a/src/declarative/qml/parser/qmljsparser_p.h b/src/declarative/qml/parser/qmljsparser_p.h index be5317b..e352f43 100644 --- a/src/declarative/qml/parser/qmljsparser_p.h +++ b/src/declarative/qml/parser/qmljsparser_p.h @@ -120,6 +120,9 @@ public: AST::UiObjectMemberList *UiObjectMemberList; AST::UiArrayMemberList *UiArrayMemberList; AST::UiQualifiedId *UiQualifiedId; + AST::UiSignature *UiSignature; + AST::UiFormalList *UiFormalList; + AST::UiFormal *UiFormal; }; public: -- cgit v0.12 From be7b6bcac093abfb1ca1afedcdc6c5d12da12c8e Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Mon, 27 Jul 2009 01:49:11 +0200 Subject: Fixed project dependencies --- src/declarative/qml/parser/parser.pri | 1 + src/declarative/qml/rewriter/rewriter.pri | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/declarative/qml/parser/parser.pri b/src/declarative/qml/parser/parser.pri index 610b2aa..1ea249a 100644 --- a/src/declarative/qml/parser/parser.pri +++ b/src/declarative/qml/parser/parser.pri @@ -1,5 +1,6 @@ INCLUDEPATH += $$PWD +DEPENDPATH += $$PWD HEADERS += $$PWD/qmljsast_p.h \ $$PWD/qmljsastfwd_p.h \ diff --git a/src/declarative/qml/rewriter/rewriter.pri b/src/declarative/qml/rewriter/rewriter.pri index de3c298..550741b 100644 --- a/src/declarative/qml/rewriter/rewriter.pri +++ b/src/declarative/qml/rewriter/rewriter.pri @@ -1,5 +1,7 @@ INCLUDEPATH += $$PWD +DEPENDPATH += $$PWD + HEADERS += $$PWD/textwriter_p.h SOURCES += $$PWD/textwriter.cpp -- cgit v0.12 From ca81810f92b6181c1854988860588d6ea84cf1b4 Mon Sep 17 00:00:00 2001 From: Henrik Hartz Date: Mon, 27 Jul 2009 10:24:49 +1000 Subject: compile fix --- src/declarative/qml/qmlmetatype.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/qml/qmlmetatype.cpp b/src/declarative/qml/qmlmetatype.cpp index 3552b44..a037702 100644 --- a/src/declarative/qml/qmlmetatype.cpp +++ b/src/declarative/qml/qmlmetatype.cpp @@ -56,7 +56,7 @@ #include #include #include -//#include +#include #include #include -- cgit v0.12 From ef1a5d6bad05b99765658b3ca916bd3c5f507db0 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Mon, 27 Jul 2009 13:34:13 +1000 Subject: Make private --- src/declarative/qml/qml.pri | 2 +- src/declarative/qml/qmlcomponentjs.cpp | 3 +- src/declarative/qml/qmlcomponentjs.h | 92 -------------------------------- src/declarative/qml/qmlcomponentjs_p.h | 47 +++++++++++----- src/declarative/qml/qmlcomponentjs_p_p.h | 77 ++++++++++++++++++++++++++ src/declarative/qml/qmlengine.cpp | 2 +- 6 files changed, 115 insertions(+), 108 deletions(-) delete mode 100644 src/declarative/qml/qmlcomponentjs.h create mode 100644 src/declarative/qml/qmlcomponentjs_p_p.h diff --git a/src/declarative/qml/qml.pri b/src/declarative/qml/qml.pri index 6ee670e..75e5692 100644 --- a/src/declarative/qml/qml.pri +++ b/src/declarative/qml/qml.pri @@ -38,8 +38,8 @@ HEADERS += qml/qmlparser_p.h \ qml/qmlbinding.h \ qml/qmlbinding_p.h \ qml/qmlmetaproperty.h \ - qml/qmlcomponentjs.h \ qml/qmlcomponentjs_p.h \ + qml/qmlcomponentjs_p_p.h \ qml/qmlcomponent.h \ qml/qmlcomponent_p.h \ qml/qmlcustomparser_p.h \ diff --git a/src/declarative/qml/qmlcomponentjs.cpp b/src/declarative/qml/qmlcomponentjs.cpp index 32c2249..89f3851 100644 --- a/src/declarative/qml/qmlcomponentjs.cpp +++ b/src/declarative/qml/qmlcomponentjs.cpp @@ -39,11 +39,12 @@ ** ****************************************************************************/ -#include "qmlcomponentjs.h" #include "qmlcomponentjs_p.h" +#include "qmlcomponentjs_p_p.h" #include "qmlcomponent.h" QT_BEGIN_NAMESPACE + QmlComponentJS::QmlComponentJS(QmlEngine *engine, QObject *parent) : QmlComponent(*(new QmlComponentJSPrivate), parent) { diff --git a/src/declarative/qml/qmlcomponentjs.h b/src/declarative/qml/qmlcomponentjs.h deleted file mode 100644 index 5ad1635..0000000 --- a/src/declarative/qml/qmlcomponentjs.h +++ /dev/null @@ -1,92 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMLBINDABLECOMPONENT_H -#define QMLBINDABLECOMPONENT_H - -#include -#include -#include -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QmlComponentJSPrivate; -class QmlEngine; -class QmlContext; -class Q_DECLARATIVE_EXPORT QmlComponentJS : public QmlComponent -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QmlComponentJS) - friend class QmlEngine; -public: - QmlComponentJS(QmlEngine *, const QUrl &url, QObject *parent = 0); - QmlComponentJS(QmlEngine *, QObject *parent=0); - Q_PROPERTY(bool isNull READ isNull NOTIFY isNullChanged); - Q_PROPERTY(bool isReady READ isReady NOTIFY isReadyChanged); - Q_PROPERTY(bool isError READ isError NOTIFY isErrorChanged); - Q_PROPERTY(bool isLoading READ isLoading NOTIFY isLoadingChanged); - - Q_INVOKABLE QScriptValue createObject(); - Q_INVOKABLE QString errorsString() const; - - void setContext(QmlContext* c); -Q_SIGNALS: - void isNullChanged(); - void isErrorChanged(); - void isReadyChanged(); - void isLoadingChanged(); -private slots: - void statusChange(QmlComponent::Status newStatus); -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QmlComponentJS) - -QT_END_HEADER -#endif diff --git a/src/declarative/qml/qmlcomponentjs_p.h b/src/declarative/qml/qmlcomponentjs_p.h index 75d5517..8c69b5f 100644 --- a/src/declarative/qml/qmlcomponentjs_p.h +++ b/src/declarative/qml/qmlcomponentjs_p.h @@ -39,8 +39,8 @@ ** ****************************************************************************/ -#ifndef QMLBINDABLECOMPONENT_P_H -#define QMLBINDABLECOMPONENT_P_H +#ifndef QMLCOMPONENTJS_P_H +#define QMLCOMPONENTJS_P_H // // W A R N I N G @@ -53,25 +53,46 @@ // We mean it. // -#include "qmlcomponent.h" -#include "qmlcomponentjs.h" -#include "qmlcomponent_p.h" +#include +#include +#include +#include +#include +#include QT_BEGIN_NAMESPACE +class QmlComponentJSPrivate; +class QmlEngine; class QmlContext; -class QmlComponentJSPrivate : public QmlComponentPrivate +class Q_DECLARATIVE_EXPORT QmlComponentJS : public QmlComponent { - Q_DECLARE_PUBLIC(QmlComponentJS) + Q_OBJECT + Q_DECLARE_PRIVATE(QmlComponentJS) + friend class QmlEngine; public: - QmlComponentJSPrivate() : QmlComponentPrivate(), - prevStatus(QmlComponentJS::Null), ctxt(0) - { } + QmlComponentJS(QmlEngine *, const QUrl &url, QObject *parent = 0); + QmlComponentJS(QmlEngine *, QObject *parent=0); + Q_PROPERTY(bool isNull READ isNull NOTIFY isNullChanged); + Q_PROPERTY(bool isReady READ isReady NOTIFY isReadyChanged); + Q_PROPERTY(bool isError READ isError NOTIFY isErrorChanged); + Q_PROPERTY(bool isLoading READ isLoading NOTIFY isLoadingChanged); - QmlComponent::Status prevStatus; - QmlContext* ctxt; + Q_INVOKABLE QScriptValue createObject(); + Q_INVOKABLE QString errorsString() const; + + void setContext(QmlContext* c); +Q_SIGNALS: + void isNullChanged(); + void isErrorChanged(); + void isReadyChanged(); + void isLoadingChanged(); +private slots: + void statusChange(QmlComponent::Status newStatus); }; QT_END_NAMESPACE -#endif +QML_DECLARE_TYPE(QmlComponentJS) + +#endif // QMLCOMPONENTJS_P_H diff --git a/src/declarative/qml/qmlcomponentjs_p_p.h b/src/declarative/qml/qmlcomponentjs_p_p.h new file mode 100644 index 0000000..47ce491 --- /dev/null +++ b/src/declarative/qml/qmlcomponentjs_p_p.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLCOMPONENTJS_P_P_H +#define QMLCOMPONENTJS_P_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qmlcomponent.h" +#include "qmlcomponentjs_p.h" +#include "qmlcomponent_p.h" + +QT_BEGIN_NAMESPACE + +class QmlContext; +class QmlComponentJSPrivate : public QmlComponentPrivate +{ + Q_DECLARE_PUBLIC(QmlComponentJS) +public: + QmlComponentJSPrivate() : QmlComponentPrivate(), + prevStatus(QmlComponentJS::Null), ctxt(0) + { } + + QmlComponent::Status prevStatus; + QmlContext* ctxt; +}; + +QT_END_NAMESPACE + +#endif // QMLCOMPONENTJS_P_P_H diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 69cc542..b478618 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -71,7 +71,7 @@ #include #include #include -#include +#include "private/qmlcomponentjs_p.h" #include "private/qmlmetaproperty_p.h" #include #include -- cgit v0.12 From 307fad7e813770c8f2a6236828b26cd14ddc57aa Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Mon, 27 Jul 2009 13:48:14 +1000 Subject: Make sure we pass through a line number for evaluating bindings. Also, don't convert URL to string each time we call evaluate. --- src/declarative/qml/qmlcompiler.cpp | 1 + src/declarative/qml/qmlexpression.cpp | 4 ++-- src/declarative/qml/qmlexpression_p.h | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp index f0473f5..9c9a7bd 100644 --- a/src/declarative/qml/qmlcompiler.cpp +++ b/src/declarative/qml/qmlcompiler.cpp @@ -2088,6 +2088,7 @@ void QmlCompiler::genBindingAssignment(QmlParser::Value *binding, store.assignBinding.value = dataRef; store.assignBinding.context = ref.bindingContext.stack; store.assignBinding.owner = ref.bindingContext.owner; + store.line = prop->location.end.line; output->bytecode << store; } diff --git a/src/declarative/qml/qmlexpression.cpp b/src/declarative/qml/qmlexpression.cpp index ea0e9aa..e88766c 100644 --- a/src/declarative/qml/qmlexpression.cpp +++ b/src/declarative/qml/qmlexpression.cpp @@ -257,7 +257,7 @@ QVariant QmlExpressionPrivate::evalQtScript() QmlRewrite::RewriteBinding rewriteBinding; const QString code = rewriteBinding(expression); - expressionFunction = scriptEngine->evaluate(code, fileName.toString(), line); + expressionFunction = scriptEngine->evaluate(code, fileName, line); expressionFunctionValid = true; } @@ -421,7 +421,7 @@ void QmlExpression::setTrackChange(bool trackChange) void QmlExpression::setSourceLocation(const QUrl &fileName, int line) { Q_D(QmlExpression); - d->fileName = fileName; + d->fileName = fileName.toString(); d->line = line; } diff --git a/src/declarative/qml/qmlexpression_p.h b/src/declarative/qml/qmlexpression_p.h index 41b7749..a20ead4 100644 --- a/src/declarative/qml/qmlexpression_p.h +++ b/src/declarative/qml/qmlexpression_p.h @@ -83,7 +83,7 @@ public: QObject *me; bool trackChange; - QUrl fileName; + QString fileName; int line; quint32 id; -- cgit v0.12 From 280e573d7881ffb5dd052f3774de3bc7aff3174a Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Mon, 27 Jul 2009 14:46:08 +1000 Subject: Fix layouts a little. Not fully, there are still some issues with the transitions. --- src/declarative/fx/qfxlayouts.cpp | 48 +++++++++++++++++++++++++-------------- src/declarative/fx/qfxlayouts.h | 3 ++- src/declarative/fx/qfxlayouts_p.h | 8 ++++++- 3 files changed, 40 insertions(+), 19 deletions(-) diff --git a/src/declarative/fx/qfxlayouts.cpp b/src/declarative/fx/qfxlayouts.cpp index 3e8a64c..6b94321 100644 --- a/src/declarative/fx/qfxlayouts.cpp +++ b/src/declarative/fx/qfxlayouts.cpp @@ -319,13 +319,15 @@ void QFxBaseLayout::preLayout() if (!d->_items.contains(child)){ QObject::connect(child, SIGNAL(visibleChanged()), this, SLOT(preLayout())); + QObject::connect(child, SIGNAL(opacityChanged()), + this, SLOT(preLayout())); QObject::connect(child, SIGNAL(heightChanged()), this, SLOT(preLayout())); QObject::connect(child, SIGNAL(widthChanged()), this, SLOT(preLayout())); d->_items += child; } - if (!child->isVisible()){ + if (child->opacity() == 0.0){ if (d->_stableItems.contains(child)){ d->_leavingItems += child; d->_stableItems -= child; @@ -339,7 +341,7 @@ void QFxBaseLayout::preLayout() foreach(QFxItem *child, d->_items){ if (!allItems.contains(child)){ if (!deletedItems.contains(child)) { - QObject::disconnect(child, SIGNAL(visibleChanged()), + QObject::disconnect(child, SIGNAL(opacityChanged()), this, SLOT(preLayout())); QObject::disconnect(child, SIGNAL(heightChanged()), this, SLOT(preLayout())); @@ -356,7 +358,7 @@ void QFxBaseLayout::preLayout() qreal width=0; qreal height=0; foreach(QFxItem *item, d->_items){ - if (item->isVisible()){ + if (item->opacity() == 0.0){ if (!d->_animated.contains(item)){ setMovingItem(item); QPointF p(item->x(), item->y()); @@ -385,21 +387,18 @@ void QFxBaseLayout::preLayout() setLayoutItem(0); } -//###This should be considered to move more centrally, as it seems useful -void QFxBaseLayout::applyTransition(const QList >& changes, QFxItem* target, QmlTransition* trans) +void QFxBaseLayout::applyTransition(const QList >& changes, QFxItem* target, QmlStateOperation::ActionList &actions) { Q_D(QFxBaseLayout); - if (!trans||!target)//TODO: if !trans, just apply changes + if (!target) return; setLayoutItem(target); - QmlStateOperation::ActionList actions; - for (int ii=0; ii_margin && - (changes[ii].first == QLatin1String("x") || + (changes[ii].first == QLatin1String("x") || changes[ii].first == QLatin1String("y"))) { val = QVariant(val.toInt() + d->_margin); } @@ -408,10 +407,19 @@ void QFxBaseLayout::applyTransition(const QList >& chan } - d->transitionManager.transition(actions, trans); d->_animated << target; } +void QFxBaseLayout::finishApplyTransitions() +{ + Q_D(QFxBaseLayout); + d->addTransitionManager.transition(d->addActions, d->addTransition); + d->moveTransitionManager.transition(d->moveActions, d->moveTransition); + d->removeTransitionManager.transition(d->removeActions, d->removeTransition); + d->addActions.clear(); + d->moveActions.clear(); + d->removeActions.clear(); +} void QFxBaseLayout::setMovingItem(QFxItem *i) { Q_D(QFxBaseLayout); @@ -424,7 +432,8 @@ void QFxBaseLayout::setMovingItem(QFxItem *i) */ void QFxBaseLayout::applyAdd(const QList >& changes, QFxItem* target) { - applyTransition(changes,target, add()); + Q_D(QFxBaseLayout); + applyTransition(changes,target, d->addActions); } /*! @@ -433,7 +442,8 @@ void QFxBaseLayout::applyAdd(const QList >& changes, QF */ void QFxBaseLayout::applyMove(const QList >& changes, QFxItem* target) { - applyTransition(changes,target, move()); + Q_D(QFxBaseLayout); + applyTransition(changes,target, d->moveActions); } /*! @@ -442,7 +452,8 @@ void QFxBaseLayout::applyMove(const QList >& changes, Q */ void QFxBaseLayout::applyRemove(const QList >& changes, QFxItem* target) { - applyTransition(changes,target, remove()); + Q_D(QFxBaseLayout); + applyTransition(changes,target, d->removeActions); } QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,VerticalLayout,QFxVerticalLayout) @@ -623,7 +634,7 @@ void QFxVerticalLayout::doLayout() QList children = childItems(); for (int ii = 0; ii < children.count(); ++ii) { QFxItem *child = qobject_cast(children.at(ii)); - if (!child || !child->isVisible()) + if (!child || child->opacity() == 0.0) continue; bool needMove = (child->y() != voffset || child->x()); @@ -643,6 +654,7 @@ void QFxVerticalLayout::doLayout() voffset += child->height(); voffset += spacing(); } + finishApplyTransitions(); setMovingItem(this); setHeight(voffset); setMovingItem(0); @@ -790,7 +802,7 @@ void QFxHorizontalLayout::doLayout() QList children = childItems(); for (int ii = 0; ii < children.count(); ++ii) { QFxItem *child = qobject_cast(children.at(ii)); - if (!child || !child->isVisible()) + if (!child || child->opacity() == 0.0) continue; bool needMove = (child->x() != hoffset || child->y()); @@ -810,6 +822,7 @@ void QFxHorizontalLayout::doLayout() hoffset += child->width(); hoffset += spacing(); } + finishApplyTransitions(); setWidth(hoffset); } @@ -1028,7 +1041,7 @@ void QFxGridLayout::doLayout() if (childIndex == children.count()) continue; QFxItem *child = qobject_cast(children.at(childIndex++)); - if (!child || !child->isVisible()) + if (!child || child->opacity() == 0.0) continue; if (child->width() > maxColWidth[j]) maxColWidth[j] = child->width(); @@ -1049,7 +1062,7 @@ void QFxGridLayout::doLayout() } foreach(QGraphicsItem* schild, children){ QFxItem *child = qobject_cast(schild); - if (!child || !child->isVisible()) + if (!child || child->opacity() == 0.0) continue; bool needMove = (child->x()!=xoffset)||(child->y()!=yoffset); QList > changes; @@ -1077,6 +1090,7 @@ void QFxGridLayout::doLayout() return; } } + finishApplyTransitions(); } QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxlayouts.h b/src/declarative/fx/qfxlayouts.h index 5767bc5..03ddf3e 100644 --- a/src/declarative/fx/qfxlayouts.h +++ b/src/declarative/fx/qfxlayouts.h @@ -96,6 +96,7 @@ protected: void applyAdd(const QList >& changes, QFxItem* target); void applyMove(const QList >& changes, QFxItem* target); void applyRemove(const QList >& changes, QFxItem* target); + void finishApplyTransitions(); Q_SIGNALS: void layoutItemChanged(); @@ -113,7 +114,7 @@ protected: private: void applyTransition(const QList >& changes, QFxItem* target, - QmlTransition* transition); + QmlStateOperation::ActionList &actions); Q_DISABLE_COPY(QFxBaseLayout) Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxBaseLayout) }; diff --git a/src/declarative/fx/qfxlayouts_p.h b/src/declarative/fx/qfxlayouts_p.h index 5ffe70e..87b944c 100644 --- a/src/declarative/fx/qfxlayouts_p.h +++ b/src/declarative/fx/qfxlayouts_p.h @@ -59,6 +59,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE class QFxBaseLayoutPrivate : public QFxItemPrivate @@ -92,7 +93,12 @@ public: QSet _newItems; QSet _animated; QFxItem *_layoutItem; - QmlTransitionManager transitionManager; + QmlStateOperation::ActionList addActions; + QmlStateOperation::ActionList moveActions; + QmlStateOperation::ActionList removeActions; + QmlTransitionManager addTransitionManager; + QmlTransitionManager moveTransitionManager; + QmlTransitionManager removeTransitionManager; // QmlStateGroup *stateGroup; QFxItem *_movingItem; }; -- cgit v0.12 From 752a15ca59b1b209aa67c3fbee53868b3a22df80 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Mon, 27 Jul 2009 15:20:37 +1000 Subject: Make private stuff private --- src/declarative/fx/qfxitem.cpp | 5 +- src/declarative/qml/qmlbasicscript.cpp | 2 +- src/declarative/qml/qmlcomponent.cpp | 10 +-- src/declarative/qml/qmlcomponentjs.cpp | 3 +- src/declarative/qml/qmlcompositetypemanager.cpp | 4 +- src/declarative/qml/qmlcontext.cpp | 4 +- src/declarative/qml/qmlengine.cpp | 112 ++++++++++++------------ src/declarative/qml/qmlengine.h | 21 ----- src/declarative/qml/qmlengine_p.h | 16 +++- src/declarative/qml/qmlexpression.cpp | 19 +--- src/declarative/qml/qmlexpression.h | 2 - src/declarative/qml/qmlexpression_p.h | 2 - src/declarative/qml/qmlvme.cpp | 2 +- src/declarative/util/qmlscript.cpp | 4 +- 14 files changed, 90 insertions(+), 116 deletions(-) diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp index 6c6fcd3..247ea53 100644 --- a/src/declarative/fx/qfxitem.cpp +++ b/src/declarative/fx/qfxitem.cpp @@ -49,7 +49,8 @@ #include #include -#include "qmlengine.h" +#include +#include #include "qmlstate.h" #include "qlistmodelinterface.h" #include "qfxanchors_p.h" @@ -819,7 +820,7 @@ void QFxItem::qmlLoaded() QFxItem* ret = qobject_cast(o); if (ret) { ret->setItemParent(this); - QScriptValue v = qmlEngine(this)->scriptEngine()->newQObject(ret); + QScriptValue v = QmlEnginePrivate::getScriptEngine(qmlEngine(this))->newQObject(ret); emit newChildCreated(d->_qmlnewloading.at(i).toString(),v); } diff --git a/src/declarative/qml/qmlbasicscript.cpp b/src/declarative/qml/qmlbasicscript.cpp index 8fcb0e1..b940d61 100644 --- a/src/declarative/qml/qmlbasicscript.cpp +++ b/src/declarative/qml/qmlbasicscript.cpp @@ -656,7 +656,7 @@ QVariant QmlBasicScript::run(QmlContext *context, void *voidCache, CacheState *c return QVariant(); QmlContextPrivate *contextPrivate = context->d_func(); - QmlEnginePrivate *enginePrivate = context->engine()->d_func(); + QmlEnginePrivate *enginePrivate = QmlEnginePrivate::get(context->engine()); QStack stack; diff --git a/src/declarative/qml/qmlcomponent.cpp b/src/declarative/qml/qmlcomponent.cpp index 7dcc373..8fb7736 100644 --- a/src/declarative/qml/qmlcomponent.cpp +++ b/src/declarative/qml/qmlcomponent.cpp @@ -330,7 +330,7 @@ void QmlComponent::setData(const QByteArray &data, const QUrl &url) d->url = url; QmlCompositeTypeData *typeData = - d->engine->d_func()->typeManager.getImmediate(data, url); + QmlEnginePrivate::get(d->engine)->typeManager.getImmediate(data, url); if (typeData->status == QmlCompositeTypeData::Waiting) { @@ -361,7 +361,7 @@ void QmlComponent::loadUrl(const QUrl &url) d->url = url; QmlCompositeTypeData *data = - d->engine->d_func()->typeManager.get(d->url); + QmlEnginePrivate::get(d->engine)->typeManager.get(d->url); if (data->status == QmlCompositeTypeData::Waiting) { @@ -481,8 +481,8 @@ QObject *QmlComponent::beginCreate(QmlContext *context) return 0; } - if (!d->engine->d_func()->rootComponent) - d->engine->d_func()->rootComponent = this; + if (!QmlEnginePrivate::get(d->engine)->rootComponent) + QmlEnginePrivate::get(d->engine)->rootComponent = this; QmlContextPrivate *contextPriv = static_cast(QObjectPrivate::get(context)); @@ -500,7 +500,7 @@ QObject *QmlComponent::beginCreate(QmlContext *context) if (vme.isError()) d->errors = vme.errors(); - QmlEnginePrivate *ep = d->engine->d_func(); + QmlEnginePrivate *ep = QmlEnginePrivate::get(d->engine); if (ep->rootComponent == this) { ep->rootComponent = 0; diff --git a/src/declarative/qml/qmlcomponentjs.cpp b/src/declarative/qml/qmlcomponentjs.cpp index 89f3851..df3e834 100644 --- a/src/declarative/qml/qmlcomponentjs.cpp +++ b/src/declarative/qml/qmlcomponentjs.cpp @@ -41,6 +41,7 @@ #include "qmlcomponentjs_p.h" #include "qmlcomponentjs_p_p.h" +#include "qmlengine_p.h" #include "qmlcomponent.h" QT_BEGIN_NAMESPACE @@ -83,7 +84,7 @@ QScriptValue QmlComponentJS::createObject() { Q_D(QmlComponentJS); QObject* ret = create(d->ctxt); - return QmlEngine::qmlScriptObject(ret, d->engine); + return QmlEnginePrivate::qmlScriptObject(ret, d->engine); } /*! diff --git a/src/declarative/qml/qmlcompositetypemanager.cpp b/src/declarative/qml/qmlcompositetypemanager.cpp index 6f17b70..b0a8642 100644 --- a/src/declarative/qml/qmlcompositetypemanager.cpp +++ b/src/declarative/qml/qmlcompositetypemanager.cpp @@ -247,7 +247,7 @@ void QmlCompositeTypeManager::setData(QmlCompositeTypeData *unit, unit->errors << unit->data.errors(); } else { foreach (QmlScriptParser::Import imp, unit->data.imports()) { - if (!engine->d_func()->addToImport(&unit->imports, imp.uri, imp.qualifier, imp.version, imp.type)) { + if (!QmlEnginePrivate::get(engine)->addToImport(&unit->imports, imp.uri, imp.qualifier, imp.version, imp.type)) { QmlError error; error.setUrl(url); error.setDescription(tr("Import %1 unavailable").arg(imp.uri)); @@ -323,7 +323,7 @@ void QmlCompositeTypeManager::compile(QmlCompositeTypeData *unit) } QUrl url; - if (!engine->d_func()->resolveType(unit->imports, type, &ref.type, &url)) { + if (!QmlEnginePrivate::get(engine)->resolveType(unit->imports, type, &ref.type, &url)) { // XXX could produce error message here. } diff --git a/src/declarative/qml/qmlcontext.cpp b/src/declarative/qml/qmlcontext.cpp index bc2e6bf..dabaa5e 100644 --- a/src/declarative/qml/qmlcontext.cpp +++ b/src/declarative/qml/qmlcontext.cpp @@ -106,9 +106,9 @@ void QmlContextPrivate::init() parent->d_func()->childContexts.insert(q); //set scope chain - QScriptEngine *scriptEngine = engine->scriptEngine(); + QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine); QScriptValue scopeObj = - scriptEngine->newObject(engine->d_func()->contextClass, scriptEngine->newVariant(QVariant::fromValue((QObject*)q))); + scriptEngine->newObject(QmlEnginePrivate::get(engine)->contextClass, scriptEngine->newVariant(QVariant::fromValue((QObject*)q))); if (!parent) scopeChain.append(scriptEngine->globalObject()); else diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index b478618..321feb9 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -94,11 +94,13 @@ struct StaticQtMetaObject : public QObject }; QmlEnginePrivate::QmlEnginePrivate(QmlEngine *e) -: rootContext(0), currentBindContext(0), currentExpression(0), q(e), - isDebugging(false), rootComponent(0), networkAccessManager(0), typeManager(e), +: rootContext(0), currentBindContext(0), currentExpression(0), + isDebugging(false), contextClass(0), objectClass(0), valueTypeClass(0), + scriptEngine(this), rootComponent(0), networkAccessManager(0), typeManager(e), uniqueId(1) { - QScriptValue qtObject = scriptEngine.newQMetaObject(StaticQtMetaObject::get()); + QScriptValue qtObject = + scriptEngine.newQMetaObject(StaticQtMetaObject::get()); scriptEngine.globalObject().setProperty(QLatin1String("Qt"), qtObject); } @@ -146,6 +148,7 @@ Q_GLOBAL_STATIC(QmlEngineDebugServer, qmlEngineDebugServer); void QmlEnginePrivate::init() { + Q_Q(QmlEngine); scriptEngine.installTranslatorFunctions(); contextClass = new QmlContextScriptClass(q); objectClass = new QmlObjectScriptClass(q); @@ -157,13 +160,11 @@ void QmlEnginePrivate::init() debugger->attachTo(&scriptEngine); } #endif - //###needed for the other funcs, but should it be exposed? - scriptEngine.globalObject().setProperty(QLatin1String("qmlEngine"), - scriptEngine.newQObject(q)); + scriptEngine.globalObject().setProperty(QLatin1String("createQmlObject"), - scriptEngine.newFunction(QmlEngine::createQmlObject, 1)); + scriptEngine.newFunction(QmlEnginePrivate::createQmlObject, 1)); scriptEngine.globalObject().setProperty(QLatin1String("createComponent"), - scriptEngine.newFunction(QmlEngine::createComponent, 1)); + scriptEngine.newFunction(QmlEnginePrivate::createComponent, 1)); if (QCoreApplication::instance()->thread() == q->thread() && QmlEngineDebugServer::isDebuggingEnabled()) { @@ -520,11 +521,13 @@ void QmlInstanceDeclarativeData::destroyed(QObject *object) } /*! \internal */ +/* QScriptEngine *QmlEngine::scriptEngine() { Q_D(QmlEngine); return &d->scriptEngine; } +*/ /*! Creates a QScriptValue allowing you to use \a object in QML script. @@ -533,17 +536,12 @@ QScriptEngine *QmlEngine::scriptEngine() The QScriptValue returned is a QtScript Object, not a QtScript QObject, due to the special needs of QML requiring more functionality than a standard QtScript QObject. - - You'll want to use this function if you are writing C++ code which - dynamically creates and returns objects when called from QtScript, - and these objects are visual items in the QML tree. - - \sa QScriptEngine::newQObject() */ -QScriptValue QmlEngine::qmlScriptObject(QObject* object, QmlEngine* engine) +QScriptValue QmlEnginePrivate::qmlScriptObject(QObject* object, + QmlEngine* engine) { - return engine->scriptEngine()->newObject(new QmlObjectScriptClass(engine), - engine->scriptEngine()->newQObject(object)); + QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine); + return scriptEngine->newObject(new QmlObjectScriptClass(engine), scriptEngine->newQObject(object)); } /*! @@ -598,21 +596,23 @@ QScriptValue QmlEngine::qmlScriptObject(QObject* object, QmlEngine* engine) If you want to just create an arbitrary string of QML, instead of loading a qml file, consider the createQmlObject() function. - \sa QmlComponent::createObject(), QmlEngine::createQmlObject() */ -QScriptValue QmlEngine::createComponent(QScriptContext *ctxt, QScriptEngine *engine) +QScriptValue QmlEnginePrivate::createComponent(QScriptContext *ctxt, + QScriptEngine *engine) { QmlComponentJS* c; - QmlEngine* activeEngine = qobject_cast( - engine->globalObject().property(QLatin1String("qmlEngine")).toQObject()); - QmlContext* context =activeEngine->d_func()->currentExpression->context(); - if(ctxt->argumentCount() != 1 || !activeEngine){ + + QmlEnginePrivate *activeEnginePriv = + static_cast(engine)->p; + QmlEngine* activeEngine = activeEnginePriv->q_func(); + + QmlContext* context = activeEnginePriv->currentExpression->context(); + if(ctxt->argumentCount() != 1) { c = new QmlComponentJS(activeEngine); }else{ QUrl url = QUrl(context->resolvedUrl(ctxt->argument(0).toString())); - if(!url.isValid()){ + if(!url.isValid()) url = QUrl(ctxt->argument(0).toString()); - } c = new QmlComponentJS(activeEngine, url, activeEngine); } c->setContext(context); @@ -643,21 +643,15 @@ QScriptValue QmlEngine::createComponent(QScriptContext *ctxt, QScriptEngine *eng instead. 'New components' refers to external QML files that have not yet been loaded, and so it is safe to use createQmlObject to load built-in components. - - \sa QmlEngine::createComponent() */ -QScriptValue QmlEngine::createQmlObject(QScriptContext *ctxt, QScriptEngine *engine) +QScriptValue QmlEnginePrivate::createQmlObject(QScriptContext *ctxt, QScriptEngine *engine) { - QmlEngine* activeEngine = qobject_cast( - engine->globalObject().property(QLatin1String("qmlEngine")).toQObject()); - if(ctxt->argumentCount() < 2 || !activeEngine){ - if(ctxt->argumentCount() < 2){ - qWarning() << "createQmlObject requires two arguments, A QML string followed by an existing QML item id."; - }else{ - qWarning() << "createQmlObject cannot find engine."; - } + QmlEnginePrivate *activeEnginePriv = + static_cast(engine)->p; + QmlEngine* activeEngine = activeEnginePriv->q_func(); + + if(ctxt->argumentCount() < 2) return engine->nullValue(); - } QString qml = ctxt->argument(0).toString(); QUrl url; @@ -669,24 +663,25 @@ QScriptValue QmlEngine::createQmlObject(QScriptContext *ctxt, QScriptEngine *eng QmlComponent component(activeEngine, qml.toUtf8(), url); if(component.isError()) { QList errors = component.errors(); - foreach (const QmlError &error, errors) { - qWarning() <<"Error in createQmlObject(): "<< error; - } + qWarning() <<"QmlEngine::createQmlObject():"; + foreach (const QmlError &error, errors) + qWarning() << " " << error; return engine->nullValue(); } QObject *obj = component.create(qmlCtxt); + if(component.isError()) { QList errors = component.errors(); - foreach (const QmlError &error, errors) { - qWarning() <<"Error in createQmlObject(): "<< error; - } + qWarning() <<"QmlEngine::createQmlObject():"; + foreach (const QmlError &error, errors) + qWarning() << " " << error; return engine->nullValue(); } - if(obj){ + if(obj) { obj->setParent(parentArg); obj->setProperty("parent", QVariant::fromValue(parentArg)); return qmlScriptObject(obj, activeEngine); @@ -695,7 +690,8 @@ QScriptValue QmlEngine::createQmlObject(QScriptContext *ctxt, QScriptEngine *eng } QmlScriptClass::QmlScriptClass(QmlEngine *bindengine) -: QScriptClass(bindengine->scriptEngine()), engine(bindengine) +: QScriptClass(QmlEnginePrivate::getScriptEngine(bindengine)), + engine(bindengine) { } @@ -762,8 +758,7 @@ QmlContextScriptClass::queryProperty(const QScriptValue &object, } for (int ii = 0; !rv && ii < bindContext->d_func()->defaultObjects.count(); ++ii) { - rv = engine->d_func()->queryObject(propName, id, - bindContext->d_func()->defaultObjects.at(ii)); + rv = QmlEnginePrivate::get(engine)->queryObject(propName, id, bindContext->d_func()->defaultObjects.at(ii)); if (rv) *id |= (ii << 24); } @@ -785,7 +780,8 @@ QScriptValue QmlContextScriptClass::property(const QScriptValue &object, uint basicId = id & QmlScriptClass::ClassIdMask; - QScriptEngine *scriptEngine = engine->scriptEngine(); + QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine); + QmlEnginePrivate *ep = QmlEnginePrivate::get(engine); switch (basicId) { case VariantPropertyId: @@ -799,18 +795,18 @@ QScriptValue QmlContextScriptClass::property(const QScriptValue &object, #endif QScriptValue rv; if (QmlMetaType::isObject(value.userType())) { - rv = scriptEngine->newObject(engine->d_func()->objectClass, scriptEngine->newVariant(value)); + rv = scriptEngine->newObject(ep->objectClass, scriptEngine->newVariant(value)); } else { rv = scriptEngine->newVariant(value); } - engine->d_func()->capturedProperties << QmlEnginePrivate::CapturedProperty(bindContext, -1, index + bindContext->d_func()->notifyIndex); + ep->capturedProperties << QmlEnginePrivate::CapturedProperty(bindContext, -1, index + bindContext->d_func()->notifyIndex); return rv; } default: { int objId = (id & ClassIdSelectorMask) >> 24; QObject *obj = bindContext->d_func()->defaultObjects.at(objId); - QScriptValue rv = engine->d_func()->propertyObject(name, obj, + QScriptValue rv = ep->propertyObject(name, obj, id & ~QmlScriptClass::ClassIdSelectorMask); if (rv.isValid()) { #ifdef PROPERTY_DEBUG @@ -844,7 +840,7 @@ void QmlContextScriptClass::setProperty(QScriptValue &object, int objIdx = (id & QmlScriptClass::ClassIdSelectorMask) >> 24; QObject *obj = bindContext->d_func()->defaultObjects.at(objIdx); - QScriptEngine *scriptEngine = engine->scriptEngine(); + QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine); QScriptValue oldact = scriptEngine->currentContext()->activationObject(); scriptEngine->currentContext()->setActivationObject(scriptEngine->globalObject()); @@ -952,9 +948,10 @@ QmlObjectScriptClass::QmlObjectScriptClass(QmlEngine *bindEngine) : QmlScriptClass(bindEngine) { engine = bindEngine; - prototypeObject = engine->scriptEngine()->newObject(); + QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(bindEngine); + prototypeObject = scriptEngine->newObject(); prototypeObject.setProperty(QLatin1String("destroy"), - engine->scriptEngine()->newFunction(QmlObjectDestroy)); + scriptEngine->newFunction(QmlObjectDestroy)); } QmlObjectScriptClass::~QmlObjectScriptClass() @@ -980,7 +977,7 @@ QScriptClass::QueryFlags QmlObjectScriptClass::queryProperty(const QScriptValue #endif if (obj) - rv = engine->d_func()->queryObject(propName, id, obj); + rv = QmlEnginePrivate::get(engine)->queryObject(propName, id, obj); return rv; } @@ -996,7 +993,8 @@ QScriptValue QmlObjectScriptClass::property(const QScriptValue &object, qWarning() << "QmlObject Property:" << propName << obj; #endif - QScriptValue rv = engine->d_func()->propertyObject(name, obj, id); + QScriptValue rv = + QmlEnginePrivate::get(engine)->propertyObject(name, obj, id); if (rv.isValid()) { #ifdef PROPERTY_DEBUG qWarning() << "~Property: Resolved property" << propName @@ -1022,7 +1020,7 @@ void QmlObjectScriptClass::setProperty(QScriptValue &object, qWarning() << "Set QmlObject Property" << name.toString() << value.toVariant(); #endif - QScriptEngine *scriptEngine = engine->scriptEngine(); + QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine); QScriptValue oldact = scriptEngine->currentContext()->activationObject(); scriptEngine->currentContext()->setActivationObject(scriptEngine->globalObject()); diff --git a/src/declarative/qml/qmlengine.h b/src/declarative/qml/qmlengine.h index 2faad66..6066059 100644 --- a/src/declarative/qml/qmlengine.h +++ b/src/declarative/qml/qmlengine.h @@ -86,28 +86,7 @@ public: static QmlContext *contextForObject(const QObject *); static void setContextForObject(QObject *, QmlContext *); - static QScriptValue qmlScriptObject(QObject*, QmlEngine*); - - static QScriptValue createComponent(QScriptContext*, QScriptEngine*); - static QScriptValue createQmlObject(QScriptContext*, QScriptEngine*); - private: - // LK: move to the private class - QScriptEngine *scriptEngine(); - friend class QFxItem; // XXX - friend class QmlScriptPrivate; - friend class QmlCompositeTypeManager; - friend class QmlCompiler; - friend class QmlScriptClass; - friend class QmlContext; - friend class QmlContextPrivate; - friend class QmlExpression; - friend class QmlExpressionPrivate; - friend class QmlBasicScript; - friend class QmlVME; - friend class QmlComponent; - friend class QmlContextScriptClass; //### - friend class QmlObjectScriptClass; //### Q_DECLARE_PRIVATE(QmlEngine) }; diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h index b8d49aa..18cdd83 100644 --- a/src/declarative/qml/qmlengine_p.h +++ b/src/declarative/qml/qmlengine_p.h @@ -114,7 +114,6 @@ public: QmlContext *rootContext; QmlContext *currentBindContext; QmlExpression *currentExpression; - QmlEngine *q; bool isDebugging; #ifdef QT_SCRIPTTOOLS_LIB QScriptEngineDebugger *debugger; @@ -127,7 +126,13 @@ public: QmlContext *setCurrentBindContext(QmlContext *); QStack activeContexts; - QScriptEngine scriptEngine; + struct QmlScriptEngine : public QScriptEngine + { + QmlScriptEngine(QmlEnginePrivate *priv) + : p(priv) {} + QmlEnginePrivate *p; + }; + QmlScriptEngine scriptEngine; QUrl baseUrl; @@ -188,6 +193,13 @@ public: bool resolveType(const Imports&, const QByteArray& type, QmlType** type_return, QUrl* url_return, ImportedNamespace** ns_return=0) const; void resolveTypeInNamespace(ImportedNamespace*, const QByteArray& type, QmlType** type_return, QUrl* url_return ) const; + + static QScriptValue qmlScriptObject(QObject*, QmlEngine*); + static QScriptValue createComponent(QScriptContext*, QScriptEngine*); + static QScriptValue createQmlObject(QScriptContext*, QScriptEngine*); + + static QScriptEngine *getScriptEngine(QmlEngine *e) { return &e->d_func()->scriptEngine; } + static QmlEnginePrivate *get(QmlEngine *e) { return e->d_func(); } }; class QmlScriptClass : public QScriptClass diff --git a/src/declarative/qml/qmlexpression.cpp b/src/declarative/qml/qmlexpression.cpp index ea0e9aa..7394004 100644 --- a/src/declarative/qml/qmlexpression.cpp +++ b/src/declarative/qml/qmlexpression.cpp @@ -51,7 +51,7 @@ Q_DECLARE_METATYPE(QList); QT_BEGIN_NAMESPACE QmlExpressionPrivate::QmlExpressionPrivate() -: ctxt(0), expressionFunctionValid(false), sseData(0), me(0), trackChange(true), line(-1), id(0), guardList(0), guardListLength(0) +: ctxt(0), expressionFunctionValid(false), sseData(0), me(0), trackChange(true), line(-1), guardList(0), guardListLength(0) { } @@ -63,8 +63,6 @@ void QmlExpressionPrivate::init(QmlContext *ctxt, const QString &expr, expression = expr; this->ctxt = ctxt; - if (ctxt && ctxt->engine()) - id = ctxt->engine()->d_func()->getUniqueId(); if (ctxt) ctxt->d_func()->childExpressions.insert(q); this->me = me; @@ -78,8 +76,6 @@ void QmlExpressionPrivate::init(QmlContext *ctxt, void *expr, QmlRefCount *rc, sse.load((const char *)expr, rc); this->ctxt = ctxt; - if (ctxt && ctxt->engine()) - id = ctxt->engine()->d_func()->getUniqueId(); if (ctxt) ctxt->d_func()->childExpressions.insert(q); this->me = me; @@ -244,7 +240,7 @@ QVariant QmlExpressionPrivate::evalQtScript() if (me) ctxtPriv->defaultObjects.insert(ctxtPriv->highPriorityCount, me); - QScriptEngine *scriptEngine = engine->scriptEngine(); + QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine); QScriptValueList oldScopeChain = scriptEngine->currentContext()->scopeChain(); @@ -346,7 +342,7 @@ QVariant QmlExpression::value() QmlBasicScript::CacheState cacheState = QmlBasicScript::Reset; - QmlEnginePrivate *ep = engine()->d_func(); + QmlEnginePrivate *ep = QmlEnginePrivate::get(engine()); QmlExpression *lastCurrentExpression = ep->currentExpression; QPODVector lastCapturedProperties; @@ -437,15 +433,6 @@ QObject *QmlExpression::scopeObject() const return d->me; } -/*! - \internal -*/ -quint32 QmlExpression::id() const -{ - Q_D(const QmlExpression); - return d->id; -} - /*! \internal */ void QmlExpression::__q_notify() { diff --git a/src/declarative/qml/qmlexpression.h b/src/declarative/qml/qmlexpression.h index 6db6ef9..d5f0cbb 100644 --- a/src/declarative/qml/qmlexpression.h +++ b/src/declarative/qml/qmlexpression.h @@ -80,8 +80,6 @@ public: QObject *scopeObject() const; - quint32 id() const; - public Q_SLOTS: QVariant value(); diff --git a/src/declarative/qml/qmlexpression_p.h b/src/declarative/qml/qmlexpression_p.h index 41b7749..7f086c2 100644 --- a/src/declarative/qml/qmlexpression_p.h +++ b/src/declarative/qml/qmlexpression_p.h @@ -86,8 +86,6 @@ public: QUrl fileName; int line; - quint32 id; - QVariant evalSSE(QmlBasicScript::CacheState &cacheState); QVariant evalQtScript(); diff --git a/src/declarative/qml/qmlvme.cpp b/src/declarative/qml/qmlvme.cpp index ebf0a73..1cfd5e9 100644 --- a/src/declarative/qml/qmlvme.cpp +++ b/src/declarative/qml/qmlvme.cpp @@ -143,7 +143,7 @@ QObject *QmlVME::run(QStack &stack, QmlContext *ctxt, QmlCompiledData QStack qliststack; vmeErrors.clear(); - QmlEnginePrivate *ep = ctxt->engine()->d_func(); + QmlEnginePrivate *ep = QmlEnginePrivate::get(ctxt->engine()); for (int ii = start; !isError() && ii < (start + count); ++ii) { QmlInstruction &instr = comp->bytecode[ii]; diff --git a/src/declarative/util/qmlscript.cpp b/src/declarative/util/qmlscript.cpp index cfe5a1e..ca9aad5 100644 --- a/src/declarative/util/qmlscript.cpp +++ b/src/declarative/util/qmlscript.cpp @@ -185,9 +185,9 @@ void QmlScriptPrivate::addScriptToEngine(const QString &script, const QString &s Q_Q(QmlScript); QmlEngine *engine = qmlEngine(q); QmlContext *context = qmlContext(q); - QScriptEngine *scriptEngine = engine->scriptEngine(); + QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine); - QScriptContext *currentContext = engine->scriptEngine()->currentContext(); + QScriptContext *currentContext = scriptEngine->currentContext(); QScriptValueList oldScopeChain = currentContext->scopeChain(); QScriptValue oldact = currentContext->activationObject(); -- cgit v0.12 From 5cddf5630ff0e408a84c19b7bb5ebc36871fa025 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Mon, 27 Jul 2009 15:22:45 +1000 Subject: Add a glowy effect like KSame to SameGame Just want this in the repo, samegame is about to be majorly revised. --- demos/declarative/samegame/content/BoomBlock.qml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/demos/declarative/samegame/content/BoomBlock.qml b/demos/declarative/samegame/content/BoomBlock.qml index 9637bd6..ec4430e 100644 --- a/demos/declarative/samegame/content/BoomBlock.qml +++ b/demos/declarative/samegame/content/BoomBlock.qml @@ -11,9 +11,17 @@ Item { id:block x: Follow { enabled: spawned; source: targetX; spring: 2; damping: 0.2 } y: Follow { source: targetY; spring: 2; damping: 0.2 } + //TODO: Replace with an image with a fuzzy effect like KSame + Rect { id: shine; radius:16; anchors.fill:parent; color: "yellow"; + opacity: 0 + opacity: SequentialAnimation{running: selected&&!dying; finishPlaying: true; repeat: true + NumberAnimation{ from: 0; to: 1; }NumberAnimation{ from:1; to:0; }} + } MouseRegion { id: gameMR; anchors.fill: parent onClicked: handleClick(Math.floor(parent.x/width), Math.floor(parent.y/height)); + onEntered: handleHover(Math.floor(parent.x/width), Math.floor(parent.y/height)); + onExited: handleHover(-1,-1); } Image { id: img -- cgit v0.12 From 1a5338d8cc96cd07d2340aa2aff5880fd2fdce68 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Mon, 27 Jul 2009 16:39:56 +1000 Subject: Repurpose SameGame to be slimmer No theming and no selected, plus some cleanup. --- demos/declarative/samegame/README | 2 - demos/declarative/samegame/SameGame.qml | 46 ++++----- demos/declarative/samegame/TODO | 2 - demos/declarative/samegame/content/BoomBlock.qml | 15 --- demos/declarative/samegame/content/FastBlock.qml | 33 ------ demos/declarative/samegame/content/MediaButton.qml | 41 -------- demos/declarative/samegame/content/SameDialog.qml | 19 ---- demos/declarative/samegame/content/SpinBlock.qml | 47 --------- .../samegame/content/pics/button-pressed.png | Bin 571 -> 0 bytes demos/declarative/samegame/content/pics/button.png | Bin 564 -> 0 bytes .../samegame/content/pics/gnome/blueStone.gif | Bin 19122 -> 0 bytes .../samegame/content/pics/gnome/greenStone.gif | Bin 20545 -> 0 bytes .../samegame/content/pics/gnome/redStone.gif | Bin 18455 -> 0 bytes demos/declarative/samegame/content/pics/qtlogo.png | Bin 2738 -> 0 bytes demos/declarative/samegame/content/samegame.js | 111 ++++----------------- 15 files changed, 42 insertions(+), 274 deletions(-) delete mode 100644 demos/declarative/samegame/TODO delete mode 100644 demos/declarative/samegame/content/FastBlock.qml delete mode 100644 demos/declarative/samegame/content/MediaButton.qml delete mode 100644 demos/declarative/samegame/content/SameDialog.qml delete mode 100644 demos/declarative/samegame/content/SpinBlock.qml delete mode 100644 demos/declarative/samegame/content/pics/button-pressed.png delete mode 100644 demos/declarative/samegame/content/pics/button.png delete mode 100644 demos/declarative/samegame/content/pics/gnome/blueStone.gif delete mode 100644 demos/declarative/samegame/content/pics/gnome/greenStone.gif delete mode 100644 demos/declarative/samegame/content/pics/gnome/redStone.gif delete mode 100644 demos/declarative/samegame/content/pics/qtlogo.png diff --git a/demos/declarative/samegame/README b/demos/declarative/samegame/README index 2f2a728..244b205 100644 --- a/demos/declarative/samegame/README +++ b/demos/declarative/samegame/README @@ -8,5 +8,3 @@ greenStone.png yellowStone.png and are presumably under the same GPL2 license as the rest of kdegames - -The images in the pics/gnome folder are from the gnome games project, and are also GPL2 licensed. diff --git a/demos/declarative/samegame/SameGame.qml b/demos/declarative/samegame/SameGame.qml index e2c2089..1788341 100644 --- a/demos/declarative/samegame/SameGame.qml +++ b/demos/declarative/samegame/SameGame.qml @@ -3,38 +3,38 @@ import Qt 4.6 import "content" Rect { - width: 460 - height: 700 - color: activePalette.window + id: page; width: 460; height: 700; color: activePalette.window Script { source: "content/samegame.js" } - Rect{ + Rect { + id: gameCanvas property int score: 0 - y:20; width:400; height:600; id: gameCanvas; - //For Fixed Size + z:20; y:20; width:400; height:600; color: "white"; pen.width: 1 anchors.horizontalCenter: parent.horizontalCenter - //For flexible width - //anchors.left: parent.left; anchors.leftMargin: 30 - //anchors.right: parent.right; anchors.rightMargin: 30 - color: "white" - pen.width: 1 Image { id:background; source: "content/pics/background.png" anchors.fill: parent } + MouseRegion { id: gameMR + anchors.fill: parent; onClicked: handleClick(mouse.x,mouse.y); + } + } + Dialog { id: dialog; anchors.centeredIn: parent; z: 21} + Button { + id: btnA; text: "New Game"; onClicked: {initBoard();} + anchors.top: gameCanvas.bottom; anchors.topMargin: 4; anchors.left: gameCanvas.left; } - HorizontalLayout { - anchors.top: gameCanvas.bottom - anchors.topMargin: 10 - anchors.horizontalCenter: parent.horizontalCenter - MediaButton { id: btnA; text: "New Game"; onClicked: {initBoard();} } - MediaButton { id: btnB; text: "Swap Tiles"; onClicked: {swapTileSrc(); dialog.opacity = 1; - dialog.text="Takes effect next game.";} } - Text{ text: "Score: " + gameCanvas.score; width:120; font.size:14 } + Text { + text: "Score: " + gameCanvas.score; width:100; font.size:14 + anchors.top: gameCanvas.bottom; anchors.topMargin: 4; anchors.right: gameCanvas.right; } - SameDialog { - id: dialog - anchors.centeredIn: parent - text: "Hello World" + Text { + text: "Just over 300 lines of QML/JS code!" + anchors.horizontalCenter: parent.horizontalCenter + anchors.bottom: parent.bottom; anchors.bottomMargin: 16; + opacity: SequentialAnimation{ running: true; repeat: true; + NumberAnimation { from: 0; to: 1; duration: 1000; easing: "easeInQuad" } + NumberAnimation { from: 1; to: 0; duration: 1000; easing: "easeInQuad" } + } } } diff --git a/demos/declarative/samegame/TODO b/demos/declarative/samegame/TODO deleted file mode 100644 index 3be2a3a..0000000 --- a/demos/declarative/samegame/TODO +++ /dev/null @@ -1,2 +0,0 @@ -Still to do: - diff --git a/demos/declarative/samegame/content/BoomBlock.qml b/demos/declarative/samegame/content/BoomBlock.qml index ec4430e..a4f4fe9 100644 --- a/demos/declarative/samegame/content/BoomBlock.qml +++ b/demos/declarative/samegame/content/BoomBlock.qml @@ -3,7 +3,6 @@ import Qt 4.6 Item { id:block property bool dying: false property bool spawned: false - property bool selected: false property int type: 0 property int targetX: 0 property int targetY: 0 @@ -11,19 +10,6 @@ Item { id:block x: Follow { enabled: spawned; source: targetX; spring: 2; damping: 0.2 } y: Follow { source: targetY; spring: 2; damping: 0.2 } - //TODO: Replace with an image with a fuzzy effect like KSame - Rect { id: shine; radius:16; anchors.fill:parent; color: "yellow"; - opacity: 0 - opacity: SequentialAnimation{running: selected&&!dying; finishPlaying: true; repeat: true - NumberAnimation{ from: 0; to: 1; }NumberAnimation{ from:1; to:0; }} - } - MouseRegion { - id: gameMR; anchors.fill: parent - onClicked: handleClick(Math.floor(parent.x/width), Math.floor(parent.y/height)); - onEntered: handleHover(Math.floor(parent.x/width), Math.floor(parent.y/height)); - onExited: handleHover(-1,-1); - } - Image { id: img source: { if(type == 0){ @@ -55,7 +41,6 @@ Item { id:block } states: [ - State{ name: "AliveState"; when: spawned == true && dying == false SetProperties { target: img; opacity: 1 } }, diff --git a/demos/declarative/samegame/content/FastBlock.qml b/demos/declarative/samegame/content/FastBlock.qml deleted file mode 100644 index f30d8da..0000000 --- a/demos/declarative/samegame/content/FastBlock.qml +++ /dev/null @@ -1,33 +0,0 @@ -import Qt 4.6 - -Rect { id:block - //Note: These properties are the interface used to control the blocks - property bool dying: false - property bool spawned: false - property bool selected: false - property int type: 0 - property int targetY: 0 - property int targetX: 0 - - color: {if(type==0){"red";}else if(type==1){"blue";}else{"green";}} - pen.width: 1 - pen.color: "black" - opacity: 0 - y: targetY - x: targetX - - MouseRegion { - id: gameMR; anchors.fill: parent - onClicked: handleClick(Math.floor(parent.x/width), Math.floor(parent.y/height)); - } - - states: [ - - State{ name: "AliveState"; when: spawned == true && dying == false - SetProperties { target: block; opacity: 1 } - }, - State{ name: "DeathState"; when: dying == true - SetProperties { target: block; opacity: 0 } - } - ] -} diff --git a/demos/declarative/samegame/content/MediaButton.qml b/demos/declarative/samegame/content/MediaButton.qml deleted file mode 100644 index cbe4265..0000000 --- a/demos/declarative/samegame/content/MediaButton.qml +++ /dev/null @@ -1,41 +0,0 @@ -import Qt 4.6 - -Item { - id: Container - - signal clicked - - property string text - - Image { - id: Image - source: "pics/button.png" - } - Image { - id: Pressed - source: "pics/button-pressed.png" - opacity: 0 - } - MouseRegion { - id: MouseRegion - anchors.fill: Image - onClicked: { Container.clicked(); } - } - Text { - font.bold: true - color: "white" - anchors.centeredIn: Image - text: Container.text - } - width: Image.width - states: [ - State { - name: "Pressed" - when: MouseRegion.pressed == true - SetProperties { - target: Pressed - opacity: 1 - } - } - ] -} diff --git a/demos/declarative/samegame/content/SameDialog.qml b/demos/declarative/samegame/content/SameDialog.qml deleted file mode 100644 index 86248a6..0000000 --- a/demos/declarative/samegame/content/SameDialog.qml +++ /dev/null @@ -1,19 +0,0 @@ -import Qt 4.6 - -Rect { - property string text: "Hello World!" - property int show: 0 - id: page - opacity: 0 - opacity: Behavior { - SequentialAnimation { - NumberAnimation {property: "opacity"; duration: 1500 } - NumberAnimation {property: "opacity"; to: 0; duration: 1500 } - } - } - color: "white" - pen.width: 1 - width: 200 - height: 60 - Text { anchors.centeredIn: parent; text: parent.text } -} diff --git a/demos/declarative/samegame/content/SpinBlock.qml b/demos/declarative/samegame/content/SpinBlock.qml deleted file mode 100644 index 4c8f123..0000000 --- a/demos/declarative/samegame/content/SpinBlock.qml +++ /dev/null @@ -1,47 +0,0 @@ -import Qt 4.6 - -Item { id:block - //Note: These properties are the interface used to control the blocks - property bool dying: false - property bool spawned: false - property bool selected: false - property int type: 0 - property int targetY: 0 - property int targetX: 0 - - AnimatedImage { - source: if(type == 0) { - "pics/gnome/redStone.gif"; - } else if (type == 1) { - "pics/gnome/blueStone.gif"; - } else { - "pics/gnome/greenStone.gif"; - } - paused: !selected - paused: Behavior { to: true; from: false; - NumberAnimation { properties:"currentFrame"; to:0; duration: 200} - } - } - opacity: 0 - y: targetY - x: targetX - y: Behavior { NumberAnimation { properties:"y"; duration: 200 } } - x: Behavior { NumberAnimation { properties:"x"; duration: 200 } } - opacity: Behavior { NumberAnimation { properties:"opacity"; duration: 200 } } - MouseRegion { - id: gameMR; anchors.fill: parent - onClicked: handleClick(Math.floor(parent.x/width), Math.floor(parent.y/height)); - onEntered: handleHover(Math.floor(parent.x/width), Math.floor(parent.y/height)); - onExited: handleHover(Math.floor(parent.x/width), Math.floor(parent.y/height)); - } - - states: [ - - State{ name: "AliveState"; when: spawned == true && dying == false - SetProperties { target: block; opacity: 1 } - }, - State{ name: "DeathState"; when: dying == true - SetProperties { target: block; opacity: 0 } - } - ] -} diff --git a/demos/declarative/samegame/content/pics/button-pressed.png b/demos/declarative/samegame/content/pics/button-pressed.png deleted file mode 100644 index e434d32..0000000 Binary files a/demos/declarative/samegame/content/pics/button-pressed.png and /dev/null differ diff --git a/demos/declarative/samegame/content/pics/button.png b/demos/declarative/samegame/content/pics/button.png deleted file mode 100644 index 56a63ce..0000000 Binary files a/demos/declarative/samegame/content/pics/button.png and /dev/null differ diff --git a/demos/declarative/samegame/content/pics/gnome/blueStone.gif b/demos/declarative/samegame/content/pics/gnome/blueStone.gif deleted file mode 100644 index 333efbe..0000000 Binary files a/demos/declarative/samegame/content/pics/gnome/blueStone.gif and /dev/null differ diff --git a/demos/declarative/samegame/content/pics/gnome/greenStone.gif b/demos/declarative/samegame/content/pics/gnome/greenStone.gif deleted file mode 100644 index 1bc5bf4..0000000 Binary files a/demos/declarative/samegame/content/pics/gnome/greenStone.gif and /dev/null differ diff --git a/demos/declarative/samegame/content/pics/gnome/redStone.gif b/demos/declarative/samegame/content/pics/gnome/redStone.gif deleted file mode 100644 index b80f901..0000000 Binary files a/demos/declarative/samegame/content/pics/gnome/redStone.gif and /dev/null differ diff --git a/demos/declarative/samegame/content/pics/qtlogo.png b/demos/declarative/samegame/content/pics/qtlogo.png deleted file mode 100644 index 399bd0b..0000000 Binary files a/demos/declarative/samegame/content/pics/qtlogo.png and /dev/null differ diff --git a/demos/declarative/samegame/content/samegame.js b/demos/declarative/samegame/content/samegame.js index ef32230..a7dd82b 100755 --- a/demos/declarative/samegame/content/samegame.js +++ b/demos/declarative/samegame/content/samegame.js @@ -1,5 +1,4 @@ /* This script file handles the game logic */ - //Note that X/Y referred to here are in game coordinates var maxX = 10;//Nums are for tileSize 40 var maxY = 15; @@ -7,19 +6,8 @@ var tileSize = 40; var maxIndex = maxX*maxY; var board = new Array(maxIndex); var tileSrc = "content/BoomBlock.qml"; -var swapped = false; - -var compSrc; var component; -function swapTileSrc(){ - if(tileSrc == "content/SpinBlock.qml"){ - tileSrc = "content/BoomBlock.qml"; - }else{ - tileSrc = "content/SpinBlock.qml"; - } -} - //Index function used instead of a 2D array function index(xIdx,yIdx){ return xIdx + (yIdx * maxX); @@ -33,11 +21,6 @@ function initBoard() board[i].destroy(); } - //Game size is as many rows/cols fit in the GameCanvas - maxX = Math.floor(gameCanvas.width/tileSize); - maxY = Math.floor(gameCanvas.height/tileSize); - maxIndex = maxX*maxY; - //Initialize Board board = new Array(maxIndex); gameCanvas.score = 0; @@ -47,43 +30,21 @@ function initBoard() startCreatingBlock(xIdx,yIdx); } } - //TODO: a flag that handleMouse uses to ignore clicks when we're loading } var fillFound;//Set after a floodFill call to the number of tiles found -var floodBoard;//Set to 1 if the floodFill ticks off that node (mostly used by floodFill) - -var lastHoveredIdx = -2 -function handleHover(xIdx,yIdx, btn) -{ - //Turn UI x,y into Game x,y - if(index(xIdx, yIdx) == lastHoveredIdx) - return; - //if(btn != 0) - // return; - //Sets 'selected' on tile underneath and all connected - floodFill(xIdx, yIdx, -1, "hover"); - //Could use the fillFound value to tell the player how many stones/points - - //Resets any previously selected - if(board[lastHoveredIdx] != null){ - lastX = lastHoveredIdx % maxX; - lastY = Math.floor(lastHoveredIdx / maxX); - floodFill(lastX, lastY, -1, "unhover"); - } - lastHoveredIdx = index(xIdx, yIdx); -} - +var floodBoard;//Set to 1 if the floodFill reaches off that node //NOTE: Be careful with vars named x,y, as the calling object's x,y are still in scope -function handleClick(xIdx,yIdx) +function handleClick(x,y) { + xIdx = Math.floor(x/tileSize); + yIdx = Math.floor(y/tileSize); if(xIdx >= maxX || xIdx < 0 || yIdx >= maxY || yIdx < 0) return; if(board[index(xIdx, yIdx)] == null) return; - //If it's a valid tile, remove it and all connected - //floodFill does nothing if it's not connected to any other tiles. - floodFill(xIdx,yIdx, -1, "kill"); + //If it's a valid tile, remove it and all connected (does nothing if it's not connected) + floodFill(xIdx,yIdx, -1); if(fillFound <= 0) return; gameCanvas.score += (fillFound - 1) * (fillFound - 1); @@ -91,18 +52,7 @@ function handleClick(xIdx,yIdx) victoryCheck(); } -/* - the floodFill function does something on all tiles connected to the - given Game position. Connected requires the adjacency of one or more - tiles of the same type. Note that if there is no tile, or the tile - is not adjacent to a similar typed tile, then it will not do anything. - - Since many things need this flood functionality, a string command is - given telling it what to do with these tiles. - - cmd = "kill" is the removal case, cmd = "hover" sets selection -*/ -function floodFill(xIdx,yIdx,type, cmd) +function floodFill(xIdx,yIdx,type) { if(board[index(xIdx, yIdx)] == null) return; @@ -117,29 +67,17 @@ function floodFill(xIdx,yIdx,type, cmd) } if(xIdx >= maxX || xIdx < 0 || yIdx >= maxY || yIdx < 0) return; - if(floodBoard[index(xIdx, yIdx)] == 1) + if(floodBoard[index(xIdx, yIdx)] == 1 || (!first && type != board[index(xIdx,yIdx)].type)) return; - if(!first && type != board[index(xIdx,yIdx)].type) - return; floodBoard[index(xIdx, yIdx)] = 1; - floodFill(xIdx+1,yIdx,type,cmd); - floodFill(xIdx-1,yIdx,type,cmd); - floodFill(xIdx,yIdx+1,type,cmd); - floodFill(xIdx,yIdx-1,type,cmd); - if(first==true && fillFound == 0){ - //TODO: Provide a way to inform the delegate + floodFill(xIdx+1,yIdx,type); + floodFill(xIdx-1,yIdx,type); + floodFill(xIdx,yIdx+1,type); + floodFill(xIdx,yIdx-1,type); + if(first==true && fillFound == 0) return;//Can't remove single tiles - } - if(cmd == "kill"){ - board[index(xIdx,yIdx)].dying = true; - board[index(xIdx,yIdx)] = null; - }else if(cmd == "hover"){ - board[index(xIdx,yIdx)].selected = true; - }else if(cmd == "unhover"){ - board[index(xIdx,yIdx)].selected = false; - }else{ - print ("Flood Error"); - } + board[index(xIdx,yIdx)].dying = true; + board[index(xIdx,yIdx)] = null; fillFound += 1; } @@ -191,17 +129,12 @@ function victoryCheck() if(deservesBonus) gameCanvas.score += 500; //Checks for game over - if(deservesBonus || noMoreMoves()){ + if(deservesBonus || !(floodMoveCheck(0,maxY-1, -1))){ dialog.text = "Game Over. Your score is " + gameCanvas.score; dialog.opacity = 1; } } -function noMoreMoves() -{ - return !floodMoveCheck(0, maxY-1, -1); -} - //only floods up and right, to see if it can find adjacent same-typed tiles function floodMoveCheck(xIdx, yIdx, type) { @@ -212,15 +145,13 @@ function floodMoveCheck(xIdx, yIdx, type) myType = board[index(xIdx, yIdx)].type; if(type == myType) return true; - aT = myType; - bT = myType; - return floodMoveCheck(xIdx + 1, yIdx, aT) || floodMoveCheck(xIdx, yIdx - 1, bT); + return floodMoveCheck(xIdx + 1, yIdx, myType) || + floodMoveCheck(xIdx, yIdx - 1, board[index(xIdx,yIdx)].type); } //If the component isn't ready, then the signal doesn't include the game x,y //So we store any x,y sent that we couldn't create at the time, and use those //if we are triggered by the signal. -//Need a simpler method of doing this? var waitStack = new Array(maxIndex); var waitTop = -1; @@ -263,15 +194,11 @@ function finishCreatingBlock(xIdx,yIdx){ } function startCreatingBlock(xIdx,yIdx){ - if(component!=null && compSrc == tileSrc){ + if(component!=null){ finishCreatingBlock(xIdx,yIdx); return; } - if(component!=null){//Changed source - //delete component; //Does the engine handle this? - compSrc = tileSrc; - } component = createComponent(tileSrc); if(finishCreatingBlock(xIdx,yIdx)) return; -- cgit v0.12 From 2ea4aec304eefa10a554e40c5f9ea948d18617a7 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Mon, 27 Jul 2009 17:07:43 +1000 Subject: Don't crash in Horizontal orientation. --- src/declarative/fx/qfxlistview.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/declarative/fx/qfxlistview.cpp b/src/declarative/fx/qfxlistview.cpp index db80967..f300d1e 100644 --- a/src/declarative/fx/qfxlistview.cpp +++ b/src/declarative/fx/qfxlistview.cpp @@ -808,9 +808,11 @@ void QFxListViewPrivate::fixupX() if (orient == Qt::Vertical) return; if (currItemMode == QFxListView::SnapAuto) { - moveReason = Mouse; - _tl.clear(); - _tl.move(_moveX, -(currentItem->position() - snapPos), QEasingCurve(QEasingCurve::InOutQuad), 200); + if (currentItem) { + moveReason = Mouse; + _tl.clear(); + _tl.move(_moveX, -(currentItem->position() - snapPos), QEasingCurve(QEasingCurve::InOutQuad), 200); + } } else if (currItemMode == QFxListView::Snap) { moveReason = Mouse; int idx = snapIndex(); -- cgit v0.12 From fd27c5ac9670b56ccd60e8d8f6791237358f3633 Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Mon, 27 Jul 2009 15:52:42 +0200 Subject: removing Q_CORE_EXPORT for q_guard_addGuard() and q_guard_removeGuard() I made the functions inline instead and moved them to qobject_p.h Reviewed-by: Aaron Kennedy --- src/corelib/kernel/kernel.pri | 1 - src/corelib/kernel/qguard.cpp | 27 --------------------------- src/corelib/kernel/qguard_p.h | 3 +-- src/corelib/kernel/qobject_p.h | 24 ++++++++++++++++++++++++ 4 files changed, 25 insertions(+), 30 deletions(-) delete mode 100644 src/corelib/kernel/qguard.cpp diff --git a/src/corelib/kernel/kernel.pri b/src/corelib/kernel/kernel.pri index d71a22a..53b8b69 100644 --- a/src/corelib/kernel/kernel.pri +++ b/src/corelib/kernel/kernel.pri @@ -58,7 +58,6 @@ SOURCES += \ kernel/qsystemsemaphore.cpp \ kernel/qmetaobjectbuilder.cpp \ kernel/qpointer.cpp \ - kernel/qguard.cpp win32 { SOURCES += \ diff --git a/src/corelib/kernel/qguard.cpp b/src/corelib/kernel/qguard.cpp deleted file mode 100644 index ae4f3a5..0000000 --- a/src/corelib/kernel/qguard.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "qguard_p.h" -#include - -void q_guard_addGuard(QGuard *g) -{ - QObjectPrivate *p = QObjectPrivate::get(g->o); - if (p->wasDeleted) { - qWarning("QGuard: cannot add guard to deleted object"); - g->o = 0; - return; - } - - g->next = p->objectGuards; - p->objectGuards = g; - g->prev = &p->objectGuards; - if (g->next) - g->next->prev = &g->next; -} - -void q_guard_removeGuard(QGuard *g) -{ - if (g->next) g->next->prev = g->prev; - *g->prev = g->next; - g->next = 0; - g->prev = 0; -} - diff --git a/src/corelib/kernel/qguard_p.h b/src/corelib/kernel/qguard_p.h index 7236ed6..cbc9cca 100644 --- a/src/corelib/kernel/qguard_p.h +++ b/src/corelib/kernel/qguard_p.h @@ -54,6 +54,7 @@ // #include "QtCore/qglobal.h" +#include "private/qobject_p.h" QT_BEGIN_NAMESPACE @@ -92,8 +93,6 @@ protected: virtual void objectDestroyed(T *) {} }; -void Q_CORE_EXPORT q_guard_addGuard(QGuard *); -void Q_CORE_EXPORT q_guard_removeGuard(QGuard *); template QGuard::QGuard() diff --git a/src/corelib/kernel/qobject_p.h b/src/corelib/kernel/qobject_p.h index 4ac0d2d..850082b 100644 --- a/src/corelib/kernel/qobject_p.h +++ b/src/corelib/kernel/qobject_p.h @@ -192,6 +192,30 @@ public: } }; +inline void q_guard_addGuard(QGuard *g) +{ + QObjectPrivate *p = QObjectPrivate::get(g->o); + if (p->wasDeleted) { + qWarning("QGuard: cannot add guard to deleted object"); + g->o = 0; + return; + } + + g->next = p->objectGuards; + p->objectGuards = g; + g->prev = &p->objectGuards; + if (g->next) + g->next->prev = &g->next; +} + +inline void q_guard_removeGuard(QGuard *g) +{ + if (g->next) g->next->prev = g->prev; + *g->prev = g->next; + g->next = 0; + g->prev = 0; +} + Q_DECLARE_TYPEINFO(QObjectPrivate::Connection, Q_MOVABLE_TYPE); Q_DECLARE_TYPEINFO(QObjectPrivate::Sender, Q_MOVABLE_TYPE); -- cgit v0.12 From ee3c71df7b0a091b078b9b6cbdf60d8f79d95913 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Mon, 27 Jul 2009 16:11:40 +0200 Subject: Added utility methods firstSourceLocation/lastSourceLocation methods to UiImport and UiImportList. --- src/declarative/qml/parser/qmljsast_p.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/declarative/qml/parser/qmljsast_p.h b/src/declarative/qml/parser/qmljsast_p.h index 9745153..ee2f472 100644 --- a/src/declarative/qml/parser/qmljsast_p.h +++ b/src/declarative/qml/parser/qmljsast_p.h @@ -2291,6 +2291,12 @@ public: : fileName(0), importUri(uri), importId(0) { kind = K; } + virtual SourceLocation firstSourceLocation() const + { return importToken; } + + virtual SourceLocation lastSourceLocation() const + { return semicolonToken; } + virtual void accept0(Visitor *visitor); // attributes @@ -2323,6 +2329,21 @@ public: previous->next = this; } + virtual SourceLocation firstSourceLocation() const + { + if (import) return import->firstSourceLocation(); + else return SourceLocation(); + } + + virtual SourceLocation lastSourceLocation() const + { + for (const UiImportList *it = this; it; it = it->next) + if (!it->next && it->import) + return it->import->lastSourceLocation(); + + return SourceLocation(); + } + UiImportList *finish() { UiImportList *head = next; -- cgit v0.12 From cc287101308fa606eb4de2597b5309c8099654c3 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Mon, 27 Jul 2009 16:35:38 +0200 Subject: Fixed missing forward declarations, which made gcc fail to compile anything that included qobject.h Reviewed-by: Thomas Hartmann --- src/corelib/kernel/qguard_p.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/corelib/kernel/qguard_p.h b/src/corelib/kernel/qguard_p.h index cbc9cca..a24680b 100644 --- a/src/corelib/kernel/qguard_p.h +++ b/src/corelib/kernel/qguard_p.h @@ -93,6 +93,8 @@ protected: virtual void objectDestroyed(T *) {} }; +void q_guard_addGuard(QGuard *); +void q_guard_removeGuard(QGuard *); template QGuard::QGuard() -- cgit v0.12 From 5cda1949899488ce19c4add30a9e0d82326499de Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 28 Jul 2009 08:11:36 +1000 Subject: Fix crashes on exit. --- src/declarative/fx/qfxitem.cpp | 3 ++- src/declarative/qml/qmlmetaproperty.cpp | 27 ++++++++++++++++++--------- src/declarative/qml/qmlmetaproperty_p.h | 3 ++- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp index 6c6fcd3..bf272d0 100644 --- a/src/declarative/fx/qfxitem.cpp +++ b/src/declarative/fx/qfxitem.cpp @@ -404,7 +404,8 @@ QFxItem::~QFxItem() } for (int ii = 0; ii < d->dependantAnchors.count(); ++ii) { QFxAnchors *anchor = d->dependantAnchors.at(ii); - anchor->d_func()->updateOnComplete(); + if (anchor->d_func()->item && anchor->d_func()->item->parentItem() != this) //child will be deleted anyway + anchor->d_func()->updateOnComplete(); } delete d->_anchorLines; d->_anchorLines = 0; } diff --git a/src/declarative/qml/qmlmetaproperty.cpp b/src/declarative/qml/qmlmetaproperty.cpp index 60b4ac6..3d040e5 100644 --- a/src/declarative/qml/qmlmetaproperty.cpp +++ b/src/declarative/qml/qmlmetaproperty.cpp @@ -313,7 +313,7 @@ QmlMetaPropertyPrivate::propertyCategory() const */ const char *QmlMetaProperty::propertyTypeName() const { - if (!d->name.isEmpty()) { + if (!d->name.isEmpty() && d->object) { return d->object->metaObject()->property(d->coreIdx).typeName(); } else { return 0; @@ -415,7 +415,7 @@ bool QmlMetaProperty::isWritable() const { if (propertyCategory() == List || propertyCategory() == QmlList) return true; - else if (!d->name.isEmpty()) + else if (!d->name.isEmpty() && d->object) return d->object->metaObject()->property(d->coreIdx).isWritable(); else if (type() & SignalProperty) return true; @@ -428,7 +428,7 @@ bool QmlMetaProperty::isWritable() const */ bool QmlMetaProperty::isDesignable() const { - if (!d->name.isEmpty()) + if (!d->name.isEmpty() && d->object) return d->object->metaObject()->property(d->coreIdx).isDesignable(); else return false; @@ -475,7 +475,10 @@ QString QmlMetaProperty::name() const */ QMetaProperty QmlMetaProperty::property() const { - return d->object->metaObject()->property(d->coreIdx); + if (d->object) + return d->object->metaObject()->property(d->coreIdx); + else + return QMetaProperty(); } /*! @@ -484,7 +487,7 @@ QMetaProperty QmlMetaProperty::property() const */ QmlBinding *QmlMetaProperty::binding() const { - if (!isProperty() || type() & Attached) + if (!isProperty() || (type() & Attached) || !d->object) return 0; const QObjectList &children = object()->children(); @@ -509,7 +512,7 @@ QmlBinding *QmlMetaProperty::binding() const */ QmlBinding *QmlMetaProperty::setBinding(QmlBinding *binding) const { - if (!isProperty() || type() & Attached) + if (!isProperty() || (type() & Attached) || !d->object) return 0; const QObjectList &children = object()->children(); @@ -577,6 +580,9 @@ QObject *QmlMetaPropertyPrivate::attachedObject() const */ QVariant QmlMetaProperty::read() const { + if (!d->object) + return QVariant(); + if (type() & SignalProperty) { const QObjectList &children = object()->children(); @@ -868,6 +874,9 @@ void QmlMetaPropertyPrivate::writeValueProperty(const QVariant &value) */ void QmlMetaProperty::write(const QVariant &value) const { + if (!d->object) + return; + QMetaProperty prop = d->object->metaObject()->property(d->coreIdx); if (type() & SignalProperty) { @@ -885,7 +894,7 @@ void QmlMetaProperty::write(const QVariant &value) const */ bool QmlMetaProperty::hasChangedNotifier() const { - if (type() & Property && !(type() & Attached)) { + if (type() & Property && !(type() & Attached) && d->object) { return d->object->metaObject()->property(d->coreIdx).hasNotifySignal(); } return false; @@ -914,7 +923,7 @@ bool QmlMetaProperty::needsChangedNotifier() const */ bool QmlMetaProperty::connectNotifier(QObject *dest, int method) const { - if (!(type() & Property) || type() & Attached) + if (!(type() & Property) || (type() & Attached) || !d->object) return false; QMetaProperty prop = d->object->metaObject()->property(d->coreIdx); @@ -935,7 +944,7 @@ bool QmlMetaProperty::connectNotifier(QObject *dest, int method) const */ bool QmlMetaProperty::connectNotifier(QObject *dest, const char *slot) const { - if (!(type() & Property) || type() & Attached) + if (!(type() & Property) || (type() & Attached) || !d->object) return false; QMetaProperty prop = d->object->metaObject()->property(d->coreIdx); diff --git a/src/declarative/qml/qmlmetaproperty_p.h b/src/declarative/qml/qmlmetaproperty_p.h index 7efdb6e..d135eda 100644 --- a/src/declarative/qml/qmlmetaproperty_p.h +++ b/src/declarative/qml/qmlmetaproperty_p.h @@ -54,6 +54,7 @@ // #include "qmlmetaproperty.h" +#include "private/qguard_p.h" QT_BEGIN_NAMESPACE @@ -80,7 +81,7 @@ public: int valueTypeId; uint type; int attachedFunc; - QObject *object; + QGuard object; int propType; mutable QmlMetaProperty::PropertyCategory category; -- cgit v0.12 From fa475c4c783c8b711134247d4c1a7ae5c909dcf2 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 28 Jul 2009 08:28:13 +1000 Subject: Compile after merge. --- src/declarative/qml/qmlmetaproperty_p.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/qml/qmlmetaproperty_p.h b/src/declarative/qml/qmlmetaproperty_p.h index d135eda..64cdbae 100644 --- a/src/declarative/qml/qmlmetaproperty_p.h +++ b/src/declarative/qml/qmlmetaproperty_p.h @@ -54,7 +54,7 @@ // #include "qmlmetaproperty.h" -#include "private/qguard_p.h" +#include "private/qobject_p.h" QT_BEGIN_NAMESPACE -- cgit v0.12 From 0cdd8518090be320fa89efaa11ced32215cc2ccc Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Tue, 28 Jul 2009 12:56:11 +1000 Subject: Make private stuff public commit 752a15ca makes some stuff private that is needed to be public. Moving some stuff back to public until we make a real decision (on how apps can interact with the engine). --- src/declarative/fx/qfxitem.cpp | 2 +- src/declarative/qml/qmlcomponentjs.cpp | 2 +- src/declarative/qml/qmlcontext.cpp | 2 +- src/declarative/qml/qmlengine.cpp | 27 +++++++++++++++++---------- src/declarative/qml/qmlengine.h | 2 ++ src/declarative/qml/qmlengine_p.h | 3 --- src/declarative/qml/qmlexpression.cpp | 2 +- src/declarative/util/qmlscript.cpp | 2 +- 8 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp index f8ed7b4..09ae22c 100644 --- a/src/declarative/fx/qfxitem.cpp +++ b/src/declarative/fx/qfxitem.cpp @@ -821,7 +821,7 @@ void QFxItem::qmlLoaded() QFxItem* ret = qobject_cast(o); if (ret) { ret->setItemParent(this); - QScriptValue v = QmlEnginePrivate::getScriptEngine(qmlEngine(this))->newQObject(ret); + QScriptValue v = QmlEngine::getScriptEngine(qmlEngine(this))->newQObject(ret); emit newChildCreated(d->_qmlnewloading.at(i).toString(),v); } diff --git a/src/declarative/qml/qmlcomponentjs.cpp b/src/declarative/qml/qmlcomponentjs.cpp index df3e834..2552f78 100644 --- a/src/declarative/qml/qmlcomponentjs.cpp +++ b/src/declarative/qml/qmlcomponentjs.cpp @@ -84,7 +84,7 @@ QScriptValue QmlComponentJS::createObject() { Q_D(QmlComponentJS); QObject* ret = create(d->ctxt); - return QmlEnginePrivate::qmlScriptObject(ret, d->engine); + return QmlEngine::qmlScriptObject(ret, d->engine); } /*! diff --git a/src/declarative/qml/qmlcontext.cpp b/src/declarative/qml/qmlcontext.cpp index dabaa5e..bf549d8 100644 --- a/src/declarative/qml/qmlcontext.cpp +++ b/src/declarative/qml/qmlcontext.cpp @@ -106,7 +106,7 @@ void QmlContextPrivate::init() parent->d_func()->childContexts.insert(q); //set scope chain - QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine); + QScriptEngine *scriptEngine = QmlEngine::getScriptEngine(engine); QScriptValue scopeObj = scriptEngine->newObject(QmlEnginePrivate::get(engine)->contextClass, scriptEngine->newVariant(QVariant::fromValue((QObject*)q))); if (!parent) diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 321feb9..0016144 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -520,6 +520,13 @@ void QmlInstanceDeclarativeData::destroyed(QObject *object) delete this; } +/*! A way to access the QScriptEngine, so that you can add your own objects. + This function is likely to be removed upon further reflection. +*/ +QScriptEngine *QmlEngine::getScriptEngine(QmlEngine *e) +{ + return &e->d_func()->scriptEngine; +} /*! \internal */ /* QScriptEngine *QmlEngine::scriptEngine() @@ -533,14 +540,14 @@ QScriptEngine *QmlEngine::scriptEngine() Creates a QScriptValue allowing you to use \a object in QML script. \a engine is the QmlEngine it is to be created in. - The QScriptValue returned is a QtScript Object, not a QtScript QObject, due - to the special needs of QML requiring more functionality than a standard + The QScriptValue returned is a Qml Script Object, not a QtScript QObject, + due to the special needs of QML requiring more functionality than a standard QtScript QObject. */ -QScriptValue QmlEnginePrivate::qmlScriptObject(QObject* object, +QScriptValue QmlEngine::qmlScriptObject(QObject* object, QmlEngine* engine) { - QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine); + QScriptEngine *scriptEngine = QmlEngine::getScriptEngine(engine); return scriptEngine->newObject(new QmlObjectScriptClass(engine), scriptEngine->newQObject(object)); } @@ -684,13 +691,13 @@ QScriptValue QmlEnginePrivate::createQmlObject(QScriptContext *ctxt, QScriptEngi if(obj) { obj->setParent(parentArg); obj->setProperty("parent", QVariant::fromValue(parentArg)); - return qmlScriptObject(obj, activeEngine); + return QmlEngine::qmlScriptObject(obj, activeEngine); } return engine->nullValue(); } QmlScriptClass::QmlScriptClass(QmlEngine *bindengine) -: QScriptClass(QmlEnginePrivate::getScriptEngine(bindengine)), +: QScriptClass(QmlEngine::getScriptEngine(bindengine)), engine(bindengine) { } @@ -780,7 +787,7 @@ QScriptValue QmlContextScriptClass::property(const QScriptValue &object, uint basicId = id & QmlScriptClass::ClassIdMask; - QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine); + QScriptEngine *scriptEngine = QmlEngine::getScriptEngine(engine); QmlEnginePrivate *ep = QmlEnginePrivate::get(engine); switch (basicId) { @@ -840,7 +847,7 @@ void QmlContextScriptClass::setProperty(QScriptValue &object, int objIdx = (id & QmlScriptClass::ClassIdSelectorMask) >> 24; QObject *obj = bindContext->d_func()->defaultObjects.at(objIdx); - QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine); + QScriptEngine *scriptEngine = QmlEngine::getScriptEngine(engine); QScriptValue oldact = scriptEngine->currentContext()->activationObject(); scriptEngine->currentContext()->setActivationObject(scriptEngine->globalObject()); @@ -948,7 +955,7 @@ QmlObjectScriptClass::QmlObjectScriptClass(QmlEngine *bindEngine) : QmlScriptClass(bindEngine) { engine = bindEngine; - QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(bindEngine); + QScriptEngine *scriptEngine = QmlEngine::getScriptEngine(bindEngine); prototypeObject = scriptEngine->newObject(); prototypeObject.setProperty(QLatin1String("destroy"), scriptEngine->newFunction(QmlObjectDestroy)); @@ -1020,7 +1027,7 @@ void QmlObjectScriptClass::setProperty(QScriptValue &object, qWarning() << "Set QmlObject Property" << name.toString() << value.toVariant(); #endif - QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine); + QScriptEngine *scriptEngine = QmlEngine::getScriptEngine(engine); QScriptValue oldact = scriptEngine->currentContext()->activationObject(); scriptEngine->currentContext()->setActivationObject(scriptEngine->globalObject()); diff --git a/src/declarative/qml/qmlengine.h b/src/declarative/qml/qmlengine.h index 6066059..a3457f0 100644 --- a/src/declarative/qml/qmlengine.h +++ b/src/declarative/qml/qmlengine.h @@ -86,6 +86,8 @@ public: static QmlContext *contextForObject(const QObject *); static void setContextForObject(QObject *, QmlContext *); + static QScriptValue qmlScriptObject(QObject*, QmlEngine*); + static QScriptEngine *getScriptEngine(QmlEngine *e); private: Q_DECLARE_PRIVATE(QmlEngine) }; diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h index 18cdd83..7b459e9 100644 --- a/src/declarative/qml/qmlengine_p.h +++ b/src/declarative/qml/qmlengine_p.h @@ -193,12 +193,9 @@ public: bool resolveType(const Imports&, const QByteArray& type, QmlType** type_return, QUrl* url_return, ImportedNamespace** ns_return=0) const; void resolveTypeInNamespace(ImportedNamespace*, const QByteArray& type, QmlType** type_return, QUrl* url_return ) const; - - static QScriptValue qmlScriptObject(QObject*, QmlEngine*); static QScriptValue createComponent(QScriptContext*, QScriptEngine*); static QScriptValue createQmlObject(QScriptContext*, QScriptEngine*); - static QScriptEngine *getScriptEngine(QmlEngine *e) { return &e->d_func()->scriptEngine; } static QmlEnginePrivate *get(QmlEngine *e) { return e->d_func(); } }; diff --git a/src/declarative/qml/qmlexpression.cpp b/src/declarative/qml/qmlexpression.cpp index 2c06efa..990722a 100644 --- a/src/declarative/qml/qmlexpression.cpp +++ b/src/declarative/qml/qmlexpression.cpp @@ -240,7 +240,7 @@ QVariant QmlExpressionPrivate::evalQtScript() if (me) ctxtPriv->defaultObjects.insert(ctxtPriv->highPriorityCount, me); - QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine); + QScriptEngine *scriptEngine = QmlEngine::getScriptEngine(engine); QScriptValueList oldScopeChain = scriptEngine->currentContext()->scopeChain(); diff --git a/src/declarative/util/qmlscript.cpp b/src/declarative/util/qmlscript.cpp index ca9aad5..df05d8e 100644 --- a/src/declarative/util/qmlscript.cpp +++ b/src/declarative/util/qmlscript.cpp @@ -185,7 +185,7 @@ void QmlScriptPrivate::addScriptToEngine(const QString &script, const QString &s Q_Q(QmlScript); QmlEngine *engine = qmlEngine(q); QmlContext *context = qmlContext(q); - QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine); + QScriptEngine *scriptEngine = QmlEngine::getScriptEngine(engine); QScriptContext *currentContext = scriptEngine->currentContext(); QScriptValueList oldScopeChain = currentContext->scopeChain(); -- cgit v0.12 From 9816567056c93f193c8d86d8e3cc8e22695b6642 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 28 Jul 2009 13:25:11 +1000 Subject: Fix ParentChange in states. Make sure we can override when necessary. --- src/declarative/util/qmlstate.cpp | 28 +++++++++++++++++++++++----- src/declarative/util/qmlstate.h | 1 + src/declarative/util/qmlstateoperations.cpp | 10 ++++++++++ src/declarative/util/qmlstateoperations.h | 1 + 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/declarative/util/qmlstate.cpp b/src/declarative/util/qmlstate.cpp index c41c31a..af60a6f 100644 --- a/src/declarative/util/qmlstate.cpp +++ b/src/declarative/util/qmlstate.cpp @@ -110,6 +110,11 @@ void ActionEvent::clearReverseBindings() { } +bool ActionEvent::override(ActionEvent *other) +{ + return false; +} + /*! \internal */ @@ -378,13 +383,15 @@ void QmlState::apply(QmlStateGroup *group, QmlTransition *trans, QmlState *rever if (action.event) { if (!action.event->isReversable()) continue; - /*for (jj = 0; jj < d->revertList.count(); ++jj) { + for (jj = 0; jj < d->revertList.count(); ++jj) { ActionEvent *event = d->revertList.at(jj).event; if (event && event->typeName() == action.event->typeName()) { - found = true; - break; + if (action.event->override(event)) { + found = true; + break; + } } - }*/ //### not a close enough match + } } else { action.fromBinding = action.property.binding(); @@ -417,7 +424,18 @@ void QmlState::apply(QmlStateGroup *group, QmlTransition *trans, QmlState *rever // into this state need to be translated into apply actions for (int ii = 0; ii < d->revertList.count(); ++ii) { bool found = false; - if (!d->revertList.at(ii).event) { //### corresponding test for events? + if (d->revertList.at(ii).event) { + ActionEvent *event = d->revertList.at(ii).event; + if (!event->isReversable()) + continue; + for (int jj = 0; !found && jj < applyList.count(); ++jj) { + const Action &action = applyList.at(jj); + if (action.event && action.event->typeName() == event->typeName()) { + if (action.event->override(event)) + found = true; + } + } + } else { for (int jj = 0; !found && jj < applyList.count(); ++jj) { const Action &action = applyList.at(jj); if (action.property == d->revertList.at(ii).property) diff --git a/src/declarative/util/qmlstate.h b/src/declarative/util/qmlstate.h index 7b3021b..7c62768 100644 --- a/src/declarative/util/qmlstate.h +++ b/src/declarative/util/qmlstate.h @@ -96,6 +96,7 @@ public: virtual bool changesBindings(); virtual void clearForwardBindings(); virtual void clearReverseBindings(); + virtual bool override(ActionEvent*other); }; class QmlStateGroup; diff --git a/src/declarative/util/qmlstateoperations.cpp b/src/declarative/util/qmlstateoperations.cpp index e2cbae4..3d03c34 100644 --- a/src/declarative/util/qmlstateoperations.cpp +++ b/src/declarative/util/qmlstateoperations.cpp @@ -202,6 +202,16 @@ QString QmlParentChange::typeName() const return QLatin1String("ParentChange"); } +bool QmlParentChange::override(ActionEvent*other) +{ + Q_D(QmlParentChange); + if (other->typeName() != QLatin1String("ParentChange")) + return false; + if (QmlParentChange *otherPC = static_cast(other)) + return (d->target == otherPC->object()); + return false; +} + class QmlRunScriptPrivate : public QObjectPrivate { public: diff --git a/src/declarative/util/qmlstateoperations.h b/src/declarative/util/qmlstateoperations.h index f595e16..4bd17a0 100644 --- a/src/declarative/util/qmlstateoperations.h +++ b/src/declarative/util/qmlstateoperations.h @@ -76,6 +76,7 @@ public: virtual bool isReversable(); virtual void reverse(); virtual QString typeName() const; + virtual bool override(ActionEvent*other); }; class QmlRunScriptPrivate; -- cgit v0.12