if (!object)
return stat;
- int cacheIndex = cacheIndexOf(object);
- if (cacheIndex != -1) {
- QQuickVisualDataModelItem *cacheItem = m_cache.at(cacheIndex);
+ if (QQuickVisualDataModelAttached *attached = QQuickVisualDataModelAttached::properties(object)) {
+ QQuickVisualDataModelItem *cacheItem = attached->m_cacheItem;
if (cacheItem->releaseObject()) {
destroy(object);
if (QQuickItem *item = qobject_cast<QQuickItem *>(object))
}
}
- ctxt->setContextProperty(QLatin1String("model"), cacheItem);
ctxt->setContextObject(cacheItem);
incubator->incubating = cacheItem;
return d->stringValue(d->m_compositorGroup, index, name);
}
-int QQuickVisualDataModelPrivate::cacheIndexOf(QObject *object) const
-{
- for (int cacheIndex = 0; cacheIndex < m_cache.count(); ++cacheIndex) {
- if (m_cache.at(cacheIndex)->object == object)
- return cacheIndex;
- }
- return -1;
-}
-
int QQuickVisualDataModel::indexOf(QQuickItem *item, QObject *) const
{
Q_D(const QQuickVisualDataModel);
- const int cacheIndex = d->cacheIndexOf(item);
- return cacheIndex != -1
- ? d->m_cache.at(cacheIndex)->index[d->m_compositorGroup]
- : -1;
+ if (QQuickVisualDataModelAttached *attached = QQuickVisualDataModelAttached::properties(item))
+ return attached->m_cacheItem->index[d->m_compositorGroup];
+ return -1;
}
void QQuickVisualDataModel::setWatchedRoles(QList<QByteArray> roles)
{
QHash<QObject *, QDeclarativePackage *>::const_iterator it = m_packaged.find(item);
if (it != m_packaged.end()) {
- const QQuickVisualDataModelPrivate *model = QQuickVisualDataModelPrivate::get(m_model);
- const int cacheIndex = model->cacheIndexOf(*it);
- return cacheIndex != -1
- ? model->m_cache.at(cacheIndex)->index[m_compositorGroup]
- : -1;
+ if (QQuickVisualDataModelAttached *attached = QQuickVisualDataModelAttached::properties(*it))
+ return attached->m_cacheItem->index[m_compositorGroup];
}
return -1;
}
#include <private/qdeclarativelistcompositor_p.h>
#include <private/qquickvisualitemmodel_p.h>
-
#include <QtCore/qabstractitemmodel.h>
#include <QtCore/qstringlist.h>
+
#include <private/qv8engine_p.h>
+#include <private/qdeclarativeglobal_p.h>
QT_BEGIN_HEADER
Q_PROPERTY(bool isUnresolved READ isUnresolved NOTIFY unresolvedChanged)
public:
QQuickVisualDataModelAttached(QObject *parent)
- : QObject(parent)
- , m_cacheItem(0)
+ : m_cacheItem(0)
, m_previousGroups(0)
, m_modelChanged(false)
- {}
+ {
+ QDeclarative_setParent_noEvent(this, parent);
+ }
~QQuickVisualDataModelAttached() { attachedProperties.remove(parent()); }
void setCacheItem(QQuickVisualDataModelItem *item);
{
Q_OBJECT
Q_PROPERTY(int index READ modelIndex NOTIFY modelIndexChanged)
+ Q_PROPERTY(QObject *model READ modelObject CONSTANT)
V8_RESOURCE_TYPE(VisualDataItemType)
public:
QQuickVisualDataModelItem(
void Dispose();
+ QObject *modelObject() { return this; }
+
int modelIndex() const { return index[0]; }
void setModelIndex(int idx) { index[0] = idx; emit modelIndexChanged(); }
void destroy(QObject *object);
QQuickVisualDataModel::ReleaseFlags release(QObject *object);
QString stringValue(Compositor::Group group, int index, const QString &name);
- int cacheIndexOf(QObject *object) const;
void emitCreatedPackage(QQuickVisualDataModelItem *cacheItem, QDeclarativePackage *package);
void emitInitPackage(QQuickVisualDataModelItem *cacheItem, QDeclarativePackage *package);
void emitCreatedItem(QQuickVisualDataModelItem *cacheItem, QQuickItem *item) {