1
/***************************************************************************
2
* Copyright (C) 2009 by the Quassel Project *
3
* devel@quassel-irc.org *
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 2 of the License, or *
8
* (at your option) version 3. *
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. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19
***************************************************************************/
21
#ifndef COREACCOUNTMODEL_H_
22
#define COREACCOUNTMODEL_H_
24
#include <QAbstractListModel>
27
#include "coreaccount.h"
29
class CoreAccountModel : public QAbstractListModel {
34
AccountIdRole = Qt::UserRole,
38
CoreAccountModel(QObject *parent = 0);
39
CoreAccountModel(const CoreAccountModel *other, QObject *parent = 0);
41
inline int rowCount(const QModelIndex &parent = QModelIndex()) const;
42
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
44
CoreAccount account(const QModelIndex &) const;
45
CoreAccount account(AccountId) const;
46
QList<CoreAccount> accounts() const;
47
QList<AccountId> accountIds() const;
48
QModelIndex accountIndex(AccountId id) const;
50
inline AccountId internalAccount() const;
52
AccountId createOrUpdateAccount(const CoreAccount &newAccountData = CoreAccount());
53
CoreAccount takeAccount(AccountId);
54
void removeAccount(AccountId);
56
void update(const CoreAccountModel *other);
58
bool operator==(const CoreAccountModel &other) const;
66
void insertAccount(const CoreAccount &);
67
int findAccountIdx(AccountId) const;
70
int listIndex(AccountId);
72
QList<CoreAccount> _accounts;
73
QSet<AccountId> _removedAccounts;
74
AccountId _internalAccount;
78
int CoreAccountModel::rowCount(const QModelIndex &) const {
79
return _accounts.count();
82
AccountId CoreAccountModel::internalAccount() const {
83
return _internalAccount;