calendarui/views/dayview/src/calendaymodel.cpp
changeset 57 bb2d3e476f29
parent 45 b6db4fd4947b
equal deleted inserted replaced
55:2c54b51f39c4 57:bb2d3e476f29
    13 *
    13 *
    14 * Description: Single day item view model
    14 * Description: Single day item view model
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 
    18 // System includes
    19 
       
    20 #include <calenservices.h>
    19 #include <calenservices.h>
    21 #include <agendautil.h>
    20 #include <agendautil.h>
       
    21 
       
    22 // User includes
    22 #include "calendaymodel.h"
    23 #include "calendaymodel.h"
    23 
    24 
    24 
    25 
    25 /*!
    26 /*!
    26 	BC Day Model constructor
    27  BC Day Model constructor
    27 	\a date defined day for which entries will be fetched \a services is handle to 
    28  \a date defined day for which entries will be fetched \a services is handle to 
    28 	organizer services \a parent
    29  organizer services \a parent
    29  */
    30  */
    30 CalenDayModel::CalenDayModel(const QDateTime &date, MCalenServices &services,
    31 CalenDayModel::CalenDayModel(const QDateTime &date, MCalenServices &services, QObject *parent) :
    31 									QObject *parent)
    32     QAbstractListModel(parent), mServices(services)
    32 									: QAbstractListModel(parent), mServices(services)
       
    33 {
    33 {
    34 	if (date.isValid())
    34     if (date.isValid()) {
    35 		{
    35         loadAndStoreInstances(date);
    36 		loadAndStoreInstances(date);
    36     }
    37 		}
       
    38 }
    37 }
    39 
    38 
    40 /*
    39 /*
    41     \reimp
    40  \reimp
    42  */
    41  */
    43 int CalenDayModel::rowCount( const QModelIndex &parent ) const
    42 int CalenDayModel::rowCount(const QModelIndex &parent) const
    44 {
    43 {
    45     Q_UNUSED( parent )
    44     Q_UNUSED( parent )
    46     return mEntryList.count();
    45     return mEntryList.count();
    47 }
    46 }
    48 
    47 
    49 /*
    48 /*
    50     \reimp
    49  \reimp
    51  */
    50  */
    52 QVariant CalenDayModel::data(const QModelIndex &index, int role) const
    51 QVariant CalenDayModel::data(const QModelIndex &index, int role) const
    53 {
    52 {
    54     if (!index.isValid())
    53     if (!index.isValid()) {
    55     	{
       
    56         return QVariant();
    54         return QVariant();
    57     	}
    55     }
    58 
    56 
    59     if (index.row() >= mEntryList.count())
    57     if (index.row() >= mEntryList.count()) {
    60     	{
       
    61         return QVariant();
    58         return QVariant();
    62     	}
    59     }
    63 
    60 
    64     if (role == CalenDayEntry)
    61     if (role == CalenDayEntry) {
    65     	{
       
    66         return mEntryList.at(index.row());
    62         return mEntryList.at(index.row());
    67     	}
    63     }
    68     else
    64     else {
    69     	{
       
    70         return QVariant();
    65         return QVariant();
    71     	}
    66     }
    72 }
    67 }
    73 
    68 
    74 /*!
    69 /*!
    75 	Resets model. Old events are removed. Evenets for given day are fetched.
    70  Resets model. Old events are removed. Evenets for given day are fetched.
    76 	\a date defined day for which entries will be fetched
    71  \a date defined day for which entries will be fetched
    77  */
    72  */
    78 void CalenDayModel::refreshModel(const QDateTime &date)
    73 void CalenDayModel::refreshModel(const QDateTime &date)
    79 {
    74 {
    80 	beginResetModel();
    75     beginResetModel();
    81 	loadAndStoreInstances(date);
    76     loadAndStoreInstances(date);
    82 	endResetModel();
    77     endResetModel();
    83 }
       
    84 
       
    85 
       
    86 /*!
       
    87 	Fetches entries via. organizer API and stores it in member container 
       
    88  */
       
    89 void CalenDayModel::loadAndStoreInstances(const QDateTime &date)
       
    90 {   
       
    91 	mDateTime = date;
       
    92     //Filter flags
       
    93 	AgendaUtil::FilterFlags filter = AgendaUtil::FilterFlags(
       
    94 			AgendaUtil::IncludeAppointments | AgendaUtil::IncludeEvents);
       
    95 	QList<AgendaEntry> list;
       
    96 	// Fetch the instance list from the agenda interface
       
    97 	list = mServices.agendaInterface()->createEntryIdListForDay(date, filter);
       
    98 
       
    99 	mEntryList.clear();
       
   100 
       
   101 	foreach(AgendaEntry entry, list)
       
   102 		{
       
   103 		mEntryList.append(QVariant::fromValue(entry));
       
   104 		}
       
   105 }
    78 }
   106 
    79 
   107 /*!
    80 /*!
   108 	Retruns date (day). Model holds events for this day. 
    81  Fetches entries via. organizer API and stores it in member container 
       
    82  */
       
    83 void CalenDayModel::loadAndStoreInstances(const QDateTime &date)
       
    84 {
       
    85     mDateTime = date;
       
    86     //Filter flags
       
    87     AgendaUtil::FilterFlags filter = AgendaUtil::FilterFlags(AgendaUtil::IncludeAppointments
       
    88         | AgendaUtil::IncludeEvents);
       
    89     QList<AgendaEntry> list;
       
    90     // Fetch the instance list from the agenda interface
       
    91     list = mServices.agendaInterface()->createEntryIdListForDay(date, filter);
       
    92 
       
    93     mEntryList.clear();
       
    94 
       
    95     foreach(AgendaEntry entry, list){
       
    96         mEntryList.append(QVariant::fromValue(entry));
       
    97     }
       
    98 }
       
    99 
       
   100 /*!
       
   101  Retruns date (day). Model holds events for this day. 
   109  */
   102  */
   110 QDateTime CalenDayModel::modelDate() const
   103 QDateTime CalenDayModel::modelDate() const
   111 {
   104 {
   112 	return mDateTime;
   105     return mDateTime;
   113 }
   106 }