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