2017-12-31 00:50:07 +01:00
|
|
|
#pragma once
|
|
|
|
|
2018-03-24 12:02:07 +01:00
|
|
|
#include "common.hpp"
|
|
|
|
|
2017-12-31 00:50:07 +01:00
|
|
|
#include <QAbstractListModel>
|
|
|
|
|
|
|
|
#include <map>
|
2018-03-24 12:02:07 +01:00
|
|
|
#include <set>
|
2017-12-31 00:50:07 +01:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace chatterino {
|
2018-03-24 12:02:07 +01:00
|
|
|
|
2017-12-31 00:50:07 +01:00
|
|
|
class CompletionModel : public QAbstractListModel
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CompletionModel(const QString &_channelName);
|
|
|
|
|
|
|
|
virtual int columnCount(const QModelIndex &) const override
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual QVariant data(const QModelIndex &index, int) const override
|
|
|
|
{
|
|
|
|
// TODO: Implement more safely
|
2018-03-24 11:12:24 +01:00
|
|
|
auto it = this->emotes.begin();
|
|
|
|
std::advance(it, index.row());
|
|
|
|
return QVariant(it->str);
|
2017-12-31 00:50:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual int rowCount(const QModelIndex &) const override
|
|
|
|
{
|
|
|
|
return this->emotes.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
void refresh();
|
|
|
|
void addString(const std::string &str);
|
|
|
|
void addString(const QString &str);
|
|
|
|
|
2018-03-24 11:12:24 +01:00
|
|
|
void addUser(const QString &str);
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct TaggedString {
|
|
|
|
QString str;
|
|
|
|
// emote == true
|
|
|
|
// username == false
|
|
|
|
bool isEmote = true;
|
|
|
|
bool operator<(const TaggedString &that) const
|
|
|
|
{
|
|
|
|
if (this->isEmote) {
|
|
|
|
if (that.isEmote) {
|
|
|
|
int k = QString::compare(this->str, that.str, Qt::CaseInsensitive);
|
2018-03-24 12:02:07 +01:00
|
|
|
if (k == 0) {
|
|
|
|
return this->str > that.str;
|
|
|
|
} else {
|
|
|
|
return k < 0;
|
|
|
|
}
|
2018-03-24 11:12:24 +01:00
|
|
|
} else
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
if (that.isEmote)
|
|
|
|
return false;
|
|
|
|
else {
|
2018-03-24 12:02:07 +01:00
|
|
|
int k = QString::compare(this->str, that.str, Qt::CaseInsensitive);
|
|
|
|
if (k == 0) {
|
|
|
|
return this->str > that.str;
|
|
|
|
} else {
|
|
|
|
return k < 0;
|
|
|
|
}
|
2018-03-24 11:12:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
TaggedString createEmote(const std::string &str)
|
|
|
|
{
|
|
|
|
return TaggedString{qS(str), true};
|
|
|
|
}
|
|
|
|
TaggedString createEmote(const QString &str)
|
|
|
|
{
|
|
|
|
return TaggedString{str, true};
|
|
|
|
}
|
|
|
|
TaggedString createUser(const QString &str)
|
|
|
|
{
|
|
|
|
return TaggedString{str, false};
|
|
|
|
}
|
|
|
|
std::set<TaggedString> emotes;
|
2017-12-31 00:50:07 +01:00
|
|
|
|
|
|
|
QString channelName;
|
|
|
|
};
|
2018-03-24 12:02:07 +01:00
|
|
|
|
2018-03-24 11:12:24 +01:00
|
|
|
} // namespace chatterino
|