blob: 8d43e0006661a8a022cadd3b0193a1236addf7b6 (
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
#pragma once
#include <QAbstractListModel>
#include <QSet>
#include <QSortFilterProxyModel>
#include <QVector>
#include "Provider.h"
namespace emoji {
/*
* Provides access to the emojis in Provider.h to QML
*/
class EmojiModel : public QAbstractListModel
{
Q_OBJECT
public:
enum Roles
{
Unicode = Qt::UserRole, // unicode of emoji
Category, // category of emoji
ShortName, // shortext of the emoji
Emoji, // Contains everything from the Emoji
};
using QAbstractListModel::QAbstractListModel;
QHash<int, QByteArray> roleNames() const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
};
class EmojiProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
Q_PROPERTY(
emoji::EmojiCategory category READ category WRITE setCategory NOTIFY categoryChanged)
Q_PROPERTY(QString filter READ filter WRITE setFilter NOTIFY filterChanged)
public:
explicit EmojiProxyModel(QObject *parent = nullptr);
~EmojiProxyModel() override;
EmojiCategory category() const;
void setCategory(EmojiCategory cat);
QString filter() const;
void setFilter(const QString &filter);
signals:
void categoryChanged();
void filterChanged();
protected:
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
private:
EmojiCategory category_ = EmojiCategory::Search;
emoji::Provider emoji_provider_;
};
}
|