on xenial help sign in
Don't use context properties but properties of the delegates
2d4bcd3Albert Astals Cid
plugins/Dash/listviewwithpageheader.cpp+13−16
@@ -97,6 +97,7 @@
97#include <qqmlengine.h>
97#include <qqmlengine.h>
98#pragma GCC diagnostic push
98#pragma GCC diagnostic push
99#pragma GCC diagnostic ignored "-pedantic"
99#pragma GCC diagnostic ignored "-pedantic"
100+#include <private/qqmlcontext_p.h>
100#include <private/qqmldelegatemodel_p.h>
101#include <private/qqmldelegatemodel_p.h>
101#include <private/qqmlglobal_p.h>
102#include <private/qqmlglobal_p.h>
102#include <private/qquickitem_p.h>
103#include <private/qquickitem_p.h>
@@ -757,8 +758,6 @@ QQuickItem *ListViewWithPageHeader::getSectionItem(const QString &sectionText, b
757
758
758 QQmlContext *creationContext = m_sectionDelegate->creationContext();
759 QQmlContext *creationContext = m_sectionDelegate->creationContext();
759 QQmlContext *context = new QQmlContext(creationContext ? creationContext : qmlContext(this));
760 QQmlContext *context = new QQmlContext(creationContext ? creationContext : qmlContext(this));
760− context->setContextProperty(QStringLiteral("section"), sectionText);
761− context->setContextProperty(QStringLiteral("delegateIndex"), -1);
762 QObject *nobj = m_sectionDelegate->beginCreate(context);
761 QObject *nobj = m_sectionDelegate->beginCreate(context);
763 if (nobj) {
762 if (nobj) {
764 QQml_setParent_noEvent(context, nobj);
763 QQml_setParent_noEvent(context, nobj);
@@ -766,6 +765,8 @@ QQuickItem *ListViewWithPageHeader::getSectionItem(const QString &sectionText, b
766 if (!sectionItem) {
765 if (!sectionItem) {
767 delete nobj;
766 delete nobj;
768 } else {
767 } else {
768+ sectionItem->setProperty("text", sectionText);
769+ sectionItem->setProperty("delegateIndex", -1);
769 sectionItem->setZ(2);
770 sectionItem->setZ(2);
770 QQml_setParent_noEvent(sectionItem, m_clipItem);
771 QQml_setParent_noEvent(sectionItem, m_clipItem);
771 sectionItem->setParentItem(m_clipItem);
772 sectionItem->setParentItem(m_clipItem);
@@ -801,8 +802,7 @@ void ListViewWithPageHeader::updateSectionItem(int modelIndex)
801 if (!item->sectionItem()) {
802 if (!item->sectionItem()) {
802 item->setSectionItem(getSectionItem(sectionText));
803 item->setSectionItem(getSectionItem(sectionText));
803 } else {
804 } else {
804− QQmlContext *context = QQmlEngine::contextForObject(item->sectionItem())->parentContext();
805+ item->sectionItem()->setProperty("text", sectionText);
805− context->setContextProperty(QStringLiteral("section"), sectionText);
806 }
806 }
807 } else {
807 } else {
808 if (item->sectionItem()) {
808 if (item->sectionItem()) {
@@ -923,8 +923,7 @@ ListViewWithPageHeader::ListItem *ListViewWithPageHeader::createItem(int modelIn
923 polish();
923 polish();
924 }
924 }
925 if (listItem->sectionItem()) {
925 if (listItem->sectionItem()) {
926− QQmlContext *context = QQmlEngine::contextForObject(listItem->sectionItem())->parentContext();
927− context->setContextProperty(QStringLiteral("delegateIndex"), modelIndex);
926+ listItem->sectionItem()->setProperty("delegateIndex", modelIndex);
928 }
927 }
929 adjustMinYExtent();
928 adjustMinYExtent();
930 m_contentHeightDirty = true;
929 m_contentHeightDirty = true;
@@ -948,9 +947,10 @@ void ListViewWithPageHeader::itemCreated(int modelIndex, QObject *object)
948 return;
947 return;
949
948
950 item->setParentItem(m_clipItem);
949 item->setParentItem(m_clipItem);
950+ // FIXME Why do we need the refreshExpressions call?
951 QQmlContext *context = QQmlEngine::contextForObject(item)->parentContext();
951 QQmlContext *context = QQmlEngine::contextForObject(item)->parentContext();
952− context->setContextProperty(QStringLiteral("ListViewWithPageHeader"), this);
952+ QQmlContextPrivate::get(context)->data->refreshExpressions();
953− context->setContextProperty(QStringLiteral("heightToClip"), QVariant::fromValue<int>(0));
953+ item->setProperty("heightToClip", QVariant::fromValue<int>(0));
954 if (modelIndex == m_asyncRequestedIndex) {
954 if (modelIndex == m_asyncRequestedIndex) {
955 createItem(modelIndex, false);
955 createItem(modelIndex, false);
956 refill();
956 refill();
@@ -1116,8 +1116,7 @@ void ListViewWithPageHeader::onModelUpdated(const QQmlChangeSet &changeSet, bool
1116 for (int i = 0; i < m_visibleItems.count(); ++i) {
1116 for (int i = 0; i < m_visibleItems.count(); ++i) {
1117 ListItem *item = m_visibleItems[i];
1117 ListItem *item = m_visibleItems[i];
1118 if (item->sectionItem()) {
1118 if (item->sectionItem()) {
1119− QQmlContext *context = QQmlEngine::contextForObject(item->sectionItem())->parentContext();
1120− context->setContextProperty(QStringLiteral("delegateIndex"), m_firstVisibleIndex + i);
1119+ item->sectionItem()->setProperty("delegateIndex", m_firstVisibleIndex + i);
1121 }
1120 }
1122 }
1121 }
1123
1122
@@ -1287,8 +1286,7 @@ void ListViewWithPageHeader::layout()
1287 } else {
1286 } else {
1288 // Update the top sticky section header
1287 // Update the top sticky section header
1289 const QString section = m_delegateModel->stringValue(modelIndex, m_sectionProperty);
1288 const QString section = m_delegateModel->stringValue(modelIndex, m_sectionProperty);
1290− QQmlContext *context = QQmlEngine::contextForObject(m_topSectionItem)->parentContext();
1289+ m_topSectionItem->setProperty("text", section);
1291− context->setContextProperty(QStringLiteral("section"), section);
1292
1290
1293 QQuickItemPrivate::get(m_topSectionItem)->setCulled(false);
1291 QQuickItemPrivate::get(m_topSectionItem)->setCulled(false);
1294 m_topSectionItem->setY(topSectionStickPos);
1292 m_topSectionItem->setY(topSectionStickPos);
@@ -1300,19 +1298,18 @@ void ListViewWithPageHeader::layout()
1300 break;
1298 break;
1301 delegateIndex--;
1299 delegateIndex--;
1302 }
1300 }
1303− context->setContextProperty(QStringLiteral("delegateIndex"), delegateIndex);
1301+ m_topSectionItem->setProperty("delegateIndex", delegateIndex);
1304 if (item->sectionItem()) {
1302 if (item->sectionItem()) {
1305 QQuickItemPrivate::get(item->sectionItem())->setCulled(true);
1303 QQuickItemPrivate::get(item->sectionItem())->setCulled(true);
1306 }
1304 }
1307 }
1305 }
1308 }
1306 }
1309 }
1307 }
1310− QQmlContext *context = QQmlEngine::contextForObject(item->m_item)->parentContext();
1311 const qreal clipFrom = visibleFrom + (!item->sectionItem() && m_topSectionItem && !QQuickItemPrivate::get(m_topSectionItem)->culled ? m_topSectionItem->height() : 0);
1308 const qreal clipFrom = visibleFrom + (!item->sectionItem() && m_topSectionItem && !QQuickItemPrivate::get(m_topSectionItem)->culled ? m_topSectionItem->height() : 0);
1312 if (!cull && pos < clipFrom) {
1309 if (!cull && pos < clipFrom) {
1313− context->setContextProperty(QStringLiteral("heightToClip"), clipFrom - pos);
1310+ item->m_item->setProperty("heightToClip", clipFrom - pos);
1314 } else {
1311 } else {
1315− context->setContextProperty(QStringLiteral("heightToClip"), QVariant::fromValue<int>(0));
1312+ item->m_item->setProperty("heightToClip", QVariant::fromValue<int>(0));
1316 }
1313 }
1317// qDebug() << "ListViewWithPageHeader::layout" << item->m_item;
1314// qDebug() << "ListViewWithPageHeader::layout" << item->m_item;
1318 pos += item->height();
1315 pos += item->height();
qml/Dash/DashCategoryBase.qml+3−11
@@ -24,17 +24,9 @@ Item {
24 /* Relevant really only for ListViewWithPageHeader case: specify how many pixels we can overlap with the section header */
24 /* Relevant really only for ListViewWithPageHeader case: specify how many pixels we can overlap with the section header */
25 readonly property int allowedOverlap: units.dp(1)
25 readonly property int allowedOverlap: units.dp(1)
26
26
27− property real __heightToClip: {
27+ property real heightToClip: 0
28− // Check this is in position where clipping is needed
29− if (typeof ListViewWithPageHeader !== 'undefined') {
30− if (typeof heightToClip !== 'undefined') {
31− if (heightToClip >= allowedOverlap) {
28+ readonly property real __heightToClip: heightToClip >= allowedOverlap ? heightToClip - allowedOverlap : 0
32− return heightToClip - allowedOverlap;
29+
33− }
34− }
35− }
36− return 0;
37− }
38
30
39 /*!
31 /*!
40 \internal
32 \internal
qml/Dash/GenericScopeView.qml+2−2
@@ -616,10 +616,10 @@ FocusScope {
616 sectionProperty: "name"
616 sectionProperty: "name"
617 sectionDelegate: ListItems.Header {
617 sectionDelegate: ListItems.Header {
618 objectName: "dashSectionHeader" + (delegate ? delegate.category : "")
618 objectName: "dashSectionHeader" + (delegate ? delegate.category : "")
619+ property int delegateIndex: -1
619 readonly property var delegate: categoryView.item(delegateIndex)
620 readonly property var delegate: categoryView.item(delegateIndex)
620 width: categoryView.width
621 width: categoryView.width
621− height: section != "" ? units.gu(5) : 0
622+ height: text != "" ? units.gu(5) : 0
622− text: section
623 color: scopeStyle ? scopeStyle.foreground : theme.palette.normal.baseText
623 color: scopeStyle ? scopeStyle.foreground : theme.palette.normal.baseText
624 iconName: delegate && delegate.headerLink ? "go-next" : ""
624 iconName: delegate && delegate.headerLink ? "go-next" : ""
625 onClicked: {
625 onClicked: {
tests/plugins/Dash/listviewwithpageheadersectionexternalmodeltest.cpp+2−2
@@ -151,12 +151,12 @@ private:
151
151
152 QString section(QQuickItem *item)
152 QString section(QQuickItem *item)
153 {
153 {
154− return item ? QQmlEngine::contextForObject(item)->parentContext()->contextProperty(QLatin1String("section")).toString() : QString();
154+ return item ? item->property("text").toString() : QString();
155 }
155 }
156
156
157 int sectionDelegateIndex(QQuickItem *item)
157 int sectionDelegateIndex(QQuickItem *item)
158 {
158 {
159− return item ? QQmlEngine::contextForObject(item)->parentContext()->contextProperty(QLatin1String("delegateIndex")).toInt() : -1;
159+ return item ? item->property("delegateIndex").toInt() : -1;
160 }
160 }
161
161
162private Q_SLOTS:
162private Q_SLOTS:
tests/plugins/Dash/listviewwithpageheadersectiontest.cpp+2−2
@@ -116,12 +116,12 @@ private:
116
116
117 QString section(QQuickItem *item) const
117 QString section(QQuickItem *item) const
118 {
118 {
119− return item ? QQmlEngine::contextForObject(item)->parentContext()->contextProperty(QLatin1String("section")).toString() : QString();
119+ return item ? item->property("text").toString() : QString();
120 }
120 }
121
121
122 int sectionDelegateIndex(QQuickItem *item) const
122 int sectionDelegateIndex(QQuickItem *item) const
123 {
123 {
124− return item ? QQmlEngine::contextForObject(item)->parentContext()->contextProperty(QLatin1String("delegateIndex")).toInt() : -1;
124+ return item ? item->property("delegateIndex").toInt() : -1;
125 }
125 }
126
126
127private Q_SLOTS:
127private Q_SLOTS:
tests/plugins/Dash/listviewwithpageheadertestsection.qml+3−2
@@ -97,9 +97,10 @@ Rectangle {
97 sectionProperty: "type"
97 sectionProperty: "type"
98 sectionDelegate: Component {
98 sectionDelegate: Component {
99 Rectangle {
99 Rectangle {
100+ property alias text: theText.text
100 color: "green"
101 color: "green"
101− height: section === "" ? 0 : section != "halfheight" ? 40 : 20;
102+ height: text === "" ? 0 : text != "halfheight" ? 40 : 20;
102− Text { text: section; font.pixelSize: 34 }
103+ Text { id: theText; font.pixelSize: 34 }
103 anchors { left: parent.left; right: parent.right }
104 anchors { left: parent.left; right: parent.right }
104 }
105 }
105 }
106 }
tests/plugins/Dash/listviewwithpageheadertestsectionexternalmodel.qml+2−1
@@ -65,9 +65,10 @@ Rectangle {
65 sectionProperty: "type"
65 sectionProperty: "type"
66 sectionDelegate: Component {
66 sectionDelegate: Component {
67 Rectangle {
67 Rectangle {
68+ property alias text: theText.text
68 color: "green"
69 color: "green"
69 height: 40
70 height: 40
70− Text { text: section; font.pixelSize: 34 }
71+ Text { id: theText; font.pixelSize: 34 }
71 anchors { left: parent.left; right: parent.right }
72 anchors { left: parent.left; right: parent.right }
72 }
73 }
73 }
74 }
tests/plugins/Dash/tst_ListViewWithPageHeaderQML.qml+4−2
@@ -81,9 +81,10 @@ Rectangle {
81 sectionDelegate: Component {
81 sectionDelegate: Component {
82 id: sectionHeaderComponent
82 id: sectionHeaderComponent
83 Rectangle {
83 Rectangle {
84+ property alias text: theText.text
84 color: "green"
85 color: "green"
85 height: listView.sectionHeaderHeight
86 height: listView.sectionHeaderHeight
86− Text { text: section; font.pixelSize: 34 }
87+ Text { id: theText; font.pixelSize: 34 }
87 anchors { left: parent.left; right: parent.right }
88 anchors { left: parent.left; right: parent.right }
88 }
89 }
89 }
90 }
@@ -92,9 +93,10 @@ Rectangle {
92 Component {
93 Component {
93 id: otherSectionHeaderComponent
94 id: otherSectionHeaderComponent
94 Rectangle {
95 Rectangle {
96+ property alias text: theText.text
95 color: "green"
97 color: "green"
96 height: 50
98 height: 50
97− Text { text: section; font.pixelSize: 34 }
99+ Text { id: theText; font.pixelSize: 34 }
98 anchors { left: parent.left; right: parent.right }
100 anchors { left: parent.left; right: parent.right }
99 }
101 }
100 }
102 }