summaryrefslogtreecommitdiffstats
path: root/src/declarative/graphicsitems
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2012-07-04 04:11:50 (GMT)
committerQt by Nokia <qt-info@nokia.com>2012-07-04 05:09:15 (GMT)
commitd25fc4c63fa4512aa1cfc5ce3877e4d8632b3fec (patch)
treefccda1762322b11b9d6e71fa4d447833e115e53d /src/declarative/graphicsitems
parent4bc2550e657ef1029919a15448f6f045354eeb96 (diff)
downloadQt-d25fc4c63fa4512aa1cfc5ce3877e4d8632b3fec.zip
Qt-d25fc4c63fa4512aa1cfc5ce3877e4d8632b3fec.tar.gz
Qt-d25fc4c63fa4512aa1cfc5ce3877e4d8632b3fec.tar.bz2
Qml ListView highlight component cannot access ListView scope
Use the component creationContext to create the highlight item. Also do this for the header and footer. Task-number: QTBUG-26043 Change-Id: Ib4b947d022cb1513f728ac66455bfd2fe2703744 Reviewed-by: Bea Lam <bea.lam@nokia.com>
Diffstat (limited to 'src/declarative/graphicsitems')
-rw-r--r--src/declarative/graphicsitems/qdeclarativegridview.cpp56
-rw-r--r--src/declarative/graphicsitems/qdeclarativelistview.cpp56
2 files changed, 48 insertions, 64 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp
index 868b6db..daf55a1 100644
--- a/src/declarative/graphicsitems/qdeclarativegridview.cpp
+++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp
@@ -165,6 +165,7 @@ public:
void clear();
FxGridItem *createItem(int modelIndex);
void releaseItem(FxGridItem *item);
+ QDeclarativeItem *createComponentItem(QDeclarativeComponent *component);
void refill(qreal from, qreal to, bool doBuffer=false);
void updateGrid();
@@ -557,6 +558,26 @@ void QDeclarativeGridViewPrivate::releaseItem(FxGridItem *item)
delete item;
}
+QDeclarativeItem *QDeclarativeGridViewPrivate::createComponentItem(QDeclarativeComponent *component)
+{
+ Q_Q(QDeclarativeGridView);
+ QDeclarativeItem *item = 0;
+ QDeclarativeContext *creationContext = component->creationContext();
+ QDeclarativeContext *context = new QDeclarativeContext(
+ creationContext ? creationContext : qmlContext(q));
+ QObject *nobj = component->create(context);
+ if (nobj) {
+ QDeclarative_setParent_noEvent(context, nobj);
+ item = qobject_cast<QDeclarativeItem *>(nobj);
+ if (!item)
+ delete nobj;
+ } else {
+ delete context;
+ }
+
+ return item;
+}
+
void QDeclarativeGridViewPrivate::refill(qreal from, qreal to, bool doBuffer)
{
Q_Q(QDeclarativeGridView);
@@ -838,16 +859,7 @@ void QDeclarativeGridViewPrivate::createHighlight()
if (currentItem) {
QDeclarativeItem *item = 0;
if (highlightComponent) {
- QDeclarativeContext *highlightContext = new QDeclarativeContext(qmlContext(q));
- QObject *nobj = highlightComponent->create(highlightContext);
- if (nobj) {
- QDeclarative_setParent_noEvent(highlightContext, nobj);
- item = qobject_cast<QDeclarativeItem *>(nobj);
- if (!item)
- delete nobj;
- } else {
- delete highlightContext;
- }
+ item = createComponentItem(highlightComponent);
} else {
item = new QDeclarativeItem;
QDeclarative_setParent_noEvent(item, q->contentItem());
@@ -935,17 +947,7 @@ void QDeclarativeGridViewPrivate::updateFooter()
{
Q_Q(QDeclarativeGridView);
if (!footer && footerComponent) {
- QDeclarativeItem *item = 0;
- QDeclarativeContext *context = new QDeclarativeContext(qmlContext(q));
- QObject *nobj = footerComponent->create(context);
- if (nobj) {
- QDeclarative_setParent_noEvent(context, nobj);
- item = qobject_cast<QDeclarativeItem *>(nobj);
- if (!item)
- delete nobj;
- } else {
- delete context;
- }
+ QDeclarativeItem *item = createComponentItem(footerComponent);
if (item) {
QDeclarative_setParent_noEvent(item, q->contentItem());
item->setParentItem(q->contentItem());
@@ -988,17 +990,7 @@ void QDeclarativeGridViewPrivate::updateHeader()
{
Q_Q(QDeclarativeGridView);
if (!header && headerComponent) {
- QDeclarativeItem *item = 0;
- QDeclarativeContext *context = new QDeclarativeContext(qmlContext(q));
- QObject *nobj = headerComponent->create(context);
- if (nobj) {
- QDeclarative_setParent_noEvent(context, nobj);
- item = qobject_cast<QDeclarativeItem *>(nobj);
- if (!item)
- delete nobj;
- } else {
- delete context;
- }
+ QDeclarativeItem *item = createComponentItem(headerComponent);
if (item) {
QDeclarative_setParent_noEvent(item, q->contentItem());
item->setParentItem(q->contentItem());
diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp
index ac91c66..be327a8 100644
--- a/src/declarative/graphicsitems/qdeclarativelistview.cpp
+++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp
@@ -217,6 +217,7 @@ public:
void clear();
FxListItem *createItem(int modelIndex);
void releaseItem(FxListItem *item);
+ QDeclarativeItem *createComponentItem(QDeclarativeComponent *component);
FxListItem *visibleItem(int modelIndex) const {
if (modelIndex >= visibleIndex && modelIndex < visibleIndex + visibleItems.count()) {
@@ -677,6 +678,26 @@ FxListItem *QDeclarativeListViewPrivate::createItem(int modelIndex)
return listItem;
}
+QDeclarativeItem *QDeclarativeListViewPrivate::createComponentItem(QDeclarativeComponent *component)
+{
+ Q_Q(QDeclarativeListView);
+ QDeclarativeItem *item = 0;
+ QDeclarativeContext *creationContext = component->creationContext();
+ QDeclarativeContext *context = new QDeclarativeContext(
+ creationContext ? creationContext : qmlContext(q));
+ QObject *nobj = component->create(context);
+ if (nobj) {
+ QDeclarative_setParent_noEvent(context, nobj);
+ item = qobject_cast<QDeclarativeItem *>(nobj);
+ if (!item)
+ delete nobj;
+ } else {
+ delete context;
+ }
+
+ return item;
+}
+
void QDeclarativeListViewPrivate::releaseItem(FxListItem *item)
{
Q_Q(QDeclarativeListView);
@@ -946,16 +967,7 @@ void QDeclarativeListViewPrivate::createHighlight()
if (currentItem) {
QDeclarativeItem *item = 0;
if (highlightComponent) {
- QDeclarativeContext *highlightContext = new QDeclarativeContext(qmlContext(q));
- QObject *nobj = highlightComponent->create(highlightContext);
- if (nobj) {
- QDeclarative_setParent_noEvent(highlightContext, nobj);
- item = qobject_cast<QDeclarativeItem *>(nobj);
- if (!item)
- delete nobj;
- } else {
- delete highlightContext;
- }
+ item = createComponentItem(highlightComponent);
} else {
item = new QDeclarativeItem;
}
@@ -1198,17 +1210,7 @@ void QDeclarativeListViewPrivate::updateFooter()
{
Q_Q(QDeclarativeListView);
if (!footer && footerComponent) {
- QDeclarativeItem *item = 0;
- QDeclarativeContext *context = new QDeclarativeContext(qmlContext(q));
- QObject *nobj = footerComponent->create(context);
- if (nobj) {
- QDeclarative_setParent_noEvent(context, nobj);
- item = qobject_cast<QDeclarativeItem *>(nobj);
- if (!item)
- delete nobj;
- } else {
- delete context;
- }
+ QDeclarativeItem *item = createComponentItem(footerComponent);
if (item) {
QDeclarative_setParent_noEvent(item, q->contentItem());
item->setParentItem(q->contentItem());
@@ -1238,17 +1240,7 @@ void QDeclarativeListViewPrivate::updateHeader()
{
Q_Q(QDeclarativeListView);
if (!header && headerComponent) {
- QDeclarativeItem *item = 0;
- QDeclarativeContext *context = new QDeclarativeContext(qmlContext(q));
- QObject *nobj = headerComponent->create(context);
- if (nobj) {
- QDeclarative_setParent_noEvent(context, nobj);
- item = qobject_cast<QDeclarativeItem *>(nobj);
- if (!item)
- delete nobj;
- } else {
- delete context;
- }
+ QDeclarativeItem *item = createComponentItem(headerComponent);
if (item) {
QDeclarative_setParent_noEvent(item, q->contentItem());
item->setParentItem(q->contentItem());