Debian Codegraph @

src/qml/CustomPickers/1.0/YearModel.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 import Lomiri.Components 1.3
19
20 PickerModelBase {
21 // local properties
22 property int from
23 circular: false
24 autoExtend: !maximum.isValid()
25
26 function reset() {
27 resetting = true;
28 clear();
29 from = (minimum.getFullYear() <= 0) ? date.getFullYear() : minimum.getFullYear();
30 var to = (maximum < minimum) ? -1 : maximum.getFullYear();
31 extend(from, to - from);
32 }
33
34 function resetLimits(label, margin) {
35 label.text = "9999";
36 narrowFormatLimit = shortFormatLimit = longFormatLimit = label.paintedWidth + 2 * margin;
37 }
38
39 function extend(baseYear, items) {
40 if (items === undefined || items < 0) {
41 items = 50;
42 }
43 for (var i = baseYear; i <= baseYear + items; i++) {
44 append({"modelData" : i});
45 }
46 }
47
48 function indexOf() {
49 var index = date.getFullYear() - from;
50 if (index >= count) {
51 index = -1;
52 }
53
54 return index;
55 }
56
57 function dateFromIndex(index) {
58 if (index < 0 || index >= count) {
59 return date;
60 }
61 var newDate = new Date(date);
62 newDate.setFullYear(index + from);
63 return newDate;
64 }
65
66 function text(value) {
67 return (value) ? value : "";
68 }
69 }