matrixion/src/emoji/EmojiSearchModel.h

37 lines
1 KiB
C
Raw Normal View History

2020-08-28 23:32:23 +03:00
#pragma once
#include "EmojiModel.h"
#include <QDebug>
#include <QEvent>
#include <QSortFilterProxyModel>
namespace emoji {
// Map emoji data to searchable data
2020-08-28 23:59:27 +03:00
class EmojiSearchModel : public QSortFilterProxyModel
{
2020-08-28 23:32:23 +03:00
public:
2020-08-28 23:59:27 +03:00
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);
}
2020-08-29 00:26:45 +03:00
2020-08-28 23:32:23 +03:00
private:
2020-08-28 23:59:27 +03:00
QString toShortcode(QString shortname) const
{
return shortname.replace(" ", "-").replace(":", "-").replace("--", "-").toLower();
}
2020-08-28 23:32:23 +03:00
};
}