on xenial help sign in
Allow setting the cacheBuffer externally
358e8f6Albert Astals
plugins/Dash/abstractdashview.cpp+24−3
@@ -23,6 +23,7 @@ AbstractDashView::AbstractDashView()
23 , m_asyncRequestedIndex(-1)
23 , m_asyncRequestedIndex(-1)
24 , m_columnSpacing(0)
24 , m_columnSpacing(0)
25 , m_rowSpacing(0)
25 , m_rowSpacing(0)
26+ , m_buffer(320) // Same value used in qquickitemview.cpp in Qt 5.4
26 , m_displayMarginBeginning(0)
27 , m_displayMarginBeginning(0)
27 , m_displayMarginEnd(0)
28 , m_displayMarginEnd(0)
28 , m_needsRelayout(false)
29 , m_needsRelayout(false)
@@ -112,6 +113,27 @@ void AbstractDashView::setRowSpacing(qreal rowSpacing)
112 }
113 }
113}
114}
114
115
116+qreal AbstractDashView::cacheBuffer() const
117+{
118+ return m_buffer;
119+}
120+
121+void AbstractDashView::setCacheBuffer(qreal buffer)
122+{
123+ if (buffer < 0) {
124+ qmlInfo(this) << "Cannot set a negative cache buffer";
125+ return;
126+ }
127+
128+ if (m_buffer != buffer) {
129+ m_buffer = buffer;
130+ if (isComponentComplete()) {
131+ relayout();
132+ }
133+ emit cacheBufferChanged();
134+ }
135+}
136+
115qreal AbstractDashView::displayMarginBeginning() const
137qreal AbstractDashView::displayMarginBeginning() const
116{
138{
117 return m_displayMarginBeginning;
139 return m_displayMarginBeginning;
@@ -160,9 +182,8 @@ void AbstractDashView::refill()
160
182
161 const qreal from = -m_displayMarginBeginning;
183 const qreal from = -m_displayMarginBeginning;
162 const qreal to = height() + m_displayMarginEnd;
184 const qreal to = height() + m_displayMarginEnd;
163− const qreal buffer = (to - from) * bufferRatio;
164− const qreal bufferFrom = from - buffer;
185+ const qreal bufferFrom = from - m_buffer;
165− const qreal bufferTo = to + buffer;
186+ const qreal bufferTo = to + m_buffer;
166
187
167 bool added = addVisibleItems(from, to, false);
188 bool added = addVisibleItems(from, to, false);
168 bool removed = removeNonVisibleItems(bufferFrom, bufferTo);
189 bool removed = removeNonVisibleItems(bufferFrom, bufferTo);
plugins/Dash/abstractdashview.h+6
@@ -35,6 +35,7 @@ class AbstractDashView : public QQuickItem
35 Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged)
35 Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged)
36 Q_PROPERTY(qreal columnSpacing READ columnSpacing WRITE setColumnSpacing NOTIFY columnSpacingChanged)
36 Q_PROPERTY(qreal columnSpacing READ columnSpacing WRITE setColumnSpacing NOTIFY columnSpacingChanged)
37 Q_PROPERTY(qreal rowSpacing READ rowSpacing WRITE setRowSpacing NOTIFY rowSpacingChanged)
37 Q_PROPERTY(qreal rowSpacing READ rowSpacing WRITE setRowSpacing NOTIFY rowSpacingChanged)
38+ Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer NOTIFY cacheBufferChanged)
38 Q_PROPERTY(qreal displayMarginBeginning READ displayMarginBeginning
39 Q_PROPERTY(qreal displayMarginBeginning READ displayMarginBeginning
39 WRITE setDisplayMarginBeginning
40 WRITE setDisplayMarginBeginning
40 NOTIFY displayMarginBeginningChanged)
41 NOTIFY displayMarginBeginningChanged)
@@ -61,6 +62,9 @@ public:
61 qreal rowSpacing() const;
62 qreal rowSpacing() const;
62 void setRowSpacing(qreal rowSpacing);
63 void setRowSpacing(qreal rowSpacing);
63
64
65+ qreal cacheBuffer() const;
66+ void setCacheBuffer(qreal);
67+
64 qreal displayMarginBeginning() const;
68 qreal displayMarginBeginning() const;
65 void setDisplayMarginBeginning(qreal);
69 void setDisplayMarginBeginning(qreal);
66
70
@@ -72,6 +76,7 @@ Q_SIGNALS:
72 void delegateChanged();
76 void delegateChanged();
73 void columnSpacingChanged();
77 void columnSpacingChanged();
74 void rowSpacingChanged();
78 void rowSpacingChanged();
79+ void cacheBufferChanged();
75 void displayMarginBeginningChanged();
80 void displayMarginBeginningChanged();
76 void displayMarginEndChanged();
81 void displayMarginEndChanged();
77
82
@@ -113,6 +118,7 @@ private:
113
118
114 int m_columnSpacing;
119 int m_columnSpacing;
115 int m_rowSpacing;
120 int m_rowSpacing;
121+ qreal m_buffer;
116 qreal m_displayMarginBeginning;
122 qreal m_displayMarginBeginning;
117 qreal m_displayMarginEnd;
123 qreal m_displayMarginEnd;
118 bool m_needsRelayout;
124 bool m_needsRelayout;
qml/Dash/GenericScopeView.qml−2
@@ -395,8 +395,6 @@ FocusScope {
395 // make sure the items in the viewport are created with the cache buffer feature
395 // make sure the items in the viewport are created with the cache buffer feature
396 // - For visible scopes we should always the have a visible range be exactly the
396 // - For visible scopes we should always the have a visible range be exactly the
397 // viewport and make sure the rest of items are created with the cache buffer feature
397 // viewport and make sure the rest of items are created with the cache buffer feature
398− // To be able to implement that feature VerticalJournal/AbstractDashView needs to
399− // make the cache buffer value setable externally
400 var extraMargins = scopeView.isCurrent ? categoryView.height * 1.5 : 0;
398 var extraMargins = scopeView.isCurrent ? categoryView.height * 1.5 : 0;
401
399
402 item.displayMarginBeginning = Math.round(-Math.max(-baseItem.y - extraMargins, 0));
400 item.displayMarginBeginning = Math.round(-Math.max(-baseItem.y - extraMargins, 0));