blob: 1ff5f4e934f68397b36a3a7613968184a7cdbbd7 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
#pragma once
#include "EmojiModel.h"
#include <QDebug>
#include <QEvent>
#include <QSortFilterProxyModel>
namespace emoji {
// Map emoji data to searchable data
class EmojiSearchModel : public QSortFilterProxyModel
{
public:
EmojiSearchModel(QObject *parent = nullptr)
: QSortFilterProxyModel(parent)
{
setSourceModel(new EmojiModel(this));
}
QVariant data(const QModelIndex &index, int role = Qt::UserRole + 1) const override
{
if (role == Qt::DisplayRole) {
auto emoji = QSortFilterProxyModel::data(index, role).toString();
return emoji + " :" +
toShortcode(data(index, EmojiModel::ShortName).toString()) + ":";
}
return QSortFilterProxyModel::data(index, role);
}
private:
QString toShortcode(QString shortname) const
{
return shortname.replace(" ", "-").replace(":", "-").replace("--", "-").toLower();
}
};
}
|