From 7429614188979f7cb68599ad2d83272dc0055e69 Mon Sep 17 00:00:00 2001 From: Diadlo Date: Sat, 5 Aug 2017 10:21:51 +0300 Subject: [PATCH] refactor(group): Store title name in Group --- src/model/group.cpp | 14 ++++++++++---- src/model/group.h | 3 ++- src/widget/groupwidget.cpp | 6 ++---- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/model/group.cpp b/src/model/group.cpp index 2cdad5e4b..54feeed31 100644 --- a/src/model/group.cpp +++ b/src/model/group.cpp @@ -28,8 +28,11 @@ #include #include -Group::Group(int groupId, QString name, bool isAvGroupchat) - : groupId(groupId) +static const int MAX_GROUP_TITLE_LENGTH = 128; + +Group::Group(int groupId, const QString& name, bool isAvGroupchat) + : title{name} + , groupId(groupId) , nPeers{0} , avGroupchat{isAvGroupchat} { @@ -70,12 +73,15 @@ void Group::updatePeer(int peerId, QString name) void Group::setName(const QString& name) { - emit titleChanged(groupId, name); + if (!name.isEmpty() && title != name) { + title = name.left(MAX_GROUP_TITLE_LENGTH); + emit titleChanged(groupId, title); + } } QString Group::getName() const { - return widget->getName(); + return title; } QString Group::getDisplayedName() const diff --git a/src/model/group.h b/src/model/group.h index 8b0be6056..90467a367 100644 --- a/src/model/group.h +++ b/src/model/group.h @@ -36,7 +36,7 @@ class Group : public Contact { Q_OBJECT public: - Group(int GroupId, QString Name, bool IsAvGroupchat); + Group(int groupId, const QString& name, bool isAvGroupchat); ~Group() override; bool isAvGroupchat() const; @@ -67,6 +67,7 @@ signals: void userListChanged(uint32_t groupId, const QMap& toxids); private: + QString title; GroupWidget* widget; GroupChatForm* chatForm; QStringList peers; diff --git a/src/widget/groupwidget.cpp b/src/widget/groupwidget.cpp index fa80893f2..3aa108809 100644 --- a/src/widget/groupwidget.cpp +++ b/src/widget/groupwidget.cpp @@ -63,10 +63,8 @@ GroupWidget::~GroupWidget() void GroupWidget::setTitle(const QString& newName) { - if (!newName.isEmpty()) { - Group* g = GroupList::findGroup(groupId); - g->setName(newName); - } + Group* g = GroupList::findGroup(groupId); + g->setName(newName); } void GroupWidget::contextMenuEvent(QContextMenuEvent* event)