Skip to content

Commit

Permalink
Minimize the number of objects created per item in VisualDataModel.
Browse files Browse the repository at this point in the history
Derive from QDeclarativeContext and reference count the context object
instead of parenting it to the context.  Combined with a weak
persistent v8 handle the allows the context object to be returned by
javascript accessors instead of creating a new instance for every use.

In addition to the efficiency advantages of creating fewer objects,
routing all data access through a single object means that object can
also persist data instead of just acting as a proxy.

Change-Id: I107dc8c901f16f2a4b420ff1cbffa7a6be27de89
Reviewed-by: Martin Jones <martin.jones@nokia.com>
  • Loading branch information
Andrew den Exter authored and Qt by Nokia committed Dec 23, 2011
1 parent 932a195 commit 347f84e
Show file tree
Hide file tree
Showing 11 changed files with 993 additions and 754 deletions.
Expand Up @@ -83,7 +83,7 @@ Item {
}
DropArea {
anchors.fill: parent
onEntered: visualModel.items.move(selectedItems, 0, packageRoot.VisualDataModel.itemsIndex, selectedItems.count)
onEntered: selectedItems.move(0, visualModel.items.get(packageRoot.VisualDataModel.itemsIndex), selectedItems.count)
}
}
Item {
Expand Down
1 change: 1 addition & 0 deletions src/quick/items/items.pri
Expand Up @@ -39,6 +39,7 @@ HEADERS += \
$$PWD/qquicklistview_p.h \
$$PWD/qquickvisualadaptormodel_p.h \
$$PWD/qquickvisualdatamodel_p.h \
$$PWD/qquickvisualdatamodel_p_p.h \
$$PWD/qquickvisualitemmodel_p.h \
$$PWD/qquickrepeater_p.h \
$$PWD/qquickrepeater_p_p.h \
Expand Down
467 changes: 280 additions & 187 deletions src/quick/items/qquickvisualadaptormodel.cpp

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/quick/items/qquickvisualadaptormodel_p.h
Expand Up @@ -45,14 +45,15 @@
#include <QtCore/qobject.h>
#include <QtCore/qabstractitemmodel.h>

#include <private/qdeclarativerefcount_p.h>

QT_BEGIN_HEADER

QT_BEGIN_NAMESPACE

class QDeclarativeEngine;

class QQuickVisualDataModelItem;
class QQuickVisualDataModelItemMetaType;

class QQuickVisualAdaptorModelPrivate;
class QQuickVisualAdaptorModel : public QObject
{
Expand Down Expand Up @@ -80,10 +81,9 @@ class QQuickVisualAdaptorModel : public QObject
QVariant parentModelIndex() const;

int count() const;
QObject *data(int index);
QQuickVisualDataModelItem *createItem(QQuickVisualDataModelItemMetaType *metaType, int index);
QString stringValue(int index, const QString &role);
void replaceWatchedRoles(const QList<QByteArray> &oldRoles, const QList<QByteArray> &newRoles);
int indexOf(QObject *object) const;

bool canFetchMore() const;
void fetchMore();
Expand Down

0 comments on commit 347f84e

Please sign in to comment.