on xenial help sign in
Fix binding loop in FilterGrid height
commit3d3a8ccf92cd4f7d84278be5aacb4496818ccf01 authorAlbert Astals <albert.astals@canonical.com> dateWed 16 Apr 2014, 17:23 (13 years ago) parent6ed5060
4 files changed+41−41
qml/Components/FilterGrid.qml+34−20 qml/Dash/CardFilterGrid.qml+2−8 qml/Dash/DashRenderer.qml+1−4 qml/Dash/GenericScopeView.qml+4−9
qml/Components/FilterGrid.qml+34−20
@@ -30,7 +30,7 @@ Item {
3030
3131 /* If true, the number of elements displayed will be limited by collapsedRowCount.
3232 If false, all elements will be displayed, effectively looking the same as a regular
33− ResponsiveGridView. */
33+ ResponsiveGridView. Manipulate this property through setFilter */
3434 property bool filter: true
3535
3636 /* Whether, when collapsed, a button should be displayed enabling the user to expand
@@ -66,29 +66,35 @@ Item {
6666 property alias highlightIndex: iconTileGrid.highlightIndex
6767 readonly property alias currentItem: iconTileGrid.currentItem
6868
69− height: !filterAnimation.running ? childrenRect.height : height
69+ height: filter ? root.collapsedHeight : root.uncollapsedHeight
7070 clip: filterAnimation.running
7171
72− NumberAnimation {
73− property bool filterEndValue
74− id: filterAnimation
75− target: root
76− property: "height"
77− to: filterEndValue ? root.collapsedHeight : root.uncollapsedHeight
78− // Duration and easing here match the ListViewWithPageHeader::m_contentYAnimation
79− // otherwise since both animations can run at the same time you'll get
80− // some visual weirdness.
81− duration: 200
82− easing.type: Easing.InOutQuad
83− onStopped: {
84− root.filter = filterEndValue;
72+ Behavior on height {
73+ id: heightBehaviour
74+ enabled: false
75+ NumberAnimation {
76+ id: filterAnimation
77+ // Duration and easing here match the ListViewWithPageHeader::m_contentYAnimation
78+ // otherwise since both animations can run at the same time you'll get
79+ // some visual weirdness.
80+ duration: 200
81+ easing.type: Easing.InOutQuad
82+ onRunningChanged: {
83+ if (!running) {
84+ limitModel.filter = root.filter;
85+ }
86+ heightBehaviour.enabled = false;
87+ }
8588 }
8689 }
8790
88− function startFilterAnimation(filter) {
89− filterAnimation.filterEndValue = filter
90− filterAnimation.start();
91− }
91+ function setFilter(filter, animate) {
92+ heightBehaviour.enabled = animate;
93+ root.filter = filter;
94+ if (!animate || !filter) {
95+ limitModel.filter = filter;
96+ }
97+ }
9298
9399 ResponsiveGridView {
94100 id: iconTileGrid
@@ -104,8 +110,16 @@ Item {
104110 verticalSpacing: units.gu(2)
105111
106112 model: LimitProxyModel {
113+ id: limitModel
114+ // We do have another filter property here because
115+ // we can't directly use filter from the root since we need to decouple
116+ // the real filtering with the animation since the closing animation
117+ // i.e. filter=false we still need to not be filtering until
118+ // t he animation finishes otherwise we hide the items when the animation
119+ // is still running
120+ property bool filter: true
107121 model: root.model
108− limit: (filter && !filterAnimation.running) ? rowsWhenCollapsed * iconTileGrid.columns : -1
122+ limit: filter ? rowsWhenCollapsed * iconTileGrid.columns : -1
109123 }
110124 }
111125}
qml/Dash/CardFilterGrid.qml+2−8
@@ -29,8 +29,8 @@ DashRenderer {
2929 currentItem: filterGrid.currentItem
3030 height: filterGrid.height
3131
32− function startFilterAnimation(filter) {
33− filterGrid.startFilterAnimation(filter)
32+ function setFilter(filter, animate) {
33+ filterGrid.setFilter(filter, animate)
3434 }
3535
3636 FilterGrid {
@@ -41,7 +41,6 @@ DashRenderer {
4141 delegateHeight: cardTool.cardHeight
4242 verticalSpacing: genericFilterGrid.verticalSpacing
4343 model: genericFilterGrid.model
44− filter: genericFilterGrid.filter
4544 collapsedRowCount: Math.min(2, cardTool && cardTool.template && cardTool.template["collapsed-rows"] || 2)
4645 delegateCreationBegin: genericFilterGrid.delegateCreationBegin
4746 delegateCreationEnd: genericFilterGrid.delegateCreationEnd
@@ -66,10 +65,5 @@ DashRenderer {
6665 onPressAndHold: genericFilterGrid.pressAndHold(index, card.y)
6766 }
6867 }
69−
70− onFilterChanged: {
71− genericFilterGrid.filter = filter
72− filter = Qt.binding(function() { return genericFilterGrid.filter })
73− }
7468 }
7569}
qml/Dash/DashRenderer.qml+1−4
@@ -20,9 +20,6 @@ Item {
2020 // Can the item be expanded?
2121 property bool expandable: false
2222
23− // In case it can be expanded, should we filter it
24− property bool filter: true
25−
2623 property int collapsedHeight: height
2724
2825 property int margins: 0
@@ -58,6 +55,6 @@ Item {
5855 /// @param itemY is y of the held delegate
5956 signal pressAndHold(int index, real itemY)
6057
61− function startFilterAnimation(filter) {
58+ function setFilter(filter, animate) {
6259 }
6360}
qml/Dash/GenericScopeView.qml+4−9
@@ -121,7 +121,7 @@ FocusScope {
121121 showDivider: false
122122
123123 readonly property bool expandable: rendererLoader.item ? rendererLoader.item.expandable : false
124− readonly property bool filtered: rendererLoader.item ? rendererLoader.item.filter : true
124+ readonly property bool filtered: categoryView.expandedCategoryId != categoryId
125125 readonly property string category: categoryId
126126 readonly property var item: rendererLoader.item
127127
@@ -167,9 +167,7 @@ FocusScope {
167167 item.objectName = Qt.binding(function() { return categoryId })
168168 if (item.expandable) {
169169 var shouldFilter = categoryId != categoryView.expandedCategoryId;
170− if (shouldFilter != item.filter) {
171− item.filter = shouldFilter;
172− }
170+ item.setFilter(shouldFilter, false /*animate*/);
173171 }
174172 updateDelegateCreationRange();
175173 item.cardTool = cardTool;
@@ -218,11 +216,8 @@ FocusScope {
218216 var shrinkingVisible = shouldFilter && y + item.collapsedHeight < categoryView.height;
219217 var growingVisible = !shouldFilter && y + height < categoryView.height;
220218 if (!previewListView.open || !shouldFilter) {
221− if (shrinkingVisible || growingVisible) {
222− item.startFilterAnimation(shouldFilter)
223− } else {
224− item.filter = shouldFilter;
225− }
219+ var animate = shrinkingVisible || growingVisible;
220+ item.setFilter(shouldFilter, animate)
226221 if (!shouldFilter && !previewListView.open) {
227222 categoryView.maximizeVisibleArea(index, item.uncollapsedHeight);
228223 }