mirror-chatterino2/src/common/CompletionModel.hpp

61 lines
1.3 KiB
C++
Raw Normal View History

2017-12-31 00:50:07 +01:00
#pragma once
#include <QAbstractListModel>
2018-03-30 13:50:43 +02:00
#include <chrono>
#include <mutex>
#include <set>
2017-12-31 00:50:07 +01:00
namespace chatterino {
2018-08-13 14:38:03 +02:00
class Channel;
2018-08-02 14:23:27 +02:00
2017-12-31 00:50:07 +01:00
class CompletionModel : public QAbstractListModel
{
struct TaggedString {
enum Type {
Username,
2017-12-31 00:50:07 +01:00
2018-07-06 17:42:00 +02:00
// emotes
EmoteStart,
FFZGlobalEmote,
FFZChannelEmote,
BTTVGlobalEmote,
BTTVChannelEmote,
TwitchGlobalEmote,
TwitchSubscriberEmote,
Emoji,
2018-07-06 17:42:00 +02:00
EmoteEnd,
// end emotes
2018-06-24 11:24:21 +02:00
Command,
2018-03-30 13:50:43 +02:00
};
2018-08-13 14:38:03 +02:00
TaggedString(const QString &string, Type type);
2018-03-30 13:50:43 +02:00
2018-07-06 17:42:00 +02:00
bool isEmote() const;
bool operator<(const TaggedString &that) const;
2018-03-30 13:50:43 +02:00
2018-08-13 14:38:03 +02:00
QString string;
2018-03-30 13:50:43 +02:00
Type type;
};
public:
2018-08-13 14:38:03 +02:00
CompletionModel(Channel &channel);
2018-07-06 17:42:00 +02:00
virtual int columnCount(const QModelIndex &) const override;
virtual QVariant data(const QModelIndex &index, int) const override;
virtual int rowCount(const QModelIndex &) const override;
2019-08-21 01:08:15 +02:00
void refresh(const QString &prefix, bool isFirstWord = false);
2018-03-30 13:50:43 +02:00
private:
2018-07-06 17:42:00 +02:00
TaggedString createUser(const QString &str);
2018-08-13 14:38:03 +02:00
std::set<TaggedString> items_;
mutable std::mutex itemsMutex_;
Channel &channel_;
2017-12-31 00:50:07 +01:00
};
} // namespace chatterino