Communi  3.4.0
A cross-platform IRC framework written with Qt
ircusermodel.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008-2015 The Communi Project
3 
4  You may use this file under the terms of BSD license as follows:
5 
6  Redistribution and use in source and binary forms, with or without
7  modification, are permitted provided that the following conditions are met:
8  * Redistributions of source code must retain the above copyright
9  notice, this list of conditions and the following disclaimer.
10  * Redistributions in binary form must reproduce the above copyright
11  notice, this list of conditions and the following disclaimer in the
12  documentation and/or other materials provided with the distribution.
13  * Neither the name of the copyright holder nor the names of its
14  contributors may be used to endorse or promote products derived
15  from this software without specific prior written permission.
16 
17  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR
21  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28 
29 #ifndef IRCUSERMODEL_H
30 #define IRCUSERMODEL_H
31 
32 #include <Irc>
33 #include <IrcGlobal>
34 #include <QtCore/qstringlist.h>
35 #include <QtCore/qabstractitemmodel.h>
36 
37 IRC_BEGIN_NAMESPACE
38 
39 class IrcUser;
40 class IrcChannel;
41 class IrcMessage;
42 class IrcUserModelPrivate;
43 
44 class IRC_MODEL_EXPORT IrcUserModel : public QAbstractListModel
45 {
46  Q_OBJECT
47  Q_PROPERTY(int count READ count NOTIFY countChanged)
48  Q_PROPERTY(bool empty READ isEmpty NOTIFY emptyChanged)
49  Q_PROPERTY(QStringList names READ names NOTIFY namesChanged)
50  Q_PROPERTY(QStringList titles READ titles NOTIFY titlesChanged)
51  Q_PROPERTY(QList<IrcUser*> users READ users NOTIFY usersChanged)
52  Q_PROPERTY(Irc::DataRole displayRole READ displayRole WRITE setDisplayRole)
53  Q_PROPERTY(IrcChannel* channel READ channel WRITE setChannel NOTIFY channelChanged)
54  Q_PROPERTY(Irc::SortMethod sortMethod READ sortMethod WRITE setSortMethod)
55  Q_PROPERTY(Qt::SortOrder sortOrder READ sortOrder WRITE setSortOrder)
56 
57 public:
58  explicit IrcUserModel(QObject* parent = 0);
59  virtual ~IrcUserModel();
60 
61  IrcChannel* channel() const;
62  void setChannel(IrcChannel* channel);
63 
64  int count() const;
65  bool isEmpty() const;
66  QStringList names() const;
67  QStringList titles() const;
68  QList<IrcUser*> users() const;
69  Q_INVOKABLE IrcUser* get(int index) const;
70  Q_INVOKABLE IrcUser* find(const QString& name) const;
71  Q_INVOKABLE bool contains(const QString& name) const;
72  Q_INVOKABLE int indexOf(IrcUser* user) const;
73 
74  Irc::DataRole displayRole() const;
75  void setDisplayRole(Irc::DataRole role);
76 
77  Irc::SortMethod sortMethod() const;
78  void setSortMethod(Irc::SortMethod method);
79 
80  Qt::SortOrder sortOrder() const;
81  void setSortOrder(Qt::SortOrder order);
82 
83  QModelIndex index(IrcUser* user) const;
84  IrcUser* user(const QModelIndex& index) const;
85 
86  QHash<int, QByteArray> roleNames() const;
87  int rowCount(const QModelIndex& parent = QModelIndex()) const;
88  QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
89  QModelIndex index(int row, int column = 0, const QModelIndex& parent = QModelIndex()) const;
90 
91 public Q_SLOTS:
92  void clear();
93  void sort(int column = 0, Qt::SortOrder order = Qt::AscendingOrder);
94  void sort(Irc::SortMethod method, Qt::SortOrder order = Qt::AscendingOrder);
95 
96 Q_SIGNALS:
97  void added(IrcUser* user);
98  void removed(IrcUser* user);
99  void aboutToBeAdded(IrcUser* user);
100  void aboutToBeRemoved(IrcUser* user);
101  void countChanged(int count);
102  void emptyChanged(bool empty);
103  void namesChanged(const QStringList& names);
104  void titlesChanged(const QStringList& titles);
105  void usersChanged(const QList<IrcUser*>& users);
106  void channelChanged(IrcChannel* channel);
107 
108 protected:
109  virtual bool lessThan(IrcUser* one, IrcUser* another, Irc::SortMethod method) const;
110 
111 private:
112  friend class IrcUserLessThan;
113  friend class IrcChannelPrivate;
114  friend class IrcUserGreaterThan;
115  QScopedPointer<IrcUserModelPrivate> d_ptr;
116  Q_DECLARE_PRIVATE(IrcUserModel)
117  Q_DISABLE_COPY(IrcUserModel)
118 };
119 
120 IRC_END_NAMESPACE
121 
122 #endif // IRCUSERMODEL_H
DataRole
Definition: irc.h:82
Keeps track of user status on a channel.
Definition: ircuser.h:42
Miscellaneous identifiers used throughout the library.
Definition: irc.h:40
Keeps track of channel users.
Definition: ircusermodel.h:44
Keeps track of channel status.
Definition: ircchannel.h:40
The base class of all messages.
Definition: ircmessage.h:47
SortMethod
Definition: irc.h:92