calendarui/views/dayview/src/calendaymodelmanager.cpp
changeset 45 b6db4fd4947b
child 57 bb2d3e476f29
equal deleted inserted replaced
23:fd30d51f876b 45:b6db4fd4947b
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: Model manager holds models for three day views
       
    15 *
       
    16 */
       
    17 
       
    18 #include <calenservices.h>
       
    19 #include <calencontext.h>
       
    20 
       
    21 #include "calendaymodelmanager.h"
       
    22 #include "calendaymodel.h"
       
    23 
       
    24 /*!
       
    25 	BC Model Manager constructor. Model manager use calendar context to
       
    26 	populate models with proper events.
       
    27 	\a services is handle to organizer services \a emptyModels if true created models
       
    28 	are not populated with events \a parent
       
    29  */
       
    30 CalenDayModelManager::CalenDayModelManager(MCalenServices &services, bool emptyModels,
       
    31 												QObject *parent)
       
    32 							: QObject(parent), mServices (services)
       
    33 {
       
    34 	if (emptyModels)
       
    35 		{
       
    36 		mCurrentDayTime = QDateTime();
       
    37 		}
       
    38 	else
       
    39 		{
       
    40 		mCurrentDayTime = mServices.Context().focusDateAndTime();
       
    41 		}
       
    42 	createAllModels();
       
    43 }
       
    44 
       
    45 CalenDayModelManager::~CalenDayModelManager()
       
    46 {
       
    47 	// not needed now
       
    48 }
       
    49 
       
    50 
       
    51 void CalenDayModelManager::viewsScrollingFinished(CalenScrollDirection scrollTo)
       
    52 	{
       
    53 	if (scrollTo == ECalenScrollToNext)
       
    54 		{
       
    55 		moveForeward();
       
    56 		}
       
    57 	else
       
    58 		{
       
    59 		moveBackward();
       
    60 		}
       
    61 	}
       
    62 
       
    63 
       
    64 /*!
       
    65 	Reorganize models after move to previous day.  
       
    66  */
       
    67 void CalenDayModelManager::moveBackward()
       
    68 {
       
    69 	mCurrentDayTime = mServices.Context().focusDateAndTime();
       
    70 
       
    71 	CalenDayModel* tmp = mModels[NextDay];
       
    72 	tmp->refreshModel( mCurrentDayTime.addDays(-1));
       
    73 	
       
    74 	mModels[NextDay] = mModels[CurrentDay];
       
    75 	mModels[CurrentDay] = mModels[PreviousDay];
       
    76 	mModels[PreviousDay] = tmp;
       
    77 }
       
    78 
       
    79 /*!
       
    80 	Reorganize models after move to next day. 
       
    81  */
       
    82 void CalenDayModelManager::moveForeward()
       
    83 {
       
    84 	mCurrentDayTime = mServices.Context().focusDateAndTime();
       
    85 	
       
    86 	CalenDayModel* tmp = mModels[PreviousDay];
       
    87 	tmp->refreshModel( mCurrentDayTime.addDays(1));
       
    88 	
       
    89 	mModels[PreviousDay] = mModels[CurrentDay];
       
    90 	mModels[CurrentDay] = mModels[NextDay];
       
    91 	mModels[NextDay] = tmp;
       
    92 }
       
    93 
       
    94 /*!
       
    95 	Returns given model
       
    96 	/a day defines model, can be (PreviousDay, CurrentDay, NextDay) only.  
       
    97  */
       
    98 QAbstractItemModel &CalenDayModelManager::getModel(ModelDay day)
       
    99 {
       
   100 	return *(mModels[day]);
       
   101 }
       
   102 
       
   103 /*!
       
   104 	Creates all models objects durring construction.  
       
   105  */
       
   106 void CalenDayModelManager::createAllModels()
       
   107 {
       
   108 	
       
   109 	mModels[CurrentDay] = new CalenDayModel(mCurrentDayTime, mServices, this);
       
   110 	
       
   111 	QDateTime previousDayTime; 
       
   112 	QDateTime nextDayTime;
       
   113 	
       
   114 	if (mCurrentDayTime.isValid())
       
   115 		{
       
   116 		previousDayTime = mCurrentDayTime.addDays(-1);
       
   117 		nextDayTime = mCurrentDayTime.addDays(1);
       
   118 		}
       
   119 		
       
   120 	mModels[PreviousDay] = new CalenDayModel(previousDayTime, mServices, this);
       
   121 	mModels[NextDay] = new CalenDayModel(nextDayTime, mServices, this);
       
   122 }
       
   123 
       
   124 
       
   125 /*!
       
   126 	Refetch data for all models. Context calendar is used to fill models
       
   127 	with correct events. Should be used for full (three days) repopulation.
       
   128  */
       
   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  */
       
   143 void CalenDayModelManager::refreshSingleModel(CalenDayModelManager::ModelDay day)
       
   144 	{
       
   145 	switch (day)
       
   146 		{
       
   147 		case PreviousDay:
       
   148 			{
       
   149 			mModels[PreviousDay]->refreshModel(mCurrentDayTime.addDays(-1));
       
   150 			}
       
   151 			break;
       
   152 		case CurrentDay:
       
   153 			{
       
   154 			mModels[CurrentDay]->refreshModel(mCurrentDayTime);
       
   155 			}
       
   156 			break;
       
   157 		case NextDay:
       
   158 			{
       
   159 			mModels[PreviousDay]->refreshModel(mCurrentDayTime.addDays(1));		
       
   160 			}
       
   161 			break;
       
   162 		default:
       
   163 			break;
       
   164 		}
       
   165 	}
       
   166 
       
   167 // End of File