20 |
20 |
21 #include "calendaymodelmanager.h" |
21 #include "calendaymodelmanager.h" |
22 #include "calendaymodel.h" |
22 #include "calendaymodel.h" |
23 |
23 |
24 /*! |
24 /*! |
25 BC Model Manager constructor. Model manager use calendar context to |
25 BC Model Manager constructor. Model manager use calendar context to |
26 populate models with proper events. |
26 populate models with proper events. |
27 \a services is handle to organizer services \a emptyModels if true created models |
27 \a services is handle to organizer services \a emptyModels if true created models |
28 are not populated with events \a parent |
28 are not populated with events \a parent |
29 */ |
29 */ |
30 CalenDayModelManager::CalenDayModelManager(MCalenServices &services, bool emptyModels, |
30 CalenDayModelManager::CalenDayModelManager( |
31 QObject *parent) |
31 MCalenServices &services, |
32 : QObject(parent), mServices (services) |
32 bool emptyModels, |
|
33 QObject *parent) : |
|
34 QObject(parent), mServices(services) |
33 { |
35 { |
34 if (emptyModels) |
36 if (emptyModels) { |
35 { |
37 mCurrentDayTime = QDateTime(); |
36 mCurrentDayTime = QDateTime(); |
38 } |
37 } |
39 else { |
38 else |
40 mCurrentDayTime = mServices.Context().focusDateAndTime(); |
39 { |
41 } |
40 mCurrentDayTime = mServices.Context().focusDateAndTime(); |
42 createAllModels(); |
41 } |
|
42 createAllModels(); |
|
43 } |
43 } |
44 |
44 |
45 CalenDayModelManager::~CalenDayModelManager() |
45 CalenDayModelManager::~CalenDayModelManager() |
46 { |
46 { |
47 // not needed now |
47 // not needed now |
48 } |
48 } |
49 |
49 |
50 |
|
51 void CalenDayModelManager::viewsScrollingFinished(CalenScrollDirection scrollTo) |
50 void CalenDayModelManager::viewsScrollingFinished(CalenScrollDirection scrollTo) |
52 { |
51 { |
53 if (scrollTo == ECalenScrollToNext) |
52 if (scrollTo == ECalenScrollToNext) { |
54 { |
53 moveForward(); |
55 moveForeward(); |
54 } |
56 } |
55 else { |
57 else |
56 moveBackward(); |
58 { |
57 } |
59 moveBackward(); |
58 } |
60 } |
|
61 } |
|
62 |
|
63 |
59 |
64 /*! |
60 /*! |
65 Reorganize models after move to previous day. |
61 Reorganize models after move to previous day. |
66 */ |
62 */ |
67 void CalenDayModelManager::moveBackward() |
63 void CalenDayModelManager::moveBackward() |
68 { |
64 { |
69 mCurrentDayTime = mServices.Context().focusDateAndTime(); |
65 mCurrentDayTime = mServices.Context().focusDateAndTime(); |
70 |
66 |
71 CalenDayModel* tmp = mModels[NextDay]; |
67 CalenDayModel* tmp = mModels[NextDay]; |
72 tmp->refreshModel( mCurrentDayTime.addDays(-1)); |
68 tmp->refreshModel(mCurrentDayTime.addDays(-1)); |
73 |
69 |
74 mModels[NextDay] = mModels[CurrentDay]; |
70 mModels[NextDay] = mModels[CurrentDay]; |
75 mModels[CurrentDay] = mModels[PreviousDay]; |
71 mModels[CurrentDay] = mModels[PreviousDay]; |
76 mModels[PreviousDay] = tmp; |
72 mModels[PreviousDay] = tmp; |
77 } |
73 } |
78 |
74 |
79 /*! |
75 /*! |
80 Reorganize models after move to next day. |
76 Reorganize models after move to next day. |
81 */ |
77 */ |
82 void CalenDayModelManager::moveForeward() |
78 void CalenDayModelManager::moveForward() |
83 { |
79 { |
84 mCurrentDayTime = mServices.Context().focusDateAndTime(); |
80 mCurrentDayTime = mServices.Context().focusDateAndTime(); |
85 |
81 |
86 CalenDayModel* tmp = mModels[PreviousDay]; |
82 CalenDayModel* tmp = mModels[PreviousDay]; |
87 tmp->refreshModel( mCurrentDayTime.addDays(1)); |
83 tmp->refreshModel(mCurrentDayTime.addDays(1)); |
88 |
84 |
89 mModels[PreviousDay] = mModels[CurrentDay]; |
85 mModels[PreviousDay] = mModels[CurrentDay]; |
90 mModels[CurrentDay] = mModels[NextDay]; |
86 mModels[CurrentDay] = mModels[NextDay]; |
91 mModels[NextDay] = tmp; |
87 mModels[NextDay] = tmp; |
92 } |
88 } |
93 |
89 |
94 /*! |
90 /*! |
95 Returns given model |
91 Returns given model |
96 /a day defines model, can be (PreviousDay, CurrentDay, NextDay) only. |
92 /a day defines model, can be (PreviousDay, CurrentDay, NextDay) only. |
97 */ |
93 */ |
98 QAbstractItemModel &CalenDayModelManager::getModel(ModelDay day) |
94 QAbstractItemModel &CalenDayModelManager::getModel(ModelDay day) |
99 { |
95 { |
100 return *(mModels[day]); |
96 return *(mModels[day]); |
101 } |
97 } |
102 |
98 |
103 /*! |
99 /*! |
104 Creates all models objects durring construction. |
100 Creates all models objects durring construction. |
105 */ |
101 */ |
106 void CalenDayModelManager::createAllModels() |
102 void CalenDayModelManager::createAllModels() |
107 { |
103 { |
108 |
104 |
109 mModels[CurrentDay] = new CalenDayModel(mCurrentDayTime, mServices, this); |
105 mModels[CurrentDay] = new CalenDayModel(mCurrentDayTime, mServices, this); |
110 |
106 |
111 QDateTime previousDayTime; |
107 QDateTime previousDayTime; |
112 QDateTime nextDayTime; |
108 QDateTime nextDayTime; |
113 |
109 |
114 if (mCurrentDayTime.isValid()) |
110 if (mCurrentDayTime.isValid()) { |
115 { |
111 previousDayTime = mCurrentDayTime.addDays(-1); |
116 previousDayTime = mCurrentDayTime.addDays(-1); |
112 nextDayTime = mCurrentDayTime.addDays(1); |
117 nextDayTime = mCurrentDayTime.addDays(1); |
113 } |
118 } |
114 |
119 |
115 mModels[PreviousDay] = new CalenDayModel(previousDayTime, mServices, this); |
120 mModels[PreviousDay] = new CalenDayModel(previousDayTime, mServices, this); |
116 mModels[NextDay] = new CalenDayModel(nextDayTime, mServices, this); |
121 mModels[NextDay] = new CalenDayModel(nextDayTime, mServices, this); |
|
122 } |
117 } |
123 |
118 |
|
119 /*! |
|
120 Refetch data for all models. Context calendar is used to fill models |
|
121 with correct events. Should be used for full (three days) repopulation. |
|
122 */ |
|
123 void CalenDayModelManager::refreshAllModels() |
|
124 { |
|
125 mCurrentDayTime = mServices.Context().focusDateAndTime(); |
|
126 |
|
127 mModels[PreviousDay]->refreshModel(mCurrentDayTime.addDays(-1)); |
|
128 mModels[CurrentDay]->refreshModel(mCurrentDayTime); |
|
129 mModels[NextDay]->refreshModel(mCurrentDayTime.addDays(1)); |
|
130 } |
124 |
131 |
125 /*! |
132 /*! |
126 Refetch data for all models. Context calendar is used to fill models |
133 Refetch data given day model. Context calendar is used to fill model |
127 with correct events. Should be used for full (three days) repopulation. |
134 with correct events. |
128 */ |
135 /a day defines model, can be (PreviousDay, CurrentDay, NextDay) only. |
129 void CalenDayModelManager::refreshAllModels() |
|
130 { |
|
131 mCurrentDayTime = mServices.Context().focusDateAndTime(); |
|
132 |
|
133 mModels[PreviousDay]->refreshModel(mCurrentDayTime.addDays(-1)); |
|
134 mModels[CurrentDay]->refreshModel(mCurrentDayTime); |
|
135 mModels[NextDay]->refreshModel(mCurrentDayTime.addDays(1)); |
|
136 } |
|
137 |
|
138 /*! |
|
139 Refetch data given day model. Context calendar is used to fill model |
|
140 with correct events. |
|
141 /a day defines model, can be (PreviousDay, CurrentDay, NextDay) only. |
|
142 */ |
136 */ |
143 void CalenDayModelManager::refreshSingleModel(CalenDayModelManager::ModelDay day) |
137 void CalenDayModelManager::refreshSingleModel(CalenDayModelManager::ModelDay day) |
144 { |
138 { |
145 switch (day) |
139 switch (day) { |
146 { |
140 case PreviousDay: { |
147 case PreviousDay: |
141 mModels[PreviousDay]->refreshModel(mCurrentDayTime.addDays(-1)); |
148 { |
142 } |
149 mModels[PreviousDay]->refreshModel(mCurrentDayTime.addDays(-1)); |
143 break; |
150 } |
144 case CurrentDay: { |
151 break; |
145 mModels[CurrentDay]->refreshModel(mCurrentDayTime); |
152 case CurrentDay: |
146 } |
153 { |
147 break; |
154 mModels[CurrentDay]->refreshModel(mCurrentDayTime); |
148 case NextDay: { |
155 } |
149 mModels[PreviousDay]->refreshModel(mCurrentDayTime.addDays(1)); |
156 break; |
150 } |
157 case NextDay: |
151 break; |
158 { |
152 default: |
159 mModels[PreviousDay]->refreshModel(mCurrentDayTime.addDays(1)); |
153 break; |
160 } |
154 } |
161 break; |
155 } |
162 default: |
|
163 break; |
|
164 } |
|
165 } |
|
166 |
156 |
167 // End of File |
157 // End of File |