File indexing completed on 2024-04-14 04:54:46

0001 /*
0002    SPDX-FileCopyrightText: 2017-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "libruqola_private_export.h"
0010 #include "user.h"
0011 #include "utils.h"
0012 #include <QAbstractListModel>
0013 
0014 class LIBRUQOLACORE_TESTS_EXPORT UserCompleterModel : public QAbstractListModel
0015 {
0016     Q_OBJECT
0017 public:
0018     enum UserRoles {
0019         UserName = Qt::UserRole + 1,
0020         DisplayName,
0021         UserId,
0022         UserIconStatus,
0023         AvatarInfo,
0024     };
0025     Q_ENUM(UserRoles)
0026 
0027     explicit UserCompleterModel(QObject *parent = nullptr);
0028     ~UserCompleterModel() override;
0029 
0030     [[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0031     [[nodiscard]] QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0032 
0033     void clear();
0034     void addUsers(const QVector<User> &users);
0035 
0036 private:
0037     [[nodiscard]] QString displayUserName(const User &user) const;
0038     [[nodiscard]] Utils::AvatarInfo avatarInfo(const User &user) const;
0039     Q_DISABLE_COPY(UserCompleterModel)
0040     QVector<User> mUsers;
0041 };