on xenial help sign in
Use the new displayMargin feature

Also port our DashViews to use same naming and behaviour + update tests

commita174c26bba0e8b6c3de3732d220522a7d7afb630 authorAlbert Astals <albert.astals@canonical.com> dateMon 19 May 2014, 07:35 (12 years ago) parentbcb22f432aac45
11 files changed+65−102
plugins/Dash/abstractdashview.cpp+18−48 plugins/Dash/abstractdashview.h+14−20 qml/Components/FilterGrid.qml+2−2 qml/Components/ResponsiveGridView.qml+3−3 qml/Dash/CardFilterGrid.qml+2−2 qml/Dash/DashRenderer.qml+2−2 qml/Dash/GenericScopeView.qml+9−7 tests/plugins/Dash/horizontaljournaltest.cpp+6−6 tests/plugins/Dash/organicgridtest.cpp+2−5 tests/plugins/Dash/verticaljournaltest.cpp+6−6 tests/qmltests/Dash/tst_GenericScopeView.qml+1−1
plugins/Dash/abstractdashview.cpp+18−48
@@ -23,10 +23,8 @@ AbstractDashView::AbstractDashView()
2323 , m_asyncRequestedIndex(-1)
2424 , m_columnSpacing(0)
2525 , m_rowSpacing(0)
26− , m_delegateCreationBegin(0)
27− , m_delegateCreationEnd(0)
28− , m_delegateCreationBeginValid(false)
29− , m_delegateCreationEndValid(false)
26+ , m_displayMarginBeginning(0)
27+ , m_displayMarginEnd(0)
3028 , m_needsRelayout(false)
3129 , m_delegateValidated(false)
3230 , m_implicitHeightDirty(false)
@@ -114,62 +112,36 @@ void AbstractDashView::setRowSpacing(qreal rowSpacing)
114112 }
115113}
116114
117−qreal AbstractDashView::delegateCreationBegin() const
115+qreal AbstractDashView::displayMarginBeginning() const
118116{
119− return m_delegateCreationBegin;
117+ return m_displayMarginBeginning;
120118}
121119
122−void AbstractDashView::setDelegateCreationBegin(qreal begin)
120+void AbstractDashView::setDisplayMarginBeginning(qreal begin)
123121{
124− m_delegateCreationBeginValid = true;
125− if (m_delegateCreationBegin == begin)
122+ if (m_displayMarginBeginning == begin)
126123 return;
127− m_delegateCreationBegin = begin;
124+ m_displayMarginBeginning = begin;
128125 if (isComponentComplete()) {
129126 polish();
130127 }
131− emit delegateCreationBeginChanged();
128+ emit displayMarginBeginningChanged();
132129}
133130
134−void AbstractDashView::resetDelegateCreationBegin()
131+qreal AbstractDashView::displayMarginEnd() const
135132{
136− m_delegateCreationBeginValid = false;
137− if (m_delegateCreationBegin == 0)
138− return;
139− m_delegateCreationBegin = 0;
140− if (isComponentComplete()) {
141− polish();
142− }
143− emit delegateCreationBeginChanged();
144−}
145−
146−qreal AbstractDashView::delegateCreationEnd() const
147−{
148− return m_delegateCreationEnd;
149−}
150−
151−void AbstractDashView::setDelegateCreationEnd(qreal end)
152−{
153− m_delegateCreationEndValid = true;
154− if (m_delegateCreationEnd == end)
155− return;
156− m_delegateCreationEnd = end;
157− if (isComponentComplete()) {
158− polish();
159− }
160− emit delegateCreationEndChanged();
133+ return m_displayMarginEnd;
161134}
162135
163−void AbstractDashView::resetDelegateCreationEnd()
136+void AbstractDashView::setDisplayMarginEnd(qreal end)
164137{
165− m_delegateCreationEndValid = false;
166− if (m_delegateCreationEnd == 0)
138+ if (m_displayMarginEnd == end)
167139 return;
168− m_delegateCreationEnd = 0;
140+ m_displayMarginEnd = end;
169141 if (isComponentComplete()) {
170142 polish();
171143 }
172− emit delegateCreationEndChanged();
144+ emit displayMarginEndChanged();
173145}
174146
175147void AbstractDashView::createDelegateModel()
@@ -186,9 +158,8 @@ void AbstractDashView::refill()
186158 return;
187159 }
188160
189− const bool delegateRangesValid = m_delegateCreationBeginValid && m_delegateCreationEndValid;
190− const qreal from = delegateRangesValid ? m_delegateCreationBegin : 0;
191− const qreal to = delegateRangesValid ? m_delegateCreationEnd : from + height();
161+ const qreal from = -m_displayMarginBeginning;
162+ const qreal to = height() + m_displayMarginEnd;
192163 const qreal buffer = (to - from) * bufferRatio;
193164 const qreal bufferFrom = from - buffer;
194165 const qreal bufferTo = to + buffer;
@@ -330,9 +301,8 @@ void AbstractDashView::updatePolish()
330301
331302 refill();
332303
333− const bool delegateRangesValid = m_delegateCreationBeginValid && m_delegateCreationEndValid;
334− const qreal from = delegateRangesValid ? m_delegateCreationBegin : 0;
335− const qreal to = delegateRangesValid ? m_delegateCreationEnd : from + height();
304+ const qreal from = -m_displayMarginBeginning;
305+ const qreal to = height() + m_displayMarginEnd;
336306 updateItemCulling(from, to);
337307
338308 if (m_implicitHeightDirty) {
plugins/Dash/abstractdashview.h+14−20
@@ -35,14 +35,12 @@ class AbstractDashView : public QQuickItem
3535 Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged)
3636 Q_PROPERTY(qreal columnSpacing READ columnSpacing WRITE setColumnSpacing NOTIFY columnSpacingChanged)
3737 Q_PROPERTY(qreal rowSpacing READ rowSpacing WRITE setRowSpacing NOTIFY rowSpacingChanged)
38− Q_PROPERTY(qreal delegateCreationBegin READ delegateCreationBegin
39− WRITE setDelegateCreationBegin
40− NOTIFY delegateCreationBeginChanged
41− RESET resetDelegateCreationBegin)
42− Q_PROPERTY(qreal delegateCreationEnd READ delegateCreationEnd
43− WRITE setDelegateCreationEnd
44− NOTIFY delegateCreationEndChanged
45− RESET resetDelegateCreationEnd)
38+ Q_PROPERTY(qreal displayMarginBeginning READ displayMarginBeginning
39+ WRITE setDisplayMarginBeginning
40+ NOTIFY displayMarginBeginningChanged)
41+ Q_PROPERTY(qreal displayMarginEnd READ displayMarginEnd
42+ WRITE setDisplayMarginEnd
43+ NOTIFY displayMarginEndChanged)
4644
4745friend class VerticalJournalTest;
4846friend class HorizontalJournalTest;
@@ -63,21 +61,19 @@ public:
6361 qreal rowSpacing() const;
6462 void setRowSpacing(qreal rowSpacing);
6563
66− qreal delegateCreationBegin() const;
67− void setDelegateCreationBegin(qreal);
68− void resetDelegateCreationBegin();
64+ qreal displayMarginBeginning() const;
65+ void setDisplayMarginBeginning(qreal);
6966
70− qreal delegateCreationEnd() const;
71− void setDelegateCreationEnd(qreal);
72− void resetDelegateCreationEnd();
67+ qreal displayMarginEnd() const;
68+ void setDisplayMarginEnd(qreal);
7369
7470Q_SIGNALS:
7571 void modelChanged();
7672 void delegateChanged();
7773 void columnSpacingChanged();
7874 void rowSpacingChanged();
79− void delegateCreationBeginChanged();
80− void delegateCreationEndChanged();
75+ void displayMarginBeginningChanged();
76+ void displayMarginEndChanged();
8177
8278protected Q_SLOTS:
8379 void relayout();
@@ -117,10 +113,8 @@ private:
117113
118114 int m_columnSpacing;
119115 int m_rowSpacing;
120− qreal m_delegateCreationBegin;
121− qreal m_delegateCreationEnd;
122− bool m_delegateCreationBeginValid;
123− bool m_delegateCreationEndValid;
116+ qreal m_displayMarginBeginning;
117+ qreal m_displayMarginEnd;
124118 bool m_needsRelayout;
125119 bool m_delegateValidated;
126120 bool m_implicitHeightDirty;
qml/Components/FilterGrid.qml+2−2
@@ -52,8 +52,8 @@ Item {
5252 property alias delegate: iconTileGrid.delegate
5353 property alias cellWidth: iconTileGrid.cellWidth
5454 property alias cellHeight: iconTileGrid.cellHeight
55− property alias delegateCreationBegin: iconTileGrid.delegateCreationBegin
56− property alias delegateCreationEnd: iconTileGrid.delegateCreationEnd
55+ property alias displayMarginBeginning: iconTileGrid.displayMarginBeginning
56+ property alias displayMarginEnd: iconTileGrid.displayMarginEnd
5757 readonly property alias originY: iconTileGrid.originY
5858 readonly property alias flicking: iconTileGrid.flicking
5959 readonly property alias moving: iconTileGrid.moving
qml/Components/ResponsiveGridView.qml+3−3
@@ -14,7 +14,7 @@
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1515 */
1616
17−import QtQuick 2.0
17+import QtQuick 2.3
1818import Ubuntu.Components 0.1
1919
2020/*
@@ -41,8 +41,8 @@ Item {
4141 readonly property alias moving: gridView.moving
4242 readonly property alias pressDelay: gridView.pressDelay
4343 readonly property alias originY: gridView.originY
44− property alias delegateCreationBegin: gridView.delegateCreationBegin
45− property alias delegateCreationEnd: gridView.delegateCreationEnd
44+ property alias displayMarginBeginning: gridView.displayMarginBeginning
45+ property alias displayMarginEnd: gridView.displayMarginEnd
4646 property alias highlightIndex: gridView.highlightIndex
4747 readonly property alias currentItem: gridView.currentItem
4848
qml/Dash/CardFilterGrid.qml+2−2
@@ -43,8 +43,8 @@ DashRenderer {
4343 verticalSpacing: genericFilterGrid.verticalSpacing
4444 model: genericFilterGrid.model
4545 collapsedRowCount: Math.min(2, cardTool && cardTool.template && cardTool.template["collapsed-rows"] || 2)
46− delegateCreationBegin: genericFilterGrid.delegateCreationBegin
47− delegateCreationEnd: genericFilterGrid.delegateCreationEnd
46+ displayMarginBeginning: genericFilterGrid.displayMarginBeginning
47+ displayMarginEnd: genericFilterGrid.displayMarginEnd
4848 delegate: Item {
4949 width: filterGrid.cellWidth
5050 height: filterGrid.cellHeight
qml/Dash/DashRenderer.qml+2−2
@@ -29,9 +29,9 @@ Item {
2929
3030 property int uncollapsedHeight: height
3131
32− property var delegateCreationBegin: undefined
32+ property int displayMarginBeginning: 0
3333
34− property var delegateCreationEnd: undefined
34+ property int displayMarginEnd: 0
3535
3636 property real originY: 0
3737
qml/Dash/GenericScopeView.qml+9−7
@@ -244,18 +244,20 @@ FocusScope {
244244 }
245245 }
246246
247− if (item && item.hasOwnProperty("delegateCreationBegin")) {
247+ if (item && item.hasOwnProperty("displayMarginBeginning")) {
248+ // TODO do we need item.originY here, test 1300302 once we have a silo
249+ // and we can run it on the phone
248250 if (baseItem.y + baseItem.height <= 0) {
249251 // Not visible (item at top of the list viewport)
250− item.delegateCreationBegin = item.originY + baseItem.height
251− item.delegateCreationEnd = item.originY + baseItem.height
252+ item.displayMarginBeginning = -baseItem.height;
253+ item.displayMarginEnd = 0;
252254 } else if (baseItem.y >= categoryView.height) {
253255 // Not visible (item at bottom of the list viewport)
254− item.delegateCreationBegin = item.originY
255− item.delegateCreationEnd = item.originY
256+ item.displayMarginBeginning = 0;
257+ item.displayMarginEnd = -baseItem.height;
256258 } else {
257− item.delegateCreationBegin = item.originY + Math.max(-baseItem.y, 0)
258− item.delegateCreationEnd = item.originY + Math.min(categoryView.height + item.delegateCreationBegin, baseItem.height)
259+ item.displayMarginBeginning = -Math.max(-baseItem.y, 0);
260+ item.displayMarginEnd = -Math.max(baseItem.height - categoryView.height + baseItem.y, 0)
259261 }
260262 }
261263 }
tests/plugins/Dash/horizontaljournaltest.cpp+6−6
@@ -258,8 +258,8 @@ private Q_SLOTS:
258258
259259 void testDelegateCreationRanges()
260260 {
261− hj->setDelegateCreationBegin(300);
262− hj->setDelegateCreationEnd(view->height());
261+ hj->setDisplayMarginBeginning(-300);
262+ hj->setDisplayMarginEnd(-(hj->height() - view->height()));
263263
264264 QTRY_COMPARE(hj->m_firstVisibleIndex, 6);
265265 QTRY_COMPARE(hj->m_visibleItems.count(), 7);
@@ -274,8 +274,8 @@ private Q_SLOTS:
274274 QTRY_COMPARE(hj->m_lastInRowIndexPosition[ 7], 210.);
275275 QTRY_COMPARE(hj->m_lastInRowIndexPosition[12], 305.);
276276
277− hj->resetDelegateCreationBegin();
278− hj->resetDelegateCreationEnd();
277+ hj->setDisplayMarginBeginning(0);
278+ hj->setDisplayMarginEnd(0);
279279
280280 // This is exactly the same block as the first again
281281 checkInitialPositions();
@@ -469,8 +469,8 @@ private Q_SLOTS:
469469
470470 void testNegativeDelegateCreationRange()
471471 {
472− hj->setDelegateCreationBegin(0);
473− hj->setDelegateCreationEnd(-100);
472+ hj->setDisplayMarginBeginning(0);
473+ hj->setDisplayMarginEnd(-(hj->height() + 100));
474474
475475 QStringList widthList;
476476 widthList << "100" << "50" << "50" << "30";
tests/plugins/Dash/organicgridtest.cpp+2−5
@@ -499,17 +499,14 @@ private Q_SLOTS:
499499 QTRY_COMPARE(grid->m_firstVisibleIndex, 0);
500500 QTRY_COMPARE(grid->m_visibleItems.count(), 198);
501501
502− grid->setDelegateCreationBegin(300);
503− grid->setDelegateCreationEnd(400);
502+ grid->setDisplayMarginBeginning(-300);
503+ grid->setDisplayMarginEnd(-(grid->height() - 400));
504504 checkImplicitHeight(2290);
505505
506506 QTRY_COMPARE(grid->m_firstVisibleIndex, 36);
507507 QTRY_COMPARE(grid->m_visibleItems.count(), 54);
508508 checkImplicitHeight(2290);
509509
510− grid->resetDelegateCreationBegin();
511− grid->resetDelegateCreationEnd();
512−
513510 view->resize(470, 470);
514511
515512 grid->setSmallDelegateSize(QSizeF(90, 90));
tests/plugins/Dash/verticaljournaltest.cpp+6−6
@@ -263,8 +263,8 @@ private Q_SLOTS:
263263
264264 void testDelegateCreationRanges()
265265 {
266− vj->setDelegateCreationBegin(200);
267− vj->setDelegateCreationEnd(view->height());
266+ vj->setDisplayMarginBeginning(-200);
267+ vj->setDisplayMarginEnd(-(vj->height() - view->height()));
268268
269269 QTRY_COMPARE(vj->m_columnVisibleItems.count(), 3);
270270 QTRY_COMPARE(vj->m_columnVisibleItems[0].count(), 4);
@@ -286,8 +286,8 @@ private Q_SLOTS:
286286 verifyItem(vj->m_columnVisibleItems[1][3], 15, 160, 430, false);
287287 QCOMPARE(vj->implicitHeight(), 690. + 4. * 690. / 16.);
288288
289− vj->resetDelegateCreationBegin();
290− vj->resetDelegateCreationEnd();
289+ vj->setDisplayMarginBeginning(0);
290+ vj->setDisplayMarginEnd(0);
291291
292292 // This is exactly the same block as the first again
293293 checkInitialPositions();
@@ -478,8 +478,8 @@ private Q_SLOTS:
478478
479479 void testNegativeDelegateCreationRange()
480480 {
481− vj->setDelegateCreationBegin(0);
482− vj->setDelegateCreationEnd(-100);
481+ vj->setDisplayMarginBeginning(0);
482+ vj->setDisplayMarginEnd(-(vj->height() + 100));
483483
484484 QStringList heightList;
485485 heightList << "100" << "50" << "50" << "30";
tests/qmltests/Dash/tst_GenericScopeView.qml+1−1
@@ -199,7 +199,7 @@ Item {
199199 var header0 = findChild(genericScopeView, "dashSectionHeader0")
200200 mouseClick(header0, header0.width / 2, header0.height / 2);
201201 tryCompare(category, "filtered", false);
202− tryCompare(category.item, "delegateCreationEnd", category.item.delegateCreationBegin + genericScopeView.height);
202+ tryCompareFunction(function() { return category.item.height == genericScopeView.height - category.item.displayMarginBeginning - category.item.displayMarginEnd; }, true);
203203 mouseClick(header0, header0.width / 2, header0.height / 2);
204204 tryCompare(category, "filtered", true);
205205 }