Communi  3.5.0
A cross-platform IRC framework written with Qt
ircusermodel.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008-2016 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/qmetatype.h>
35 #include <QtCore/qstringlist.h>
36 #include <QtCore/qabstractitemmodel.h>
37 
38 IRC_BEGIN_NAMESPACE
39 
40 class IrcUser;
41 class IrcChannel;
42 class IrcMessage;
43 class IrcUserModelPrivate;
44 
45 class IRC_MODEL_EXPORT IrcUserModel : public QAbstractListModel
46 {
47  Q_OBJECT
48  Q_PROPERTY(int count READ count NOTIFY countChanged)
49  Q_PROPERTY(bool empty READ isEmpty NOTIFY emptyChanged)
50  Q_PROPERTY(QStringList names READ names NOTIFY namesChanged)
51  Q_PROPERTY(QStringList titles READ titles NOTIFY titlesChanged)
52  Q_PROPERTY(QList<IrcUser*> users READ users NOTIFY usersChanged)
53  Q_PROPERTY(Irc::DataRole displayRole READ displayRole WRITE setDisplayRole)
54  Q_PROPERTY(IrcChannel* channel READ channel WRITE setChannel NOTIFY channelChanged)
55  Q_PROPERTY(Irc::SortMethod sortMethod READ sortMethod WRITE setSortMethod)
56  Q_PROPERTY(Qt::SortOrder sortOrder READ sortOrder WRITE setSortOrder)
57 
58 public:
59  explicit IrcUserModel(QObject* parent = 0);
60  virtual ~IrcUserModel();
61 
62  IrcChannel* channel() const;
63  void setChannel(IrcChannel* channel);
64 
65  int count() const;
66  bool isEmpty() const;
67  QStringList names() const;
68  QStringList titles() const;
69  QList<IrcUser*> users() const;
70  Q_INVOKABLE IrcUser* get(int index) const;
71  Q_INVOKABLE IrcUser* find(const QString& name) const;
72  Q_INVOKABLE bool contains(const QString& name) const;
73  Q_INVOKABLE int indexOf(IrcUser* user) const;
74 
75  Irc::DataRole displayRole() const;
76  void setDisplayRole(Irc::DataRole role);
77 
78  Irc::SortMethod sortMethod() const;
79  void setSortMethod(Irc::SortMethod method);
80 
81  Qt::SortOrder sortOrder() const;
82  void setSortOrder(Qt::SortOrder order);
83 
84  QModelIndex index(IrcUser* user) const;
85  IrcUser* user(const QModelIndex& index) const;
86 
87  QHash<int, QByteArray> roleNames() const;
88  int rowCount(const QModelIndex& parent = QModelIndex()) const;
89  QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
90  QModelIndex index(int row, int column = 0, const QModelIndex& parent = QModelIndex()) const;
91 
92 public Q_SLOTS:
93  void clear();
94  void sort(int column = 0, Qt::SortOrder order = Qt::AscendingOrder);
95  void sort(Irc::SortMethod method, Qt::SortOrder order = Qt::AscendingOrder);
96 
97 Q_SIGNALS:
98  void added(IrcUser* user);
99  void removed(IrcUser* user);
100  void aboutToBeAdded(IrcUser* user);
101  void aboutToBeRemoved(IrcUser* user);
102  void countChanged(int count);
103  void emptyChanged(bool empty);
104  void namesChanged(const QStringList& names);
105  void titlesChanged(const QStringList& titles);
106  void usersChanged(const QList<IrcUser*>& users);
107  void channelChanged(IrcChannel* channel);
108 
109 protected:
110  virtual bool lessThan(IrcUser* one, IrcUser* another, Irc::SortMethod method) const;
111 
112 private:
113  friend class IrcUserLessThan;
114  friend class IrcChannelPrivate;
115  friend class IrcUserGreaterThan;
116  QScopedPointer<IrcUserModelPrivate> d_ptr;
117  Q_DECLARE_PRIVATE(IrcUserModel)
118  Q_DISABLE_COPY(IrcUserModel)
119 };
120 
121 IRC_END_NAMESPACE
122 
123 Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcUserModel*))
124 
125 #endif // IRCUSERMODEL_H
Keeps track of user status on a channel.
Definition: ircuser.h:42
Keeps track of channel users.
Definition: ircusermodel.h:45
Keeps track of channel status.
Definition: ircchannel.h:40
The base class of all messages.
Definition: ircmessage.h:47
Miscellaneous identifiers used throughout the library.
Definition: irc.h:39