8#include "textemoticonscore_debug.h"
9#include <TextEmoticonsCore/CustomEmojiIconManager>
10using namespace TextEmoticonsCore;
11EmojiModel::EmojiModel(
QObject *parent)
16EmojiModel::~EmojiModel() =
default;
18int EmojiModel::rowCount(
const QModelIndex &parent)
const
23 return mEmoticonList.count() + mCustomEmojiList.count();
26QVariant EmojiModel::data(
const QModelIndex &index,
int role)
const
28 if (
index.row() < 0 ||
index.row() >= (mEmoticonList.count() + mCustomEmojiList.count())) {
31 if (
index.row() < mEmoticonList.count()) {
32 const auto &unicodeEmoti = mEmoticonList.at(
index.row());
34 case AnimatedFileName:
40 return unicodeEmoti.unicode();
42 return unicodeEmoti.category();
44 return unicodeEmoti.order();
47 return unicodeEmoti.identifier();
50 case DiversityChildren:
51 return unicodeEmoti.diversityChildren();
54 const auto &customEmoji = mCustomEmojiList.at(
index.row() - mEmoticonList.count());
56 case AnimatedFileName:
57 if (mCustomEmojiIconManager) {
58 if (customEmoji.isAnimatedEmoji()) {
59 const QString filename = mCustomEmojiIconManager->fileName(customEmoji.identifier());
64 qCWarning(TEXTEMOTICONSCORE_LOG) <<
"mCustomEmojiIconManager is null. It's a bug";
68 return customEmoji.isAnimatedEmoji();
70 if (mCustomEmojiIconManager) {
71 if (customEmoji.isAnimatedEmoji()) {
72 const QString filename = mCustomEmojiIconManager->fileName(customEmoji.identifier());
74 const QIcon icon(filename);
78 const QIcon icon = mCustomEmojiIconManager->generateIcon(customEmoji.identifier());
81 qCWarning(TEXTEMOTICONSCORE_LOG) <<
"mCustomEmojiIconManager is null. It's a bug";
86 return customEmoji.category();
92 return customEmoji.identifier();
96 if (mCustomEmojiIconManager) {
97 return mCustomEmojiIconManager->fileName(customEmoji.identifier());
99 return customEmoji.fileName();
101 case DiversityChildren:
108const QList<TextEmoticonsCore::UnicodeEmoticon> &EmojiModel::emoticonList()
const
110 return mEmoticonList;
113void EmojiModel::setUnicodeEmoticonList(
const QList<TextEmoticonsCore::UnicodeEmoticon> &newEmoticonList)
116 mEmoticonList = newEmoticonList;
120QList<TextEmoticonsCore::CustomEmoji> EmojiModel::customEmojiList()
const
122 return mCustomEmojiList;
125void EmojiModel::setCustomEmojiList(
const QList<TextEmoticonsCore::CustomEmoji> &newCustomEmojiList)
128 mCustomEmojiList = newCustomEmojiList;
132TextEmoticonsCore::CustomEmojiIconManager *EmojiModel::customEmojiIconManager()
const
134 return mCustomEmojiIconManager;
137void EmojiModel::setCustomEmojiIconManager(TextEmoticonsCore::CustomEmojiIconManager *newCustomEmojiIconManager)
139 mCustomEmojiIconManager = newCustomEmojiIconManager;
142void EmojiModel::setExcludeEmoticons(
const QStringList &emoticons)
144 bool emoticonsRemoved =
false;
145 for (
const auto &identifier : emoticons) {
146 auto index = std::find_if(mEmoticonList.begin(), mEmoticonList.end(), [identifier](
const TextEmoticonsCore::UnicodeEmoticon &emoji) {
147 return (identifier == emoji.identifier());
149 if (
index != mEmoticonList.end()) {
150 mEmoticonList.removeAll(*
index);
151 emoticonsRemoved =
true;
154 if (emoticonsRemoved) {
160QHash<int, QByteArray> EmojiModel::roleNames()
const
162 return {{{UnicodeEmoji, QByteArrayLiteral(
"unicode")},
163 {Identifier, QByteArrayLiteral(
"identifier")},
164 {Category, QByteArrayLiteral(
"category")},
165 {IsCustom, QByteArrayLiteral(
"isCustom")},
166 {FileName, QByteArrayLiteral(
"fileName")},
167 {DiversityChildren, QByteArrayLiteral(
"diversityChildren")}}};
170#include "moc_emojimodel.cpp"
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const=0
virtual QModelIndex parent(const QModelIndex &index) const const=0
bool isEmpty() const const