Commit fa91f252 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Use a model manager

parent dd7402c7
Pipeline #81048 canceled with stage
......@@ -57,6 +57,7 @@ target_sources(KF5PimTextEdit PRIVATE
emoticon/emoticonunicodemodel.cpp
emoticon/emoticonlistview.cpp
emoticon/emoticonunicodeproxymodel.cpp
emoticon/emoticonunicodemodelmanager.cpp
)
target_sources(KF5PimTextEdit PRIVATE
......
/*
SPDX-FileCopyrightText: 2021 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "emoticonunicodemodelmanager.h"
#include "emoticonunicodemodel.h"
using namespace KPIMTextEdit;
EmoticonUnicodeModelManager::EmoticonUnicodeModelManager(QObject *parent)
: QObject(parent)
, mEmoticonUnicodeModel(new EmoticonUnicodeModel(this))
{
mEmoticonUnicodeModel->setEmoticonList(EmoticonUnicodeUtils::allUnicode());
}
EmoticonUnicodeModelManager::~EmoticonUnicodeModelManager()
{
}
EmoticonUnicodeModelManager *EmoticonUnicodeModelManager::self()
{
static EmoticonUnicodeModelManager s_self;
return &s_self;
}
EmoticonUnicodeModel *EmoticonUnicodeModelManager::emoticonUnicodeModel() const
{
return mEmoticonUnicodeModel;
}
/*
SPDX-FileCopyrightText: 2021 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#pragma once
#include <QObject>
namespace KPIMTextEdit
{
class EmoticonUnicodeModel;
class EmoticonUnicodeModelManager : public QObject
{
Q_OBJECT
public:
explicit EmoticonUnicodeModelManager(QObject *parent = nullptr);
~EmoticonUnicodeModelManager() override;
static EmoticonUnicodeModelManager *self();
Q_REQUIRED_RESULT EmoticonUnicodeModel *emoticonUnicodeModel() const;
private:
EmoticonUnicodeModel *const mEmoticonUnicodeModel;
};
}
......@@ -7,6 +7,7 @@
#include "emoticonunicodetab.h"
#include "emoticonlistview.h"
#include "emoticonunicodemodel.h"
#include "emoticonunicodemodelmanager.h"
#include "emoticonunicodeproxymodel.h"
#include "textutils.h"
#include <KLocalizedString>
......@@ -15,9 +16,7 @@
using namespace KPIMTextEdit;
EmoticonUnicodeTab::EmoticonUnicodeTab(QWidget *parent)
: QTabWidget(parent)
, mEmoticonUnicodeModel(new EmoticonUnicodeModel(this))
{
mEmoticonUnicodeModel->setEmoticonList(EmoticonUnicodeUtils::allUnicode());
setTabBarAutoHide(true);
loadEmoticons();
......@@ -45,7 +44,7 @@ void EmoticonUnicodeTab::createSearchTab()
{
auto allEmojisView = new EmoticonListView(this);
mEmoticonUnicodeSearchProxyModel = new EmoticonUnicodeProxyModel(this);
mEmoticonUnicodeSearchProxyModel->setSourceModel(mEmoticonUnicodeModel);
mEmoticonUnicodeSearchProxyModel->setSourceModel(EmoticonUnicodeModelManager::self()->emoticonUnicodeModel());
allEmojisView->setModel(mEmoticonUnicodeSearchProxyModel);
mSearchTabIndex = addTab(allEmojisView, QIcon::fromTheme(QStringLiteral("edit-find")), {});
connect(allEmojisView, &KPIMTextEdit::EmoticonListView::emojiItemSelected, this, &EmoticonUnicodeTab::itemSelected);
......@@ -58,7 +57,7 @@ void EmoticonUnicodeTab::createEmoticonTab(const QString &str, const QVector<Emo
EmoticonUnicodeProxyModel *emoticonUnicodeProxyModel = new EmoticonUnicodeProxyModel(this);
const auto emoji = emoticons.constFirst();
emoticonUnicodeProxyModel->setCategories(emoji.emoticonCategory);
emoticonUnicodeProxyModel->setSourceModel(mEmoticonUnicodeModel);
emoticonUnicodeProxyModel->setSourceModel(EmoticonUnicodeModelManager::self()->emoticonUnicodeModel());
emojisView->setModel(emoticonUnicodeProxyModel);
addTab(emojisView, str);
const QString strTab = emoji.emoticonCode;
......
......@@ -14,7 +14,6 @@
namespace KPIMTextEdit
{
class EmoticonUnicodeProxyModel;
class EmoticonUnicodeModel;
/**
* @brief The EmoticonUnicodeTab class
* @author Laurent Montel <montel@kde.org>
......@@ -35,7 +34,6 @@ Q_SIGNALS:
private:
void createEmoticonTab(const QString &str, const QVector<EmoticonUnicodeUtils::EmoticonStruct> &emoticons);
void createSearchTab();
EmoticonUnicodeModel *const mEmoticonUnicodeModel;
EmoticonUnicodeProxyModel *mEmoticonUnicodeSearchProxyModel = nullptr;
int mSearchTabIndex = -1;
};
......
Supports Markdown
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