6#include "emojiproxymodel.h"
8#include "emoticonunicodeutils.h"
10using namespace TextEmoticonsCore;
12class EmojiProxyModel::EmojiProxyModelPrivate
15 EmojiProxyModelPrivate(EmojiProxyModel *qq)
21 q->setSearchIdentifier(QString());
24 QStringList mRecentEmoticons;
25 QString mSearchIdentifier;
26 EmojiProxyModel *
const q;
29EmojiProxyModel::EmojiProxyModel(
QObject *parent)
34 setFilterRole(EmojiModel::Identifier);
38EmojiProxyModel::~EmojiProxyModel() =
default;
40bool EmojiProxyModel::filterAcceptsRow(
int source_row,
const QModelIndex &source_parent)
const
42 if (d->mCategory.isEmpty()) {
46 if (!d->mSearchIdentifier.isEmpty()) {
47 const QModelIndex sourceIndex =
sourceModel()->index(source_row, 0, source_parent);
48 const QString identifier = sourceIndex.
data(EmojiModel::Identifier).
toString();
49 if (identifier.
contains(d->mSearchIdentifier)) {
54 if (d->mCategory == TextEmoticonsCore::EmoticonUnicodeUtils::recentIdentifier()) {
55 const QModelIndex sourceIndex =
sourceModel()->index(source_row, 0, source_parent);
56 const QString identifier = sourceIndex.
data(EmojiModel::Identifier).
toString();
57 if (d->mRecentEmoticons.contains(identifier)) {
61 const QModelIndex sourceIndex =
sourceModel()->index(source_row, 0, source_parent);
62 const auto category = sourceIndex.
data(EmojiModel::Category).
toString();
63 if (d->mCategory == category) {
70QString EmojiProxyModel::searchIdentifier()
const
72 return d->mSearchIdentifier;
75void EmojiProxyModel::setSearchIdentifier(
const QString &newSearchIdentifier)
77 if (d->mSearchIdentifier != newSearchIdentifier) {
78 d->mSearchIdentifier = newSearchIdentifier;
83QStringList EmojiProxyModel::recentEmoticons()
const
85 return d->mRecentEmoticons;
88void EmojiProxyModel::setRecentEmoticons(
const QStringList &newRecentEmoticons)
90 if (d->mRecentEmoticons != newRecentEmoticons) {
91 d->mRecentEmoticons = newRecentEmoticons;
92 if (TextEmoticonsCore::EmoticonUnicodeUtils::recentIdentifier() == d->mCategory) {
95 Q_EMIT recentEmoticonsChanged();
99QString EmojiProxyModel::category()
const
104void EmojiProxyModel::setCategory(
const QString &newCategorie)
106 if (d->mCategory != newCategorie) {
107 d->mCategory = newCategorie;
108 if (!d->mSearchIdentifier.isEmpty()) {
113 if ((TextEmoticonsCore::EmoticonUnicodeUtils::recentIdentifier() == d->mCategory)
114 || (TextEmoticonsCore::EmoticonUnicodeUtils::customIdentifier() == d->mCategory)) {
122bool EmojiProxyModel::lessThan(
const QModelIndex &left,
const QModelIndex &right)
const
124 if (TextEmoticonsCore::EmoticonUnicodeUtils::recentIdentifier() == d->mCategory) {
125 const QString leftIdentifier =
sourceModel()->data(left, EmojiModel::Identifier).toString();
126 const QString rightIdentifier =
sourceModel()->data(right, EmojiModel::Identifier).toString();
127 const int positionIdentifierLeft = d->mRecentEmoticons.indexOf(leftIdentifier);
128 const int positionIdentifierRight = d->mRecentEmoticons.indexOf(rightIdentifier);
133 return positionIdentifierLeft < positionIdentifierRight;
135 const int leftOrder =
sourceModel()->data(left, EmojiModel::Order).toInt();
136 const int rightOrder =
sourceModel()->data(right, EmojiModel::Order).toInt();
138 return leftOrder < rightOrder;
142#include "moc_emojiproxymodel.cpp"
The EmojiProxyModel class.
QVariant data(int role) const const
virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const const
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
QString toString() const const