forked from mohammadhasanzadeh/yacalendar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CalendarModel.qml
54 lines (45 loc) · 1.37 KB
/
CalendarModel.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import QtQuick 2.14
import QtQml.Models 2.14
import "util.js" as UTIL
Item
{
id: control
property alias model: private_props.model
property date from: new Date (1950, 1, 1)
property date to: new Date (2050, 12, 1)
Component.onCompleted:
{
init();
}
function index_of(year, month)
{
return UTIL.find_in_model(private_props.model, (item) => {
return (item.year === year && item.month === month);
});
}
QtObject
{
id: private_props
property ListModel model: ListModel {}
}
function init()
{
if (!(from) || !(to) || (from > to))
return;
private_props.model.clear();
const start_year = from.getFullYear();
const end_year = to.getFullYear();
for (let year = start_year; year <= end_year; year++)
{
const end_month = (year === end_year) ? to.getMonth() : 12;
const start_month = (year === start_year) ? from.getMonth() : 1;
for (let month = start_month; month <= end_month; month++)
{
private_props.model.append({
year: year,
month: month
});
}
}
}
}