source: SMSSender/frontend/gui/ui/models/contactgroupmodel.h @ 319:1ec456878bcb

separation-frontend-backend
Last change on this file since 319:1ec456878bcb was 319:1ec456878bcb, checked in by Sämy Zehnder <saemy.zehnder@…>, 8 years ago
  • Adjusts header guards to follow common pattern based on the filename.
File size: 3.0 KB
Line 
1/*
2 smssender - A frontend for fast and easy SMS sending over different gateways.
3 Copyright (C) 2007-2014, gorrión. See http://smssender.gorrion.ch
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program 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
13 GNU General Public License for more details.
14
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 FRONTEND_GUI_UI_MODELS_CONTACTGROUPMODEL_H
19#define FRONTEND_GUI_UI_MODELS_CONTACTGROUPMODEL_H
20
21#include <QAbstractListModel>
22#include <QList>
23#include <QSet>
24
25#include "common/domain/scontact.h"
26#include "common/domain/sgroup.h"
27#include "frontend/business/contactmanager.h"
28#include "frontend/business/groupmanager.h"
29
30namespace UI {
31
32struct ContactGroupContainer {
33    const SContact *contact;
34    const SGroup *group;
35
36    ContactGroupContainer() {}
37    ContactGroupContainer(const SContact *contact)
38        : contact(contact)
39        , group(NULL)
40    {}
41    ContactGroupContainer(const SGroup *group)
42        : contact(NULL)
43        , group(group)
44    {}
45
46    bool operator ==(const ContactGroupContainer &other) const {
47        return contact == other.contact &&
48                group == other.group;
49    }
50};
51inline uint qHash(const ContactGroupContainer& container) {
52    return qHash(container.contact) ^ qHash(container.group);
53}
54
55
56class ContactGroupListModel: public QAbstractListModel {
57    Q_OBJECT
58
59public:
60    ContactGroupListModel(QObject *parent, const ContactManager &contactManager, const GroupManager &groupManager);
61
62    QVariant      data(const QModelIndex& index, int role = Qt::DisplayRole) const;
63    int           columnCount(const QModelIndex& parent = QModelIndex()) const;
64    int           rowCount(const QModelIndex& parent = QModelIndex()) const;
65
66    ContactGroupContainer dataObject(const QModelIndex& index) const;
67
68    void          addFilteredContact(const SContact& contact);
69    void          removeFilteredContact(const SContact& contact);
70
71private slots:
72    void onDataUpdated(SContact *contact);
73    void onDataUpdated(SGroup *group);
74    void onListAltered();
75
76private:
77    QSet<const SGroup*> groups() const;
78    QSet<const SContact*> contacts() const;
79    QSet<const SGroup*> filteredGroups() const;
80    QSet<const SContact*> filteredContacts() const;
81
82    void reloadList();
83    void dataUpdated(const ContactGroupContainer& container);
84
85    const ContactManager &m_contactManager;
86    const GroupManager &m_groupManager;
87
88    QList<ContactGroupContainer> m_items;
89    QSet<ContactGroupContainer> m_filteredItems;
90};
91
92} // namespace UI
93
94#endif // FRONTEND_GUI_UI_MODELS_CONTACTGROUPMODEL_H
Note: See TracBrowser for help on using the repository browser.