1
/****************************************************************************
2
* Copyright (C) 2013-2014 by Savoir-Faire Linux *
3
* Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> *
5
* This library is free software; you can redistribute it and/or *
6
* modify it under the terms of the GNU Lesser General Public *
7
* License as published by the Free Software Foundation; either *
8
* version 2.1 of the License, or (at your option) any later version. *
10
* This library is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
13
* Lesser General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
17
***************************************************************************/
18
#ifndef CONTACT_PROXY_MODEL_H
19
#define CONTACT_PROXY_MODEL_H
21
#include <QtCore/QHash>
22
#include <QtCore/QStringList>
23
#include <QtCore/QAbstractItemModel>
26
#include "../lib/typedefs.h"
27
#include "../lib/contact.h"
28
class AbstractContactBackend;
29
class ContactTreeNode;
31
class ContactTreeBinder;
33
class LIB_EXPORT ContactProxyModel : public QAbstractItemModel
35
#pragma GCC diagnostic push
36
#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
38
#pragma GCC diagnostic pop
40
friend class AbstractContactBackend;
41
friend class ContactTreeNode;
42
friend class ContactTreeBinder;
43
explicit ContactProxyModel(AbstractContactBackend* parent,int role = Qt::DisplayRole, bool showAll = false);
44
virtual ~ContactProxyModel();
47
void setRole(int role);
48
void setShowAll(bool showAll);
50
//Model implementation
51
virtual bool setData ( const QModelIndex& index, const QVariant &value, int role );
52
virtual QVariant data ( const QModelIndex& index, int role = Qt::DisplayRole ) const;
53
virtual int rowCount ( const QModelIndex& parent = QModelIndex() ) const;
54
virtual Qt::ItemFlags flags ( const QModelIndex& index ) const;
55
virtual int columnCount ( const QModelIndex& parent = QModelIndex() ) const;
56
virtual QModelIndex parent ( const QModelIndex& index ) const;
57
virtual QModelIndex index ( int row, int column, const QModelIndex& parent=QModelIndex()) const;
58
virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
59
virtual QStringList mimeTypes ( ) const;
60
virtual QMimeData* mimeData ( const QModelIndexList &indexes ) const;
61
virtual bool dropMimeData ( const QMimeData*, Qt::DropAction, int, int, const QModelIndex& );
64
static int acceptedPayloadTypes();
69
QString category(Contact* ct) const;
72
QHash<Contact*, time_t> m_hContactByDate ;
73
AbstractContactBackend* m_pModel ;
74
QVector<TopLevelItem*> m_lCategoryCounter ;
75
QHash<QString,TopLevelItem*> m_hCategories ;
78
QStringList m_lMimes ;
81
TopLevelItem* getTopLevelItem(const QString& category);
84
void reloadCategories();
85
void slotContactAdded(Contact* c);
88
class ContactTreeBinder : public QObject { //FIXME Qt5 remove when dropping Qt4
91
ContactTreeBinder(ContactProxyModel* m,ContactTreeNode* n);
93
ContactTreeNode* m_pTreeNode;
94
ContactProxyModel* m_pModel;
96
void slotContactChanged();
97
void slotStatusChanged();
98
void slotPhoneNumberCountChanged(int,int);
99
void slotPhoneNumberCountAboutToChange(int,int);