qTox  Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
friendlistmanager.h
Go to the documentation of this file.
1 /*
2  Copyright © 2021 by The qTox Project Contributors
3 
4  This file is part of qTox, a Qt-based graphical interface for Tox.
5 
6  qTox is libre software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  qTox is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with qTox. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 
22 #include "ifriendlistitem.h"
23 
24 #include <QObject>
25 #include <QVector>
26 
27 #include <memory>
28 
29 class FriendListManager : public QObject
30 {
31  Q_OBJECT
32 public:
33  using IFriendListItemPtr = std::shared_ptr<IFriendListItem>;
34 
35  explicit FriendListManager(int countContacts, QObject *parent = nullptr);
36 
37  QVector<IFriendListItemPtr> getItems() const;
38  bool needHideCircles() const;
39  // If the contact positions have changed, need to redraw view
40  bool getPositionsChanged() const;
41 
44  void sortByName();
45  void sortByActivity();
46  void resetParents();
47  void setFilter(const QString& searchString, bool hideOnline,
48  bool hideOffline, bool hideGroups);
49  void applyFilter();
50  void updatePositions();
51  void setSortRequired();
52 
53  void setGroupsOnTop(bool v);
54 
55 signals:
56  void itemsChanged();
57 
58 private:
59  struct FilterParams {
60  QString searchString = "";
61  bool hideOnline = false;
62  bool hideOffline = false;
63  bool hideGroups = false;
64  } filterParams;
65 
66  void removeAll(IFriendListItem*);
69 
70  bool byName = true;
71  bool hideCircles = false;
74  bool needSort;
75  QVector<IFriendListItemPtr> items;
76  // At startup, while the size of items is less than countContacts, the view will not be processed to improve performance
78 
79 };
FriendListManager::FilterParams
Definition: friendlistmanager.h:59
FriendListManager::FilterParams::hideOnline
bool hideOnline
Definition: friendlistmanager.h:61
FriendListManager::resetParents
void resetParents()
Definition: friendlistmanager.cpp:76
FriendListManager::getItems
QVector< IFriendListItemPtr > getItems() const
Definition: friendlistmanager.cpp:28
FriendListManager::byName
bool byName
Definition: friendlistmanager.h:70
FriendListManager::setFilter
void setFilter(const QString &searchString, bool hideOnline, bool hideOffline, bool hideGroups)
Definition: friendlistmanager.cpp:84
FriendListManager::groupsOnTop
bool groupsOnTop
Definition: friendlistmanager.h:72
FriendListManager::needHideCircles
bool needHideCircles() const
Definition: friendlistmanager.cpp:33
IFriendListItem
Definition: ifriendlistitem.h:26
FriendListManager::cmpByName
bool cmpByName(const IFriendListItemPtr &, const IFriendListItemPtr &, bool groupsOnTop)
Definition: friendlistmanager.cpp:186
FriendListManager::sortByActivity
void sortByActivity()
Definition: friendlistmanager.cpp:70
FriendListManager::positionsChanged
bool positionsChanged
Definition: friendlistmanager.h:73
FriendListManager::filterParams
struct FriendListManager::FilterParams filterParams
FriendListManager::removeFriendListItem
void removeFriendListItem(IFriendListItem *item)
Definition: friendlistmanager.cpp:58
FriendListManager::FilterParams::hideGroups
bool hideGroups
Definition: friendlistmanager.h:63
FriendListManager::setSortRequired
void setSortRequired()
Definition: friendlistmanager.cpp:165
FriendListManager::removeAll
void removeAll(IFriendListItem *)
Definition: friendlistmanager.cpp:176
FriendListManager
Definition: friendlistmanager.h:29
FriendListManager::setGroupsOnTop
void setGroupsOnTop(bool v)
Definition: friendlistmanager.cpp:171
ifriendlistitem.h
FriendListManager::hideCircles
bool hideCircles
Definition: friendlistmanager.h:71
FriendListManager::items
QVector< IFriendListItemPtr > items
Definition: friendlistmanager.h:75
FriendListManager::getPositionsChanged
bool getPositionsChanged() const
Definition: friendlistmanager.cpp:38
FriendListManager::FriendListManager
FriendListManager(int countContacts, QObject *parent=nullptr)
Definition: friendlistmanager.cpp:23
FriendListManager::itemsChanged
void itemsChanged()
FriendListManager::needSort
bool needSort
Definition: friendlistmanager.h:74
FriendListManager::updatePositions
void updatePositions()
Definition: friendlistmanager.cpp:133
FriendListManager::cmpByActivity
bool cmpByActivity(const IFriendListItemPtr &, const IFriendListItemPtr &)
Definition: friendlistmanager.cpp:214
FriendListManager::sortByName
void sortByName()
Definition: friendlistmanager.cpp:64
FriendListManager::addFriendListItem
void addFriendListItem(IFriendListItem *item)
Definition: friendlistmanager.cpp:43
FriendListManager::countContacts
int countContacts
Definition: friendlistmanager.h:77
FriendListManager::FilterParams::searchString
QString searchString
Definition: friendlistmanager.h:60
FriendListManager::applyFilter
void applyFilter()
Definition: friendlistmanager.cpp:99
FriendListManager::IFriendListItemPtr
std::shared_ptr< IFriendListItem > IFriendListItemPtr
Definition: friendlistmanager.h:33
FriendListManager::FilterParams::hideOffline
bool hideOffline
Definition: friendlistmanager.h:62