Debian Codegraph @

src/qml/CustomPickers/1.0/PickerModelBase.qml

raw
1 /*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 import QtQuick 2.4
18
19 /*
20 Base model type for DatePicker
21 */
22 ListModel {
23
24 /*
25 Holds the picker instance, the component the model is attached to. Should
26 not be confused with the DatePicker.
27 */
28 property Item pickerItem
29
30 /*
31 Property holding the composit picker component.
32 */
33 property Item mainComponent
34
35 /*
36 The property holds the width of the picker tumbler to be set.
37 */
38 property real pickerWidth: 0
39
40 /*
41 Specifies whether the model is circular or not.
42 */
43 property bool circular: false
44
45 /*
46 The property specifies whenther the Picker should auto-extend the model.
47 Typical for year model.
48 */
49 property bool autoExtend: false
50
51 /*
52 Narow, normal and long format limits.
53 */
54 property real narrowFormatLimit: 0.0
55 property real shortFormatLimit: 0.0
56 property real longFormatLimit: 0.0
57
58 /*
59 The function resets the model and the attached Picker specified in the item.
60 The Picker must have a resetPicker() function available.
61 */
62 function reset() {}
63
64 /*
65 The function completes the reset operation.
66 */
67 function resetCompleted() {
68 resetting = false;
69 }
70
71 /*
72 Function called by the Picker to re-calculate values for the limit properties.
73 The locale is retrieved from pickerItem.
74 */
75 function resetLimits(label, margin) {}
76
77 /*
78 The function is called by the Picker component when a value gets selected to
79 keep the pickers in sync.
80 */
81 function syncModels() {}
82
83 /*
84 The function extends the model starting from a certain \a baseValue.
85 */
86 function extend(baseValue) {}
87
88 /*
89 Returns the index of the value from the model.
90 */
91 function indexOf() {
92 return -1;
93 }
94
95 /*
96 Returns a Date object from the model's \a index, relative to the given \a date.
97 */
98 function dateFromIndex(index) {
99 return new Date();
100 }
101
102 /*
103 Returns the date string for the value relative to the date, which fits into the
104 given width. Uses the locale from pickerItem to fetch the localized date string.
105 */
106 function text(value) {
107 return "";
108 }
109
110 /*
111 Readonly properties to the composit picker's date properties
112 */
113 readonly property date date: mainComponent.date
114 readonly property date minimum: mainComponent.minimum
115 readonly property date maximum: mainComponent.maximum
116
117 property bool pickerCompleted: false
118
119 /*
120 The property specifies whether there is a reset operation in progress or not.
121 Derivates overwriting reset() function must also set this flag to avoid unwanted
122 date changes that may occur during reset operation due to selectedIndex changes.
123 */
124 property bool resetting: false
125
126 /*
127 Call reset() whenever minimum or maximum changes, and update
128 selected index of pickerItem whenever date changes.
129 */
130 onMinimumChanged: {
131 if (pickerCompleted && pickerItem && !resetting) {
132 pickerItem.resetPicker();
133 }
134 }
135 onMaximumChanged: {
136 if (pickerCompleted && pickerItem && !resetting) {
137 pickerItem.resetPicker();
138 }
139 }
140 onDateChanged: {
141 if (!pickerCompleted || !pickerItem || resetting) {
142 return;
143 }
144 // use animated index update only if the change had happened because of the delegate update
145 if (pickerItem.__clickedIndex >= 0) {
146 pickerItem.selectedIndex = indexOf();
147 } else {
148 // in case the date property was changed due to binding/update,
149 // position tumbler without animating
150 pickerItem.positionViewAtIndex(indexOf());
151 }
152 }
153
154 }