File indexing completed on 2024-12-08 07:33:44

0001 // SPDX-FileCopyrightText: 2023 Tobias Fella <tobias.fella@kde.org>
0002 // SPDX-License-Identifier: GPL-2.0-or-later
0003 
0004 #include "emoticonfiltermodel.h"
0005 
0006 #include "accountemoticonmodel.h"
0007 #include "stickermodel.h"
0008 
0009 EmoticonFilterModel::EmoticonFilterModel(QObject *parent)
0010     : QSortFilterProxyModel(parent)
0011 {
0012     connect(this, &EmoticonFilterModel::sourceModelChanged, this, [this]() {
0013         if (dynamic_cast<StickerModel *>(sourceModel())) {
0014             m_stickerRole = StickerModel::IsStickerRole;
0015             m_emojiRole = StickerModel::IsEmojiRole;
0016         } else {
0017             m_stickerRole = AccountEmoticonModel::IsStickerRole;
0018             m_emojiRole = AccountEmoticonModel::IsEmojiRole;
0019         }
0020     });
0021 }
0022 
0023 bool EmoticonFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
0024 {
0025     Q_UNUSED(sourceParent);
0026     auto stickerUsage = sourceModel()->data(sourceModel()->index(sourceRow, 0), m_stickerRole).toBool();
0027     auto emojiUsage = sourceModel()->data(sourceModel()->index(sourceRow, 0), m_emojiRole).toBool();
0028     return (stickerUsage && m_showStickers) || (emojiUsage && m_showEmojis);
0029 }
0030 
0031 bool EmoticonFilterModel::showStickers() const
0032 {
0033     return m_showStickers;
0034 }
0035 
0036 void EmoticonFilterModel::setShowStickers(bool showStickers)
0037 {
0038     beginResetModel();
0039     m_showStickers = showStickers;
0040     endResetModel();
0041     Q_EMIT showStickersChanged();
0042 }
0043 
0044 bool EmoticonFilterModel::showEmojis() const
0045 {
0046     return m_showEmojis;
0047 }
0048 
0049 void EmoticonFilterModel::setShowEmojis(bool showEmojis)
0050 {
0051     beginResetModel();
0052     m_showEmojis = showEmojis;
0053     endResetModel();
0054     Q_EMIT showEmojisChanged();
0055 }
0056 
0057 #include "moc_emoticonfiltermodel.cpp"