1
/****************************************************************************
3
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4
** All rights reserved.
5
** Contact: Nokia Corporation (qt-info@nokia.com)
7
** This file is part of the Qt Mobility Components.
9
** $QT_BEGIN_LICENSE:BSD$
10
** You may use this file under the terms of the BSD license as follows:
12
** "Redistribution and use in source and binary forms, with or without
13
** modification, are permitted provided that the following conditions are
15
** * Redistributions of source code must retain the above copyright
16
** notice, this list of conditions and the following disclaimer.
17
** * Redistributions in binary form must reproduce the above copyright
18
** notice, this list of conditions and the following disclaimer in
19
** the documentation and/or other materials provided with the
21
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
22
** the names of its contributors may be used to endorse or promote
23
** products derived from this software without specific prior written
26
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
39
****************************************************************************/
41
#include <qorganizeritemdetails.h>
42
#include <qorganizeritemrequests.h>
43
#include "qmlorganizermodel.h"
44
#include "qmlorganizeritem.h"
46
#include <QSharedPointer>
48
QMLOrganizerModel::QMLOrganizerModel(QObject *parent)
49
:QAbstractListModel(parent),
51
m_start(QDateTime::currentDateTime()),
52
m_end(QDateTime::currentDateTime())
57
QMLOrganizerModel::QMLOrganizerModel(QOrganizerItemManager* manager, const QDateTime& start, const QDateTime& end, QObject *parent) :
58
QAbstractListModel(parent),
62
QHash<int, QByteArray> roleNames;
63
roleNames = QAbstractItemModel::roleNames();
64
roleNames.insert(OrganizerItemIdRole, "itemId");
65
roleNames.insert(OrganizerItemRole, "item");
66
setRoleNames(roleNames);
69
connect(&m_request, SIGNAL(resultsAvailable()), this, SLOT(itemsReceived()));
71
m_filter.setStartPeriod(start);
72
m_filter.setEndPeriod(end);
73
m_request.setFilter(m_filter);
78
QString QMLOrganizerModel::manager()
81
return m_manager->managerName();
85
QDateTime QMLOrganizerModel::startPeriod() const
90
QDateTime QMLOrganizerModel::endPeriod() const
95
void QMLOrganizerModel::setStartPeriod(const QDateTime& start)
98
m_filter.setStartPeriod(m_start);
99
m_request.setFilter(m_filter);
102
void QMLOrganizerModel::setEndPeriod(const QDateTime& end)
105
m_filter.setEndPeriod(m_end);
106
m_request.setFilter(m_filter);
110
int QMLOrganizerModel::rowCount(const QModelIndex &parent) const
113
return m_items.count();
116
void QMLOrganizerModel::setManager(QOrganizerItemManager* manager)
118
disconnect(this, SLOT(reloadData()));
120
connect(m_manager, SIGNAL(dataChanged()), this, SLOT(reloadData()));
121
m_request.setManager(m_manager);
125
void QMLOrganizerModel::reloadData()
130
void QMLOrganizerModel::itemsReceived()
133
foreach (QMLOrganizerItem* qitem, m_items) {
138
QList<QOrganizerItem> items = m_request.items();
139
beginInsertRows(QModelIndex(), 0, items.count());
140
foreach (const QOrganizerItem& item, items) {
141
QMLOrganizerItem* qitem = new QMLOrganizerItem(this);
142
qitem->setItem(item);
143
m_items.append(qitem);
150
QVariant QMLOrganizerModel::data(const QModelIndex &index, int role) const
152
QMLOrganizerItem* item = m_items.at(index.row());
154
case OrganizerItemRole:
155
return QVariant::fromValue(item);