phonebookui/cntlistmodel/cntlistmodel.h
changeset 81 640d30f4fb64
equal deleted inserted replaced
77:c18f9fa7f42e 81:640d30f4fb64
       
     1 /*
       
     2 * Copyright (c) 2009 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:
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef CNTLISTMODEL_H
       
    19 #define CNTLISTMODEL_H
       
    20 
       
    21 #include <QAbstractListModel>
       
    22 #include <QSharedData>
       
    23 #include <cntlistmodelglobal.h>
       
    24 #include <qcontactmanager.h>
       
    25 #include <qcontact.h>
       
    26 #include <qcontactid.h>
       
    27 #include <qcontactfilter.h>
       
    28 
       
    29 QTM_USE_NAMESPACE
       
    30 
       
    31 class CntListModelData;
       
    32 class XQSettingsKey;
       
    33 class CntDisplayTextFormatter;
       
    34 
       
    35 class CNTLISTMODEL_EXPORT CntListModel : public QAbstractListModel
       
    36 {
       
    37     Q_OBJECT
       
    38 public:
       
    39     CntListModel(QContactManager *manager,
       
    40                  const QContactFilter &contactFilter = QContactFilter(),
       
    41                  bool showMyCard = true,
       
    42                  QObject *parent = 0);
       
    43     ~CntListModel();
       
    44 
       
    45 public: // from QAbstractTableModel/QAbstractItemModel
       
    46     QVariant data(const QModelIndex &index, int role) const;
       
    47     int rowCount(const QModelIndex &parent = QModelIndex()) const;
       
    48 
       
    49 public:
       
    50 	QContact contact(const QModelIndex &index) const;
       
    51     QContactLocalId contactId(const QModelIndex &index) const;
       
    52 	QModelIndex indexOfContact(const QContact &contact) const;
       
    53 	QModelIndex indexOfContactId(const QContactLocalId &contactId) const;
       
    54 	void setFilter(const QContactFilter& contactFilter = QContactFilter());
       
    55 	void showMyCard(bool enabled);
       
    56 	bool isMyCardShown() const;
       
    57 	QContactLocalId myCardId() const;
       
    58 
       
    59 private:
       
    60     void updateContactIdsArray();
       
    61     QContact contact(int row) const;
       
    62     bool isValidRow(int row) const;
       
    63     int row(const QContactLocalId &contactId) const;
       
    64     QVariant dataForRole(int row, int role) const;
       
    65     void updateRelationships();
       
    66 
       
    67 private slots:
       
    68     void handleAdded(const QList<QContactLocalId> &contactIds);
       
    69     void handleChanged(const QList<QContactLocalId> &contactIds);
       
    70     void handleRemoved(const QList<QContactLocalId> &contactIds);
       
    71     void handleMyCardChanged(const QContactLocalId &oldId, const QContactLocalId &newId);
       
    72     void handleContactInfoUpdated(QContactLocalId contactId);
       
    73     void handleAddedRelationship(const QList<QContactLocalId> &contactIds);
       
    74     void handleRemovedRelationship(const QList<QContactLocalId> &contactIds);
       
    75     void handleRowSettingChanged(const XQSettingsKey &key, const QVariant &value);
       
    76     void refreshModel();
       
    77 
       
    78 private:
       
    79     QSharedDataPointer<CntListModelData> d;
       
    80 
       
    81     friend class TestCntListModel;
       
    82 };
       
    83 
       
    84 #endif