Browse Source

fix(FriendList): exclusion of possible undefined behavior

pull/6614/head
bodwok 3 years ago
parent
commit
a1b08d6493
No known key found for this signature in database
GPG Key ID: A279D059178DA7BA
  1. 5
      src/model/friendlist/friendlistmanager.cpp
  2. 9
      src/model/friendlist/friendlistmanager.h
  3. 6
      test/model/friendlistmanager_test.cpp

5
src/model/friendlist/friendlistmanager.cpp

@ -40,6 +40,11 @@ bool FriendListManager::getPositionsChanged() const
return positionsChanged; return positionsChanged;
} }
bool FriendListManager::getGroupsOnTop() const
{
return groupsOnTop;
}
void FriendListManager::addFriendListItem(IFriendListItem *item) void FriendListManager::addFriendListItem(IFriendListItem *item)
{ {
if (item->isGroup() && item->getWidget() != nullptr) { if (item->isGroup() && item->getWidget() != nullptr) {

9
src/model/friendlist/friendlistmanager.h

@ -38,6 +38,7 @@ public:
bool needHideCircles() const; bool needHideCircles() const;
// If the contact positions have changed, need to redraw view // If the contact positions have changed, need to redraw view
bool getPositionsChanged() const; bool getPositionsChanged() const;
bool getGroupsOnTop() const;
void addFriendListItem(IFriendListItem* item); void addFriendListItem(IFriendListItem* item);
void removeFriendListItem(IFriendListItem* item); void removeFriendListItem(IFriendListItem* item);
@ -69,11 +70,11 @@ private:
bool byName = true; bool byName = true;
bool hideCircles = false; bool hideCircles = false;
bool groupsOnTop; bool groupsOnTop = true;
bool positionsChanged; bool positionsChanged = false;
bool needSort; bool needSort = false;
QVector<IFriendListItemPtr> items; QVector<IFriendListItemPtr> items;
// At startup, while the size of items is less than countContacts, the view will not be processed to improve performance // At startup, while the size of items is less than countContacts, the view will not be processed to improve performance
int countContacts; int countContacts = 0;
}; };

6
test/model/friendlistmanager_test.cpp

@ -148,6 +148,11 @@ public:
return this; return this;
} }
bool getGroupsOnTop()
{
return groupsOnTop;
}
/** /**
* @brief buildUnsorted Creates items to init the FriendListManager. * @brief buildUnsorted Creates items to init the FriendListManager.
* FriendListManager will own and manage these items * FriendListManager will own and manage these items
@ -341,6 +346,7 @@ void TestFriendListManager::testSortByName()
QCOMPARE(success, true); QCOMPARE(success, true);
QCOMPARE(manager->getPositionsChanged(), false); QCOMPARE(manager->getPositionsChanged(), false);
QCOMPARE(manager->getItems().size(), sortedVec.size()); QCOMPARE(manager->getItems().size(), sortedVec.size());
QCOMPARE(manager->getGroupsOnTop(), listBuilder.getGroupsOnTop());
for (int i = 0; i < sortedVec.size(); ++i) { for (int i = 0; i < sortedVec.size(); ++i) {
IFriendListItem* fromManager = manager->getItems().at(i).get(); IFriendListItem* fromManager = manager->getItems().at(i).get();

Loading…
Cancel
Save