2022-02-16 21:51:04 +00:00
|
|
|
#include "section_model.h"
|
|
|
|
|
|
|
|
namespace Shared::Models
|
|
|
|
{
|
|
|
|
SectionModel::SectionModel(QObject* parent)
|
|
|
|
: QAbstractListModel(parent)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
QHash<int, QByteArray> SectionModel::roleNames() const
|
|
|
|
{
|
|
|
|
QHash<int, QByteArray> roles;
|
|
|
|
|
|
|
|
roles[Id] = "id";
|
|
|
|
roles[SectionType] = "sectionType";
|
|
|
|
roles[Name] = "name";
|
|
|
|
roles[AmISectionAdmin] = "amISectionAdmin";
|
|
|
|
roles[Description] = "description";
|
|
|
|
roles[Image] = "image";
|
|
|
|
roles[Icon] = "icon";
|
|
|
|
roles[Color] = "color";
|
|
|
|
roles[HasNotification] = "hasNotification";
|
|
|
|
roles[NotificationsCount] = "notificationsCount";
|
|
|
|
roles[Active] = "active";
|
|
|
|
roles[Enabled] = "enabled";
|
|
|
|
roles[Joined] = "joined";
|
|
|
|
roles[IsMember] = "isMember";
|
|
|
|
roles[CanJoin] = "canJoin";
|
|
|
|
roles[CanManageUsers] = "canManageUsers";
|
|
|
|
roles[CanRequestAccess] = "canRequestAccess";
|
|
|
|
roles[Access] = "access";
|
|
|
|
roles[EnsOnly] = "ensOnly";
|
|
|
|
roles[MembersModel] = "members";
|
|
|
|
roles[PendingRequestsToJoinModel] = "pendingRequestsToJoin";
|
|
|
|
return roles;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SectionModel::rowCount(const QModelIndex& parent = QModelIndex()) const
|
|
|
|
{
|
|
|
|
return m_items.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant SectionModel::data(const QModelIndex& index, int role) const
|
|
|
|
{
|
|
|
|
if(!index.isValid())
|
|
|
|
{
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(index.row() < 0 || index.row() >= m_items.size())
|
|
|
|
{
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
SectionItem* item = m_items.at(index.row());
|
|
|
|
|
|
|
|
switch(role)
|
|
|
|
{
|
2022-02-21 17:07:16 +00:00
|
|
|
case Id: return item->getId();
|
|
|
|
case SectionType: return item->getSectionType();
|
|
|
|
case Name: return item->getName();
|
|
|
|
case AmISectionAdmin: return item->getAmISectionAdmin();
|
|
|
|
case Description: return item->getDescription();
|
|
|
|
case Image: return item->getImage();
|
|
|
|
case Icon: return item->getIcon();
|
|
|
|
case Color: return item->getColor();
|
|
|
|
case HasNotification: return item->getHasNotification();
|
|
|
|
case NotificationsCount: return item->getNotificationsCount();
|
|
|
|
case Active: return item->getIsActive();
|
|
|
|
case Enabled: return item->getIsEnabled();
|
|
|
|
case Joined: return item->getHasJoined();
|
|
|
|
case IsMember: return item->getIsMember();
|
|
|
|
case CanJoin: return item->getCanJoin();
|
|
|
|
case CanManageUsers: return item->getCanManageUsers();
|
|
|
|
case CanRequestAccess: return item->getCanRequestAccess();
|
|
|
|
case Access: return item->getAccess();
|
2022-02-22 08:02:34 +00:00
|
|
|
case EnsOnly:
|
|
|
|
return item->getIsEnsOnly();
|
2022-02-16 21:51:04 +00:00
|
|
|
// To Do
|
|
|
|
case MembersModel: return QVariant();
|
|
|
|
case PendingRequestsToJoinModel: return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SectionModel::addItem(SectionItem* item)
|
|
|
|
{
|
|
|
|
beginInsertRows(QModelIndex(), m_items.size(), m_items.size());
|
|
|
|
m_items.append(item);
|
|
|
|
endInsertRows();
|
|
|
|
}
|
|
|
|
|
2022-02-21 18:03:38 +00:00
|
|
|
void SectionModel::setActiveSection(const QString& Id)
|
2022-02-16 21:51:04 +00:00
|
|
|
{
|
|
|
|
|
2022-02-21 18:03:38 +00:00
|
|
|
for(int i = 0; i < m_items.size(); ++i)
|
|
|
|
{
|
2022-02-16 21:51:04 +00:00
|
|
|
auto newIndex = createIndex(i, 0, nullptr);
|
|
|
|
if(m_items.at(i)->getIsActive())
|
|
|
|
{
|
|
|
|
m_items.at(i)->setIsActive(false);
|
|
|
|
dataChanged(newIndex, newIndex, QVector<int>(ModelRole::Active));
|
|
|
|
}
|
2022-02-21 18:03:38 +00:00
|
|
|
if(m_items.at(i)->getId() == Id)
|
2022-02-16 21:51:04 +00:00
|
|
|
{
|
|
|
|
m_items.at(i)->setIsActive(true);
|
|
|
|
dataChanged(newIndex, newIndex, QVector<int>(ModelRole::Active));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-22 08:02:34 +00:00
|
|
|
QPointer<SectionItem> SectionModel::getActiveItem() const
|
2022-02-16 21:51:04 +00:00
|
|
|
{
|
|
|
|
SectionItem* activeItem = nullptr;
|
|
|
|
for(auto item : m_items)
|
|
|
|
{
|
|
|
|
if(item->getIsActive())
|
|
|
|
{
|
2022-02-21 18:03:38 +00:00
|
|
|
activeItem = item;
|
|
|
|
break;
|
2022-02-16 21:51:04 +00:00
|
|
|
}
|
|
|
|
}
|
2022-02-21 18:03:38 +00:00
|
|
|
return activeItem;
|
2022-02-16 21:51:04 +00:00
|
|
|
}
|
|
|
|
} // namespace Shared::Models
|