File indexing completed on 2024-11-24 04:50:42
0001 // SPDX-FileCopyrightText: 2009 Tobias Koenig <tokoe@kde.org> 0002 // SPDX-License-Identifier: LGPL-2.0-or-later 0003 0004 #pragma once 0005 0006 #include <QAbstractListModel> 0007 0008 #include <KContacts/ContactGroup> 0009 0010 #include <memory> 0011 0012 class ContactGroupModelPrivate; 0013 0014 class ContactGroupModel : public QAbstractListModel 0015 { 0016 Q_OBJECT 0017 0018 public: 0019 enum Role { 0020 IsReferenceRole = Qt::UserRole, 0021 DisplayNameRole, 0022 AllEmailsRole, 0023 EmailRole, 0024 IconNameRole, 0025 }; 0026 0027 explicit ContactGroupModel(bool isEditing, QObject *parent = nullptr); 0028 ~ContactGroupModel() override; 0029 0030 void loadContactGroup(const KContacts::ContactGroup &contactGroup); 0031 bool storeContactGroup(KContacts::ContactGroup &contactGroup) const; 0032 0033 QString lastErrorMessage() const; 0034 0035 QModelIndex index(int row, int col, const QModelIndex &parent = QModelIndex()) const override; 0036 QModelIndex parent(const QModelIndex &child) const override; 0037 QVariant data(const QModelIndex &index, int role) const override; 0038 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; 0039 QHash<int, QByteArray> roleNames() const override; 0040 QVariant headerData(int section, Qt::Orientation orientation, int role) const override; 0041 Qt::ItemFlags flags(const QModelIndex &index) const override; 0042 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0043 0044 Q_INVOKABLE void removeContact(int row); 0045 Q_INVOKABLE void addContactFromReference(const QString &gid, const QString &email); 0046 Q_INVOKABLE void addContactFromData(const QString &name, const QString &email); 0047 0048 private: 0049 friend class ContactGroupModelPrivate; 0050 std::unique_ptr<ContactGroupModelPrivate> const d; 0051 };