Communi  3.0.0
A cross-platform IRC framework written with Qt
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Macros Groups Pages
ircusermodel.h
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2008-2013 The Communi Project
3 *
4 * This library is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
12 * License for more details.
13 */
14 
15 #ifndef IRCUSERMODEL_H
16 #define IRCUSERMODEL_H
17 
18 #include <Irc>
19 #include <IrcGlobal>
20 #include <QtCore/qstringlist.h>
21 #include <QtCore/qabstractitemmodel.h>
22 
23 IRC_BEGIN_NAMESPACE
24 
25 class IrcUser;
26 class IrcChannel;
27 class IrcMessage;
28 class IrcUserModelPrivate;
29 
30 class IRC_MODEL_EXPORT IrcUserModel : public QAbstractListModel
31 {
32  Q_OBJECT
33  Q_PROPERTY(int count READ count NOTIFY countChanged)
34  Q_PROPERTY(QStringList names READ names NOTIFY namesChanged)
35  Q_PROPERTY(QList<IrcUser*> users READ users NOTIFY usersChanged)
36  Q_PROPERTY(Irc::DataRole displayRole READ displayRole WRITE setDisplayRole)
37  Q_PROPERTY(IrcChannel* channel READ channel WRITE setChannel NOTIFY channelChanged)
38  Q_PROPERTY(Irc::SortMethod sortMethod READ sortMethod WRITE setSortMethod)
39  Q_PROPERTY(Qt::SortOrder sortOrder READ sortOrder WRITE setSortOrder)
40 
41 public:
42  explicit IrcUserModel(QObject* parent = 0);
43  virtual ~IrcUserModel();
44 
45  IrcChannel* channel() const;
46  void setChannel(IrcChannel* channel);
47 
48  int count() const;
49  QStringList names() const;
50  QList<IrcUser*> users() const;
51  Q_INVOKABLE IrcUser* get(int index) const;
52  Q_INVOKABLE IrcUser* find(const QString& name) const;
53  Q_INVOKABLE bool contains(const QString& name) const;
54  Q_INVOKABLE int indexOf(IrcUser* user) const;
55 
56  Irc::DataRole displayRole() const;
57  void setDisplayRole(Irc::DataRole role);
58 
59  Irc::SortMethod sortMethod() const;
60  void setSortMethod(Irc::SortMethod method);
61 
62  Qt::SortOrder sortOrder() const;
63  void setSortOrder(Qt::SortOrder order);
64 
65  QModelIndex index(IrcUser* user) const;
66  IrcUser* user(const QModelIndex& index) const;
67 
68  QHash<int, QByteArray> roleNames() const;
69  int rowCount(const QModelIndex& parent = QModelIndex()) const;
70  QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
71  QModelIndex index(int row, int column = 0, const QModelIndex& parent = QModelIndex()) const;
72 
73 public Q_SLOTS:
74  void clear();
75  void sort(int column = 0, Qt::SortOrder order = Qt::AscendingOrder);
76  void sort(Irc::SortMethod method, Qt::SortOrder order = Qt::AscendingOrder);
77 
78 Q_SIGNALS:
79  void added(IrcUser* user);
80  void removed(IrcUser* user);
81  void aboutToBeAdded(IrcUser* user);
82  void aboutToBeRemoved(IrcUser* user);
83  void countChanged(int count);
84  void namesChanged(const QStringList& names);
85  void usersChanged(const QList<IrcUser*>& users);
86  void channelChanged(IrcChannel* channel);
87 
88 protected:
89  virtual bool lessThan(IrcUser* one, IrcUser* another, Irc::SortMethod method) const;
90 
91 private:
92  friend class IrcUserLessThan;
93  friend class IrcChannelPrivate;
94  friend class IrcUserGreaterThan;
95  QScopedPointer<IrcUserModelPrivate> d_ptr;
96  Q_DECLARE_PRIVATE(IrcUserModel)
97  Q_DISABLE_COPY(IrcUserModel)
98 };
99 
100 IRC_END_NAMESPACE
101 
102 #endif // IRCUSERMODEL_H
Keeps track of channel status.
Definition: ircchannel.h:26
Keeps track of user status on a channel.
Definition: ircuser.h:28
SortMethod
Definition: irc.h:78
Keeps track of channel users.
Definition: ircusermodel.h:30
The base class of all messages.
Definition: ircmessage.h:32
DataRole
Definition: irc.h:68