Commit 5dbddecc authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Try to sort recent emoji

parent 594e73f1
Pipeline #95337 canceled with stage
......@@ -14,6 +14,7 @@ using namespace KPIMTextEdit;
EmoticonRecentUsedFilterProxyModel::EmoticonRecentUsedFilterProxyModel(QObject *parent)
: QSortFilterProxyModel(parent)
{
sort(0);
}
EmoticonRecentUsedFilterProxyModel::~EmoticonRecentUsedFilterProxyModel()
......@@ -43,3 +44,12 @@ bool EmoticonRecentUsedFilterProxyModel::filterAcceptsRow(int source_row, const
}
return false;
}
bool EmoticonRecentUsedFilterProxyModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const
{
const QString identifierLeft = source_left.data(EmoticonUnicodeModel::Identifier).toString();
const QString identifierRight = source_right.data(EmoticonUnicodeModel::Identifier).toString();
const int indexLeft = mUsedIdentifier.indexOf(identifierLeft);
const int indexRight = mUsedIdentifier.indexOf(identifierRight);
return indexLeft < indexRight;
}
......@@ -23,6 +23,8 @@ public:
protected:
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override;
private:
QStringList mUsedIdentifier;
};
......
......@@ -51,10 +51,14 @@ void EmoticonUnicodeModelManager::setRecentIdentifier(const QStringList &newRece
void EmoticonUnicodeModelManager::addIdentifier(const QString &identifier)
{
if (!mRecentIdentifier.contains(identifier)) {
mRecentIdentifier.append(identifier);
writeRecentUsed();
if (int i = mRecentIdentifier.indexOf(identifier)) {
// Remove it for adding in top of list
if (i != -1) {
mRecentIdentifier.removeAt(i);
}
}
mRecentIdentifier.prepend(identifier);
writeRecentUsed();
Q_EMIT usedIdentifierChanged(mRecentIdentifier);
}
......
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