Commit 0807b104 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Use enum for categories

parent 83ca52c5
......@@ -15,5 +15,5 @@ EmoticonUnicodeProxyModelTest::EmoticonUnicodeProxyModelTest(QObject *parent)
void EmoticonUnicodeProxyModelTest::shouldHaveDefaultValues()
{
KPIMTextEdit::EmoticonUnicodeProxyModel m;
QVERIFY(m.categories().isEmpty());
QCOMPARE(m.categories(), KPIMTextEdit::EmoticonUnicodeUtils::EmoticonStruct::Unknown);
}
......@@ -20,23 +20,24 @@ EmoticonUnicodeProxyModel::~EmoticonUnicodeProxyModel()
bool EmoticonUnicodeProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
{
if (mCategories.isEmpty()) {
if (mCategories == EmoticonUnicodeUtils::EmoticonStruct::Unknown) {
return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
}
const QModelIndex sourceIndex = sourceModel()->index(source_row, 0, source_parent);
const QString category = sourceIndex.data(EmoticonUnicodeModel::Category).toString();
if (mCategories.contains(category)) {
const EmoticonUnicodeUtils::EmoticonStruct::EmoticonType category =
sourceIndex.data(EmoticonUnicodeModel::Category).value<EmoticonUnicodeUtils::EmoticonStruct::EmoticonType>();
if (mCategories == category) {
return true;
}
return false;
}
const QStringList &EmoticonUnicodeProxyModel::categories() const
EmoticonUnicodeUtils::EmoticonStruct::EmoticonType EmoticonUnicodeProxyModel::categories() const
{
return mCategories;
}
void EmoticonUnicodeProxyModel::setCategories(const QStringList &newCategories)
void EmoticonUnicodeProxyModel::setCategories(EmoticonUnicodeUtils::EmoticonStruct::EmoticonType newCategories)
{
mCategories = newCategories;
}
......@@ -5,6 +5,7 @@
*/
#pragma once
#include "emoticonunicodeutils.h"
#include "kpimtextedit_private_export.h"
#include <QSortFilterProxyModel>
namespace KPIMTextEdit
......@@ -15,13 +16,13 @@ class KPIMTEXTEDIT_TESTS_EXPORT EmoticonUnicodeProxyModel : public QSortFilterPr
public:
explicit EmoticonUnicodeProxyModel(QObject *parent = nullptr);
~EmoticonUnicodeProxyModel() override;
const QStringList &categories() const;
void setCategories(const QStringList &newCategories);
EmoticonUnicodeUtils::EmoticonStruct::EmoticonType categories() const;
void setCategories(EmoticonUnicodeUtils::EmoticonStruct::EmoticonType newCategories);
protected:
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
private:
QStringList mCategories;
EmoticonUnicodeUtils::EmoticonStruct::EmoticonType mCategories = EmoticonUnicodeUtils::EmoticonStruct::Unknown;
};
}
This diff is collapsed.
......@@ -7,6 +7,7 @@
#pragma once
#include "kpimtextedit_export.h"
#include <QObject>
#include <QString>
#include <QVector>
namespace KPIMTextEdit
......@@ -14,7 +15,44 @@ namespace KPIMTextEdit
namespace EmoticonUnicodeUtils
{
struct EmoticonStruct {
EmoticonStruct(const QString &name, const QString &code, const QString &category)
enum EmoticonType {
Unknown = 0,
FlagsEmoji,
FaceEmoji,
AnimalsEmoji,
PlantEmoji,
ScienceEmoji,
ComputerEmoji,
BookPaperEmoji,
SoundMusicEmoji,
WeatherEmoji,
TimeEmoji,
GameEmoji,
ClothingEmoji,
EventEmoji,
FoodEmoji,
TransportEmoji,
PersonEmoji,
PlaceEmoji,
SymbolsEmoji,
SportEmoji,
EmotionEmoji,
MoneyEmoji,
BodyEmoji,
MailEmoji,
OfficeEmoji,
ToolsEmoji,
PhoneEmoji,
LockEmoji,
DrinkEmoji,
VideoEmoji,
HouseEmoji,
DishwareEmoji,
HotelEmoji,
AwardMedalEmoji,
};
EmoticonStruct(const QString &name, const QString &code, EmoticonType category)
: emoticonName(name)
, emoticonCode(code)
, emoticonCategory(category)
......@@ -23,7 +61,7 @@ struct EmoticonStruct {
QString emoticonName;
QString emoticonCode;
QString emoticonCategory;
EmoticonType emoticonCategory = EmoticonType::Unknown;
};
KPIMTEXTEDIT_EXPORT Q_REQUIRED_RESULT QVector<EmoticonStruct> unicodeFlagsEmoji();
KPIMTEXTEDIT_EXPORT Q_REQUIRED_RESULT QVector<EmoticonStruct> unicodeFaceEmoji();
......@@ -62,3 +100,4 @@ KPIMTEXTEDIT_EXPORT Q_REQUIRED_RESULT QVector<EmoticonStruct> allUnicode();
}
}
Q_DECLARE_METATYPE(KPIMTextEdit::EmoticonUnicodeUtils::EmoticonStruct::EmoticonType)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment