diff options
26 files changed, 228 insertions, 522 deletions
diff --git a/doc/src/declarative/elements.qdoc b/doc/src/declarative/elements.qdoc index b6dec25..ae1428a 100644 --- a/doc/src/declarative/elements.qdoc +++ b/doc/src/declarative/elements.qdoc @@ -97,7 +97,10 @@ The following table lists the Qml elements provided by the Qt Declarative module \o \list \o \l Repeater -\o \l Content +\o \l ContentWrapper + \list + \o \l Content + \endlist \o \l ComponentInstance \o \l WidgetContainer \endlist diff --git a/doc/src/declarative/pics/content.png b/doc/src/declarative/pics/content.png Binary files differnew file mode 100644 index 0000000..47a98ac --- /dev/null +++ b/doc/src/declarative/pics/content.png diff --git a/doc/src/declarative/pics/gridview.png b/doc/src/declarative/pics/gridview.png Binary files differindex d5c8b4b..3726893 100644 --- a/doc/src/declarative/pics/gridview.png +++ b/doc/src/declarative/pics/gridview.png diff --git a/doc/src/snippets/declarative/GroupBox.qml b/doc/src/snippets/declarative/GroupBox.qml index a8ff5be..fd8d60b 100644 --- a/doc/src/snippets/declarative/GroupBox.qml +++ b/doc/src/snippets/declarative/GroupBox.qml @@ -1,11 +1,13 @@ ContentWrapper { - id: Container; width: parent.width - Rect { - width: parent.width; color: "white"; pen.width: 2; pen.color: "#adaeb0"; radius: 10 - clip: false; height: contents.height - VerticalLayout { - id: layout; width: parent.width - Content {} + id: Container; width: parent.width; height: contents.height + children: [ + Rect { + width: parent.width; height: contents.height + color: "white"; pen.width: 2; pen.color: "#adaeb0"; radius: 10 + VerticalLayout { + id: layout; width: parent.width; margin: 5; spacing: 2 + Content { } + } } - } + ] } diff --git a/doc/src/snippets/declarative/content.qml b/doc/src/snippets/declarative/content.qml index be04c6e..6f9e0d8 100644 --- a/doc/src/snippets/declarative/content.qml +++ b/doc/src/snippets/declarative/content.qml @@ -1,6 +1,7 @@ -GroupBox { - content: [ +Rect { + width: 200; height: 100; color: "lightgray" + GroupBox { Text { text: "First Item" } Text { text: "Second Item" } - ] + } } diff --git a/doc/src/snippets/declarative/gridview/dummydata/ContactModel.qml b/doc/src/snippets/declarative/gridview/dummydata/ContactModel.qml new file mode 100644 index 0000000..accbc3e --- /dev/null +++ b/doc/src/snippets/declarative/gridview/dummydata/ContactModel.qml @@ -0,0 +1,23 @@ +ListModel { + id: ContactModel + ListElement { + name: "Bill Smith" + number: "555 3264" + portrait: "pics/portrait.png" + } + ListElement { + name: "Jim Williams" + number: "555 5673" + portrait: "pics/portrait.png" + } + ListElement { + name: "John Brown" + number: "555 8426" + portrait: "pics/portrait.png" + } + ListElement { + name: "Sam Wise" + number: "555 0473" + portrait: "pics/portrait.png" + } +} diff --git a/doc/src/snippets/declarative/gridview/gridview.qml b/doc/src/snippets/declarative/gridview/gridview.qml new file mode 100644 index 0000000..0fca789 --- /dev/null +++ b/doc/src/snippets/declarative/gridview/gridview.qml @@ -0,0 +1,45 @@ +//! [3] +Rect { + width: 240; height: 180; color: "white" + // ContactModel model is defined in dummydata/ContactModel.qml + // The viewer automatically loads files in dummydata/* to assist + // development without a real data source. + + // Define a delegate component. A component will be + // instantiated for each visible item in the list. +//! [0] + Component { + id: Delegate + Item { + id: Wrapper + width: 80; height: 78 + VerticalLayout { + Image { source: portrait; anchors.horizontalCenter: parent.horizontalCenter } + Text { text: name; anchors.horizontalCenter: parent.horizontalCenter } + } + } + } +//! [0] + // Define a highlight component. Just one of these will be instantiated + // by each ListView and placed behind the current item. +//! [1] + Component { + id: Highlight + Rect { + color: "lightsteelblue" + radius: 5 + } + } +//! [1] + // The actual grid +//! [2] + GridView { + width: parent.width; height: parent.height + model: ContactModel; delegate: Delegate + cellWidth: 80; cellHeight: 80 + highlight: Highlight + focus: true + } +//! [2] +} +//! [3] diff --git a/doc/src/snippets/declarative/gridview/pics/portrait.png b/doc/src/snippets/declarative/gridview/pics/portrait.png Binary files differnew file mode 100644 index 0000000..fb5052a --- /dev/null +++ b/doc/src/snippets/declarative/gridview/pics/portrait.png diff --git a/doc/src/snippets/declarative/listview/dummydata/ContactModel.qml b/doc/src/snippets/declarative/listview/dummydata/ContactModel.qml index 302dfd2..53c745e 100644 --- a/doc/src/snippets/declarative/listview/dummydata/ContactModel.qml +++ b/doc/src/snippets/declarative/listview/dummydata/ContactModel.qml @@ -1,18 +1,15 @@ -<!-- -ListModel allows free form list models to be defined and populated. -Be sure to name the file the same as the id. ---> -<ListModel id="ContactModel"> - <Contact> - <name>Bill Smith</name> - <number>555 3264</number> - </Contact> - <Contact> - <name>John Brown</name> - <number>555 8426</number> - </Contact> - <Contact> - <name>Sam Wise</name> - <number>555 0473</number> - </Contact> -</ListModel> +ListModel { + id: ContactModel + ListElement { + name: "Bill Smith" + number: "555 3264" + } + ListElement { + name: "John Brown" + number: "555 8426" + } + ListElement { + name: "Sam Wise" + number: "555 0473" + } +} diff --git a/doc/src/snippets/declarative/listview/listview.qml b/doc/src/snippets/declarative/listview/listview.qml index 5b99bbd..3596af1 100644 --- a/doc/src/snippets/declarative/listview/listview.qml +++ b/doc/src/snippets/declarative/listview/listview.qml @@ -1,7 +1,7 @@ //! [3] Rect { - width: 480 - height: 40 + width: 180 + height: 200 color: "white" // ContactModel model is defined in dummydata/ContactModel.qml // The viewer automatically loads files in dummydata/* to assist @@ -48,7 +48,6 @@ Rect { delegate: Delegate highlight: Highlight focus: true - orientation: 'Horizontal' } //! [2] } diff --git a/examples/declarative/contacts/contacts.pro b/examples/declarative/contacts/contacts.pro deleted file mode 100644 index 18293ee..0000000 --- a/examples/declarative/contacts/contacts.pro +++ /dev/null @@ -1,22 +0,0 @@ -TEMPLATE = app -TARGET = contacts - -MOC_DIR = .moc -OBJECTS_DIR = .obj - -QT += declarative script sql - -unix { - sqlitedb.output = ${QMAKE_FILE_BASE}.sqlite - sqlitedb.commands = rm -f ${QMAKE_FILE_OUT}; if which sqlite3 ; then sqlite3 ${QMAKE_FILE_OUT} < ${QMAKE_FILE_NAME} ; fi - sqlitedb.input = SQL_SOURCES - sqlitedb.CONFIG += no_link target_predeps - - QMAKE_EXTRA_COMPILERS += sqlitedb - QMAKE_EXTRA_TARGETS = sqlitedb -} - -SQL_SOURCES += data/contacts.sql - -SOURCES += main.cpp - diff --git a/examples/declarative/contacts/contacts.qml b/examples/declarative/contacts/contacts.qml deleted file mode 100644 index f9901ed..0000000 --- a/examples/declarative/contacts/contacts.qml +++ /dev/null @@ -1,121 +0,0 @@ -Rect { - id: page - width: 320 - height: 480 - color: "white" - resources: [ - Component { - id: contactDelegate - Rect { - id: wrapper - x: 20 - width: List.width-40 - color: "#FEFFEE" - pen.color: "#FFBE4F" - radius: 5 - filter: Shadow { - xOffset: 5 - yOffset: 5 - } - MouseRegion { - id: pageMouse - anchors.fill: parent - onClicked: { if (wrapper.state == 'Details') { wrapper.state = '';} else {wrapper.state = 'Details';} } - } - Image { - id: portraitPic - source: portrait - x: 10 - y: 10 - } - Text { - id: name - text: firstName + ' ' + lastName - anchors.left: portraitPic.right - anchors.leftMargin: 10 - anchors.top: portraitPic.top - anchors.right: wrapper.right - anchors.rightMargin: 10 - font.family: "Comic Sans MS" - font.bold: true - font.size: 11 - } - VerticalLayout { - id: email_layout - anchors.left: name.left - anchors.top: name.bottom - anchors.topMargin: 10 - Repeater { - id: email_list - dataSource: emails - Component { - Text { - text: modelData - height: 18 - font.italic: true - color: "midnightblue" - } - } - } - } - height: Math.max(email_layout.height + name.height + 25, portraitPic.height+20) - states: [ - State { - name: "Details" - SetProperty { - target: wrapper - property: "color" - value: "white" - } - SetProperty { - target: wrapper - property: "x" - value: 0 - } - SetProperty { - target: wrapper - property: "height" - value: List.height - } - SetProperty { - target: wrapper - property: "width" - value: List.width - } - SetProperty { - target: wrapper.ListView.view - property: "yPosition" - value: wrapper.y - } - SetProperty { - target: wrapper.ListView.view - property: "locked" - value: 1 - } - } - ] - transitions: [ - Transition { - ParallelAnimation { - ColorAnimation { - duration: 500 - } - NumericAnimation { - duration: 150 - properties: "x,yPosition,height,width" - } - } - } - ] - } - } - ] - ListView { - id: List - model: contactModel - width: 320 - height: 480 - clip: true - delegate: contactDelegate - } -} diff --git a/examples/declarative/contacts/dummydata/contactModel.qml b/examples/declarative/contacts/dummydata/contactModel.qml deleted file mode 100644 index 53f6b7b..0000000 --- a/examples/declarative/contacts/dummydata/contactModel.qml +++ /dev/null @@ -1,103 +0,0 @@ -ListModel { - ListElement { - firstName: "Aaron" - lastName: "Kennedy" - portrait: "contact.png" - emails: [ - ListElement { address: "akennedy@trolltech.com" }, - ListElement { address: "aaron.kennedy@trolltech.com" } - ] - } - ListElement { - firstName: "ListElement" - lastName: 1 - portrait: "contact.png" - } - ListElement { - firstName: "ListElement" - lastName: 2 - portrait: "contact.png" - } - ListElement { - firstName: "ListElement" - lastName: 3 - portrait: "contact.png" - } - ListElement { - firstName: "ListElement" - lastName: 4 - portrait: "contact.png" - } - ListElement { - firstName: "ListElement" - lastName: 5 - portrait: "contact.png" - } - ListElement { - firstName: "ListElement" - lastName: 6 - portrait: "contact.png" - } - ListElement { - firstName: "ListElement" - lastName: 7 - portrait: "contact.png" - } - ListElement { - firstName: "ListElement" - lastName: 8 - portrait: "contact.png" - } - ListElement { - firstName: "ListElement" - lastName: 9 - portrait: "contact.png" - } - ListElement { - firstName: "Alan" - lastName: "Alpert" - portrait: "contact.png" - } - ListElement { - firstName: "Betty" - lastName: "Boo" - portrait: "contact.png" - } - ListElement { - firstName: "Foo" - lastName: "Bar" - portrait: "contact.png" - } - ListElement { - firstName: "Marius" - lastName: "Bugge Monsen" - portrait: "contact.png" - } - ListElement { - firstName: "Martin" - lastName: "Jones" - portrait: "contact.png" - emails: [ - ListElement { address: "mjones@trolltech.com" }, - ListElement { address: "martin.jones@trolltech.com" } - ] - } - ListElement { - firstName: "Michael" - lastName: "Brasser" - portrait: "contact.png" - emails: ListElement { - address: "mbrasser@trolltech.com" - } - } - ListElement { - firstName: "Yann" - lastName: "Bodson" - portrait: "contact.png" - } - ListElement { - firstName: "Yogi" - lastName: "Bear" - portrait: "contact.png" - } -} diff --git a/examples/declarative/contacts/main.cpp b/examples/declarative/contacts/main.cpp deleted file mode 100644 index bda6565..0000000 --- a/examples/declarative/contacts/main.cpp +++ /dev/null @@ -1,80 +0,0 @@ -#include "qml.h" -#include <qfxview.h> - -#include <QWidget> -#include <QApplication> -#include <QFile> -#include <QTime> -#include <QVBoxLayout> - -const char *defaultFileName("contacts.qml"); - -class Contacts : public QWidget -{ -Q_OBJECT -public: - Contacts(const QString &fileName, int = 240, int = 320, QWidget *parent=0, Qt::WindowFlags flags=0); - -public slots: - void sceneResized(QSize size) - { - if(size.width() > 0 && size.height() > 0) - canvas->setFixedSize(size.width(), size.height()); - } - -private: - QFxView *canvas; -}; - -Contacts::Contacts(const QString &fileName, int width, int height, QWidget *parent, Qt::WindowFlags flags) -: QWidget(parent, flags), canvas(0) -{ - setAttribute(Qt::WA_OpaquePaintEvent); - setAttribute(Qt::WA_NoSystemBackground); - - QVBoxLayout *vbox = new QVBoxLayout; - vbox->setMargin(0); - setLayout(vbox); - - canvas = new QFxView(this); - QObject::connect(canvas, SIGNAL(sceneResized(QSize)), this, SLOT(sceneResized(QSize))); - canvas->setFixedSize(width, height); - vbox->addWidget(canvas); - - QFile file(fileName); - file.open(QFile::ReadOnly); - QString qml = file.readAll(); - canvas->setQml(qml, fileName); - - canvas->execute(); -} - -int main(int argc, char ** argv) -{ - QApplication app(argc, argv); - - bool frameless = false; - - int width = 240; - int height = 320; - - QString fileName; - for (int i = 1; i < argc; ++i) { - QString arg = argv[i]; - if (arg == "-frameless") { - frameless = true; - } else { - fileName = arg; - break; - } - } - if (fileName.isEmpty()) - fileName = QLatin1String(defaultFileName); - - Contacts contacts(fileName, width, height, 0, frameless ? Qt::FramelessWindowHint : Qt::Widget); - contacts.show(); - - return app.exec(); -} - -#include "main.moc" diff --git a/src/declarative/fx/qfxcontentwrapper.cpp b/src/declarative/fx/qfxcontentwrapper.cpp index 2b95ff6..d493990 100644 --- a/src/declarative/fx/qfxcontentwrapper.cpp +++ b/src/declarative/fx/qfxcontentwrapper.cpp @@ -46,6 +46,36 @@ QT_BEGIN_NAMESPACE QML_DEFINE_TYPE(QFxContentWrapper,ContentWrapper); +/*! + \qmlclass ContentWrapper QFxContentWrapper + \ingroup group_utility + \brief ContentWrapper provides a component which contains content. + \inherits Item + + In some cases the content of a component is not defined by the component itself. + For example, the items placed in a group box need to be specified external to + group box component definition itself. + In cases like these \l Content can be used to specify at what location in the component + the content should be placed. It is used in conjuntion with the \e content property of + ContentWrapper: any items listed as content will be placed in the location + specified by Content. The component containing the Content must be of type + ContentWrapper. + + GroupBox component definition: + \quotefile doc/src/snippets/declarative/GroupBox.qml + + \bold Note that in the above component definition ContentWrapper's \e children + property is specified explicitly since \e content is the default property. + + Component use: + \table + \row \o \image content.png + \o \quotefile doc/src/snippets/declarative/content.qml + \endtable + + \sa Content +*/ + QFxContentWrapper::QFxContentWrapper(QFxItem *parent) : QFxItem(*(new QFxContentWrapperPrivate), parent) { @@ -56,6 +86,14 @@ QFxContentWrapper::QFxContentWrapper(QFxContentWrapperPrivate &dd, QFxItem *pare { } +/*! + \qmlproperty list<Item> ContentWrapper::content + + Contains the list of elements to replace the \l Content + placeholder. + + \sa Content +*/ QList<QFxItem *> *QFxContentWrapper::content() { Q_D(QFxContentWrapper); @@ -99,40 +137,8 @@ QML_DEFINE_TYPE(QFxContent,Content); \brief Content is used as a placeholder for the content of a component. \inherits Item - In some cases the content of a component is not defined by the component itself. - For example, the items placed in a group box need to be specified external to - the where the group box component itself is defined. - In cases like these Content can be used to specify at what location in the component - the content should be placed. It is used in conjuntion with the content property of - the component instance: any items listed as content will be placed in the location - specified by Content. - - Example: - \qml -// GroupBox component definition -Rect { - width: parent.width - color: "white" - pen.width: 2 - pen.color: "#adaeb0" - radius: 10 - clip: false - height: contents.height - VerticalLayout { - id: layout - width: parent.width - Content { } // content property will go here - } -} - -// component use -GroupBox { - content: Text { - text: "First Item" - ... - } -} - \endqml + The Content element is used to place content within a component. + See \l ContentWrapper for usage. */ QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxgridview.cpp b/src/declarative/fx/qfxgridview.cpp index 8416234..acfb57e 100644 --- a/src/declarative/fx/qfxgridview.cpp +++ b/src/declarative/fx/qfxgridview.cpp @@ -656,32 +656,18 @@ void QFxGridViewPrivate::updateCurrent(int modelIndex) and may be flicked to scroll. The below example creates a very simple grid, using a QML model. - \code - <resources> - <ListModel id="contactModel"> - <Contact> - <firstName>John</firstName> - <lastName>Smith</lastName> - </Contact> - <Contact> - <firstName>Bill</firstName> - <lastName>Jones</lastName> - </Contact> - <Contact> - <firstName>Jane</firstName> - <lastName>Doe</lastName> - </Contact> - </ListModel> - <Component id="contactDelegate"> - <Rect pen.color="blue" z="-1" height="20" width="80" color="white" radius="2"> - <Text id="name" text="{firstName + ' ' + lastName}" font.size="11"/> - </Rect> - </Component> - </resources> - - <GridView id="Grid" width="160" height="240" cellWidth="80" cellHeight="20" clip="true" - model="{contactModel}" delegate="{contactDelegate}"/> - \endcode + + \image gridview.png + + \snippet doc/src/snippets/declarative/gridview/gridview.qml 3 + + The model is defined as a ListModel using QML: + \quotefile doc/src/snippets/declarative/gridview/dummydata/ContactModel.qml + + In this case ListModel is a handy way for us to test our UI. In practice + the model would be implemented in C++, or perhaps via a SQL data source. + + */ QFxGridView::QFxGridView(QFxItem *parent) : QFxFlickable(*(new QFxGridViewPrivate), parent) @@ -703,28 +689,8 @@ QFxGridView::~QFxGridView() The model provides a set of data that is used to create the items for the view. For large or dynamic datasets the model is usually provided by a C++ model object. - The C++ model object must be a \l QListModelInterface subclass, a \l VisualModel, + The C++ model object must be a \l QAbstractItemModel subclass, a \l VisualModel, or a simple list. - - Models can also be created directly in QML, using the \l ListModel object. For example: - \code - <ListModel id="contactModel"> - <Contact> - <firstName>John</firstName> - <lastName>Smith</lastName> - </Contact> - <Contact> - <firstName>Bill</firstName> - <lastName>Jones</lastName> - </Contact> - <Contact> - <firstName>Jane</firstName> - <lastName>Doe</lastName> - </Contact> - </ListModel> - - <GridView model="{contactModel}" .../> - \endcode */ QVariant QFxGridView::model() const { @@ -774,17 +740,7 @@ void QFxGridView::setModel(const QVariant &model) The delegate provides a template describing what each item in the view should look and act like. Here is an example delegate: - \code - <Component id="contactDelegate"> - <Item id="wrapper"> - <Image id="pic" width="100" height="100" file="{portrait}"/> - <Text id="name" text="{firstName + ' ' + lastName}" - anchors.left="{pic.right}" anchors.leftMargin="5"/> - </Item> - </Component> - ... - <GridView delegate="{contactDelegate}" .../> - \endcode + \snippet doc/src/snippets/declarative/gridview/gridview.qml 0 */ QmlComponent *QFxGridView::delegate() const { @@ -860,12 +816,7 @@ int QFxGridView::count() const so as to stay with the current item, unless the autoHighlight property is false. The below example demonstrates how to make a simple highlight: - \code - <Component id="ListHighlight"> - <Rect color="lightsteelblue" radius="4"/> - </Component> - <GridView highlight="{ListHighlight}"> - \endcode + \snippet doc/src/snippets/declarative/gridview/gridview.qml 1 \sa autoHighlight */ @@ -890,19 +841,17 @@ void QFxGridView::setHighlight(QmlComponent *highlight) If autoHighlight is true, the highlight will be moved smoothly to follow the current item. If autoHighlight is false, the highlight will not be moved by the view, and must be implemented - by the highlight, for example: + by the highlight component, for example: \code - <Component id="Highlight"> - <Rect id="Wrapper" color="#242424" radius="4" width="320" height="60" > - <y> - <Follow source="{Wrapper.GridView.view.current.y}" spring="3" damping="0.2"/> - </y> - <x> - <Follow source="{Wrapper.GridView.view.current.x}" spring="3" damping="0.2"/> - </x> - </Rect> - </Component> + Component { + id: Highlight + Rect { + id: Wrapper; color: "lightsteelblue"; radius: 4; width: 320; height: 60 > + y: Follow { source: Wrapper.GridView.view.current.y; spring: 3; damping: 0.2 } + x: Follow { source: Wrapper.GridView.view.current.x; spring: 3; damping: 0.2 } + } + } \endcode */ bool QFxGridView::autoHighlight() const @@ -1007,9 +956,11 @@ void QFxGridView::setCacheBuffer(int buffer) /*! \qmlproperty int GridView::cellWidth - This property holds the width of each cell in the grid + \qmlproperty int GridView::cellHeight + + These properties holds the width and height of each cell in the grid - The default cellWidth is 100. + The default sell size is 100x100. */ int QFxGridView::cellWidth() const { @@ -1028,12 +979,6 @@ void QFxGridView::setCellWidth(int cellWidth) } } -/*! - \qmlproperty int GridView::cellHeight - This property holds the height of each cell in the grid - - The default cellHeight is 100. -*/ int QFxGridView::cellHeight() const { Q_D(const QFxGridView); diff --git a/src/declarative/fx/qfxlistview.cpp b/src/declarative/fx/qfxlistview.cpp index 9d076d0..b256c4a 100644 --- a/src/declarative/fx/qfxlistview.cpp +++ b/src/declarative/fx/qfxlistview.cpp @@ -809,9 +809,7 @@ void QFxListViewPrivate::fixupX() \snippet doc/src/snippets/declarative/listview/listview.qml 3 The model is defined as a ListModel using QML: - \quotefromfile doc/src/snippets/declarative/listview/dummydata/ContactModel.qml - \skipto <ListModel - \printuntil </ListModel + \quotefile doc/src/snippets/declarative/listview/dummydata/ContactModel.qml In this case ListModel is a handy way for us to test our UI. In practice the model would be implemented in C++, or perhaps via a SQL data source. diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp index f0cf4cc..67a0a04 100644 --- a/src/declarative/qml/qmlcompiler.cpp +++ b/src/declarative/qml/qmlcompiler.cpp @@ -1276,9 +1276,10 @@ bool QmlCompiler::compileDynamicMeta(QmlParser::Object *obj) if (obj->metatype) builder.setSuperClass(obj->metatype); - obj->extObject = builder.toMetaObject(); + obj->extObjectData = builder.toMetaObject(); + static_cast<QMetaObject &>(obj->extObject) = *obj->extObjectData; - output->mos << obj->extObject; + output->mos << obj->extObjectData; QmlInstruction store; store.type = QmlInstruction::StoreMetaObject; store.storeMeta.data = output->mos.count() - 1; diff --git a/src/declarative/qml/qmlcomponent.cpp b/src/declarative/qml/qmlcomponent.cpp index f0d23ee..b257d5f 100644 --- a/src/declarative/qml/qmlcomponent.cpp +++ b/src/declarative/qml/qmlcomponent.cpp @@ -264,7 +264,7 @@ QmlComponent::QmlComponent(QmlEngine *engine, const QUrl &url, QObject *parent) /*! Create a QmlComponent from the given QML \a data and give it the - specified \a parent. If \a url is provided, it is used to set + specified \a parent and \a engine. If \a url is provided, it is used to set the component name, and to provide a base path for items resolved by this component. diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index bcea325..4d6b64f 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -410,6 +410,9 @@ QmlEngine::~QmlEngine() /*! Clears the engine's internal component cache. + + Normally the QmlEngine caches components loaded from qml files. This method + clears this cache and forces the component to be reloaded. */ void QmlEngine::clearComponentCache() { @@ -600,7 +603,11 @@ QNetworkAccessManager *QmlEngine::networkAccessManager() const } /*! - Returns the QmlContext for the \a object. + Returns the QmlContext for the \a object, or 0 if no context has been set. + + When the QmlEngine instantiates a QObject, the context is set automatically. + + \sa qmlContext() */ QmlContext *QmlEngine::contextForObject(const QObject *object) { @@ -616,6 +623,8 @@ QmlContext *QmlEngine::contextForObject(const QObject *object) Sets the QmlContext for the \a object to \a context. If the \a object already has a context, a warning is output, but the context is not changed. + + When the QmlEngine instantiates a QObject, the context is set automatically. */ void QmlEngine::setContextForObject(QObject *object, QmlContext *context) { diff --git a/src/declarative/qml/qmlerror.cpp b/src/declarative/qml/qmlerror.cpp index 2ed3500..149e173 100644 --- a/src/declarative/qml/qmlerror.cpp +++ b/src/declarative/qml/qmlerror.cpp @@ -188,10 +188,9 @@ QDebug operator<<(QDebug debug, const QmlError &error) output += QLatin1String(": ") + error.description(); - debug << qPrintable(output) << "\n"; + debug << qPrintable(output); - if (error.line() > 0 && error.column() > 0 && - url.scheme() == QLatin1String("file")) { + if (error.line() > 0 && url.scheme() == QLatin1String("file")) { QString file = url.toLocalFile(); QFile f(file); if (f.open(QIODevice::ReadOnly)) { @@ -202,22 +201,24 @@ QDebug operator<<(QDebug debug, const QmlError &error) if (lines.count() >= error.line()) { const QString &line = lines.at(error.line() - 1); - debug << qPrintable(line) << "\n"; - - int column = qMax(0, error.column() - 1); - column = qMin(column, line.length()); - - QByteArray ind; - ind.reserve(column); - for (int i = 0; i < column; ++i) { - const QChar ch = line.at(i); - if (ch.isSpace()) - ind.append(ch.unicode()); - else - ind.append(' '); + debug << "\n " << qPrintable(line); + + if(error.column() > 0) { + int column = qMax(0, error.column() - 1); + column = qMin(column, line.length()); + + QByteArray ind; + ind.reserve(column); + for (int i = 0; i < column; ++i) { + const QChar ch = line.at(i); + if (ch.isSpace()) + ind.append(ch.unicode()); + else + ind.append(' '); + } + ind.append('^'); + debug << "\n " << ind.constData(); } - ind.append('^'); - debug << ind.constData(); } } } diff --git a/src/declarative/qml/qmlmetaproperty.cpp b/src/declarative/qml/qmlmetaproperty.cpp index 14a45dc..40c9b0e 100644 --- a/src/declarative/qml/qmlmetaproperty.cpp +++ b/src/declarative/qml/qmlmetaproperty.cpp @@ -265,13 +265,13 @@ QmlMetaProperty::QmlMetaProperty(const QmlMetaProperty &other) This enum specifies a category of QML property. - \value Unknown - \value InvalidProperty - \value Bindable - \value List - \value QmlList - \value Object - \value Normal + \value Unknown The category is unknown. This will never be returned from propertyCategory() + \value InvalidProperty The property is invalid. + \value Bindable The property is a QmlBindableValue. + \value List The property is a QList pointer + \value QmlList The property is a QmlList pointer + \value Object The property is a QObject derived type pointer + \value Normal The property is none of the above. */ /*! @@ -279,12 +279,12 @@ QmlMetaProperty::QmlMetaProperty(const QmlMetaProperty &other) This enum specifies a type of QML property. - \value Invalid - \value Property - \value SignalProperty - \value Signal - \value Default - \value Attached + \value Invalid The property is invalid. + \value Property The property is a regular Qt property. + \value SignalProperty The property is a signal property. + \value Signal The property is a signal. + \value Default The property is the default property. + \value Attached The property is an attached property. */ /*! diff --git a/src/declarative/qml/qmlparser.cpp b/src/declarative/qml/qmlparser.cpp index a943c4d..d68eb68 100644 --- a/src/declarative/qml/qmlparser.cpp +++ b/src/declarative/qml/qmlparser.cpp @@ -63,7 +63,7 @@ QT_BEGIN_NAMESPACE using namespace QmlParser; QmlParser::Object::Object() -: type(-1), metatype(0), extObject(0), defaultProperty(0), line(-1), column(-1) +: type(-1), metatype(0), extObjectData(0), defaultProperty(0), line(-1), column(-1) { } @@ -76,8 +76,8 @@ QmlParser::Object::~Object() const QMetaObject *Object::metaObject() const { - if (extObject && metatype) - return extObject; + if (extObjectData && metatype) + return &extObject; else return metatype; } diff --git a/src/declarative/qml/qmlparser_p.h b/src/declarative/qml/qmlparser_p.h index 676e25e..2c9b0f1 100644 --- a/src/declarative/qml/qmlparser_p.h +++ b/src/declarative/qml/qmlparser_p.h @@ -94,7 +94,8 @@ namespace QmlParser const QMetaObject *metatype; // The synthesized metaobject, if QML added signals or properties to // this type. Otherwise null - QMetaObject *extObject; + QMetaObject *extObjectData; + QAbstractDynamicMetaObject extObject; Property *getDefaultProperty(); Property *getProperty(const QByteArray &name, bool create=true); diff --git a/src/declarative/qml/qmlvme.cpp b/src/declarative/qml/qmlvme.cpp index ee7a881..82df3bc 100644 --- a/src/declarative/qml/qmlvme.cpp +++ b/src/declarative/qml/qmlvme.cpp @@ -170,7 +170,6 @@ static inline int qIndexOfProperty(QObject *o, const char *name) } QmlVME::QmlVME() -: exceptionLine(-1) { } @@ -261,8 +260,12 @@ QObject *QmlVME::run(QmlContext *ctxt, QmlCompiledComponent *comp, int start, in QFxCompilerTimer<QFxCompiler::InstrCreateObject> cc; #endif QObject *o = types.at(instr.create.type).createInstance(QmlContext::activeContext()); - if (!o) + if (!o) { + if(types.at(instr.create.type).component) + vmeErrors << types.at(instr.create.type).component->errors(); + VME_EXCEPTION("Unable to create object of type" << types.at(instr.create.type).className); + } if (instr.create.data != -1) { QmlCustomParser *customParser = diff --git a/src/declarative/qml/qmlvme_p.h b/src/declarative/qml/qmlvme_p.h index 86cd040..f7e13d6 100644 --- a/src/declarative/qml/qmlvme_p.h +++ b/src/declarative/qml/qmlvme_p.h @@ -68,8 +68,6 @@ private: QmlInstruction &, QmlCompiledData *); QList<QmlError> vmeErrors; - qint64 exceptionLine; - QString exceptionDescription; }; QT_END_NAMESPACE |